mirror of
https://github.com/ukui/kernel.git
synced 2026-03-09 10:07:04 -07:00
[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: Robert Love <robert.w.love@intel.com> [jejb: added include of delay.h to fix ppc64 compile prob spotted by sfr] Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
This commit is contained in:
committed by
James Bottomley
parent
f032c2f7cd
commit
42e9a92fe6
@@ -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
|
||||
|
||||
12
drivers/scsi/libfc/Makefile
Normal file
12
drivers/scsi/libfc/Makefile
Normal file
@@ -0,0 +1,12 @@
|
||||
# $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
|
||||
845
drivers/scsi/libfc/fc_disc.c
Normal file
845
drivers/scsi/libfc/fc_disc.c
Normal file
File diff suppressed because it is too large
Load Diff
71
drivers/scsi/libfc/fc_elsct.c
Normal file
71
drivers/scsi/libfc/fc_elsct.c
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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);
|
||||
1970
drivers/scsi/libfc/fc_exch.c
Normal file
1970
drivers/scsi/libfc/fc_exch.c
Normal file
File diff suppressed because it is too large
Load Diff
2131
drivers/scsi/libfc/fc_fcp.c
Normal file
2131
drivers/scsi/libfc/fc_fcp.c
Normal file
File diff suppressed because it is too large
Load Diff
89
drivers/scsi/libfc/fc_frame.c
Normal file
89
drivers/scsi/libfc/fc_frame.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
1604
drivers/scsi/libfc/fc_lport.c
Normal file
1604
drivers/scsi/libfc/fc_lport.c
Normal file
File diff suppressed because it is too large
Load Diff
1291
drivers/scsi/libfc/fc_rport.c
Normal file
1291
drivers/scsi/libfc/fc_rport.c
Normal file
File diff suppressed because it is too large
Load Diff
309
include/scsi/fc_encode.h
Normal file
309
include/scsi/fc_encode.h
Normal file
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
* 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_ */
|
||||
242
include/scsi/fc_frame.h
Normal file
242
include/scsi/fc_frame.h
Normal file
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef _FC_FRAME_H_
|
||||
#define _FC_FRAME_H_
|
||||
|
||||
#include <linux/scatterlist.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <scsi/scsi_cmnd.h>
|
||||
|
||||
#include <scsi/fc/fc_fs.h>
|
||||
#include <scsi/fc/fc_fcp.h>
|
||||
#include <scsi/fc/fc_encaps.h>
|
||||
|
||||
/*
|
||||
* The fc_frame interface is used to pass frame data between functions.
|
||||
* The frame includes the data buffer, length, and SOF / EOF delimiter types.
|
||||
* A pointer to the port structure of the receiving port is also includeded.
|
||||
*/
|
||||
|
||||
#define FC_FRAME_HEADROOM 32 /* headroom for VLAN + FCoE headers */
|
||||
#define FC_FRAME_TAILROOM 8 /* trailer space for FCoE */
|
||||
|
||||
/*
|
||||
* Information about an individual fibre channel frame received or to be sent.
|
||||
* The buffer may be in up to 4 additional non-contiguous sections,
|
||||
* but the linear section must hold the frame header.
|
||||
*/
|
||||
#define FC_FRAME_SG_LEN 4 /* scatter/gather list maximum length */
|
||||
|
||||
#define fp_skb(fp) (&((fp)->skb))
|
||||
#define fr_hdr(fp) ((fp)->skb.data)
|
||||
#define fr_len(fp) ((fp)->skb.len)
|
||||
#define fr_cb(fp) ((struct fcoe_rcv_info *)&((fp)->skb.cb[0]))
|
||||
#define fr_dev(fp) (fr_cb(fp)->fr_dev)
|
||||
#define fr_seq(fp) (fr_cb(fp)->fr_seq)
|
||||
#define fr_sof(fp) (fr_cb(fp)->fr_sof)
|
||||
#define fr_eof(fp) (fr_cb(fp)->fr_eof)
|
||||
#define fr_flags(fp) (fr_cb(fp)->fr_flags)
|
||||
#define fr_max_payload(fp) (fr_cb(fp)->fr_max_payload)
|
||||
#define fr_cmd(fp) (fr_cb(fp)->fr_cmd)
|
||||
#define fr_dir(fp) (fr_cmd(fp)->sc_data_direction)
|
||||
#define fr_crc(fp) (fr_cb(fp)->fr_crc)
|
||||
|
||||
struct fc_frame {
|
||||
struct sk_buff skb;
|
||||
};
|
||||
|
||||
struct fcoe_rcv_info {
|
||||
struct packet_type *ptype;
|
||||
struct fc_lport *fr_dev; /* transport layer private pointer */
|
||||
struct fc_seq *fr_seq; /* for use with exchange manager */
|
||||
struct scsi_cmnd *fr_cmd; /* for use of scsi command */
|
||||
u32 fr_crc;
|
||||
u16 fr_max_payload; /* max FC payload */
|
||||
enum fc_sof fr_sof; /* start of frame delimiter */
|
||||
enum fc_eof fr_eof; /* end of frame delimiter */
|
||||
u8 fr_flags; /* flags - see below */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Get fc_frame pointer for an skb that's already been imported.
|
||||
*/
|
||||
static inline struct fcoe_rcv_info *fcoe_dev_from_skb(const struct sk_buff *skb)
|
||||
{
|
||||
BUILD_BUG_ON(sizeof(struct fcoe_rcv_info) > sizeof(skb->cb));
|
||||
return (struct fcoe_rcv_info *) skb->cb;
|
||||
}
|
||||
|
||||
/*
|
||||
* fr_flags.
|
||||
*/
|
||||
#define FCPHF_CRC_UNCHECKED 0x01 /* CRC not computed, still appended */
|
||||
|
||||
/*
|
||||
* Initialize a frame.
|
||||
* We don't do a complete memset here for performance reasons.
|
||||
* The caller must set fr_free, fr_hdr, fr_len, fr_sof, and fr_eof eventually.
|
||||
*/
|
||||
static inline void fc_frame_init(struct fc_frame *fp)
|
||||
{
|
||||
fr_dev(fp) = NULL;
|
||||
fr_seq(fp) = NULL;
|
||||
fr_flags(fp) = 0;
|
||||
}
|
||||
|
||||
struct fc_frame *fc_frame_alloc_fill(struct fc_lport *, size_t payload_len);
|
||||
|
||||
struct fc_frame *__fc_frame_alloc(size_t payload_len);
|
||||
|
||||
/*
|
||||
* Get frame for sending via port.
|
||||
*/
|
||||
static inline struct fc_frame *_fc_frame_alloc(struct fc_lport *dev,
|
||||
size_t payload_len)
|
||||
{
|
||||
return __fc_frame_alloc(payload_len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate fc_frame structure and buffer. Set the initial length to
|
||||
* payload_size + sizeof (struct fc_frame_header).
|
||||
*/
|
||||
static inline struct fc_frame *fc_frame_alloc(struct fc_lport *dev, size_t len)
|
||||
{
|
||||
struct fc_frame *fp;
|
||||
|
||||
/*
|
||||
* Note: Since len will often be a constant multiple of 4,
|
||||
* this check will usually be evaluated and eliminated at compile time.
|
||||
*/
|
||||
if ((len % 4) != 0)
|
||||
fp = fc_frame_alloc_fill(dev, len);
|
||||
else
|
||||
fp = _fc_frame_alloc(dev, len);
|
||||
return fp;
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the fc_frame structure and buffer.
|
||||
*/
|
||||
static inline void fc_frame_free(struct fc_frame *fp)
|
||||
{
|
||||
kfree_skb(fp_skb(fp));
|
||||
}
|
||||
|
||||
static inline int fc_frame_is_linear(struct fc_frame *fp)
|
||||
{
|
||||
return !skb_is_nonlinear(fp_skb(fp));
|
||||
}
|
||||
|
||||
/*
|
||||
* Get frame header from message in fc_frame structure.
|
||||
* This hides a cast and provides a place to add some checking.
|
||||
*/
|
||||
static inline
|
||||
struct fc_frame_header *fc_frame_header_get(const struct fc_frame *fp)
|
||||
{
|
||||
WARN_ON(fr_len(fp) < sizeof(struct fc_frame_header));
|
||||
return (struct fc_frame_header *) fr_hdr(fp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get frame payload from message in fc_frame structure.
|
||||
* This hides a cast and provides a place to add some checking.
|
||||
* The len parameter is the minimum length for the payload portion.
|
||||
* Returns NULL if the frame is too short.
|
||||
*
|
||||
* This assumes the interesting part of the payload is in the first part
|
||||
* of the buffer for received data. This may not be appropriate to use for
|
||||
* buffers being transmitted.
|
||||
*/
|
||||
static inline void *fc_frame_payload_get(const struct fc_frame *fp,
|
||||
size_t len)
|
||||
{
|
||||
void *pp = NULL;
|
||||
|
||||
if (fr_len(fp) >= sizeof(struct fc_frame_header) + len)
|
||||
pp = fc_frame_header_get(fp) + 1;
|
||||
return pp;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get frame payload opcode (first byte) from message in fc_frame structure.
|
||||
* This hides a cast and provides a place to add some checking. Return 0
|
||||
* if the frame has no payload.
|
||||
*/
|
||||
static inline u8 fc_frame_payload_op(const struct fc_frame *fp)
|
||||
{
|
||||
u8 *cp;
|
||||
|
||||
cp = fc_frame_payload_get(fp, sizeof(u8));
|
||||
if (!cp)
|
||||
return 0;
|
||||
return *cp;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Get FC class from frame.
|
||||
*/
|
||||
static inline enum fc_class fc_frame_class(const struct fc_frame *fp)
|
||||
{
|
||||
return fc_sof_class(fr_sof(fp));
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the CRC in a frame.
|
||||
* The CRC immediately follows the last data item *AFTER* the length.
|
||||
* The return value is zero if the CRC matches.
|
||||
*/
|
||||
u32 fc_frame_crc_check(struct fc_frame *);
|
||||
|
||||
static inline u8 fc_frame_rctl(const struct fc_frame *fp)
|
||||
{
|
||||
return fc_frame_header_get(fp)->fh_r_ctl;
|
||||
}
|
||||
|
||||
static inline bool fc_frame_is_cmd(const struct fc_frame *fp)
|
||||
{
|
||||
return fc_frame_rctl(fp) == FC_RCTL_DD_UNSOL_CMD;
|
||||
}
|
||||
|
||||
static inline bool fc_frame_is_read(const struct fc_frame *fp)
|
||||
{
|
||||
if (fc_frame_is_cmd(fp) && fr_cmd(fp))
|
||||
return fr_dir(fp) == DMA_FROM_DEVICE;
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool fc_frame_is_write(const struct fc_frame *fp)
|
||||
{
|
||||
if (fc_frame_is_cmd(fp) && fr_cmd(fp))
|
||||
return fr_dir(fp) == DMA_TO_DEVICE;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for leaks.
|
||||
* Print the frame header of any currently allocated frame, assuming there
|
||||
* should be none at this point.
|
||||
*/
|
||||
void fc_frame_leak_check(void);
|
||||
|
||||
#endif /* _FC_FRAME_H_ */
|
||||
938
include/scsi/libfc.h
Normal file
938
include/scsi/libfc.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user