aboutsummaryrefslogtreecommitdiffstats
path: root/include/scsi
diff options
context:
space:
mode:
Diffstat (limited to 'include/scsi')
-rw-r--r--include/scsi/Kbuild1
-rw-r--r--include/scsi/fc/Kbuild4
-rw-r--r--include/scsi/fc/fc_els.h6
-rw-r--r--include/scsi/fc/fc_fcoe.h12
-rw-r--r--include/scsi/fc/fc_fcp.h8
-rw-r--r--include/scsi/fc/fc_fip.h12
-rw-r--r--include/scsi/fc/fc_fs.h2
-rw-r--r--include/scsi/fc/fc_gs.h2
-rw-r--r--include/scsi/fc/fc_ns.h35
-rw-r--r--include/scsi/fc_encode.h68
-rw-r--r--include/scsi/fc_frame.h22
-rw-r--r--include/scsi/iscsi_if.h3
-rw-r--r--include/scsi/iscsi_proto.h2
-rw-r--r--include/scsi/libfc.h1158
-rw-r--r--include/scsi/libfcoe.h93
-rw-r--r--include/scsi/libiscsi.h4
-rw-r--r--include/scsi/libsas.h3
-rw-r--r--include/scsi/osd_initiator.h81
-rw-r--r--include/scsi/osd_protocol.h1
-rw-r--r--include/scsi/osd_sense.h3
-rw-r--r--include/scsi/scsi.h4
-rw-r--r--include/scsi/scsi_device.h12
-rw-r--r--include/scsi/scsi_dh.h6
-rw-r--r--include/scsi/scsi_host.h24
-rw-r--r--include/scsi/scsi_transport_fc.h1
25 files changed, 889 insertions, 678 deletions
diff --git a/include/scsi/Kbuild b/include/scsi/Kbuild
index 33b2750e9283..b3a0ee6b2f1c 100644
--- a/include/scsi/Kbuild
+++ b/include/scsi/Kbuild
@@ -2,3 +2,4 @@ header-y += scsi.h
2header-y += scsi_netlink.h 2header-y += scsi_netlink.h
3header-y += scsi_netlink_fc.h 3header-y += scsi_netlink_fc.h
4header-y += scsi_bsg_fc.h 4header-y += scsi_bsg_fc.h
5header-y += fc/
diff --git a/include/scsi/fc/Kbuild b/include/scsi/fc/Kbuild
new file mode 100644
index 000000000000..56603813c6cd
--- /dev/null
+++ b/include/scsi/fc/Kbuild
@@ -0,0 +1,4 @@
1header-y += fc_els.h
2header-y += fc_fs.h
3header-y += fc_gs.h
4header-y += fc_ns.h
diff --git a/include/scsi/fc/fc_els.h b/include/scsi/fc/fc_els.h
index 195ca014d3ce..f94328132a26 100644
--- a/include/scsi/fc/fc_els.h
+++ b/include/scsi/fc/fc_els.h
@@ -20,6 +20,8 @@
20#ifndef _FC_ELS_H_ 20#ifndef _FC_ELS_H_
21#define _FC_ELS_H_ 21#define _FC_ELS_H_
22 22
23#include <linux/types.h>
24
23/* 25/*
24 * Fibre Channel Switch - Enhanced Link Services definitions. 26 * Fibre Channel Switch - Enhanced Link Services definitions.
25 * From T11 FC-LS Rev 1.2 June 7, 2005. 27 * From T11 FC-LS Rev 1.2 June 7, 2005.
@@ -248,10 +250,12 @@ struct fc_els_csp {
248/* 250/*
249 * sp_features 251 * sp_features
250 */ 252 */
251#define FC_SP_FT_CIRO 0x8000 /* continuously increasing rel. off. */ 253#define FC_SP_FT_NPIV 0x8000 /* multiple N_Port_ID support (FLOGI) */
254#define FC_SP_FT_CIRO 0x8000 /* continuously increasing rel off (PLOGI) */
252#define FC_SP_FT_CLAD 0x8000 /* clean address (in FLOGI LS_ACC) */ 255#define FC_SP_FT_CLAD 0x8000 /* clean address (in FLOGI LS_ACC) */
253#define FC_SP_FT_RAND 0x4000 /* random relative offset */ 256#define FC_SP_FT_RAND 0x4000 /* random relative offset */
254#define FC_SP_FT_VAL 0x2000 /* valid vendor version level */ 257#define FC_SP_FT_VAL 0x2000 /* valid vendor version level */
258#define FC_SP_FT_NPIV_ACC 0x2000 /* NPIV assignment (FLOGI LS_ACC) */
255#define FC_SP_FT_FPORT 0x1000 /* F port (1) vs. N port (0) */ 259#define FC_SP_FT_FPORT 0x1000 /* F port (1) vs. N port (0) */
256#define FC_SP_FT_ABB 0x0800 /* alternate BB_credit management */ 260#define FC_SP_FT_ABB 0x0800 /* alternate BB_credit management */
257#define FC_SP_FT_EDTR 0x0400 /* E_D_TOV Resolution is nanoseconds */ 261#define FC_SP_FT_EDTR 0x0400 /* E_D_TOV Resolution is nanoseconds */
diff --git a/include/scsi/fc/fc_fcoe.h b/include/scsi/fc/fc_fcoe.h
index ccb3dbe90463..e6ad3d2ae475 100644
--- a/include/scsi/fc/fc_fcoe.h
+++ b/include/scsi/fc/fc_fcoe.h
@@ -86,6 +86,18 @@ struct fcoe_crc_eof {
86#define FCOE_MIN_FRAME 46 86#define FCOE_MIN_FRAME 46
87 87
88/* 88/*
89 * FCoE Link Error Status Block: T11 FC-BB-5 Rev2.0, Clause 7.10.
90 */
91struct fcoe_fc_els_lesb {
92 __be32 lesb_link_fail; /* link failure count */
93 __be32 lesb_vlink_fail; /* virtual link failure count */
94 __be32 lesb_miss_fka; /* missing FIP keep-alive count */
95 __be32 lesb_symb_err; /* symbol error during carrier count */
96 __be32 lesb_err_block; /* errored block count */
97 __be32 lesb_fcs_error; /* frame check sequence error count */
98};
99
100/*
89 * fc_fcoe_set_mac - Store OUI + DID into MAC address field. 101 * fc_fcoe_set_mac - Store OUI + DID into MAC address field.
90 * @mac: mac address to be set 102 * @mac: mac address to be set
91 * @did: fc dest id to use 103 * @did: fc dest id to use
diff --git a/include/scsi/fc/fc_fcp.h b/include/scsi/fc/fc_fcp.h
index 5d38f1989f37..747e2c7d88d6 100644
--- a/include/scsi/fc/fc_fcp.h
+++ b/include/scsi/fc/fc_fcp.h
@@ -83,6 +83,8 @@ struct fcp_cmnd32 {
83 * fc_tm_flags - task management flags field. 83 * fc_tm_flags - task management flags field.
84 */ 84 */
85#define FCP_TMF_CLR_ACA 0x40 /* clear ACA condition */ 85#define FCP_TMF_CLR_ACA 0x40 /* clear ACA condition */
86#define FCP_TMF_TGT_RESET 0x20 /* target reset task management,
87 deprecated as of FCP-3 */
86#define FCP_TMF_LUN_RESET 0x10 /* logical unit reset task management */ 88#define FCP_TMF_LUN_RESET 0x10 /* logical unit reset task management */
87#define FCP_TMF_CLR_TASK_SET 0x04 /* clear task set */ 89#define FCP_TMF_CLR_TASK_SET 0x04 /* clear task set */
88#define FCP_TMF_ABT_TASK_SET 0x02 /* abort task set */ 90#define FCP_TMF_ABT_TASK_SET 0x02 /* abort task set */
@@ -196,4 +198,10 @@ struct fcp_srr {
196 __u8 srr_resvd2[3]; /* reserved */ 198 __u8 srr_resvd2[3]; /* reserved */
197}; 199};
198 200
201/*
202 * Feature bits in name server FC-4 Features object.
203 */
204#define FCP_FEAT_TARG (1 << 0) /* target function supported */
205#define FCP_FEAT_INIT (1 << 1) /* initiator function supported */
206
199#endif /* _FC_FCP_H_ */ 207#endif /* _FC_FCP_H_ */
diff --git a/include/scsi/fc/fc_fip.h b/include/scsi/fc/fc_fip.h
index 3d138c1fcf8a..17baa19380f0 100644
--- a/include/scsi/fc/fc_fip.h
+++ b/include/scsi/fc/fc_fip.h
@@ -214,11 +214,21 @@ struct fip_vn_desc {
214 */ 214 */
215struct fip_fka_desc { 215struct fip_fka_desc {
216 struct fip_desc fd_desc; 216 struct fip_desc fd_desc;
217 __u8 fd_resvd[2]; 217 __u8 fd_resvd;
218 __u8 fd_flags; /* bit0 is fka disable flag */
218 __be32 fd_fka_period; /* adv./keep-alive period in mS */ 219 __be32 fd_fka_period; /* adv./keep-alive period in mS */
219} __attribute__((packed)); 220} __attribute__((packed));
220 221
221/* 222/*
223 * flags for fip_fka_desc.fd_flags
224 */
225enum fip_fka_flags {
226 FIP_FKA_ADV_D = 0x01, /* no need for FKA from ENode */
227};
228
229/* FIP_DT_FKA flags */
230
231/*
222 * FIP_DT_VENDOR descriptor. 232 * FIP_DT_VENDOR descriptor.
223 */ 233 */
224struct fip_vendor_desc { 234struct fip_vendor_desc {
diff --git a/include/scsi/fc/fc_fs.h b/include/scsi/fc/fc_fs.h
index ac4cd38c860e..50f28b143451 100644
--- a/include/scsi/fc/fc_fs.h
+++ b/include/scsi/fc/fc_fs.h
@@ -20,6 +20,8 @@
20#ifndef _FC_FS_H_ 20#ifndef _FC_FS_H_
21#define _FC_FS_H_ 21#define _FC_FS_H_
22 22
23#include <linux/types.h>
24
23/* 25/*
24 * Fibre Channel Framing and Signalling definitions. 26 * Fibre Channel Framing and Signalling definitions.
25 * From T11 FC-FS-2 Rev 0.90 - 9 August 2005. 27 * From T11 FC-FS-2 Rev 0.90 - 9 August 2005.
diff --git a/include/scsi/fc/fc_gs.h b/include/scsi/fc/fc_gs.h
index 324dd0e3c622..a37346d47eb1 100644
--- a/include/scsi/fc/fc_gs.h
+++ b/include/scsi/fc/fc_gs.h
@@ -20,6 +20,8 @@
20#ifndef _FC_GS_H_ 20#ifndef _FC_GS_H_
21#define _FC_GS_H_ 21#define _FC_GS_H_
22 22
23#include <linux/types.h>
24
23/* 25/*
24 * Fibre Channel Services - Common Transport. 26 * Fibre Channel Services - Common Transport.
25 * From T11.org FC-GS-2 Rev 5.3 November 1998. 27 * From T11.org FC-GS-2 Rev 5.3 November 1998.
diff --git a/include/scsi/fc/fc_ns.h b/include/scsi/fc/fc_ns.h
index 790d7b97d4bc..e7d3ac497d7d 100644
--- a/include/scsi/fc/fc_ns.h
+++ b/include/scsi/fc/fc_ns.h
@@ -20,6 +20,8 @@
20#ifndef _FC_NS_H_ 20#ifndef _FC_NS_H_
21#define _FC_NS_H_ 21#define _FC_NS_H_
22 22
23#include <linux/types.h>
24
23/* 25/*
24 * Fibre Channel Services - Name Service (dNS) 26 * Fibre Channel Services - Name Service (dNS)
25 * From T11.org FC-GS-2 Rev 5.3 November 1998. 27 * From T11.org FC-GS-2 Rev 5.3 November 1998.
@@ -44,9 +46,12 @@ enum fc_ns_req {
44 FC_NS_GID_FT = 0x0171, /* get IDs by FC4 type */ 46 FC_NS_GID_FT = 0x0171, /* get IDs by FC4 type */
45 FC_NS_GPN_FT = 0x0172, /* get port names by FC4 type */ 47 FC_NS_GPN_FT = 0x0172, /* get port names by FC4 type */
46 FC_NS_GID_PT = 0x01a1, /* get IDs by port type */ 48 FC_NS_GID_PT = 0x01a1, /* get IDs by port type */
47 FC_NS_RFT_ID = 0x0217, /* reg FC4 type for ID */
48 FC_NS_RPN_ID = 0x0212, /* reg port name for ID */ 49 FC_NS_RPN_ID = 0x0212, /* reg port name for ID */
49 FC_NS_RNN_ID = 0x0213, /* reg node name for ID */ 50 FC_NS_RNN_ID = 0x0213, /* reg node name for ID */
51 FC_NS_RFT_ID = 0x0217, /* reg FC4 type for ID */
52 FC_NS_RSPN_ID = 0x0218, /* reg symbolic port name */
53 FC_NS_RFF_ID = 0x021f, /* reg FC4 Features for ID */
54 FC_NS_RSNN_NN = 0x0239, /* reg symbolic node name */
50}; 55};
51 56
52/* 57/*
@@ -156,4 +161,32 @@ struct fc_ns_rn_id {
156 __be64 fr_wwn; /* node name or port name */ 161 __be64 fr_wwn; /* node name or port name */
157} __attribute__((__packed__)); 162} __attribute__((__packed__));
158 163
164/*
165 * RSNN_NN request - register symbolic node name
166 */
167struct fc_ns_rsnn {
168 __be64 fr_wwn; /* node name */
169 __u8 fr_name_len;
170 char fr_name[];
171} __attribute__((__packed__));
172
173/*
174 * RSPN_ID request - register symbolic port name
175 */
176struct fc_ns_rspn {
177 struct fc_ns_fid fr_fid; /* port ID object */
178 __u8 fr_name_len;
179 char fr_name[];
180} __attribute__((__packed__));
181
182/*
183 * RFF_ID request - register FC-4 Features for ID.
184 */
185struct fc_ns_rff_id {
186 struct fc_ns_fid fr_fid; /* port ID object */
187 __u8 fr_resvd[2];
188 __u8 fr_feat; /* FC-4 Feature bits */
189 __u8 fr_type; /* FC-4 type */
190} __attribute__((__packed__));
191
159#endif /* _FC_NS_H_ */ 192#endif /* _FC_NS_H_ */
diff --git a/include/scsi/fc_encode.h b/include/scsi/fc_encode.h
index 27dad703824f..8eb0a0fc0a71 100644
--- a/include/scsi/fc_encode.h
+++ b/include/scsi/fc_encode.h
@@ -32,7 +32,10 @@ struct fc_ct_req {
32 struct fc_ns_gid_ft gid; 32 struct fc_ns_gid_ft gid;
33 struct fc_ns_rn_id rn; 33 struct fc_ns_rn_id rn;
34 struct fc_ns_rft rft; 34 struct fc_ns_rft rft;
35 struct fc_ns_rff_id rff;
35 struct fc_ns_fid fid; 36 struct fc_ns_fid fid;
37 struct fc_ns_rsnn snn;
38 struct fc_ns_rspn spn;
36 } payload; 39 } payload;
37}; 40};
38 41
@@ -109,6 +112,7 @@ static inline int fc_ct_fill(struct fc_lport *lport,
109 enum fc_fh_type *fh_type) 112 enum fc_fh_type *fh_type)
110{ 113{
111 struct fc_ct_req *ct; 114 struct fc_ct_req *ct;
115 size_t len;
112 116
113 switch (op) { 117 switch (op) {
114 case FC_NS_GPN_FT: 118 case FC_NS_GPN_FT:
@@ -128,12 +132,41 @@ static inline int fc_ct_fill(struct fc_lport *lport,
128 ct->payload.rft.fts = lport->fcts; 132 ct->payload.rft.fts = lport->fcts;
129 break; 133 break;
130 134
131 case FC_NS_RPN_ID: 135 case FC_NS_RFF_ID:
136 ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rff_id));
137 hton24(ct->payload.rff.fr_fid.fp_fid,
138 fc_host_port_id(lport->host));
139 ct->payload.rff.fr_type = FC_TYPE_FCP;
140 if (lport->service_params & FCP_SPPF_INIT_FCN)
141 ct->payload.rff.fr_feat = FCP_FEAT_INIT;
142 if (lport->service_params & FCP_SPPF_TARG_FCN)
143 ct->payload.rff.fr_feat |= FCP_FEAT_TARG;
144 break;
145
146 case FC_NS_RNN_ID:
132 ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rn_id)); 147 ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rn_id));
133 hton24(ct->payload.rn.fr_fid.fp_fid, 148 hton24(ct->payload.rn.fr_fid.fp_fid,
134 fc_host_port_id(lport->host)); 149 fc_host_port_id(lport->host));
135 ct->payload.rft.fts = lport->fcts; 150 put_unaligned_be64(lport->wwnn, &ct->payload.rn.fr_wwn);
136 put_unaligned_be64(lport->wwpn, &ct->payload.rn.fr_wwn); 151 break;
152
153 case FC_NS_RSPN_ID:
154 len = strnlen(fc_host_symbolic_name(lport->host), 255);
155 ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rspn) + len);
156 hton24(ct->payload.spn.fr_fid.fp_fid,
157 fc_host_port_id(lport->host));
158 strncpy(ct->payload.spn.fr_name,
159 fc_host_symbolic_name(lport->host), len);
160 ct->payload.spn.fr_name_len = len;
161 break;
162
163 case FC_NS_RSNN_NN:
164 len = strnlen(fc_host_symbolic_name(lport->host), 255);
165 ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rsnn) + len);
166 put_unaligned_be64(lport->wwnn, &ct->payload.snn.fr_wwn);
167 strncpy(ct->payload.snn.fr_name,
168 fc_host_symbolic_name(lport->host), len);
169 ct->payload.snn.fr_name_len = len;
137 break; 170 break;
138 171
139 default: 172 default:
@@ -198,6 +231,31 @@ static inline void fc_flogi_fill(struct fc_lport *lport, struct fc_frame *fp)
198 sp->sp_bb_data = htons((u16) lport->mfs); 231 sp->sp_bb_data = htons((u16) lport->mfs);
199 cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */ 232 cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */
200 cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ); 233 cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
234 if (lport->does_npiv)
235 sp->sp_features = htons(FC_SP_FT_NPIV);
236}
237
238/**
239 * fc_fdisc_fill - Fill in a fdisc request frame.
240 */
241static inline void fc_fdisc_fill(struct fc_lport *lport, struct fc_frame *fp)
242{
243 struct fc_els_csp *sp;
244 struct fc_els_cssp *cp;
245 struct fc_els_flogi *fdisc;
246
247 fdisc = fc_frame_payload_get(fp, sizeof(*fdisc));
248 memset(fdisc, 0, sizeof(*fdisc));
249 fdisc->fl_cmd = (u8) ELS_FDISC;
250 put_unaligned_be64(lport->wwpn, &fdisc->fl_wwpn);
251 put_unaligned_be64(lport->wwnn, &fdisc->fl_wwnn);
252 sp = &fdisc->fl_csp;
253 sp->sp_hi_ver = 0x20;
254 sp->sp_lo_ver = 0x20;
255 sp->sp_bb_cred = htons(10); /* this gets set by gateway */
256 sp->sp_bb_data = htons((u16) lport->mfs);
257 cp = &fdisc->fl_cssp[3 - 1]; /* class 3 parameters */
258 cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
201} 259}
202 260
203/** 261/**
@@ -296,6 +354,10 @@ static inline int fc_els_fill(struct fc_lport *lport,
296 fc_flogi_fill(lport, fp); 354 fc_flogi_fill(lport, fp);
297 break; 355 break;
298 356
357 case ELS_FDISC:
358 fc_fdisc_fill(lport, fp);
359 break;
360
299 case ELS_LOGO: 361 case ELS_LOGO:
300 fc_logo_fill(lport, fp); 362 fc_logo_fill(lport, fp);
301 break; 363 break;
diff --git a/include/scsi/fc_frame.h b/include/scsi/fc_frame.h
index c35d2383cc26..4d3e9c7b7c57 100644
--- a/include/scsi/fc_frame.h
+++ b/include/scsi/fc_frame.h
@@ -28,6 +28,8 @@
28#include <scsi/fc/fc_fcp.h> 28#include <scsi/fc/fc_fcp.h>
29#include <scsi/fc/fc_encaps.h> 29#include <scsi/fc/fc_encaps.h>
30 30
31#include <linux/if_ether.h>
32
31/* 33/*
32 * The fc_frame interface is used to pass frame data between functions. 34 * The fc_frame interface is used to pass frame data between functions.
33 * The frame includes the data buffer, length, and SOF / EOF delimiter types. 35 * The frame includes the data buffer, length, and SOF / EOF delimiter types.
@@ -37,6 +39,9 @@
37#define FC_FRAME_HEADROOM 32 /* headroom for VLAN + FCoE headers */ 39#define FC_FRAME_HEADROOM 32 /* headroom for VLAN + FCoE headers */
38#define FC_FRAME_TAILROOM 8 /* trailer space for FCoE */ 40#define FC_FRAME_TAILROOM 8 /* trailer space for FCoE */
39 41
42/* Max number of skb frags allowed, reserving one for fcoe_crc_eof page */
43#define FC_FRAME_SG_LEN (MAX_SKB_FRAGS - 1)
44
40#define fp_skb(fp) (&((fp)->skb)) 45#define fp_skb(fp) (&((fp)->skb))
41#define fr_hdr(fp) ((fp)->skb.data) 46#define fr_hdr(fp) ((fp)->skb.data)
42#define fr_len(fp) ((fp)->skb.len) 47#define fr_len(fp) ((fp)->skb.len)
@@ -64,6 +69,7 @@ struct fcoe_rcv_info {
64 enum fc_sof fr_sof; /* start of frame delimiter */ 69 enum fc_sof fr_sof; /* start of frame delimiter */
65 enum fc_eof fr_eof; /* end of frame delimiter */ 70 enum fc_eof fr_eof; /* end of frame delimiter */
66 u8 fr_flags; /* flags - see below */ 71 u8 fr_flags; /* flags - see below */
72 u8 granted_mac[ETH_ALEN]; /* FCoE MAC address */
67}; 73};
68 74
69 75
@@ -94,17 +100,7 @@ static inline void fc_frame_init(struct fc_frame *fp)
94} 100}
95 101
96struct fc_frame *fc_frame_alloc_fill(struct fc_lport *, size_t payload_len); 102struct fc_frame *fc_frame_alloc_fill(struct fc_lport *, size_t payload_len);
97 103struct fc_frame *_fc_frame_alloc(size_t payload_len);
98struct fc_frame *__fc_frame_alloc(size_t payload_len);
99
100/*
101 * Get frame for sending via port.
102 */
103static inline struct fc_frame *_fc_frame_alloc(struct fc_lport *dev,
104 size_t payload_len)
105{
106 return __fc_frame_alloc(payload_len);
107}
108 104
109/* 105/*
110 * Allocate fc_frame structure and buffer. Set the initial length to 106 * Allocate fc_frame structure and buffer. Set the initial length to
@@ -118,10 +114,10 @@ static inline struct fc_frame *fc_frame_alloc(struct fc_lport *dev, size_t len)
118 * Note: Since len will often be a constant multiple of 4, 114 * Note: Since len will often be a constant multiple of 4,
119 * this check will usually be evaluated and eliminated at compile time. 115 * this check will usually be evaluated and eliminated at compile time.
120 */ 116 */
121 if ((len % 4) != 0) 117 if (len && len % 4)
122 fp = fc_frame_alloc_fill(dev, len); 118 fp = fc_frame_alloc_fill(dev, len);
123 else 119 else
124 fp = _fc_frame_alloc(dev, len); 120 fp = _fc_frame_alloc(len);
125 return fp; 121 return fp;
126} 122}
127 123
diff --git a/include/scsi/iscsi_if.h b/include/scsi/iscsi_if.h
index d67dda2b6aa0..66d377b9c72b 100644
--- a/include/scsi/iscsi_if.h
+++ b/include/scsi/iscsi_if.h
@@ -311,6 +311,8 @@ enum iscsi_param {
311 ISCSI_PARAM_IFACE_NAME, 311 ISCSI_PARAM_IFACE_NAME,
312 ISCSI_PARAM_ISID, 312 ISCSI_PARAM_ISID,
313 ISCSI_PARAM_INITIATOR_NAME, 313 ISCSI_PARAM_INITIATOR_NAME,
314
315 ISCSI_PARAM_TGT_RESET_TMO,
314 /* must always be last */ 316 /* must always be last */
315 ISCSI_PARAM_MAX, 317 ISCSI_PARAM_MAX,
316}; 318};
@@ -350,6 +352,7 @@ enum iscsi_param {
350#define ISCSI_IFACE_NAME (1ULL << ISCSI_PARAM_IFACE_NAME) 352#define ISCSI_IFACE_NAME (1ULL << ISCSI_PARAM_IFACE_NAME)
351#define ISCSI_ISID (1ULL << ISCSI_PARAM_ISID) 353#define ISCSI_ISID (1ULL << ISCSI_PARAM_ISID)
352#define ISCSI_INITIATOR_NAME (1ULL << ISCSI_PARAM_INITIATOR_NAME) 354#define ISCSI_INITIATOR_NAME (1ULL << ISCSI_PARAM_INITIATOR_NAME)
355#define ISCSI_TGT_RESET_TMO (1ULL << ISCSI_PARAM_TGT_RESET_TMO)
353 356
354/* iSCSI HBA params */ 357/* iSCSI HBA params */
355enum iscsi_host_param { 358enum iscsi_host_param {
diff --git a/include/scsi/iscsi_proto.h b/include/scsi/iscsi_proto.h
index f2a2c1169486..dd0a52cea95a 100644
--- a/include/scsi/iscsi_proto.h
+++ b/include/scsi/iscsi_proto.h
@@ -279,6 +279,8 @@ struct iscsi_tm {
279#define ISCSI_TM_FUNC_TARGET_COLD_RESET 7 279#define ISCSI_TM_FUNC_TARGET_COLD_RESET 7
280#define ISCSI_TM_FUNC_TASK_REASSIGN 8 280#define ISCSI_TM_FUNC_TASK_REASSIGN 8
281 281
282#define ISCSI_TM_FUNC_VALUE(hdr) ((hdr)->flags & ISCSI_FLAG_TM_FUNC_MASK)
283
282/* SCSI Task Management Response Header */ 284/* SCSI Task Management Response Header */
283struct iscsi_tm_rsp { 285struct iscsi_tm_rsp {
284 uint8_t opcode; 286 uint8_t opcode;
diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
index 65dc9aacbf70..4b912eee33e5 100644
--- a/include/scsi/libfc.h
+++ b/include/scsi/libfc.h
@@ -26,6 +26,7 @@
26 26
27#include <scsi/scsi_transport.h> 27#include <scsi/scsi_transport.h>
28#include <scsi/scsi_transport_fc.h> 28#include <scsi/scsi_transport_fc.h>
29#include <scsi/scsi_bsg_fc.h>
29 30
30#include <scsi/fc/fc_fcp.h> 31#include <scsi/fc/fc_fcp.h>
31#include <scsi/fc/fc_ns.h> 32#include <scsi/fc/fc_ns.h>
@@ -34,67 +35,6 @@
34 35
35#include <scsi/fc_frame.h> 36#include <scsi/fc_frame.h>
36 37
37#define FC_LIBFC_LOGGING 0x01 /* General logging, not categorized */
38#define FC_LPORT_LOGGING 0x02 /* lport layer logging */
39#define FC_DISC_LOGGING 0x04 /* discovery layer logging */
40#define FC_RPORT_LOGGING 0x08 /* rport layer logging */
41#define FC_FCP_LOGGING 0x10 /* I/O path logging */
42#define FC_EM_LOGGING 0x20 /* Exchange Manager logging */
43#define FC_EXCH_LOGGING 0x40 /* Exchange/Sequence logging */
44#define FC_SCSI_LOGGING 0x80 /* SCSI logging (mostly error handling) */
45
46extern unsigned int fc_debug_logging;
47
48#define FC_CHECK_LOGGING(LEVEL, CMD) \
49do { \
50 if (unlikely(fc_debug_logging & LEVEL)) \
51 do { \
52 CMD; \
53 } while (0); \
54} while (0)
55
56#define FC_LIBFC_DBG(fmt, args...) \
57 FC_CHECK_LOGGING(FC_LIBFC_LOGGING, \
58 printk(KERN_INFO "libfc: " fmt, ##args))
59
60#define FC_LPORT_DBG(lport, fmt, args...) \
61 FC_CHECK_LOGGING(FC_LPORT_LOGGING, \
62 printk(KERN_INFO "host%u: lport %6x: " fmt, \
63 (lport)->host->host_no, \
64 fc_host_port_id((lport)->host), ##args))
65
66#define FC_DISC_DBG(disc, fmt, args...) \
67 FC_CHECK_LOGGING(FC_DISC_LOGGING, \
68 printk(KERN_INFO "host%u: disc: " fmt, \
69 (disc)->lport->host->host_no, \
70 ##args))
71
72#define FC_RPORT_ID_DBG(lport, port_id, fmt, args...) \
73 FC_CHECK_LOGGING(FC_RPORT_LOGGING, \
74 printk(KERN_INFO "host%u: rport %6x: " fmt, \
75 (lport)->host->host_no, \
76 (port_id), ##args))
77
78#define FC_RPORT_DBG(rdata, fmt, args...) \
79 FC_RPORT_ID_DBG((rdata)->local_port, (rdata)->ids.port_id, fmt, ##args)
80
81#define FC_FCP_DBG(pkt, fmt, args...) \
82 FC_CHECK_LOGGING(FC_FCP_LOGGING, \
83 printk(KERN_INFO "host%u: fcp: %6x: " fmt, \
84 (pkt)->lp->host->host_no, \
85 pkt->rport->port_id, ##args))
86
87#define FC_EXCH_DBG(exch, fmt, args...) \
88 FC_CHECK_LOGGING(FC_EXCH_LOGGING, \
89 printk(KERN_INFO "host%u: xid %4x: " fmt, \
90 (exch)->lp->host->host_no, \
91 exch->xid, ##args))
92
93#define FC_SCSI_DBG(lport, fmt, args...) \
94 FC_CHECK_LOGGING(FC_SCSI_LOGGING, \
95 printk(KERN_INFO "host%u: scsi: " fmt, \
96 (lport)->host->host_no, ##args))
97
98/* 38/*
99 * libfc error codes 39 * libfc error codes
100 */ 40 */
@@ -115,15 +55,28 @@ do { \
115 p[2] = ((v) & 0xFF); \ 55 p[2] = ((v) & 0xFF); \
116 } while (0) 56 } while (0)
117 57
118/* 58/**
119 * FC HBA status 59 * enum fc_lport_state - Local port states
60 * @LPORT_ST_DISABLED: Disabled
61 * @LPORT_ST_FLOGI: Fabric login (FLOGI) sent
62 * @LPORT_ST_DNS: Waiting for name server remote port to become ready
63 * @LPORT_ST_RPN_ID: Register port name by ID (RPN_ID) sent
64 * @LPORT_ST_RFT_ID: Register Fibre Channel types by ID (RFT_ID) sent
65 * @LPORT_ST_RFF_ID: Register FC-4 Features by ID (RFF_ID) sent
66 * @LPORT_ST_SCR: State Change Register (SCR) sent
67 * @LPORT_ST_READY: Ready for use
68 * @LPORT_ST_LOGO: Local port logout (LOGO) sent
69 * @LPORT_ST_RESET: Local port reset
120 */ 70 */
121enum fc_lport_state { 71enum fc_lport_state {
122 LPORT_ST_DISABLED = 0, 72 LPORT_ST_DISABLED = 0,
123 LPORT_ST_FLOGI, 73 LPORT_ST_FLOGI,
124 LPORT_ST_DNS, 74 LPORT_ST_DNS,
125 LPORT_ST_RPN_ID, 75 LPORT_ST_RNN_ID,
76 LPORT_ST_RSNN_NN,
77 LPORT_ST_RSPN_ID,
126 LPORT_ST_RFT_ID, 78 LPORT_ST_RFT_ID,
79 LPORT_ST_RFF_ID,
127 LPORT_ST_SCR, 80 LPORT_ST_SCR,
128 LPORT_ST_READY, 81 LPORT_ST_READY,
129 LPORT_ST_LOGO, 82 LPORT_ST_LOGO,
@@ -136,15 +89,28 @@ enum fc_disc_event {
136 DISC_EV_FAILED 89 DISC_EV_FAILED
137}; 90};
138 91
92/**
93 * enum fc_rport_state - Remote port states
94 * @RPORT_ST_INIT: Initialized
95 * @RPORT_ST_PLOGI: Waiting for PLOGI completion
96 * @RPORT_ST_PRLI: Waiting for PRLI completion
97 * @RPORT_ST_RTV: Waiting for RTV completion
98 * @RPORT_ST_READY: Ready for use
99 * @RPORT_ST_LOGO: Remote port logout (LOGO) sent
100 * @RPORT_ST_ADISC: Discover Address sent
101 * @RPORT_ST_DELETE: Remote port being deleted
102 * @RPORT_ST_RESTART: Remote port being deleted and will restart
103*/
139enum fc_rport_state { 104enum fc_rport_state {
140 RPORT_ST_INIT, /* initialized */ 105 RPORT_ST_INIT,
141 RPORT_ST_PLOGI, /* waiting for PLOGI completion */ 106 RPORT_ST_PLOGI,
142 RPORT_ST_PRLI, /* waiting for PRLI completion */ 107 RPORT_ST_PRLI,
143 RPORT_ST_RTV, /* waiting for RTV completion */ 108 RPORT_ST_RTV,
144 RPORT_ST_READY, /* ready for use */ 109 RPORT_ST_READY,
145 RPORT_ST_LOGO, /* port logout sent */ 110 RPORT_ST_LOGO,
146 RPORT_ST_ADISC, /* Discover Address sent */ 111 RPORT_ST_ADISC,
147 RPORT_ST_DELETE, /* port being deleted */ 112 RPORT_ST_DELETE,
113 RPORT_ST_RESTART,
148}; 114};
149 115
150/** 116/**
@@ -155,12 +121,20 @@ enum fc_rport_state {
155 * @port_id: Port ID of the discovered port 121 * @port_id: Port ID of the discovered port
156 */ 122 */
157struct fc_disc_port { 123struct fc_disc_port {
158 struct fc_lport *lp; 124 struct fc_lport *lp;
159 struct list_head peers; 125 struct list_head peers;
160 struct work_struct rport_work; 126 struct work_struct rport_work;
161 u32 port_id; 127 u32 port_id;
162}; 128};
163 129
130/**
131 * enum fc_rport_event - Remote port events
132 * @RPORT_EV_NONE: No event
133 * @RPORT_EV_READY: Remote port is ready for use
134 * @RPORT_EV_FAILED: State machine failed, remote port is not ready
135 * @RPORT_EV_STOP: Remote port has been stopped
136 * @RPORT_EV_LOGO: Remote port logout (LOGO) sent
137 */
164enum fc_rport_event { 138enum fc_rport_event {
165 RPORT_EV_NONE = 0, 139 RPORT_EV_NONE = 0,
166 RPORT_EV_READY, 140 RPORT_EV_READY,
@@ -171,6 +145,10 @@ enum fc_rport_event {
171 145
172struct fc_rport_priv; 146struct fc_rport_priv;
173 147
148/**
149 * struct fc_rport_operations - Operations for a remote port
150 * @event_callback: Function to be called for remote port events
151 */
174struct fc_rport_operations { 152struct fc_rport_operations {
175 void (*event_callback)(struct fc_lport *, struct fc_rport_priv *, 153 void (*event_callback)(struct fc_lport *, struct fc_rport_priv *,
176 enum fc_rport_event); 154 enum fc_rport_event);
@@ -178,11 +156,11 @@ struct fc_rport_operations {
178 156
179/** 157/**
180 * struct fc_rport_libfc_priv - libfc internal information about a remote port 158 * struct fc_rport_libfc_priv - libfc internal information about a remote port
181 * @local_port: Fibre Channel host port instance 159 * @local_port: The associated local port
182 * @rp_state: indicates READY for I/O or DELETE when blocked. 160 * @rp_state: Indicates READY for I/O or DELETE when blocked
183 * @flags: REC and RETRY supported flags 161 * @flags: REC and RETRY supported flags
184 * @e_d_tov: error detect timeout value (in msec) 162 * @e_d_tov: Error detect timeout value (in msec)
185 * @r_a_tov: resource allocation timeout value (in msec) 163 * @r_a_tov: Resource allocation timeout value (in msec)
186 */ 164 */
187struct fc_rport_libfc_priv { 165struct fc_rport_libfc_priv {
188 struct fc_lport *local_port; 166 struct fc_lport *local_port;
@@ -195,47 +173,66 @@ struct fc_rport_libfc_priv {
195}; 173};
196 174
197/** 175/**
198 * struct fc_rport_priv - libfc rport and discovery info about a remote port 176 * struct fc_rport_priv - libfc remote port and discovery info
199 * @local_port: Fibre Channel host port instance 177 * @local_port: The associated local port
200 * @rport: transport remote port 178 * @rport: The FC transport remote port
201 * @kref: reference counter 179 * @kref: Reference counter
202 * @rp_state: state tracks progress of PLOGI, PRLI, and RTV exchanges 180 * @rp_state: Enumeration that tracks progress of PLOGI, PRLI,
203 * @ids: remote port identifiers and roles 181 * and RTV exchanges
204 * @flags: REC and RETRY supported flags 182 * @ids: The remote port identifiers and roles
205 * @max_seq: maximum number of concurrent sequences 183 * @flags: REC and RETRY supported flags
206 * @disc_id: discovery identifier 184 * @max_seq: Maximum number of concurrent sequences
207 * @maxframe_size: maximum frame size 185 * @disc_id: The discovery identifier
208 * @retries: retry count in current state 186 * @maxframe_size: The maximum frame size
209 * @e_d_tov: error detect timeout value (in msec) 187 * @retries: The retry count for the current state
210 * @r_a_tov: resource allocation timeout value (in msec) 188 * @e_d_tov: Error detect timeout value (in msec)
211 * @rp_mutex: mutex protects rport 189 * @r_a_tov: Resource allocation timeout value (in msec)
212 * @retry_work: 190 * @rp_mutex: The mutex that protects the remote port
213 * @event_callback: Callback for rport READY, FAILED or LOGO 191 * @retry_work: Handle for retries
192 * @event_callback: Callback when READY, FAILED or LOGO states complete
214 */ 193 */
215struct fc_rport_priv { 194struct fc_rport_priv {
216 struct fc_lport *local_port; 195 struct fc_lport *local_port;
217 struct fc_rport *rport; 196 struct fc_rport *rport;
218 struct kref kref; 197 struct kref kref;
219 enum fc_rport_state rp_state; 198 enum fc_rport_state rp_state;
220 struct fc_rport_identifiers ids; 199 struct fc_rport_identifiers ids;
221 u16 flags; 200 u16 flags;
222 u16 max_seq; 201 u16 max_seq;
223 u16 disc_id; 202 u16 disc_id;
224 u16 maxframe_size; 203 u16 maxframe_size;
225 unsigned int retries; 204 unsigned int retries;
226 unsigned int e_d_tov; 205 unsigned int e_d_tov;
227 unsigned int r_a_tov; 206 unsigned int r_a_tov;
228 struct mutex rp_mutex; 207 struct mutex rp_mutex;
229 struct delayed_work retry_work; 208 struct delayed_work retry_work;
230 enum fc_rport_event event; 209 enum fc_rport_event event;
231 struct fc_rport_operations *ops; 210 struct fc_rport_operations *ops;
232 struct list_head peers; 211 struct list_head peers;
233 struct work_struct event_work; 212 struct work_struct event_work;
234 u32 supported_classes; 213 u32 supported_classes;
235}; 214};
236 215
237/* 216/**
238 * fcoe stats structure 217 * struct fcoe_dev_stats - fcoe stats structure
218 * @SecondsSinceLastReset: Seconds since the last reset
219 * @TxFrames: Number of transmitted frames
220 * @TxWords: Number of transmitted words
221 * @RxFrames: Number of received frames
222 * @RxWords: Number of received words
223 * @ErrorFrames: Number of received error frames
224 * @DumpedFrames: Number of dumped frames
225 * @LinkFailureCount: Number of link failures
226 * @LossOfSignalCount: Number for signal losses
227 * @InvalidTxWordCount: Number of invalid transmitted words
228 * @InvalidCRCCount: Number of invalid CRCs
229 * @InputRequests: Number of input requests
230 * @OutputRequests: Number of output requests
231 * @ControlRequests: Number of control requests
232 * @InputMegabytes: Number of received megabytes
233 * @OutputMegabytes: Number of transmitted megabytes
234 * @VLinkFailureCount: Number of virtual link failures
235 * @MissDiscAdvCount: Number of missing FIP discovery advertisement
239 */ 236 */
240struct fcoe_dev_stats { 237struct fcoe_dev_stats {
241 u64 SecondsSinceLastReset; 238 u64 SecondsSinceLastReset;
@@ -254,12 +251,17 @@ struct fcoe_dev_stats {
254 u64 ControlRequests; 251 u64 ControlRequests;
255 u64 InputMegabytes; 252 u64 InputMegabytes;
256 u64 OutputMegabytes; 253 u64 OutputMegabytes;
254 u64 VLinkFailureCount;
255 u64 MissDiscAdvCount;
257}; 256};
258 257
259/* 258/**
260 * els data is used for passing ELS respone specific 259 * struct fc_seq_els_data - ELS data used for passing ELS specific responses
261 * data to send ELS response mainly using infomation 260 * @fp: The ELS frame
262 * in exchange and sequence in EM layer. 261 * @reason: The reason for rejection
262 * @explan: The explaination of the rejection
263 *
264 * Mainly used by the exchange manager layer.
263 */ 265 */
264struct fc_seq_els_data { 266struct fc_seq_els_data {
265 struct fc_frame *fp; 267 struct fc_frame *fp;
@@ -267,77 +269,87 @@ struct fc_seq_els_data {
267 enum fc_els_rjt_explan explan; 269 enum fc_els_rjt_explan explan;
268}; 270};
269 271
270/* 272/**
271 * FCP request structure, one for each scsi cmd request 273 * struct fc_fcp_pkt - FCP request structure (one for each scsi_cmnd request)
274 * @lp: The associated local port
275 * @state: The state of the I/O
276 * @tgt_flags: Target's flags
277 * @ref_cnt: Reference count
278 * @scsi_pkt_lock: Lock to protect the SCSI packet (must be taken before the
279 * host_lock if both are to be held at the same time)
280 * @cmd: The SCSI command (set and clear with the host_lock held)
281 * @list: Tracks queued commands (accessed with the host_lock held)
282 * @timer: The command timer
283 * @tm_done: Completion indicator
284 * @wait_for_comp: Indicator to wait for completion of the I/O (in jiffies)
285 * @start_time: Timestamp indicating the start of the I/O (in jiffies)
286 * @end_time: Timestamp indicating the end of the I/O (in jiffies)
287 * @last_pkt_time: Timestamp of the last frame received (in jiffies)
288 * @data_len: The length of the data
289 * @cdb_cmd: The CDB command
290 * @xfer_len: The transfer length
291 * @xfer_ddp: Indicates if this transfer used DDP (XID of the exchange
292 * will be set here if DDP was setup)
293 * @xfer_contig_end: The offset into the buffer if the buffer is contiguous
294 * (Tx and Rx)
295 * @max_payload: The maximum payload size (in bytes)
296 * @io_status: SCSI result (upper 24 bits)
297 * @cdb_status: CDB status
298 * @status_code: FCP I/O status
299 * @scsi_comp_flags: Completion flags (bit 3 Underrun bit 2: overrun)
300 * @req_flags: Request flags (bit 0: read bit:1 write)
301 * @scsi_resid: SCSI residule length
302 * @rport: The remote port that the SCSI command is targeted at
303 * @seq_ptr: The sequence that will carry the SCSI command
304 * @recov_retry: Number of recovery retries
305 * @recov_seq: The sequence for REC or SRR
272 */ 306 */
273struct fc_fcp_pkt { 307struct fc_fcp_pkt {
274 /* 308 /* Housekeeping information */
275 * housekeeping stuff 309 struct fc_lport *lp;
276 */ 310 u16 state;
277 struct fc_lport *lp; /* handle to hba struct */ 311 u16 tgt_flags;
278 u16 state; /* scsi_pkt state state */ 312 atomic_t ref_cnt;
279 u16 tgt_flags; /* target flags */ 313 spinlock_t scsi_pkt_lock;
280 atomic_t ref_cnt; /* fcp pkt ref count */ 314
281 spinlock_t scsi_pkt_lock; /* Must be taken before the host lock 315 /* SCSI I/O related information */
282 * if both are held at the same time */ 316 struct scsi_cmnd *cmd;
283 /* 317 struct list_head list;
284 * SCSI I/O related stuff 318
285 */ 319 /* Timeout related information */
286 struct scsi_cmnd *cmd; /* scsi command pointer. set/clear 320 struct timer_list timer;
287 * under host lock */
288 struct list_head list; /* tracks queued commands. access under
289 * host lock */
290 /*
291 * timeout related stuff
292 */
293 struct timer_list timer; /* command timer */
294 struct completion tm_done; 321 struct completion tm_done;
295 int wait_for_comp; 322 int wait_for_comp;
296 unsigned long start_time; /* start jiffie */ 323 unsigned long start_time;
297 unsigned long end_time; /* end jiffie */ 324 unsigned long end_time;
298 unsigned long last_pkt_time; /* jiffies of last frame received */ 325 unsigned long last_pkt_time;
299 326
300 /* 327 /* SCSI command and data transfer information */
301 * scsi cmd and data transfer information 328 u32 data_len;
302 */ 329
303 u32 data_len; 330 /* Transport related veriables */
304 /* 331 struct fcp_cmnd cdb_cmd;
305 * transport related veriables 332 size_t xfer_len;
306 */ 333 u16 xfer_ddp;
307 struct fcp_cmnd cdb_cmd; 334 u32 xfer_contig_end;
308 size_t xfer_len; 335 u16 max_payload;
309 u16 xfer_ddp; /* this xfer is ddped */ 336
310 u32 xfer_contig_end; /* offset of end of contiguous xfer */ 337 /* SCSI/FCP return status */
311 u16 max_payload; /* max payload size in bytes */ 338 u32 io_status;
312 339 u8 cdb_status;
313 /* 340 u8 status_code;
314 * scsi/fcp return status 341 u8 scsi_comp_flags;
315 */ 342 u32 req_flags;
316 u32 io_status; /* SCSI result upper 24 bits */ 343 u32 scsi_resid;
317 u8 cdb_status; 344
318 u8 status_code; /* FCP I/O status */ 345 /* Associated structures */
319 /* bit 3 Underrun bit 2: overrun */ 346 struct fc_rport *rport;
320 u8 scsi_comp_flags; 347 struct fc_seq *seq_ptr;
321 u32 req_flags; /* bit 0: read bit:1 write */ 348
322 u32 scsi_resid; /* residule length */ 349 /* Error Processing information */
323 350 u8 recov_retry;
324 struct fc_rport *rport; /* remote port pointer */ 351 struct fc_seq *recov_seq;
325 struct fc_seq *seq_ptr; /* current sequence pointer */
326 /*
327 * Error Processing
328 */
329 u8 recov_retry; /* count of recovery retries */
330 struct fc_seq *recov_seq; /* sequence for REC or SRR */
331}; 352};
332/*
333 * FC_FCP HELPER FUNCTIONS
334 *****************************/
335static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp)
336{
337 if (fsp && fsp->cmd)
338 return fsp->cmd->sc_data_direction == DMA_FROM_DEVICE;
339 return false;
340}
341 353
342/* 354/*
343 * Structure and function definitions for managing Fibre Channel Exchanges 355 * Structure and function definitions for managing Fibre Channel Exchanges
@@ -350,23 +362,51 @@ static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp)
350 362
351struct fc_exch_mgr; 363struct fc_exch_mgr;
352struct fc_exch_mgr_anchor; 364struct fc_exch_mgr_anchor;
353extern u16 fc_cpu_mask; /* cpu mask for possible cpus */ 365extern u16 fc_cpu_mask; /* cpu mask for possible cpus */
354 366
355/* 367/**
356 * Sequence. 368 * struct fc_seq - FC sequence
369 * @id: The sequence ID
370 * @ssb_stat: Status flags for the sequence status block (SSB)
371 * @cnt: Number of frames sent so far
372 * @rec_data: FC-4 value for REC
357 */ 373 */
358struct fc_seq { 374struct fc_seq {
359 u8 id; /* seq ID */ 375 u8 id;
360 u16 ssb_stat; /* status flags for sequence status block */ 376 u16 ssb_stat;
361 u16 cnt; /* frames sent so far on sequence */ 377 u16 cnt;
362 u32 rec_data; /* FC-4 value for REC */ 378 u32 rec_data;
363}; 379};
364 380
365#define FC_EX_DONE (1 << 0) /* ep is completed */ 381#define FC_EX_DONE (1 << 0) /* ep is completed */
366#define FC_EX_RST_CLEANUP (1 << 1) /* reset is forcing completion */ 382#define FC_EX_RST_CLEANUP (1 << 1) /* reset is forcing completion */
367 383
368/* 384/**
369 * Exchange. 385 * struct fc_exch - Fibre Channel Exchange
386 * @em: Exchange manager
387 * @pool: Exchange pool
388 * @state: The exchange's state
389 * @xid: The exchange ID
390 * @ex_list: Handle used by the EM to track free exchanges
391 * @ex_lock: Lock that protects the exchange
392 * @ex_refcnt: Reference count
393 * @timeout_work: Handle for timeout handler
394 * @lp: The local port that this exchange is on
395 * @oxid: Originator's exchange ID
396 * @rxid: Responder's exchange ID
397 * @oid: Originator's FCID
398 * @sid: Source FCID
399 * @did: Destination FCID
400 * @esb_stat: ESB exchange status
401 * @r_a_tov: Resouce allocation time out value (in msecs)
402 * @seq_id: The next sequence ID to use
403 * @f_ctl: F_CTL flags for the sequence
404 * @fh_type: The frame type
405 * @class: The class of service
406 * @seq: The sequence in use on this exchange
407 * @resp: Callback for responses on this exchange
408 * @destructor: Called when destroying the exchange
409 * @arg: Passed as a void pointer to the resp() callback
370 * 410 *
371 * Locking notes: The ex_lock protects following items: 411 * Locking notes: The ex_lock protects following items:
372 * state, esb_stat, f_ctl, seq.ssb_stat 412 * state, esb_stat, f_ctl, seq.ssb_stat
@@ -374,76 +414,59 @@ struct fc_seq {
374 * sequence allocation 414 * sequence allocation
375 */ 415 */
376struct fc_exch { 416struct fc_exch {
377 struct fc_exch_mgr *em; /* exchange manager */ 417 struct fc_exch_mgr *em;
378 struct fc_exch_pool *pool; /* per cpu exches pool */ 418 struct fc_exch_pool *pool;
379 u32 state; /* internal driver state */ 419 u32 state;
380 u16 xid; /* our exchange ID */ 420 u16 xid;
381 struct list_head ex_list; /* free or busy list linkage */ 421 struct list_head ex_list;
382 spinlock_t ex_lock; /* lock covering exchange state */ 422 spinlock_t ex_lock;
383 atomic_t ex_refcnt; /* reference counter */ 423 atomic_t ex_refcnt;
384 struct delayed_work timeout_work; /* timer for upper level protocols */ 424 struct delayed_work timeout_work;
385 struct fc_lport *lp; /* fc device instance */ 425 struct fc_lport *lp;
386 u16 oxid; /* originator's exchange ID */ 426 u16 oxid;
387 u16 rxid; /* responder's exchange ID */ 427 u16 rxid;
388 u32 oid; /* originator's FCID */ 428 u32 oid;
389 u32 sid; /* source FCID */ 429 u32 sid;
390 u32 did; /* destination FCID */ 430 u32 did;
391 u32 esb_stat; /* exchange status for ESB */ 431 u32 esb_stat;
392 u32 r_a_tov; /* r_a_tov from rport (msec) */ 432 u32 r_a_tov;
393 u8 seq_id; /* next sequence ID to use */ 433 u8 seq_id;
394 u32 f_ctl; /* F_CTL flags for sequences */ 434 u32 f_ctl;
395 u8 fh_type; /* frame type */ 435 u8 fh_type;
396 enum fc_class class; /* class of service */ 436 enum fc_class class;
397 struct fc_seq seq; /* single sequence */ 437 struct fc_seq seq;
398 /* 438
399 * Handler for responses to this current exchange. 439 void (*resp)(struct fc_seq *, struct fc_frame *, void *);
400 */ 440 void *arg;
401 void (*resp)(struct fc_seq *, struct fc_frame *, void *); 441
402 void (*destructor)(struct fc_seq *, void *); 442 void (*destructor)(struct fc_seq *, void *);
403 /* 443
404 * arg is passed as void pointer to exchange
405 * resp and destructor handlers
406 */
407 void *arg;
408}; 444};
409#define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq) 445#define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
410 446
411struct libfc_function_template {
412 447
448struct libfc_function_template {
413 /* 449 /*
414 * Interface to send a FC frame 450 * Interface to send a FC frame
415 * 451 *
416 * STATUS: REQUIRED 452 * STATUS: REQUIRED
417 */ 453 */
418 int (*frame_send)(struct fc_lport *lp, struct fc_frame *fp); 454 int (*frame_send)(struct fc_lport *, struct fc_frame *);
419 455
420 /* 456 /*
421 * Interface to send ELS/CT frames 457 * Interface to send ELS/CT frames
422 * 458 *
423 * STATUS: OPTIONAL 459 * STATUS: OPTIONAL
424 */ 460 */
425 struct fc_seq *(*elsct_send)(struct fc_lport *lport, 461 struct fc_seq *(*elsct_send)(struct fc_lport *, u32 did,
426 u32 did, 462 struct fc_frame *, unsigned int op,
427 struct fc_frame *fp,
428 unsigned int op,
429 void (*resp)(struct fc_seq *, 463 void (*resp)(struct fc_seq *,
430 struct fc_frame *fp, 464 struct fc_frame *, void *arg),
431 void *arg),
432 void *arg, u32 timer_msec); 465 void *arg, u32 timer_msec);
433 466
434 /* 467 /*
435 * Send the FC frame payload using a new exchange and sequence. 468 * Send the FC frame payload using a new exchange and sequence.
436 * 469 *
437 * The frame pointer with some of the header's fields must be
438 * filled before calling exch_seq_send(), those fields are,
439 *
440 * - routing control
441 * - FC port did
442 * - FC port sid
443 * - FC header type
444 * - frame control
445 * - parameter or relative offset
446 *
447 * The exchange response handler is set in this routine to resp() 470 * The exchange response handler is set in this routine to resp()
448 * function pointer. It can be called in two scenarios: if a timeout 471 * function pointer. It can be called in two scenarios: if a timeout
449 * occurs or if a response frame is received for the exchange. The 472 * occurs or if a response frame is received for the exchange. The
@@ -464,14 +487,13 @@ struct libfc_function_template {
464 * 487 *
465 * STATUS: OPTIONAL 488 * STATUS: OPTIONAL
466 */ 489 */
467 struct fc_seq *(*exch_seq_send)(struct fc_lport *lp, 490 struct fc_seq *(*exch_seq_send)(struct fc_lport *, struct fc_frame *,
468 struct fc_frame *fp, 491 void (*resp)(struct fc_seq *,
469 void (*resp)(struct fc_seq *sp, 492 struct fc_frame *,
470 struct fc_frame *fp, 493 void *),
471 void *arg), 494 void (*destructor)(struct fc_seq *,
472 void (*destructor)(struct fc_seq *sp, 495 void *),
473 void *arg), 496 void *, unsigned int timer_msec);
474 void *arg, unsigned int timer_msec);
475 497
476 /* 498 /*
477 * Sets up the DDP context for a given exchange id on the given 499 * Sets up the DDP context for a given exchange id on the given
@@ -479,22 +501,28 @@ struct libfc_function_template {
479 * 501 *
480 * STATUS: OPTIONAL 502 * STATUS: OPTIONAL
481 */ 503 */
482 int (*ddp_setup)(struct fc_lport *lp, u16 xid, 504 int (*ddp_setup)(struct fc_lport *, u16, struct scatterlist *,
483 struct scatterlist *sgl, unsigned int sgc); 505 unsigned int);
484 /* 506 /*
485 * Completes the DDP transfer and returns the length of data DDPed 507 * Completes the DDP transfer and returns the length of data DDPed
486 * for the given exchange id. 508 * for the given exchange id.
487 * 509 *
488 * STATUS: OPTIONAL 510 * STATUS: OPTIONAL
489 */ 511 */
490 int (*ddp_done)(struct fc_lport *lp, u16 xid); 512 int (*ddp_done)(struct fc_lport *, u16);
513 /*
514 * Allow LLD to fill its own Link Error Status Block
515 *
516 * STATUS: OPTIONAL
517 */
518 void (*get_lesb)(struct fc_lport *, struct fc_els_lesb *lesb);
491 /* 519 /*
492 * Send a frame using an existing sequence and exchange. 520 * Send a frame using an existing sequence and exchange.
493 * 521 *
494 * STATUS: OPTIONAL 522 * STATUS: OPTIONAL
495 */ 523 */
496 int (*seq_send)(struct fc_lport *lp, struct fc_seq *sp, 524 int (*seq_send)(struct fc_lport *, struct fc_seq *,
497 struct fc_frame *fp); 525 struct fc_frame *);
498 526
499 /* 527 /*
500 * Send an ELS response using infomation from a previous 528 * Send an ELS response using infomation from a previous
@@ -502,8 +530,8 @@ struct libfc_function_template {
502 * 530 *
503 * STATUS: OPTIONAL 531 * STATUS: OPTIONAL
504 */ 532 */
505 void (*seq_els_rsp_send)(struct fc_seq *sp, enum fc_els_cmd els_cmd, 533 void (*seq_els_rsp_send)(struct fc_seq *, enum fc_els_cmd,
506 struct fc_seq_els_data *els_data); 534 struct fc_seq_els_data *);
507 535
508 /* 536 /*
509 * Abort an exchange and sequence. Generally called because of a 537 * Abort an exchange and sequence. Generally called because of a
@@ -515,7 +543,7 @@ struct libfc_function_template {
515 * 543 *
516 * STATUS: OPTIONAL 544 * STATUS: OPTIONAL
517 */ 545 */
518 int (*seq_exch_abort)(const struct fc_seq *req_sp, 546 int (*seq_exch_abort)(const struct fc_seq *,
519 unsigned int timer_msec); 547 unsigned int timer_msec);
520 548
521 /* 549 /*
@@ -524,14 +552,14 @@ struct libfc_function_template {
524 * 552 *
525 * STATUS: OPTIONAL 553 * STATUS: OPTIONAL
526 */ 554 */
527 void (*exch_done)(struct fc_seq *sp); 555 void (*exch_done)(struct fc_seq *);
528 556
529 /* 557 /*
530 * Start a new sequence on the same exchange/sequence tuple. 558 * Start a new sequence on the same exchange/sequence tuple.
531 * 559 *
532 * STATUS: OPTIONAL 560 * STATUS: OPTIONAL
533 */ 561 */
534 struct fc_seq *(*seq_start_next)(struct fc_seq *sp); 562 struct fc_seq *(*seq_start_next)(struct fc_seq *);
535 563
536 /* 564 /*
537 * Reset an exchange manager, completing all sequences and exchanges. 565 * Reset an exchange manager, completing all sequences and exchanges.
@@ -540,8 +568,7 @@ struct libfc_function_template {
540 * 568 *
541 * STATUS: OPTIONAL 569 * STATUS: OPTIONAL
542 */ 570 */
543 void (*exch_mgr_reset)(struct fc_lport *, 571 void (*exch_mgr_reset)(struct fc_lport *, u32 s_id, u32 d_id);
544 u32 s_id, u32 d_id);
545 572
546 /* 573 /*
547 * Flush the rport work queue. Generally used before shutdown. 574 * Flush the rport work queue. Generally used before shutdown.
@@ -555,8 +582,8 @@ struct libfc_function_template {
555 * 582 *
556 * STATUS: OPTIONAL 583 * STATUS: OPTIONAL
557 */ 584 */
558 void (*lport_recv)(struct fc_lport *lp, struct fc_seq *sp, 585 void (*lport_recv)(struct fc_lport *, struct fc_seq *,
559 struct fc_frame *fp); 586 struct fc_frame *);
560 587
561 /* 588 /*
562 * Reset the local port. 589 * Reset the local port.
@@ -566,6 +593,26 @@ struct libfc_function_template {
566 int (*lport_reset)(struct fc_lport *); 593 int (*lport_reset)(struct fc_lport *);
567 594
568 /* 595 /*
596 * Set the local port FC_ID.
597 *
598 * This may be provided by the LLD to allow it to be
599 * notified when the local port is assigned a FC-ID.
600 *
601 * The frame, if non-NULL, is the incoming frame with the
602 * FLOGI LS_ACC or FLOGI, and may contain the granted MAC
603 * address for the LLD. The frame pointer may be NULL if
604 * no MAC is associated with this assignment (LOGO or PLOGI).
605 *
606 * If FC_ID is non-zero, r_a_tov and e_d_tov must be valid.
607 *
608 * Note: this is called with the local port mutex held.
609 *
610 * STATUS: OPTIONAL
611 */
612 void (*lport_set_port_id)(struct fc_lport *, u32 port_id,
613 struct fc_frame *);
614
615 /*
569 * Create a remote port with a given port ID 616 * Create a remote port with a given port ID
570 * 617 *
571 * STATUS: OPTIONAL 618 * STATUS: OPTIONAL
@@ -622,31 +669,31 @@ struct libfc_function_template {
622 * 669 *
623 * STATUS: OPTIONAL 670 * STATUS: OPTIONAL
624 */ 671 */
625 int (*fcp_cmd_send)(struct fc_lport *lp, struct fc_fcp_pkt *fsp, 672 int (*fcp_cmd_send)(struct fc_lport *, struct fc_fcp_pkt *,
626 void (*resp)(struct fc_seq *, struct fc_frame *fp, 673 void (*resp)(struct fc_seq *, struct fc_frame *,
627 void *arg)); 674 void *));
628 675
629 /* 676 /*
630 * Cleanup the FCP layer, used durring link down and reset 677 * Cleanup the FCP layer, used durring link down and reset
631 * 678 *
632 * STATUS: OPTIONAL 679 * STATUS: OPTIONAL
633 */ 680 */
634 void (*fcp_cleanup)(struct fc_lport *lp); 681 void (*fcp_cleanup)(struct fc_lport *);
635 682
636 /* 683 /*
637 * Abort all I/O on a local port 684 * Abort all I/O on a local port
638 * 685 *
639 * STATUS: OPTIONAL 686 * STATUS: OPTIONAL
640 */ 687 */
641 void (*fcp_abort_io)(struct fc_lport *lp); 688 void (*fcp_abort_io)(struct fc_lport *);
642 689
643 /* 690 /*
644 * Receive a request for the discovery layer. 691 * Receive a request for the discovery layer.
645 * 692 *
646 * STATUS: OPTIONAL 693 * STATUS: OPTIONAL
647 */ 694 */
648 void (*disc_recv_req)(struct fc_seq *, 695 void (*disc_recv_req)(struct fc_seq *, struct fc_frame *,
649 struct fc_frame *, struct fc_lport *); 696 struct fc_lport *);
650 697
651 /* 698 /*
652 * Start discovery for a local port. 699 * Start discovery for a local port.
@@ -675,419 +722,340 @@ struct libfc_function_template {
675 void (*disc_stop_final) (struct fc_lport *); 722 void (*disc_stop_final) (struct fc_lport *);
676}; 723};
677 724
678/* information used by the discovery layer */ 725/**
726 * struct fc_disc - Discovery context
727 * @retry_count: Number of retries
728 * @pending: 1 if discovery is pending, 0 if not
729 * @requesting: 1 if discovery has been requested, 0 if not
730 * @seq_count: Number of sequences used for discovery
731 * @buf_len: Length of the discovery buffer
732 * @disc_id: Discovery ID
733 * @rports: List of discovered remote ports
734 * @lport: The local port that discovery is for
735 * @disc_mutex: Mutex that protects the discovery context
736 * @partial_buf: Partial name buffer (if names are returned
737 * in multiple frames)
738 * @disc_work: handle for delayed work context
739 * @disc_callback: Callback routine called when discovery completes
740 */
679struct fc_disc { 741struct fc_disc {
680 unsigned char retry_count; 742 unsigned char retry_count;
681 unsigned char pending; 743 unsigned char pending;
682 unsigned char requested; 744 unsigned char requested;
683 unsigned short seq_count; 745 unsigned short seq_count;
684 unsigned char buf_len; 746 unsigned char buf_len;
685 u16 disc_id; 747 u16 disc_id;
748
749 struct list_head rports;
750 struct fc_lport *lport;
751 struct mutex disc_mutex;
752 struct fc_gpn_ft_resp partial_buf;
753 struct delayed_work disc_work;
686 754
687 void (*disc_callback)(struct fc_lport *, 755 void (*disc_callback)(struct fc_lport *,
688 enum fc_disc_event); 756 enum fc_disc_event);
689
690 struct list_head rports;
691 struct fc_lport *lport;
692 struct mutex disc_mutex;
693 struct fc_gpn_ft_resp partial_buf; /* partial name buffer */
694 struct delayed_work disc_work;
695}; 757};
696 758
759/**
760 * struct fc_lport - Local port
761 * @host: The SCSI host associated with a local port
762 * @ema_list: Exchange manager anchor list
763 * @dns_rdata: The directory server remote port
764 * @ptp_rdata: Point to point remote port
765 * @scsi_priv: FCP layer internal data
766 * @disc: Discovery context
767 * @vports: Child vports if N_Port
768 * @vport: Parent vport if VN_Port
769 * @tt: Libfc function template
770 * @link_up: Link state (1 = link up, 0 = link down)
771 * @qfull: Queue state (1 queue is full, 0 queue is not full)
772 * @state: Identifies the state
773 * @boot_time: Timestamp indicating when the local port came online
774 * @host_stats: SCSI host statistics
775 * @dev_stats: FCoE device stats (TODO: libfc should not be
776 * FCoE aware)
777 * @retry_count: Number of retries in the current state
778 * @wwpn: World Wide Port Name
779 * @wwnn: World Wide Node Name
780 * @service_params: Common service parameters
781 * @e_d_tov: Error detection timeout value
782 * @r_a_tov: Resouce allocation timeout value
783 * @rnid_gen: RNID information
784 * @sg_supp: Indicates if scatter gather is supported
785 * @seq_offload: Indicates if sequence offload is supported
786 * @crc_offload: Indicates if CRC offload is supported
787 * @lro_enabled: Indicates if large receive offload is supported
788 * @does_npiv: Supports multiple vports
789 * @npiv_enabled: Switch/fabric allows NPIV
790 * @mfs: The maximum Fibre Channel payload size
791 * @max_retry_count: The maximum retry attempts
792 * @max_rport_retry_count: The maximum remote port retry attempts
793 * @lro_xid: The maximum XID for LRO
794 * @lso_max: The maximum large offload send size
795 * @fcts: FC-4 type mask
796 * @lp_mutex: Mutex to protect the local port
797 * @list: Handle for list of local ports
798 * @retry_work: Handle to local port for delayed retry context
799 */
697struct fc_lport { 800struct fc_lport {
698 struct list_head list;
699
700 /* Associations */ 801 /* Associations */
701 struct Scsi_Host *host; 802 struct Scsi_Host *host;
702 struct list_head ema_list; 803 struct list_head ema_list;
703 struct fc_rport_priv *dns_rp; 804 struct fc_rport_priv *dns_rdata;
704 struct fc_rport_priv *ptp_rp; 805 struct fc_rport_priv *ptp_rdata;
705 void *scsi_priv; 806 void *scsi_priv;
706 struct fc_disc disc; 807 struct fc_disc disc;
808
809 /* Virtual port information */
810 struct list_head vports;
811 struct fc_vport *vport;
707 812
708 /* Operational Information */ 813 /* Operational Information */
709 struct libfc_function_template tt; 814 struct libfc_function_template tt;
710 u8 link_up; 815 u8 link_up;
711 u8 qfull; 816 u8 qfull;
712 enum fc_lport_state state; 817 enum fc_lport_state state;
713 unsigned long boot_time; 818 unsigned long boot_time;
714 819 struct fc_host_statistics host_stats;
715 struct fc_host_statistics host_stats; 820 struct fcoe_dev_stats *dev_stats;
716 struct fcoe_dev_stats *dev_stats; 821 u8 retry_count;
717 822
718 u64 wwpn; 823 /* Fabric information */
719 u64 wwnn; 824 u64 wwpn;
720 u8 retry_count; 825 u64 wwnn;
826 unsigned int service_params;
827 unsigned int e_d_tov;
828 unsigned int r_a_tov;
829 struct fc_els_rnid_gen rnid_gen;
721 830
722 /* Capabilities */ 831 /* Capabilities */
723 u32 sg_supp:1; /* scatter gather supported */ 832 u32 sg_supp:1;
724 u32 seq_offload:1; /* seq offload supported */ 833 u32 seq_offload:1;
725 u32 crc_offload:1; /* crc offload supported */ 834 u32 crc_offload:1;
726 u32 lro_enabled:1; /* large receive offload */ 835 u32 lro_enabled:1;
727 u32 mfs; /* max FC payload size */ 836 u32 does_npiv:1;
728 unsigned int service_params; 837 u32 npiv_enabled:1;
729 unsigned int e_d_tov; 838 u32 mfs;
730 unsigned int r_a_tov; 839 u8 max_retry_count;
731 u8 max_retry_count; 840 u8 max_rport_retry_count;
732 u8 max_rport_retry_count; 841 u16 link_speed;
733 u16 link_speed; 842 u16 link_supported_speeds;
734 u16 link_supported_speeds; 843 u16 lro_xid;
735 u16 lro_xid; /* max xid for fcoe lro */ 844 unsigned int lso_max;
736 unsigned int lso_max; /* max large send size */ 845 struct fc_ns_fts fcts;
737 struct fc_ns_fts fcts; /* FC-4 type masks */
738 struct fc_els_rnid_gen rnid_gen; /* RNID information */
739
740 /* Semaphores */
741 struct mutex lp_mutex;
742 846
743 /* Miscellaneous */ 847 /* Miscellaneous */
744 struct delayed_work retry_work; 848 struct mutex lp_mutex;
745 struct delayed_work disc_work; 849 struct list_head list;
850 struct delayed_work retry_work;
746}; 851};
747 852
748/* 853/*
749 * FC_LPORT HELPER FUNCTIONS 854 * FC_LPORT HELPER FUNCTIONS
750 *****************************/ 855 *****************************/
751static inline int fc_lport_test_ready(struct fc_lport *lp) 856
857/**
858 * fc_lport_test_ready() - Determine if a local port is in the READY state
859 * @lport: The local port to test
860 */
861static inline int fc_lport_test_ready(struct fc_lport *lport)
752{ 862{
753 return lp->state == LPORT_ST_READY; 863 return lport->state == LPORT_ST_READY;
754} 864}
755 865
756static inline void fc_set_wwnn(struct fc_lport *lp, u64 wwnn) 866/**
867 * fc_set_wwnn() - Set the World Wide Node Name of a local port
868 * @lport: The local port whose WWNN is to be set
869 * @wwnn: The new WWNN
870 */
871static inline void fc_set_wwnn(struct fc_lport *lport, u64 wwnn)
757{ 872{
758 lp->wwnn = wwnn; 873 lport->wwnn = wwnn;
759} 874}
760 875
761static inline void fc_set_wwpn(struct fc_lport *lp, u64 wwnn) 876/**
877 * fc_set_wwpn() - Set the World Wide Port Name of a local port
878 * @lport: The local port whose WWPN is to be set
879 * @wwnn: The new WWPN
880 */
881static inline void fc_set_wwpn(struct fc_lport *lport, u64 wwnn)
762{ 882{
763 lp->wwpn = wwnn; 883 lport->wwpn = wwnn;
764} 884}
765 885
766static inline void fc_lport_state_enter(struct fc_lport *lp, 886/**
887 * fc_lport_state_enter() - Change a local port's state
888 * @lport: The local port whose state is to change
889 * @state: The new state
890 */
891static inline void fc_lport_state_enter(struct fc_lport *lport,
767 enum fc_lport_state state) 892 enum fc_lport_state state)
768{ 893{
769 if (state != lp->state) 894 if (state != lport->state)
770 lp->retry_count = 0; 895 lport->retry_count = 0;
771 lp->state = state; 896 lport->state = state;
772} 897}
773 898
774static inline int fc_lport_init_stats(struct fc_lport *lp) 899/**
900 * fc_lport_init_stats() - Allocate per-CPU statistics for a local port
901 * @lport: The local port whose statistics are to be initialized
902 */
903static inline int fc_lport_init_stats(struct fc_lport *lport)
775{ 904{
776 /* allocate per cpu stats block */ 905 lport->dev_stats = alloc_percpu(struct fcoe_dev_stats);
777 lp->dev_stats = alloc_percpu(struct fcoe_dev_stats); 906 if (!lport->dev_stats)
778 if (!lp->dev_stats)
779 return -ENOMEM; 907 return -ENOMEM;
780 return 0; 908 return 0;
781} 909}
782 910
783static inline void fc_lport_free_stats(struct fc_lport *lp) 911/**
912 * fc_lport_free_stats() - Free memory for a local port's statistics
913 * @lport: The local port whose statistics are to be freed
914 */
915static inline void fc_lport_free_stats(struct fc_lport *lport)
784{ 916{
785 free_percpu(lp->dev_stats); 917 free_percpu(lport->dev_stats);
786} 918}
787 919
788static inline struct fcoe_dev_stats *fc_lport_get_stats(struct fc_lport *lp) 920/**
921 * fc_lport_get_stats() - Get a local port's statistics
922 * @lport: The local port whose statistics are to be retreived
923 */
924static inline struct fcoe_dev_stats *fc_lport_get_stats(struct fc_lport *lport)
789{ 925{
790 return per_cpu_ptr(lp->dev_stats, smp_processor_id()); 926 return per_cpu_ptr(lport->dev_stats, smp_processor_id());
791} 927}
792 928
793static inline void *lport_priv(const struct fc_lport *lp) 929/**
930 * lport_priv() - Return the private data from a local port
931 * @lport: The local port whose private data is to be retreived
932 */
933static inline void *lport_priv(const struct fc_lport *lport)
794{ 934{
795 return (void *)(lp + 1); 935 return (void *)(lport + 1);
796} 936}
797 937
798/** 938/**
799 * libfc_host_alloc() - Allocate a Scsi_Host with room for the fc_lport 939 * libfc_host_alloc() - Allocate a Scsi_Host with room for a local port and
800 * @sht: ptr to the scsi host templ 940 * LLD private data
801 * @priv_size: size of private data after fc_lport 941 * @sht: The SCSI host template
942 * @priv_size: Size of private data
802 * 943 *
803 * Returns: ptr to Scsi_Host 944 * Returns: libfc lport
804 */ 945 */
805static inline struct Scsi_Host * 946static inline struct fc_lport *
806libfc_host_alloc(struct scsi_host_template *sht, int priv_size) 947libfc_host_alloc(struct scsi_host_template *sht, int priv_size)
807{ 948{
808 return scsi_host_alloc(sht, sizeof(struct fc_lport) + priv_size); 949 struct fc_lport *lport;
950 struct Scsi_Host *shost;
951
952 shost = scsi_host_alloc(sht, sizeof(*lport) + priv_size);
953 if (!shost)
954 return NULL;
955 lport = shost_priv(shost);
956 lport->host = shost;
957 INIT_LIST_HEAD(&lport->ema_list);
958 INIT_LIST_HEAD(&lport->vports);
959 return lport;
809} 960}
810 961
811/* 962/*
812 * LOCAL PORT LAYER 963 * FC_FCP HELPER FUNCTIONS
813 *****************************/ 964 *****************************/
814int fc_lport_init(struct fc_lport *lp); 965static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp)
815 966{
816/* 967 if (fsp && fsp->cmd)
817 * Destroy the specified local port by finding and freeing all 968 return fsp->cmd->sc_data_direction == DMA_FROM_DEVICE;
818 * fc_rports associated with it and then by freeing the fc_lport 969 return false;
819 * itself. 970}
820 */
821int fc_lport_destroy(struct fc_lport *lp);
822
823/*
824 * Logout the specified local port from the fabric
825 */
826int fc_fabric_logoff(struct fc_lport *lp);
827
828/*
829 * Initiate the LP state machine. This handler will use fc_host_attr
830 * to store the FLOGI service parameters, so fc_host_attr must be
831 * initialized before calling this handler.
832 */
833int fc_fabric_login(struct fc_lport *lp);
834 971
835/* 972/*
836 * The link is up for the given local port. 973 * LOCAL PORT LAYER
837 */ 974 *****************************/
975int fc_lport_init(struct fc_lport *);
976int fc_lport_destroy(struct fc_lport *);
977int fc_fabric_logoff(struct fc_lport *);
978int fc_fabric_login(struct fc_lport *);
979void __fc_linkup(struct fc_lport *);
838void fc_linkup(struct fc_lport *); 980void fc_linkup(struct fc_lport *);
839 981void __fc_linkdown(struct fc_lport *);
840/*
841 * Link is down for the given local port.
842 */
843void fc_linkdown(struct fc_lport *); 982void fc_linkdown(struct fc_lport *);
844 983void fc_vport_setlink(struct fc_lport *);
845/* 984void fc_vports_linkchange(struct fc_lport *);
846 * Configure the local port.
847 */
848int fc_lport_config(struct fc_lport *); 985int fc_lport_config(struct fc_lport *);
849
850/*
851 * Reset the local port.
852 */
853int fc_lport_reset(struct fc_lport *); 986int fc_lport_reset(struct fc_lport *);
854 987int fc_set_mfs(struct fc_lport *, u32 mfs);
855/* 988struct fc_lport *libfc_vport_create(struct fc_vport *, int privsize);
856 * Set the mfs or reset 989struct fc_lport *fc_vport_id_lookup(struct fc_lport *, u32 port_id);
857 */ 990int fc_lport_bsg_request(struct fc_bsg_job *);
858int fc_set_mfs(struct fc_lport *lp, u32 mfs);
859
860 991
861/* 992/*
862 * REMOTE PORT LAYER 993 * REMOTE PORT LAYER
863 *****************************/ 994 *****************************/
864int fc_rport_init(struct fc_lport *lp); 995int fc_rport_init(struct fc_lport *);
865void fc_rport_terminate_io(struct fc_rport *rp); 996void fc_rport_terminate_io(struct fc_rport *);
866 997
867/* 998/*
868 * DISCOVERY LAYER 999 * DISCOVERY LAYER
869 *****************************/ 1000 *****************************/
870int fc_disc_init(struct fc_lport *lp); 1001int fc_disc_init(struct fc_lport *);
871
872 1002
873/* 1003/*
874 * SCSI LAYER 1004 * FCP LAYER
875 *****************************/ 1005 *****************************/
876/*
877 * Initialize the SCSI block of libfc
878 */
879int fc_fcp_init(struct fc_lport *); 1006int fc_fcp_init(struct fc_lport *);
880
881/*
882 * This section provides an API which allows direct interaction
883 * with the SCSI-ml. Each of these functions satisfies a function
884 * pointer defined in Scsi_Host and therefore is always called
885 * directly from the SCSI-ml.
886 */
887int fc_queuecommand(struct scsi_cmnd *sc_cmd,
888 void (*done)(struct scsi_cmnd *));
889
890/*
891 * complete processing of a fcp packet
892 *
893 * This function may sleep if a fsp timer is pending.
894 * The host lock must not be held by caller.
895 */
896void fc_fcp_complete(struct fc_fcp_pkt *fsp);
897
898/*
899 * Send an ABTS frame to the target device. The sc_cmd argument
900 * is a pointer to the SCSI command to be aborted.
901 */
902int fc_eh_abort(struct scsi_cmnd *sc_cmd);
903
904/*
905 * Reset a LUN by sending send the tm cmd to the target.
906 */
907int fc_eh_device_reset(struct scsi_cmnd *sc_cmd);
908
909/*
910 * Reset the host adapter.
911 */
912int fc_eh_host_reset(struct scsi_cmnd *sc_cmd);
913
914/*
915 * Check rport status.
916 */
917int fc_slave_alloc(struct scsi_device *sdev);
918
919/*
920 * Adjust the queue depth.
921 */
922int fc_change_queue_depth(struct scsi_device *sdev, int qdepth);
923
924/*
925 * Change the tag type.
926 */
927int fc_change_queue_type(struct scsi_device *sdev, int tag_type);
928
929/*
930 * Free memory pools used by the FCP layer.
931 */
932void fc_fcp_destroy(struct fc_lport *); 1007void fc_fcp_destroy(struct fc_lport *);
933 1008
934/* 1009/*
935 * Set up direct-data placement for this I/O request 1010 * SCSI INTERACTION LAYER
936 */ 1011 *****************************/
937void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid); 1012int fc_queuecommand(struct scsi_cmnd *,
1013 void (*done)(struct scsi_cmnd *));
1014int fc_eh_abort(struct scsi_cmnd *);
1015int fc_eh_device_reset(struct scsi_cmnd *);
1016int fc_eh_host_reset(struct scsi_cmnd *);
1017int fc_slave_alloc(struct scsi_device *);
1018int fc_change_queue_depth(struct scsi_device *, int qdepth, int reason);
1019int fc_change_queue_type(struct scsi_device *, int tag_type);
938 1020
939/* 1021/*
940 * ELS/CT interface 1022 * ELS/CT interface
941 *****************************/ 1023 *****************************/
942/* 1024int fc_elsct_init(struct fc_lport *);
943 * Initializes ELS/CT interface 1025struct fc_seq *fc_elsct_send(struct fc_lport *, u32 did,
944 */ 1026 struct fc_frame *,
945int fc_elsct_init(struct fc_lport *lp); 1027 unsigned int op,
1028 void (*resp)(struct fc_seq *,
1029 struct fc_frame *,
1030 void *arg),
1031 void *arg, u32 timer_msec);
1032void fc_lport_flogi_resp(struct fc_seq *, struct fc_frame *, void *);
1033void fc_lport_logo_resp(struct fc_seq *, struct fc_frame *, void *);
946 1034
947 1035
948/* 1036/*
949 * EXCHANGE MANAGER LAYER 1037 * EXCHANGE MANAGER LAYER
950 *****************************/ 1038 *****************************/
951/* 1039int fc_exch_init(struct fc_lport *);
952 * Initializes Exchange Manager related 1040struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *,
953 * function pointers in struct libfc_function_template. 1041 struct fc_exch_mgr *,
954 */
955int fc_exch_init(struct fc_lport *lp);
956
957/*
958 * Adds Exchange Manager (EM) mp to lport.
959 *
960 * Adds specified mp to lport using struct fc_exch_mgr_anchor,
961 * the struct fc_exch_mgr_anchor allows same EM sharing by
962 * more than one lport with their specified match function,
963 * the match function is used in allocating exchange from
964 * added mp.
965 */
966struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *lport,
967 struct fc_exch_mgr *mp,
968 bool (*match)(struct fc_frame *)); 1042 bool (*match)(struct fc_frame *));
969 1043void fc_exch_mgr_del(struct fc_exch_mgr_anchor *);
970/* 1044int fc_exch_mgr_list_clone(struct fc_lport *src, struct fc_lport *dst);
971 * Deletes Exchange Manager (EM) from lport by removing 1045struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *, enum fc_class class,
972 * its anchor ema from lport. 1046 u16 min_xid, u16 max_xid,
973 *
974 * If removed anchor ema was the last user of its associated EM
975 * then also destroys associated EM.
976 */
977void fc_exch_mgr_del(struct fc_exch_mgr_anchor *ema);
978
979/*
980 * Allocates an Exchange Manager (EM).
981 *
982 * The EM manages exchanges for their allocation and
983 * free, also allows exchange lookup for received
984 * frame.
985 *
986 * The class is used for initializing FC class of
987 * allocated exchange from EM.
988 *
989 * The min_xid and max_xid will limit new
990 * exchange ID (XID) within this range for
991 * a new exchange.
992 * The LLD may choose to have multiple EMs,
993 * e.g. one EM instance per CPU receive thread in LLD.
994 *
995 * Specified match function is used in allocating exchanges
996 * from newly allocated EM.
997 */
998struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp,
999 enum fc_class class,
1000 u16 min_xid,
1001 u16 max_xid,
1002 bool (*match)(struct fc_frame *)); 1047 bool (*match)(struct fc_frame *));
1003 1048void fc_exch_mgr_free(struct fc_lport *);
1004/* 1049void fc_exch_recv(struct fc_lport *, struct fc_frame *);
1005 * Free all exchange managers of a lport.
1006 */
1007void fc_exch_mgr_free(struct fc_lport *lport);
1008
1009/*
1010 * Receive a frame on specified local port and exchange manager.
1011 */
1012void fc_exch_recv(struct fc_lport *lp, struct fc_frame *fp);
1013
1014/*
1015 * This function is for exch_seq_send function pointer in
1016 * struct libfc_function_template, see comment block on
1017 * exch_seq_send for description of this function.
1018 */
1019struct fc_seq *fc_exch_seq_send(struct fc_lport *lp,
1020 struct fc_frame *fp,
1021 void (*resp)(struct fc_seq *sp,
1022 struct fc_frame *fp,
1023 void *arg),
1024 void (*destructor)(struct fc_seq *sp,
1025 void *arg),
1026 void *arg, u32 timer_msec);
1027
1028/*
1029 * send a frame using existing sequence and exchange.
1030 */
1031int fc_seq_send(struct fc_lport *lp, struct fc_seq *sp, struct fc_frame *fp);
1032
1033/*
1034 * Send ELS response using mainly infomation
1035 * in exchange and sequence in EM layer.
1036 */
1037void fc_seq_els_rsp_send(struct fc_seq *sp, enum fc_els_cmd els_cmd,
1038 struct fc_seq_els_data *els_data);
1039
1040/*
1041 * This function is for seq_exch_abort function pointer in
1042 * struct libfc_function_template, see comment block on
1043 * seq_exch_abort for description of this function.
1044 */
1045int fc_seq_exch_abort(const struct fc_seq *req_sp, unsigned int timer_msec);
1046
1047/*
1048 * Indicate that an exchange/sequence tuple is complete and the memory
1049 * allocated for the related objects may be freed.
1050 */
1051void fc_exch_done(struct fc_seq *sp);
1052
1053/*
1054 * Allocate a new exchange and sequence pair.
1055 */
1056struct fc_exch *fc_exch_alloc(struct fc_lport *lport, struct fc_frame *fp);
1057/*
1058 * Start a new sequence on the same exchange as the supplied sequence.
1059 */
1060struct fc_seq *fc_seq_start_next(struct fc_seq *sp);
1061
1062
1063/*
1064 * Reset all EMs of a lport, releasing its all sequences and
1065 * exchanges. If sid is non-zero, then reset only exchanges
1066 * we sourced from that FID. If did is non-zero, reset only
1067 * exchanges destined to that FID.
1068 */
1069void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id); 1050void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id);
1070 1051
1071/* 1052/*
1072 * Functions for fc_functions_template 1053 * Functions for fc_functions_template
1073 */ 1054 */
1074void fc_get_host_speed(struct Scsi_Host *shost); 1055void fc_get_host_speed(struct Scsi_Host *);
1075void fc_get_host_port_type(struct Scsi_Host *shost); 1056void fc_get_host_port_type(struct Scsi_Host *);
1076void fc_get_host_port_state(struct Scsi_Host *shost); 1057void fc_get_host_port_state(struct Scsi_Host *);
1077void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout); 1058void fc_set_rport_loss_tmo(struct fc_rport *, u32 timeout);
1078struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *); 1059struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *);
1079 1060
1080/*
1081 * module setup functions.
1082 */
1083int fc_setup_exch_mgr(void);
1084void fc_destroy_exch_mgr(void);
1085int fc_setup_rport(void);
1086void fc_destroy_rport(void);
1087
1088/*
1089 * Internal libfc functions.
1090 */
1091const char *fc_els_resp_type(struct fc_frame *);
1092
1093#endif /* _LIBFC_H_ */ 1061#endif /* _LIBFC_H_ */
diff --git a/include/scsi/libfcoe.h b/include/scsi/libfcoe.h
index b2410605b740..c603f4a7e7fc 100644
--- a/include/scsi/libfcoe.h
+++ b/include/scsi/libfcoe.h
@@ -53,33 +53,36 @@ enum fip_state {
53}; 53};
54 54
55/** 55/**
56 * struct fcoe_ctlr - FCoE Controller and FIP state. 56 * struct fcoe_ctlr - FCoE Controller and FIP state
57 * @state: internal FIP state for network link and FIP or non-FIP mode. 57 * @state: internal FIP state for network link and FIP or non-FIP mode.
58 * @lp: &fc_lport: libfc local port. 58 * @mode: LLD-selected mode.
59 * @sel_fcf: currently selected FCF, or NULL. 59 * @lp: &fc_lport: libfc local port.
60 * @fcfs: list of discovered FCFs. 60 * @sel_fcf: currently selected FCF, or NULL.
61 * @fcf_count: number of discovered FCF entries. 61 * @fcfs: list of discovered FCFs.
62 * @sol_time: time when a multicast solicitation was last sent. 62 * @fcf_count: number of discovered FCF entries.
63 * @sel_time: time after which to select an FCF. 63 * @sol_time: time when a multicast solicitation was last sent.
64 * @port_ka_time: time of next port keep-alive. 64 * @sel_time: time after which to select an FCF.
65 * @ctlr_ka_time: time of next controller keep-alive. 65 * @port_ka_time: time of next port keep-alive.
66 * @timer: timer struct used for all delayed events. 66 * @ctlr_ka_time: time of next controller keep-alive.
67 * @link_work: &work_struct for doing FCF selection. 67 * @timer: timer struct used for all delayed events.
68 * @recv_work: &work_struct for receiving FIP frames. 68 * @link_work: &work_struct for doing FCF selection.
69 * @recv_work: &work_struct for receiving FIP frames.
69 * @fip_recv_list: list of received FIP frames. 70 * @fip_recv_list: list of received FIP frames.
70 * @user_mfs: configured maximum FC frame size, including FC header. 71 * @user_mfs: configured maximum FC frame size, including FC header.
71 * @flogi_oxid: exchange ID of most recent fabric login. 72 * @flogi_oxid: exchange ID of most recent fabric login.
72 * @flogi_count: number of FLOGI attempts in AUTO mode. 73 * @flogi_count: number of FLOGI attempts in AUTO mode.
73 * @link: current link status for libfc. 74 * @link: current link status for libfc.
74 * @last_link: last link state reported to libfc. 75 * @last_link: last link state reported to libfc.
75 * @map_dest: use the FC_MAP mode for destination MAC addresses. 76 * @map_dest: use the FC_MAP mode for destination MAC addresses.
76 * @spma: supports SPMA server-provided MACs mode 77 * @spma: supports SPMA server-provided MACs mode
77 * @dest_addr: MAC address of the selected FC forwarder. 78 * @send_ctlr_ka: need to send controller keep alive
78 * @ctl_src_addr: the native MAC address of our local port. 79 * @send_port_ka: need to send port keep alives
79 * @data_src_addr: the assigned MAC address for the local port after FLOGI. 80 * @dest_addr: MAC address of the selected FC forwarder.
80 * @send: LLD-supplied function to handle sending of FIP Ethernet frames. 81 * @ctl_src_addr: the native MAC address of our local port.
81 * @update_mac: LLD-supplied function to handle changes to MAC addresses. 82 * @send: LLD-supplied function to handle sending FIP Ethernet frames
82 * @lock: lock protecting this structure. 83 * @update_mac: LLD-supplied function to handle changes to MAC addresses.
84 * @get_src_addr: LLD-supplied function to supply a source MAC address.
85 * @lock: lock protecting this structure.
83 * 86 *
84 * This structure is used by all FCoE drivers. It contains information 87 * This structure is used by all FCoE drivers. It contains information
85 * needed by all FCoE low-level drivers (LLDs) as well as internal state 88 * needed by all FCoE low-level drivers (LLDs) as well as internal state
@@ -87,6 +90,7 @@ enum fip_state {
87 */ 90 */
88struct fcoe_ctlr { 91struct fcoe_ctlr {
89 enum fip_state state; 92 enum fip_state state;
93 enum fip_state mode;
90 struct fc_lport *lp; 94 struct fc_lport *lp;
91 struct fcoe_fcf *sel_fcf; 95 struct fcoe_fcf *sel_fcf;
92 struct list_head fcfs; 96 struct list_head fcfs;
@@ -104,29 +108,32 @@ struct fcoe_ctlr {
104 u8 flogi_count; 108 u8 flogi_count;
105 u8 link; 109 u8 link;
106 u8 last_link; 110 u8 last_link;
111 u8 reset_req;
107 u8 map_dest; 112 u8 map_dest;
108 u8 spma; 113 u8 spma;
114 u8 send_ctlr_ka;
115 u8 send_port_ka;
109 u8 dest_addr[ETH_ALEN]; 116 u8 dest_addr[ETH_ALEN];
110 u8 ctl_src_addr[ETH_ALEN]; 117 u8 ctl_src_addr[ETH_ALEN];
111 u8 data_src_addr[ETH_ALEN];
112 118
113 void (*send)(struct fcoe_ctlr *, struct sk_buff *); 119 void (*send)(struct fcoe_ctlr *, struct sk_buff *);
114 void (*update_mac)(struct fcoe_ctlr *, u8 *old, u8 *new); 120 void (*update_mac)(struct fc_lport *, u8 *addr);
121 u8 * (*get_src_addr)(struct fc_lport *);
115 spinlock_t lock; 122 spinlock_t lock;
116}; 123};
117 124
118/* 125/**
119 * struct fcoe_fcf - Fibre-Channel Forwarder. 126 * struct fcoe_fcf - Fibre-Channel Forwarder
120 * @list: list linkage. 127 * @list: list linkage
121 * @time: system time (jiffies) when an advertisement was last received. 128 * @time: system time (jiffies) when an advertisement was last received
122 * @switch_name: WWN of switch from advertisement. 129 * @switch_name: WWN of switch from advertisement
123 * @fabric_name: WWN of fabric from advertisement. 130 * @fabric_name: WWN of fabric from advertisement
124 * @fc_map: FC_MAP value from advertisement. 131 * @fc_map: FC_MAP value from advertisement
125 * @fcf_mac: Ethernet address of the FCF. 132 * @fcf_mac: Ethernet address of the FCF
126 * @vfid: virtual fabric ID. 133 * @vfid: virtual fabric ID
127 * @pri: seletion priority, smaller values are better. 134 * @pri: selection priority, smaller values are better
128 * @flags: flags received from advertisement. 135 * @flags: flags received from advertisement
129 * @fka_period: keep-alive period, in jiffies. 136 * @fka_period: keep-alive period, in jiffies
130 * 137 *
131 * A Fibre-Channel Forwarder (FCF) is the entity on the Ethernet that 138 * A Fibre-Channel Forwarder (FCF) is the entity on the Ethernet that
132 * passes FCoE frames on to an FC fabric. This structure represents 139 * passes FCoE frames on to an FC fabric. This structure represents
@@ -148,6 +155,7 @@ struct fcoe_fcf {
148 u8 pri; 155 u8 pri;
149 u16 flags; 156 u16 flags;
150 u32 fka_period; 157 u32 fka_period;
158 u8 fd_flags:1;
151}; 159};
152 160
153/* FIP API functions */ 161/* FIP API functions */
@@ -155,9 +163,10 @@ void fcoe_ctlr_init(struct fcoe_ctlr *);
155void fcoe_ctlr_destroy(struct fcoe_ctlr *); 163void fcoe_ctlr_destroy(struct fcoe_ctlr *);
156void fcoe_ctlr_link_up(struct fcoe_ctlr *); 164void fcoe_ctlr_link_up(struct fcoe_ctlr *);
157int fcoe_ctlr_link_down(struct fcoe_ctlr *); 165int fcoe_ctlr_link_down(struct fcoe_ctlr *);
158int fcoe_ctlr_els_send(struct fcoe_ctlr *, struct sk_buff *); 166int fcoe_ctlr_els_send(struct fcoe_ctlr *, struct fc_lport *, struct sk_buff *);
159void fcoe_ctlr_recv(struct fcoe_ctlr *, struct sk_buff *); 167void fcoe_ctlr_recv(struct fcoe_ctlr *, struct sk_buff *);
160int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *, struct fc_frame *fp, u8 *sa); 168int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *, struct fc_lport *,
169 struct fc_frame *);
161 170
162/* libfcoe funcs */ 171/* libfcoe funcs */
163u64 fcoe_wwn_from_mac(unsigned char mac[], unsigned int, unsigned int); 172u64 fcoe_wwn_from_mac(unsigned char mac[], unsigned int, unsigned int);
diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h
index a72edd4eceec..7394e3bc8f4b 100644
--- a/include/scsi/libiscsi.h
+++ b/include/scsi/libiscsi.h
@@ -267,6 +267,7 @@ struct iscsi_session {
267 /* configuration */ 267 /* configuration */
268 int abort_timeout; 268 int abort_timeout;
269 int lu_reset_timeout; 269 int lu_reset_timeout;
270 int tgt_reset_timeout;
270 int initial_r2t_en; 271 int initial_r2t_en;
271 unsigned max_r2t; 272 unsigned max_r2t;
272 int imm_data_en; 273 int imm_data_en;
@@ -333,7 +334,8 @@ struct iscsi_host {
333/* 334/*
334 * scsi host template 335 * scsi host template
335 */ 336 */
336extern int iscsi_change_queue_depth(struct scsi_device *sdev, int depth); 337extern int iscsi_change_queue_depth(struct scsi_device *sdev, int depth,
338 int reason);
337extern int iscsi_eh_abort(struct scsi_cmnd *sc); 339extern int iscsi_eh_abort(struct scsi_cmnd *sc);
338extern int iscsi_eh_target_reset(struct scsi_cmnd *sc); 340extern int iscsi_eh_target_reset(struct scsi_cmnd *sc);
339extern int iscsi_eh_device_reset(struct scsi_cmnd *sc); 341extern int iscsi_eh_device_reset(struct scsi_cmnd *sc);
diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h
index e78d3b62d8ec..9eaa3f05f954 100644
--- a/include/scsi/libsas.h
+++ b/include/scsi/libsas.h
@@ -634,7 +634,8 @@ extern int sas_target_alloc(struct scsi_target *);
634extern int sas_slave_alloc(struct scsi_device *); 634extern int sas_slave_alloc(struct scsi_device *);
635extern int sas_slave_configure(struct scsi_device *); 635extern int sas_slave_configure(struct scsi_device *);
636extern void sas_slave_destroy(struct scsi_device *); 636extern void sas_slave_destroy(struct scsi_device *);
637extern int sas_change_queue_depth(struct scsi_device *, int new_depth); 637extern int sas_change_queue_depth(struct scsi_device *, int new_depth,
638 int reason);
638extern int sas_change_queue_type(struct scsi_device *, int qt); 639extern int sas_change_queue_type(struct scsi_device *, int qt);
639extern int sas_bios_param(struct scsi_device *, 640extern int sas_bios_param(struct scsi_device *,
640 struct block_device *, 641 struct block_device *,
diff --git a/include/scsi/osd_initiator.h b/include/scsi/osd_initiator.h
index 02bd9f716357..39d6d1097153 100644
--- a/include/scsi/osd_initiator.h
+++ b/include/scsi/osd_initiator.h
@@ -48,7 +48,6 @@ enum osd_std_version {
48 */ 48 */
49struct osd_dev { 49struct osd_dev {
50 struct scsi_device *scsi_device; 50 struct scsi_device *scsi_device;
51 struct file *file;
52 unsigned def_timeout; 51 unsigned def_timeout;
53 52
54#ifdef OSD_VER1_SUPPORT 53#ifdef OSD_VER1_SUPPORT
@@ -56,10 +55,24 @@ struct osd_dev {
56#endif 55#endif
57}; 56};
58 57
59/* Retrieve/return osd_dev(s) for use by Kernel clients */ 58/* Unique Identification of an OSD device */
60struct osd_dev *osduld_path_lookup(const char *dev_name); /*Use IS_ERR/ERR_PTR*/ 59struct osd_dev_info {
60 unsigned systemid_len;
61 u8 systemid[OSD_SYSTEMID_LEN];
62 unsigned osdname_len;
63 u8 *osdname;
64};
65
66/* Retrieve/return osd_dev(s) for use by Kernel clients
67 * Use IS_ERR/ERR_PTR on returned "osd_dev *".
68 */
69struct osd_dev *osduld_path_lookup(const char *dev_name);
70struct osd_dev *osduld_info_lookup(const struct osd_dev_info *odi);
61void osduld_put_device(struct osd_dev *od); 71void osduld_put_device(struct osd_dev *od);
62 72
73const struct osd_dev_info *osduld_device_info(struct osd_dev *od);
74bool osduld_device_same(struct osd_dev *od, const struct osd_dev_info *odi);
75
63/* Add/remove test ioctls from external modules */ 76/* Add/remove test ioctls from external modules */
64typedef int (do_test_fn)(struct osd_dev *od, unsigned cmd, unsigned long arg); 77typedef int (do_test_fn)(struct osd_dev *od, unsigned cmd, unsigned long arg);
65int osduld_register_test(unsigned ioctl, do_test_fn *do_test); 78int osduld_register_test(unsigned ioctl, do_test_fn *do_test);
@@ -69,8 +82,24 @@ void osduld_unregister_test(unsigned ioctl);
69void osd_dev_init(struct osd_dev *od, struct scsi_device *scsi_device); 82void osd_dev_init(struct osd_dev *od, struct scsi_device *scsi_device);
70void osd_dev_fini(struct osd_dev *od); 83void osd_dev_fini(struct osd_dev *od);
71 84
72/* some hi level device operations */ 85/**
73int osd_auto_detect_ver(struct osd_dev *od, void *caps); /* GFP_KERNEL */ 86 * osd_auto_detect_ver - Detect the OSD version, return Unique Identification
87 *
88 * @od: OSD target lun handle
89 * @caps: Capabilities authorizing OSD root read attributes access
90 * @odi: Retrieved information uniquely identifying the osd target lun
91 * Note: odi->osdname must be kfreed by caller.
92 *
93 * Auto detects the OSD version of the OSD target and sets the @od
94 * accordingly. Meanwhile also returns the "system id" and "osd name" root
95 * attributes which uniquely identify the OSD target. This member is usually
96 * called by the ULD. ULD users should call osduld_device_info().
97 * This rutine allocates osd requests and memory at GFP_KERNEL level and might
98 * sleep.
99 */
100int osd_auto_detect_ver(struct osd_dev *od,
101 void *caps, struct osd_dev_info *odi);
102
74static inline struct request_queue *osd_request_queue(struct osd_dev *od) 103static inline struct request_queue *osd_request_queue(struct osd_dev *od)
75{ 104{
76 return od->scsi_device->request_queue; 105 return od->scsi_device->request_queue;
@@ -84,6 +113,15 @@ static inline void osd_dev_set_ver(struct osd_dev *od, enum osd_std_version v)
84#endif 113#endif
85} 114}
86 115
116static inline bool osd_dev_is_ver1(struct osd_dev *od)
117{
118#ifdef OSD_VER1_SUPPORT
119 return od->version == OSD_VER1;
120#else
121 return false;
122#endif
123}
124
87struct osd_request; 125struct osd_request;
88typedef void (osd_req_done_fn)(struct osd_request *or, void *private); 126typedef void (osd_req_done_fn)(struct osd_request *or, void *private);
89 127
@@ -120,14 +158,9 @@ struct osd_request {
120 int async_error; 158 int async_error;
121}; 159};
122 160
123/* OSD Version control */
124static inline bool osd_req_is_ver1(struct osd_request *or) 161static inline bool osd_req_is_ver1(struct osd_request *or)
125{ 162{
126#ifdef OSD_VER1_SUPPORT 163 return osd_dev_is_ver1(or->osd_dev);
127 return or->osd_dev->version == OSD_VER1;
128#else
129 return false;
130#endif
131} 164}
132 165
133/* 166/*
@@ -234,7 +267,7 @@ int osd_execute_request_async(struct osd_request *or,
234 * @bad_attr_list - List of failing attributes (optional) 267 * @bad_attr_list - List of failing attributes (optional)
235 * @max_attr - Size of @bad_attr_list. 268 * @max_attr - Size of @bad_attr_list.
236 * 269 *
237 * After execution, sense + return code can be analyzed using this function. The 270 * After execution, osd_request results are analyzed using this function. The
238 * return code is the final disposition on the error. So it is possible that a 271 * return code is the final disposition on the error. So it is possible that a
239 * CHECK_CONDITION was returned from target but this will return NO_ERROR, for 272 * CHECK_CONDITION was returned from target but this will return NO_ERROR, for
240 * example on recovered errors. All parameters are optional if caller does 273 * example on recovered errors. All parameters are optional if caller does
@@ -243,7 +276,31 @@ int osd_execute_request_async(struct osd_request *or,
243 * of the SCSI_OSD_DPRINT_SENSE Kconfig value. Set @silent if you know the 276 * of the SCSI_OSD_DPRINT_SENSE Kconfig value. Set @silent if you know the
244 * command would routinely fail, to not spam the dmsg file. 277 * command would routinely fail, to not spam the dmsg file.
245 */ 278 */
279
280/**
281 * osd_err_priority - osd categorized return codes in ascending severity.
282 *
283 * The categories are borrowed from the pnfs_osd_errno enum.
284 * See comments for translated Linux codes returned by osd_req_decode_sense.
285 */
286enum osd_err_priority {
287 OSD_ERR_PRI_NO_ERROR = 0,
288 /* Recoverable, caller should clear_highpage() all pages */
289 OSD_ERR_PRI_CLEAR_PAGES = 1, /* -EFAULT */
290 OSD_ERR_PRI_RESOURCE = 2, /* -ENOMEM */
291 OSD_ERR_PRI_BAD_CRED = 3, /* -EINVAL */
292 OSD_ERR_PRI_NO_ACCESS = 4, /* -EACCES */
293 OSD_ERR_PRI_UNREACHABLE = 5, /* any other */
294 OSD_ERR_PRI_NOT_FOUND = 6, /* -ENOENT */
295 OSD_ERR_PRI_NO_SPACE = 7, /* -ENOSPC */
296 OSD_ERR_PRI_EIO = 8, /* -EIO */
297};
298
246struct osd_sense_info { 299struct osd_sense_info {
300 u64 out_resid; /* Zero on success otherwise out residual */
301 u64 in_resid; /* Zero on success otherwise in residual */
302 enum osd_err_priority osd_err_pri;
303
247 int key; /* one of enum scsi_sense_keys */ 304 int key; /* one of enum scsi_sense_keys */
248 int additional_code ; /* enum osd_additional_sense_codes */ 305 int additional_code ; /* enum osd_additional_sense_codes */
249 union { /* Sense specific information */ 306 union { /* Sense specific information */
diff --git a/include/scsi/osd_protocol.h b/include/scsi/osd_protocol.h
index 2cc8e8b1cc19..685661283540 100644
--- a/include/scsi/osd_protocol.h
+++ b/include/scsi/osd_protocol.h
@@ -17,6 +17,7 @@
17#define __OSD_PROTOCOL_H__ 17#define __OSD_PROTOCOL_H__
18 18
19#include <linux/types.h> 19#include <linux/types.h>
20#include <linux/kernel.h>
20#include <asm/unaligned.h> 21#include <asm/unaligned.h>
21#include <scsi/scsi.h> 22#include <scsi/scsi.h>
22 23
diff --git a/include/scsi/osd_sense.h b/include/scsi/osd_sense.h
index ff9b33c773c7..91db543a5502 100644
--- a/include/scsi/osd_sense.h
+++ b/include/scsi/osd_sense.h
@@ -255,6 +255,9 @@ enum osdv2_cdb_field_offset {
255 OSD_CFO_STARTING_BYTE = OSD_CDB_OFFSET(v2.start_address), 255 OSD_CFO_STARTING_BYTE = OSD_CDB_OFFSET(v2.start_address),
256 OSD_CFO_PARTITION_ID = OSD_CDB_OFFSET(partition), 256 OSD_CFO_PARTITION_ID = OSD_CDB_OFFSET(partition),
257 OSD_CFO_OBJECT_ID = OSD_CDB_OFFSET(object), 257 OSD_CFO_OBJECT_ID = OSD_CDB_OFFSET(object),
258 OSD_CFO_PERMISSIONS = sizeof(struct osd_cdb_head) +
259 offsetof(struct osd_capability_head,
260 permissions_bit_mask),
258}; 261};
259 262
260#endif /* ndef __OSD_SENSE_H__ */ 263#endif /* ndef __OSD_SENSE_H__ */
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index 34c46ab5c31b..8b4deca996ad 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -94,6 +94,7 @@ struct scsi_cmnd;
94#define WRITE_LONG 0x3f 94#define WRITE_LONG 0x3f
95#define CHANGE_DEFINITION 0x40 95#define CHANGE_DEFINITION 0x40
96#define WRITE_SAME 0x41 96#define WRITE_SAME 0x41
97#define UNMAP 0x42
97#define READ_TOC 0x43 98#define READ_TOC 0x43
98#define LOG_SELECT 0x4c 99#define LOG_SELECT 0x4c
99#define LOG_SENSE 0x4d 100#define LOG_SENSE 0x4d
@@ -122,9 +123,11 @@ struct scsi_cmnd;
122#define READ_16 0x88 123#define READ_16 0x88
123#define WRITE_16 0x8a 124#define WRITE_16 0x8a
124#define VERIFY_16 0x8f 125#define VERIFY_16 0x8f
126#define WRITE_SAME_16 0x93
125#define SERVICE_ACTION_IN 0x9e 127#define SERVICE_ACTION_IN 0x9e
126/* values for service action in */ 128/* values for service action in */
127#define SAI_READ_CAPACITY_16 0x10 129#define SAI_READ_CAPACITY_16 0x10
130#define SAI_GET_LBA_STATUS 0x12
128/* values for maintenance in */ 131/* values for maintenance in */
129#define MI_REPORT_TARGET_PGS 0x0a 132#define MI_REPORT_TARGET_PGS 0x0a
130/* values for maintenance out */ 133/* values for maintenance out */
@@ -132,6 +135,7 @@ struct scsi_cmnd;
132/* values for variable length command */ 135/* values for variable length command */
133#define READ_32 0x09 136#define READ_32 0x09
134#define WRITE_32 0x0b 137#define WRITE_32 0x0b
138#define WRITE_SAME_32 0x0d
135 139
136/* Values for T10/04-262r7 */ 140/* Values for T10/04-262r7 */
137#define ATA_16 0x85 /* 16-byte pass-thru */ 141#define ATA_16 0x85 /* 16-byte pass-thru */
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index f097ae340bc1..7c4449900c24 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -81,11 +81,14 @@ struct scsi_device {
81 struct list_head starved_entry; 81 struct list_head starved_entry;
82 struct scsi_cmnd *current_cmnd; /* currently active command */ 82 struct scsi_cmnd *current_cmnd; /* currently active command */
83 unsigned short queue_depth; /* How deep of a queue we want */ 83 unsigned short queue_depth; /* How deep of a queue we want */
84 unsigned short max_queue_depth; /* max queue depth */
84 unsigned short last_queue_full_depth; /* These two are used by */ 85 unsigned short last_queue_full_depth; /* These two are used by */
85 unsigned short last_queue_full_count; /* scsi_track_queue_full() */ 86 unsigned short last_queue_full_count; /* scsi_track_queue_full() */
86 unsigned long last_queue_full_time;/* don't let QUEUE_FULLs on the same 87 unsigned long last_queue_full_time; /* last queue full time */
87 jiffie count on our counter, they 88 unsigned long queue_ramp_up_period; /* ramp up period in jiffies */
88 could all be from the same event. */ 89#define SCSI_DEFAULT_RAMP_UP_PERIOD (120 * HZ)
90
91 unsigned long last_queue_ramp_up; /* last queue ramp up time */
89 92
90 unsigned int id, lun, channel; 93 unsigned int id, lun, channel;
91 94
@@ -175,6 +178,7 @@ struct scsi_dh_devlist {
175 char *model; 178 char *model;
176}; 179};
177 180
181typedef void (*activate_complete)(void *, int);
178struct scsi_device_handler { 182struct scsi_device_handler {
179 /* Used by the infrastructure */ 183 /* Used by the infrastructure */
180 struct list_head list; /* list of scsi_device_handlers */ 184 struct list_head list; /* list of scsi_device_handlers */
@@ -186,7 +190,7 @@ struct scsi_device_handler {
186 int (*check_sense)(struct scsi_device *, struct scsi_sense_hdr *); 190 int (*check_sense)(struct scsi_device *, struct scsi_sense_hdr *);
187 int (*attach)(struct scsi_device *); 191 int (*attach)(struct scsi_device *);
188 void (*detach)(struct scsi_device *); 192 void (*detach)(struct scsi_device *);
189 int (*activate)(struct scsi_device *); 193 int (*activate)(struct scsi_device *, activate_complete, void *);
190 int (*prep_fn)(struct scsi_device *, struct request *); 194 int (*prep_fn)(struct scsi_device *, struct request *);
191 int (*set_params)(struct scsi_device *, const char *); 195 int (*set_params)(struct scsi_device *, const char *);
192}; 196};
diff --git a/include/scsi/scsi_dh.h b/include/scsi/scsi_dh.h
index ff2407405b42..e3f2db212ddc 100644
--- a/include/scsi/scsi_dh.h
+++ b/include/scsi/scsi_dh.h
@@ -56,14 +56,16 @@ enum {
56 SCSI_DH_DRIVER_MAX, 56 SCSI_DH_DRIVER_MAX,
57}; 57};
58#if defined(CONFIG_SCSI_DH) || defined(CONFIG_SCSI_DH_MODULE) 58#if defined(CONFIG_SCSI_DH) || defined(CONFIG_SCSI_DH_MODULE)
59extern int scsi_dh_activate(struct request_queue *); 59extern int scsi_dh_activate(struct request_queue *, activate_complete, void *);
60extern int scsi_dh_handler_exist(const char *); 60extern int scsi_dh_handler_exist(const char *);
61extern int scsi_dh_attach(struct request_queue *, const char *); 61extern int scsi_dh_attach(struct request_queue *, const char *);
62extern void scsi_dh_detach(struct request_queue *); 62extern void scsi_dh_detach(struct request_queue *);
63extern int scsi_dh_set_params(struct request_queue *, const char *); 63extern int scsi_dh_set_params(struct request_queue *, const char *);
64#else 64#else
65static inline int scsi_dh_activate(struct request_queue *req) 65static inline int scsi_dh_activate(struct request_queue *req,
66 activate_complete fn, void *data)
66{ 67{
68 fn(data, 0);
67 return 0; 69 return 0;
68} 70}
69static inline int scsi_dh_handler_exist(const char *name) 71static inline int scsi_dh_handler_exist(const char *name)
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index 47941fc5aba7..c50a97fc76f9 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -43,6 +43,12 @@ struct blk_queue_tags;
43#define DISABLE_CLUSTERING 0 43#define DISABLE_CLUSTERING 0
44#define ENABLE_CLUSTERING 1 44#define ENABLE_CLUSTERING 1
45 45
46enum {
47 SCSI_QDEPTH_DEFAULT, /* default requested change, e.g. from sysfs */
48 SCSI_QDEPTH_QFULL, /* scsi-ml requested due to queue full */
49 SCSI_QDEPTH_RAMP_UP, /* scsi-ml requested due to threshhold event */
50};
51
46struct scsi_host_template { 52struct scsi_host_template {
47 struct module *module; 53 struct module *module;
48 const char *name; 54 const char *name;
@@ -294,7 +300,7 @@ struct scsi_host_template {
294 * 300 *
295 * Status: OPTIONAL 301 * Status: OPTIONAL
296 */ 302 */
297 int (* change_queue_depth)(struct scsi_device *, int); 303 int (* change_queue_depth)(struct scsi_device *, int, int);
298 304
299 /* 305 /*
300 * Fill in this function to allow the changing of tag types 306 * Fill in this function to allow the changing of tag types
@@ -677,6 +683,12 @@ struct Scsi_Host {
677 void *shost_data; 683 void *shost_data;
678 684
679 /* 685 /*
686 * Points to the physical bus device we'd use to do DMA
687 * Needed just in case we have virtual hosts.
688 */
689 struct device *dma_dev;
690
691 /*
680 * We should ensure that this is aligned, both for better performance 692 * We should ensure that this is aligned, both for better performance
681 * and also because some compilers (m68k) don't automatically force 693 * and also because some compilers (m68k) don't automatically force
682 * alignment to a long boundary. 694 * alignment to a long boundary.
@@ -720,7 +732,9 @@ extern int scsi_queue_work(struct Scsi_Host *, struct work_struct *);
720extern void scsi_flush_work(struct Scsi_Host *); 732extern void scsi_flush_work(struct Scsi_Host *);
721 733
722extern struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *, int); 734extern struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *, int);
723extern int __must_check scsi_add_host(struct Scsi_Host *, struct device *); 735extern int __must_check scsi_add_host_with_dma(struct Scsi_Host *,
736 struct device *,
737 struct device *);
724extern void scsi_scan_host(struct Scsi_Host *); 738extern void scsi_scan_host(struct Scsi_Host *);
725extern void scsi_rescan_device(struct device *); 739extern void scsi_rescan_device(struct device *);
726extern void scsi_remove_host(struct Scsi_Host *); 740extern void scsi_remove_host(struct Scsi_Host *);
@@ -731,6 +745,12 @@ extern const char *scsi_host_state_name(enum scsi_host_state);
731 745
732extern u64 scsi_calculate_bounce_limit(struct Scsi_Host *); 746extern u64 scsi_calculate_bounce_limit(struct Scsi_Host *);
733 747
748static inline int __must_check scsi_add_host(struct Scsi_Host *host,
749 struct device *dev)
750{
751 return scsi_add_host_with_dma(host, dev, dev);
752}
753
734static inline struct device *scsi_get_device(struct Scsi_Host *shost) 754static inline struct device *scsi_get_device(struct Scsi_Host *shost)
735{ 755{
736 return shost->shost_gendev.parent; 756 return shost->shost_gendev.parent;
diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
index fc50bd64aa4e..8e86a94faf06 100644
--- a/include/scsi/scsi_transport_fc.h
+++ b/include/scsi/scsi_transport_fc.h
@@ -807,5 +807,6 @@ void fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
807struct fc_vport *fc_vport_create(struct Scsi_Host *shost, int channel, 807struct fc_vport *fc_vport_create(struct Scsi_Host *shost, int channel,
808 struct fc_vport_identifiers *); 808 struct fc_vport_identifiers *);
809int fc_vport_terminate(struct fc_vport *vport); 809int fc_vport_terminate(struct fc_vport *vport);
810void fc_block_scsi_eh(struct scsi_cmnd *cmnd);
810 811
811#endif /* SCSI_TRANSPORT_FC_H */ 812#endif /* SCSI_TRANSPORT_FC_H */