Commit 42e9a92f authored by Robert Love's avatar Robert Love Committed by James Bottomley

[SCSI] libfc: A modular Fibre Channel library

libFC is composed of 4 blocks supported by an exchange manager
and a framing library. The upper 4 layers are fc_lport, fc_disc,
fc_rport and fc_fcp. A LLD that uses libfc could choose to
either use libfc's block, or using the transport template
defined in libfc.h, override one or more blocks with its own
implementation.

The EM (Exchange Manager) manages exhcanges/sequences for all
commands- ELS, CT and FCP.

The framing library frames ELS and CT commands.

The fc_lport block manages the library's representation of the
host's FC enabled ports.

The fc_disc block manages discovery of targets as well as
handling changes that occur in the FC fabric (via. RSCN events).

The fc_rport block manages the library's representation of other
entities in the FC fabric. Currently the library uses this block
for targets, its peer when in point-to-point mode and the
directory server, but can be extended for other entities if
needed.

The fc_fcp block interacts with the scsi-ml and handles all
I/O.
Signed-off-by: default avatarRobert Love <robert.w.love@intel.com>
[jejb: added include of delay.h to fix ppc64 compile prob spotted by sfr]
Signed-off-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
parent f032c2f7
......@@ -603,6 +603,12 @@ config SCSI_FLASHPOINT
substantial, so users of MultiMaster Host Adapters may not
wish to include it.
config LIBFC
tristate "LibFC module"
depends on SCSI && SCSI_FC_ATTRS
---help---
Fibre Channel library module
config SCSI_DMX3191D
tristate "DMX3191D SCSI support"
depends on PCI && SCSI
......
......@@ -36,6 +36,7 @@ obj-$(CONFIG_SCSI_SAS_LIBSAS) += libsas/
obj-$(CONFIG_SCSI_SRP_ATTRS) += scsi_transport_srp.o
obj-$(CONFIG_SCSI_DH) += device_handler/
obj-$(CONFIG_LIBFC) += libfc/
obj-$(CONFIG_ISCSI_TCP) += libiscsi.o libiscsi_tcp.o iscsi_tcp.o
obj-$(CONFIG_INFINIBAND_ISER) += libiscsi.o
obj-$(CONFIG_SCSI_A4000T) += 53c700.o a4000t.o
......
# $Id: Makefile
obj-$(CONFIG_LIBFC) += libfc.o
libfc-objs := \
fc_disc.o \
fc_exch.o \
fc_elsct.o \
fc_frame.o \
fc_lport.o \
fc_rport.o \
fc_fcp.o
This diff is collapsed.
/*
* Copyright(c) 2008 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*
* Maintained at www.Open-FCoE.org
*/
/*
* Provide interface to send ELS/CT FC frames
*/
#include <asm/unaligned.h>
#include <scsi/fc/fc_gs.h>
#include <scsi/fc/fc_ns.h>
#include <scsi/fc/fc_els.h>
#include <scsi/libfc.h>
#include <scsi/fc_encode.h>
/*
* fc_elsct_send - sends ELS/CT frame
*/
static struct fc_seq *fc_elsct_send(struct fc_lport *lport,
struct fc_rport *rport,
struct fc_frame *fp,
unsigned int op,
void (*resp)(struct fc_seq *,
struct fc_frame *fp,
void *arg),
void *arg, u32 timer_msec)
{
enum fc_rctl r_ctl;
u32 did;
enum fc_fh_type fh_type;
int rc;
/* ELS requests */
if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS))
rc = fc_els_fill(lport, rport, fp, op, &r_ctl, &did, &fh_type);
else
/* CT requests */
rc = fc_ct_fill(lport, fp, op, &r_ctl, &did, &fh_type);
if (rc)
return NULL;
fc_fill_fc_hdr(fp, r_ctl, did, fc_host_port_id(lport->host), fh_type,
FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
return lport->tt.exch_seq_send(lport, fp, resp, NULL, arg, timer_msec);
}
int fc_elsct_init(struct fc_lport *lport)
{
if (!lport->tt.elsct_send)
lport->tt.elsct_send = fc_elsct_send;
return 0;
}
EXPORT_SYMBOL(fc_elsct_init);
This diff is collapsed.
This diff is collapsed.
/*
* Copyright(c) 2007 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*
* Maintained at www.Open-FCoE.org
*/
/*
* Frame allocation.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/crc32.h>
#include <scsi/fc_frame.h>
/*
* Check the CRC in a frame.
*/
u32 fc_frame_crc_check(struct fc_frame *fp)
{
u32 crc;
u32 error;
const u8 *bp;
unsigned int len;
WARN_ON(!fc_frame_is_linear(fp));
fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
len = (fr_len(fp) + 3) & ~3; /* round up length to include fill */
bp = (const u8 *) fr_hdr(fp);
crc = ~crc32(~0, bp, len);
error = crc ^ fr_crc(fp);
return error;
}
EXPORT_SYMBOL(fc_frame_crc_check);
/*
* Allocate a frame intended to be sent via fcoe_xmit.
* Get an sk_buff for the frame and set the length.
*/
struct fc_frame *__fc_frame_alloc(size_t len)
{
struct fc_frame *fp;
struct sk_buff *skb;
WARN_ON((len % sizeof(u32)) != 0);
len += sizeof(struct fc_frame_header);
skb = dev_alloc_skb(len + FC_FRAME_HEADROOM + FC_FRAME_TAILROOM);
if (!skb)
return NULL;
fp = (struct fc_frame *) skb;
fc_frame_init(fp);
skb_reserve(skb, FC_FRAME_HEADROOM);
skb_put(skb, len);
return fp;
}
EXPORT_SYMBOL(__fc_frame_alloc);
struct fc_frame *fc_frame_alloc_fill(struct fc_lport *lp, size_t payload_len)
{
struct fc_frame *fp;
size_t fill;
fill = payload_len % 4;
if (fill != 0)
fill = 4 - fill;
fp = __fc_frame_alloc(payload_len + fill);
if (fp) {
memset((char *) fr_hdr(fp) + payload_len, 0, fill);
/* trim is OK, we just allocated it so there are no fragments */
skb_trim(fp_skb(fp),
payload_len + sizeof(struct fc_frame_header));
}
return fp;
}
This diff is collapsed.
This diff is collapsed.
/*
* Copyright(c) 2008 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*
* Maintained at www.Open-FCoE.org
*/
#ifndef _FC_ENCODE_H_
#define _FC_ENCODE_H_
#include <asm/unaligned.h>
struct fc_ns_rft {
struct fc_ns_fid fid; /* port ID object */
struct fc_ns_fts fts; /* FC4-types object */
};
struct fc_ct_req {
struct fc_ct_hdr hdr;
union {
struct fc_ns_gid_ft gid;
struct fc_ns_rn_id rn;
struct fc_ns_rft rft;
} payload;
};
/**
* fill FC header fields in specified fc_frame
*/
static inline void fc_fill_fc_hdr(struct fc_frame *fp, enum fc_rctl r_ctl,
u32 did, u32 sid, enum fc_fh_type type,
u32 f_ctl, u32 parm_offset)
{
struct fc_frame_header *fh;
fh = fc_frame_header_get(fp);
WARN_ON(r_ctl == 0);
fh->fh_r_ctl = r_ctl;
hton24(fh->fh_d_id, did);
hton24(fh->fh_s_id, sid);
fh->fh_type = type;
hton24(fh->fh_f_ctl, f_ctl);
fh->fh_cs_ctl = 0;
fh->fh_df_ctl = 0;
fh->fh_parm_offset = htonl(parm_offset);
}
/**
* fc_ct_hdr_fill- fills ct header and reset ct payload
* returns pointer to ct request.
*/
static inline struct fc_ct_req *fc_ct_hdr_fill(const struct fc_frame *fp,
unsigned int op, size_t req_size)
{
struct fc_ct_req *ct;
size_t ct_plen;
ct_plen = sizeof(struct fc_ct_hdr) + req_size;
ct = fc_frame_payload_get(fp, ct_plen);
memset(ct, 0, ct_plen);
ct->hdr.ct_rev = FC_CT_REV;
ct->hdr.ct_fs_type = FC_FST_DIR;
ct->hdr.ct_fs_subtype = FC_NS_SUBTYPE;
ct->hdr.ct_cmd = htons((u16) op);
return ct;
}
/**
* fc_ct_fill - Fill in a name service request frame
*/
static inline int fc_ct_fill(struct fc_lport *lport, struct fc_frame *fp,
unsigned int op, enum fc_rctl *r_ctl, u32 *did,
enum fc_fh_type *fh_type)
{
struct fc_ct_req *ct;
switch (op) {
case FC_NS_GPN_FT:
ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_gid_ft));
ct->payload.gid.fn_fc4_type = FC_TYPE_FCP;
break;
case FC_NS_RFT_ID:
ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rft));
hton24(ct->payload.rft.fid.fp_fid,
fc_host_port_id(lport->host));
ct->payload.rft.fts = lport->fcts;
break;
case FC_NS_RPN_ID:
ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rn_id));
hton24(ct->payload.rn.fr_fid.fp_fid,
fc_host_port_id(lport->host));
ct->payload.rft.fts = lport->fcts;
put_unaligned_be64(lport->wwpn, &ct->payload.rn.fr_wwn);
break;
default:
FC_DBG("Invalid op code %x \n", op);
return -EINVAL;
}
*r_ctl = FC_RCTL_DD_UNSOL_CTL;
*did = FC_FID_DIR_SERV;
*fh_type = FC_TYPE_CT;
return 0;
}
/**
* fc_plogi_fill - Fill in plogi request frame
*/
static inline void fc_plogi_fill(struct fc_lport *lport, struct fc_frame *fp,
unsigned int op)
{
struct fc_els_flogi *plogi;
struct fc_els_csp *csp;
struct fc_els_cssp *cp;
plogi = fc_frame_payload_get(fp, sizeof(*plogi));
memset(plogi, 0, sizeof(*plogi));
plogi->fl_cmd = (u8) op;
put_unaligned_be64(lport->wwpn, &plogi->fl_wwpn);
put_unaligned_be64(lport->wwnn, &plogi->fl_wwnn);
csp = &plogi->fl_csp;
csp->sp_hi_ver = 0x20;
csp->sp_lo_ver = 0x20;
csp->sp_bb_cred = htons(10); /* this gets set by gateway */
csp->sp_bb_data = htons((u16) lport->mfs);
cp = &plogi->fl_cssp[3 - 1]; /* class 3 parameters */
cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
csp->sp_features = htons(FC_SP_FT_CIRO);
csp->sp_tot_seq = htons(255); /* seq. we accept */
csp->sp_rel_off = htons(0x1f);
csp->sp_e_d_tov = htonl(lport->e_d_tov);
cp->cp_rdfs = htons((u16) lport->mfs);
cp->cp_con_seq = htons(255);
cp->cp_open_seq = 1;
}
/**
* fc_flogi_fill - Fill in a flogi request frame.
*/
static inline void fc_flogi_fill(struct fc_lport *lport, struct fc_frame *fp)
{
struct fc_els_csp *sp;
struct fc_els_cssp *cp;
struct fc_els_flogi *flogi;
flogi = fc_frame_payload_get(fp, sizeof(*flogi));
memset(flogi, 0, sizeof(*flogi));
flogi->fl_cmd = (u8) ELS_FLOGI;
put_unaligned_be64(lport->wwpn, &flogi->fl_wwpn);
put_unaligned_be64(lport->wwnn, &flogi->fl_wwnn);
sp = &flogi->fl_csp;
sp->sp_hi_ver = 0x20;
sp->sp_lo_ver = 0x20;
sp->sp_bb_cred = htons(10); /* this gets set by gateway */
sp->sp_bb_data = htons((u16) lport->mfs);
cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */
cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
}
/**
* fc_logo_fill - Fill in a logo request frame.
*/
static inline void fc_logo_fill(struct fc_lport *lport, struct fc_frame *fp)
{
struct fc_els_logo *logo;
logo = fc_frame_payload_get(fp, sizeof(*logo));
memset(logo, 0, sizeof(*logo));
logo->fl_cmd = ELS_LOGO;
hton24(logo->fl_n_port_id, fc_host_port_id(lport->host));
logo->fl_n_port_wwn = htonll(lport->wwpn);
}
/**
* fc_rtv_fill - Fill in RTV (read timeout value) request frame.
*/
static inline void fc_rtv_fill(struct fc_lport *lport, struct fc_frame *fp)
{
struct fc_els_rtv *rtv;
rtv = fc_frame_payload_get(fp, sizeof(*rtv));
memset(rtv, 0, sizeof(*rtv));
rtv->rtv_cmd = ELS_RTV;
}
/**
* fc_rec_fill - Fill in rec request frame
*/
static inline void fc_rec_fill(struct fc_lport *lport, struct fc_frame *fp)
{
struct fc_els_rec *rec;
struct fc_exch *ep = fc_seq_exch(fr_seq(fp));
rec = fc_frame_payload_get(fp, sizeof(*rec));
memset(rec, 0, sizeof(*rec));
rec->rec_cmd = ELS_REC;
hton24(rec->rec_s_id, fc_host_port_id(lport->host));
rec->rec_ox_id = htons(ep->oxid);
rec->rec_rx_id = htons(ep->rxid);
}
/**
* fc_prli_fill - Fill in prli request frame
*/
static inline void fc_prli_fill(struct fc_lport *lport, struct fc_frame *fp)
{
struct {
struct fc_els_prli prli;
struct fc_els_spp spp;
} *pp;
pp = fc_frame_payload_get(fp, sizeof(*pp));
memset(pp, 0, sizeof(*pp));
pp->prli.prli_cmd = ELS_PRLI;
pp->prli.prli_spp_len = sizeof(struct fc_els_spp);
pp->prli.prli_len = htons(sizeof(*pp));
pp->spp.spp_type = FC_TYPE_FCP;
pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR;
pp->spp.spp_params = htonl(lport->service_params);
}
/**
* fc_scr_fill - Fill in a scr request frame.
*/
static inline void fc_scr_fill(struct fc_lport *lport, struct fc_frame *fp)
{
struct fc_els_scr *scr;
scr = fc_frame_payload_get(fp, sizeof(*scr));
memset(scr, 0, sizeof(*scr));
scr->scr_cmd = ELS_SCR;
scr->scr_reg_func = ELS_SCRF_FULL;
}
/**
* fc_els_fill - Fill in an ELS request frame
*/
static inline int fc_els_fill(struct fc_lport *lport, struct fc_rport *rport,
struct fc_frame *fp, unsigned int op,
enum fc_rctl *r_ctl, u32 *did, enum fc_fh_type *fh_type)
{
switch (op) {
case ELS_PLOGI:
fc_plogi_fill(lport, fp, ELS_PLOGI);
*did = rport->port_id;
break;
case ELS_FLOGI:
fc_flogi_fill(lport, fp);
*did = FC_FID_FLOGI;
break;
case ELS_LOGO:
fc_logo_fill(lport, fp);
*did = FC_FID_FLOGI;
/*
* if rport is valid then it
* is port logo, therefore
* set did to rport id.
*/
if (rport)
*did = rport->port_id;
break;
case ELS_RTV:
fc_rtv_fill(lport, fp);
*did = rport->port_id;
break;
case ELS_REC:
fc_rec_fill(lport, fp);
*did = rport->port_id;
break;
case ELS_PRLI:
fc_prli_fill(lport, fp);
*did = rport->port_id;
break;
case ELS_SCR:
fc_scr_fill(lport, fp);
*did = FC_FID_FCTRL;
break;
default:
FC_DBG("Invalid op code %x \n", op);
return -EINVAL;
}
*r_ctl = FC_RCTL_ELS_REQ;
*fh_type = FC_TYPE_ELS;
return 0;
}
#endif /* _FC_ENCODE_H_ */
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment