diff options
Diffstat (limited to 'include/scsi/libfc.h')
-rw-r--r-- | include/scsi/libfc.h | 994 |
1 files changed, 505 insertions, 489 deletions
diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h index 54df9fe00c14..310d8a22b726 100644 --- a/include/scsi/libfc.h +++ b/include/scsi/libfc.h | |||
@@ -55,8 +55,17 @@ | |||
55 | p[2] = ((v) & 0xFF); \ | 55 | p[2] = ((v) & 0xFF); \ |
56 | } while (0) | 56 | } while (0) |
57 | 57 | ||
58 | /* | 58 | /** |
59 | * 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_SCR: State Change Register (SCR) sent | ||
66 | * @LPORT_ST_READY: Ready for use | ||
67 | * @LPORT_ST_LOGO: Local port logout (LOGO) sent | ||
68 | * @LPORT_ST_RESET: Local port reset | ||
60 | */ | 69 | */ |
61 | enum fc_lport_state { | 70 | enum fc_lport_state { |
62 | LPORT_ST_DISABLED = 0, | 71 | LPORT_ST_DISABLED = 0, |
@@ -78,16 +87,28 @@ enum fc_disc_event { | |||
78 | DISC_EV_FAILED | 87 | DISC_EV_FAILED |
79 | }; | 88 | }; |
80 | 89 | ||
90 | /** | ||
91 | * enum fc_rport_state - Remote port states | ||
92 | * @RPORT_ST_INIT: Initialized | ||
93 | * @RPORT_ST_PLOGI: Waiting for PLOGI completion | ||
94 | * @RPORT_ST_PRLI: Waiting for PRLI completion | ||
95 | * @RPORT_ST_RTV: Waiting for RTV completion | ||
96 | * @RPORT_ST_READY: Ready for use | ||
97 | * @RPORT_ST_LOGO: Remote port logout (LOGO) sent | ||
98 | * @RPORT_ST_ADISC: Discover Address sent | ||
99 | * @RPORT_ST_DELETE: Remote port being deleted | ||
100 | * @RPORT_ST_RESTART: Remote port being deleted and will restart | ||
101 | */ | ||
81 | enum fc_rport_state { | 102 | enum fc_rport_state { |
82 | RPORT_ST_INIT, /* initialized */ | 103 | RPORT_ST_INIT, |
83 | RPORT_ST_PLOGI, /* waiting for PLOGI completion */ | 104 | RPORT_ST_PLOGI, |
84 | RPORT_ST_PRLI, /* waiting for PRLI completion */ | 105 | RPORT_ST_PRLI, |
85 | RPORT_ST_RTV, /* waiting for RTV completion */ | 106 | RPORT_ST_RTV, |
86 | RPORT_ST_READY, /* ready for use */ | 107 | RPORT_ST_READY, |
87 | RPORT_ST_LOGO, /* port logout sent */ | 108 | RPORT_ST_LOGO, |
88 | RPORT_ST_ADISC, /* Discover Address sent */ | 109 | RPORT_ST_ADISC, |
89 | RPORT_ST_DELETE, /* port being deleted */ | 110 | RPORT_ST_DELETE, |
90 | RPORT_ST_RESTART, /* remote port being deleted and will restart */ | 111 | RPORT_ST_RESTART, |
91 | }; | 112 | }; |
92 | 113 | ||
93 | /** | 114 | /** |
@@ -98,12 +119,20 @@ enum fc_rport_state { | |||
98 | * @port_id: Port ID of the discovered port | 119 | * @port_id: Port ID of the discovered port |
99 | */ | 120 | */ |
100 | struct fc_disc_port { | 121 | struct fc_disc_port { |
101 | struct fc_lport *lp; | 122 | struct fc_lport *lp; |
102 | struct list_head peers; | 123 | struct list_head peers; |
103 | struct work_struct rport_work; | 124 | struct work_struct rport_work; |
104 | u32 port_id; | 125 | u32 port_id; |
105 | }; | 126 | }; |
106 | 127 | ||
128 | /** | ||
129 | * enum fc_rport_event - Remote port events | ||
130 | * @RPORT_EV_NONE: No event | ||
131 | * @RPORT_EV_READY: Remote port is ready for use | ||
132 | * @RPORT_EV_FAILED: State machine failed, remote port is not ready | ||
133 | * @RPORT_EV_STOP: Remote port has been stopped | ||
134 | * @RPORT_EV_LOGO: Remote port logout (LOGO) sent | ||
135 | */ | ||
107 | enum fc_rport_event { | 136 | enum fc_rport_event { |
108 | RPORT_EV_NONE = 0, | 137 | RPORT_EV_NONE = 0, |
109 | RPORT_EV_READY, | 138 | RPORT_EV_READY, |
@@ -114,6 +143,10 @@ enum fc_rport_event { | |||
114 | 143 | ||
115 | struct fc_rport_priv; | 144 | struct fc_rport_priv; |
116 | 145 | ||
146 | /** | ||
147 | * struct fc_rport_operations - Operations for a remote port | ||
148 | * @event_callback: Function to be called for remote port events | ||
149 | */ | ||
117 | struct fc_rport_operations { | 150 | struct fc_rport_operations { |
118 | void (*event_callback)(struct fc_lport *, struct fc_rport_priv *, | 151 | void (*event_callback)(struct fc_lport *, struct fc_rport_priv *, |
119 | enum fc_rport_event); | 152 | enum fc_rport_event); |
@@ -121,11 +154,11 @@ struct fc_rport_operations { | |||
121 | 154 | ||
122 | /** | 155 | /** |
123 | * struct fc_rport_libfc_priv - libfc internal information about a remote port | 156 | * struct fc_rport_libfc_priv - libfc internal information about a remote port |
124 | * @local_port: Fibre Channel host port instance | 157 | * @local_port: The associated local port |
125 | * @rp_state: indicates READY for I/O or DELETE when blocked. | 158 | * @rp_state: Indicates READY for I/O or DELETE when blocked |
126 | * @flags: REC and RETRY supported flags | 159 | * @flags: REC and RETRY supported flags |
127 | * @e_d_tov: error detect timeout value (in msec) | 160 | * @e_d_tov: Error detect timeout value (in msec) |
128 | * @r_a_tov: resource allocation timeout value (in msec) | 161 | * @r_a_tov: Resource allocation timeout value (in msec) |
129 | */ | 162 | */ |
130 | struct fc_rport_libfc_priv { | 163 | struct fc_rport_libfc_priv { |
131 | struct fc_lport *local_port; | 164 | struct fc_lport *local_port; |
@@ -138,47 +171,64 @@ struct fc_rport_libfc_priv { | |||
138 | }; | 171 | }; |
139 | 172 | ||
140 | /** | 173 | /** |
141 | * struct fc_rport_priv - libfc rport and discovery info about a remote port | 174 | * struct fc_rport_priv - libfc remote port and discovery info |
142 | * @local_port: Fibre Channel host port instance | 175 | * @local_port: The associated local port |
143 | * @rport: transport remote port | 176 | * @rport: The FC transport remote port |
144 | * @kref: reference counter | 177 | * @kref: Reference counter |
145 | * @rp_state: state tracks progress of PLOGI, PRLI, and RTV exchanges | 178 | * @rp_state: Enumeration that tracks progress of PLOGI, PRLI, |
146 | * @ids: remote port identifiers and roles | 179 | * and RTV exchanges |
147 | * @flags: REC and RETRY supported flags | 180 | * @ids: The remote port identifiers and roles |
148 | * @max_seq: maximum number of concurrent sequences | 181 | * @flags: REC and RETRY supported flags |
149 | * @disc_id: discovery identifier | 182 | * @max_seq: Maximum number of concurrent sequences |
150 | * @maxframe_size: maximum frame size | 183 | * @disc_id: The discovery identifier |
151 | * @retries: retry count in current state | 184 | * @maxframe_size: The maximum frame size |
152 | * @e_d_tov: error detect timeout value (in msec) | 185 | * @retries: The retry count for the current state |
153 | * @r_a_tov: resource allocation timeout value (in msec) | 186 | * @e_d_tov: Error detect timeout value (in msec) |
154 | * @rp_mutex: mutex protects rport | 187 | * @r_a_tov: Resource allocation timeout value (in msec) |
155 | * @retry_work: | 188 | * @rp_mutex: The mutex that protects the remote port |
156 | * @event_callback: Callback for rport READY, FAILED or LOGO | 189 | * @retry_work: Handle for retries |
190 | * @event_callback: Callback when READY, FAILED or LOGO states complete | ||
157 | */ | 191 | */ |
158 | struct fc_rport_priv { | 192 | struct fc_rport_priv { |
159 | struct fc_lport *local_port; | 193 | struct fc_lport *local_port; |
160 | struct fc_rport *rport; | 194 | struct fc_rport *rport; |
161 | struct kref kref; | 195 | struct kref kref; |
162 | enum fc_rport_state rp_state; | 196 | enum fc_rport_state rp_state; |
163 | struct fc_rport_identifiers ids; | 197 | struct fc_rport_identifiers ids; |
164 | u16 flags; | 198 | u16 flags; |
165 | u16 max_seq; | 199 | u16 max_seq; |
166 | u16 disc_id; | 200 | u16 disc_id; |
167 | u16 maxframe_size; | 201 | u16 maxframe_size; |
168 | unsigned int retries; | 202 | unsigned int retries; |
169 | unsigned int e_d_tov; | 203 | unsigned int e_d_tov; |
170 | unsigned int r_a_tov; | 204 | unsigned int r_a_tov; |
171 | struct mutex rp_mutex; | 205 | struct mutex rp_mutex; |
172 | struct delayed_work retry_work; | 206 | struct delayed_work retry_work; |
173 | enum fc_rport_event event; | 207 | enum fc_rport_event event; |
174 | struct fc_rport_operations *ops; | 208 | struct fc_rport_operations *ops; |
175 | struct list_head peers; | 209 | struct list_head peers; |
176 | struct work_struct event_work; | 210 | struct work_struct event_work; |
177 | u32 supported_classes; | 211 | u32 supported_classes; |
178 | }; | 212 | }; |
179 | 213 | ||
180 | /* | 214 | /** |
181 | * fcoe stats structure | 215 | * struct fcoe_dev_stats - fcoe stats structure |
216 | * @SecondsSinceLastReset: Seconds since the last reset | ||
217 | * @TxFrames: Number of transmitted frames | ||
218 | * @TxWords: Number of transmitted words | ||
219 | * @RxFrames: Number of received frames | ||
220 | * @RxWords: Number of received words | ||
221 | * @ErrorFrames: Number of received error frames | ||
222 | * @DumpedFrames: Number of dumped frames | ||
223 | * @LinkFailureCount: Number of link failures | ||
224 | * @LossOfSignalCount: Number for signal losses | ||
225 | * @InvalidTxWordCount: Number of invalid transmitted words | ||
226 | * @InvalidCRCCount: Number of invalid CRCs | ||
227 | * @InputRequests: Number of input requests | ||
228 | * @OutputRequests: Number of output requests | ||
229 | * @ControlRequests: Number of control requests | ||
230 | * @InputMegabytes: Number of received megabytes | ||
231 | * @OutputMegabytes: Number of transmitted megabytes | ||
182 | */ | 232 | */ |
183 | struct fcoe_dev_stats { | 233 | struct fcoe_dev_stats { |
184 | u64 SecondsSinceLastReset; | 234 | u64 SecondsSinceLastReset; |
@@ -199,10 +249,13 @@ struct fcoe_dev_stats { | |||
199 | u64 OutputMegabytes; | 249 | u64 OutputMegabytes; |
200 | }; | 250 | }; |
201 | 251 | ||
202 | /* | 252 | /** |
203 | * els data is used for passing ELS respone specific | 253 | * struct fc_seq_els_data - ELS data used for passing ELS specific responses |
204 | * data to send ELS response mainly using infomation | 254 | * @fp: The ELS frame |
205 | * in exchange and sequence in EM layer. | 255 | * @reason: The reason for rejection |
256 | * @explan: The explaination of the rejection | ||
257 | * | ||
258 | * Mainly used by the exchange manager layer. | ||
206 | */ | 259 | */ |
207 | struct fc_seq_els_data { | 260 | struct fc_seq_els_data { |
208 | struct fc_frame *fp; | 261 | struct fc_frame *fp; |
@@ -210,77 +263,87 @@ struct fc_seq_els_data { | |||
210 | enum fc_els_rjt_explan explan; | 263 | enum fc_els_rjt_explan explan; |
211 | }; | 264 | }; |
212 | 265 | ||
213 | /* | 266 | /** |
214 | * FCP request structure, one for each scsi cmd request | 267 | * struct fc_fcp_pkt - FCP request structure (one for each scsi_cmnd request) |
268 | * @lp: The associated local port | ||
269 | * @state: The state of the I/O | ||
270 | * @tgt_flags: Target's flags | ||
271 | * @ref_cnt: Reference count | ||
272 | * @scsi_pkt_lock: Lock to protect the SCSI packet (must be taken before the | ||
273 | * host_lock if both are to be held at the same time) | ||
274 | * @cmd: The SCSI command (set and clear with the host_lock held) | ||
275 | * @list: Tracks queued commands (accessed with the host_lock held) | ||
276 | * @timer: The command timer | ||
277 | * @tm_done: Completion indicator | ||
278 | * @wait_for_comp: Indicator to wait for completion of the I/O (in jiffies) | ||
279 | * @start_time: Timestamp indicating the start of the I/O (in jiffies) | ||
280 | * @end_time: Timestamp indicating the end of the I/O (in jiffies) | ||
281 | * @last_pkt_time: Timestamp of the last frame received (in jiffies) | ||
282 | * @data_len: The length of the data | ||
283 | * @cdb_cmd: The CDB command | ||
284 | * @xfer_len: The transfer length | ||
285 | * @xfer_ddp: Indicates if this transfer used DDP (XID of the exchange | ||
286 | * will be set here if DDP was setup) | ||
287 | * @xfer_contig_end: The offset into the buffer if the buffer is contiguous | ||
288 | * (Tx and Rx) | ||
289 | * @max_payload: The maximum payload size (in bytes) | ||
290 | * @io_status: SCSI result (upper 24 bits) | ||
291 | * @cdb_status: CDB status | ||
292 | * @status_code: FCP I/O status | ||
293 | * @scsi_comp_flags: Completion flags (bit 3 Underrun bit 2: overrun) | ||
294 | * @req_flags: Request flags (bit 0: read bit:1 write) | ||
295 | * @scsi_resid: SCSI residule length | ||
296 | * @rport: The remote port that the SCSI command is targeted at | ||
297 | * @seq_ptr: The sequence that will carry the SCSI command | ||
298 | * @recov_retry: Number of recovery retries | ||
299 | * @recov_seq: The sequence for REC or SRR | ||
215 | */ | 300 | */ |
216 | struct fc_fcp_pkt { | 301 | struct fc_fcp_pkt { |
217 | /* | 302 | /* Housekeeping information */ |
218 | * housekeeping stuff | 303 | struct fc_lport *lp; |
219 | */ | 304 | u16 state; |
220 | struct fc_lport *lp; /* handle to hba struct */ | 305 | u16 tgt_flags; |
221 | u16 state; /* scsi_pkt state state */ | 306 | atomic_t ref_cnt; |
222 | u16 tgt_flags; /* target flags */ | 307 | spinlock_t scsi_pkt_lock; |
223 | atomic_t ref_cnt; /* fcp pkt ref count */ | 308 | |
224 | spinlock_t scsi_pkt_lock; /* Must be taken before the host lock | 309 | /* SCSI I/O related information */ |
225 | * if both are held at the same time */ | 310 | struct scsi_cmnd *cmd; |
226 | /* | 311 | struct list_head list; |
227 | * SCSI I/O related stuff | 312 | |
228 | */ | 313 | /* Timeout related information */ |
229 | struct scsi_cmnd *cmd; /* scsi command pointer. set/clear | 314 | struct timer_list timer; |
230 | * under host lock */ | ||
231 | struct list_head list; /* tracks queued commands. access under | ||
232 | * host lock */ | ||
233 | /* | ||
234 | * timeout related stuff | ||
235 | */ | ||
236 | struct timer_list timer; /* command timer */ | ||
237 | struct completion tm_done; | 315 | struct completion tm_done; |
238 | int wait_for_comp; | 316 | int wait_for_comp; |
239 | unsigned long start_time; /* start jiffie */ | 317 | unsigned long start_time; |
240 | unsigned long end_time; /* end jiffie */ | 318 | unsigned long end_time; |
241 | unsigned long last_pkt_time; /* jiffies of last frame received */ | 319 | unsigned long last_pkt_time; |
242 | 320 | ||
243 | /* | 321 | /* SCSI command and data transfer information */ |
244 | * scsi cmd and data transfer information | 322 | u32 data_len; |
245 | */ | 323 | |
246 | u32 data_len; | 324 | /* Transport related veriables */ |
247 | /* | 325 | struct fcp_cmnd cdb_cmd; |
248 | * transport related veriables | 326 | size_t xfer_len; |
249 | */ | 327 | u16 xfer_ddp; |
250 | struct fcp_cmnd cdb_cmd; | 328 | u32 xfer_contig_end; |
251 | size_t xfer_len; | 329 | u16 max_payload; |
252 | u16 xfer_ddp; /* this xfer is ddped */ | 330 | |
253 | u32 xfer_contig_end; /* offset of end of contiguous xfer */ | 331 | /* SCSI/FCP return status */ |
254 | u16 max_payload; /* max payload size in bytes */ | 332 | u32 io_status; |
255 | 333 | u8 cdb_status; | |
256 | /* | 334 | u8 status_code; |
257 | * scsi/fcp return status | 335 | u8 scsi_comp_flags; |
258 | */ | 336 | u32 req_flags; |
259 | u32 io_status; /* SCSI result upper 24 bits */ | 337 | u32 scsi_resid; |
260 | u8 cdb_status; | 338 | |
261 | u8 status_code; /* FCP I/O status */ | 339 | /* Associated structures */ |
262 | /* bit 3 Underrun bit 2: overrun */ | 340 | struct fc_rport *rport; |
263 | u8 scsi_comp_flags; | 341 | struct fc_seq *seq_ptr; |
264 | u32 req_flags; /* bit 0: read bit:1 write */ | 342 | |
265 | u32 scsi_resid; /* residule length */ | 343 | /* Error Processing information */ |
266 | 344 | u8 recov_retry; | |
267 | struct fc_rport *rport; /* remote port pointer */ | 345 | struct fc_seq *recov_seq; |
268 | struct fc_seq *seq_ptr; /* current sequence pointer */ | ||
269 | /* | ||
270 | * Error Processing | ||
271 | */ | ||
272 | u8 recov_retry; /* count of recovery retries */ | ||
273 | struct fc_seq *recov_seq; /* sequence for REC or SRR */ | ||
274 | }; | 346 | }; |
275 | /* | ||
276 | * FC_FCP HELPER FUNCTIONS | ||
277 | *****************************/ | ||
278 | static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp) | ||
279 | { | ||
280 | if (fsp && fsp->cmd) | ||
281 | return fsp->cmd->sc_data_direction == DMA_FROM_DEVICE; | ||
282 | return false; | ||
283 | } | ||
284 | 347 | ||
285 | /* | 348 | /* |
286 | * Structure and function definitions for managing Fibre Channel Exchanges | 349 | * Structure and function definitions for managing Fibre Channel Exchanges |
@@ -293,23 +356,51 @@ static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp) | |||
293 | 356 | ||
294 | struct fc_exch_mgr; | 357 | struct fc_exch_mgr; |
295 | struct fc_exch_mgr_anchor; | 358 | struct fc_exch_mgr_anchor; |
296 | extern u16 fc_cpu_mask; /* cpu mask for possible cpus */ | 359 | extern u16 fc_cpu_mask; /* cpu mask for possible cpus */ |
297 | 360 | ||
298 | /* | 361 | /** |
299 | * Sequence. | 362 | * struct fc_seq - FC sequence |
363 | * @id: The sequence ID | ||
364 | * @ssb_stat: Status flags for the sequence status block (SSB) | ||
365 | * @cnt: Number of frames sent so far | ||
366 | * @rec_data: FC-4 value for REC | ||
300 | */ | 367 | */ |
301 | struct fc_seq { | 368 | struct fc_seq { |
302 | u8 id; /* seq ID */ | 369 | u8 id; |
303 | u16 ssb_stat; /* status flags for sequence status block */ | 370 | u16 ssb_stat; |
304 | u16 cnt; /* frames sent so far on sequence */ | 371 | u16 cnt; |
305 | u32 rec_data; /* FC-4 value for REC */ | 372 | u32 rec_data; |
306 | }; | 373 | }; |
307 | 374 | ||
308 | #define FC_EX_DONE (1 << 0) /* ep is completed */ | 375 | #define FC_EX_DONE (1 << 0) /* ep is completed */ |
309 | #define FC_EX_RST_CLEANUP (1 << 1) /* reset is forcing completion */ | 376 | #define FC_EX_RST_CLEANUP (1 << 1) /* reset is forcing completion */ |
310 | 377 | ||
311 | /* | 378 | /** |
312 | * Exchange. | 379 | * struct fc_exch - Fibre Channel Exchange |
380 | * @em: Exchange manager | ||
381 | * @pool: Exchange pool | ||
382 | * @state: The exchange's state | ||
383 | * @xid: The exchange ID | ||
384 | * @ex_list: Handle used by the EM to track free exchanges | ||
385 | * @ex_lock: Lock that protects the exchange | ||
386 | * @ex_refcnt: Reference count | ||
387 | * @timeout_work: Handle for timeout handler | ||
388 | * @lp: The local port that this exchange is on | ||
389 | * @oxid: Originator's exchange ID | ||
390 | * @rxid: Responder's exchange ID | ||
391 | * @oid: Originator's FCID | ||
392 | * @sid: Source FCID | ||
393 | * @did: Destination FCID | ||
394 | * @esb_stat: ESB exchange status | ||
395 | * @r_a_tov: Resouce allocation time out value (in msecs) | ||
396 | * @seq_id: The next sequence ID to use | ||
397 | * @f_ctl: F_CTL flags for the sequence | ||
398 | * @fh_type: The frame type | ||
399 | * @class: The class of service | ||
400 | * @seq: The sequence in use on this exchange | ||
401 | * @resp: Callback for responses on this exchange | ||
402 | * @destructor: Called when destroying the exchange | ||
403 | * @arg: Passed as a void pointer to the resp() callback | ||
313 | * | 404 | * |
314 | * Locking notes: The ex_lock protects following items: | 405 | * Locking notes: The ex_lock protects following items: |
315 | * state, esb_stat, f_ctl, seq.ssb_stat | 406 | * state, esb_stat, f_ctl, seq.ssb_stat |
@@ -317,76 +408,59 @@ struct fc_seq { | |||
317 | * sequence allocation | 408 | * sequence allocation |
318 | */ | 409 | */ |
319 | struct fc_exch { | 410 | struct fc_exch { |
320 | struct fc_exch_mgr *em; /* exchange manager */ | 411 | struct fc_exch_mgr *em; |
321 | struct fc_exch_pool *pool; /* per cpu exches pool */ | 412 | struct fc_exch_pool *pool; |
322 | u32 state; /* internal driver state */ | 413 | u32 state; |
323 | u16 xid; /* our exchange ID */ | 414 | u16 xid; |
324 | struct list_head ex_list; /* free or busy list linkage */ | 415 | struct list_head ex_list; |
325 | spinlock_t ex_lock; /* lock covering exchange state */ | 416 | spinlock_t ex_lock; |
326 | atomic_t ex_refcnt; /* reference counter */ | 417 | atomic_t ex_refcnt; |
327 | struct delayed_work timeout_work; /* timer for upper level protocols */ | 418 | struct delayed_work timeout_work; |
328 | struct fc_lport *lp; /* fc device instance */ | 419 | struct fc_lport *lp; |
329 | u16 oxid; /* originator's exchange ID */ | 420 | u16 oxid; |
330 | u16 rxid; /* responder's exchange ID */ | 421 | u16 rxid; |
331 | u32 oid; /* originator's FCID */ | 422 | u32 oid; |
332 | u32 sid; /* source FCID */ | 423 | u32 sid; |
333 | u32 did; /* destination FCID */ | 424 | u32 did; |
334 | u32 esb_stat; /* exchange status for ESB */ | 425 | u32 esb_stat; |
335 | u32 r_a_tov; /* r_a_tov from rport (msec) */ | 426 | u32 r_a_tov; |
336 | u8 seq_id; /* next sequence ID to use */ | 427 | u8 seq_id; |
337 | u32 f_ctl; /* F_CTL flags for sequences */ | 428 | u32 f_ctl; |
338 | u8 fh_type; /* frame type */ | 429 | u8 fh_type; |
339 | enum fc_class class; /* class of service */ | 430 | enum fc_class class; |
340 | struct fc_seq seq; /* single sequence */ | 431 | struct fc_seq seq; |
341 | /* | 432 | |
342 | * Handler for responses to this current exchange. | 433 | void (*resp)(struct fc_seq *, struct fc_frame *, void *); |
343 | */ | 434 | void *arg; |
344 | void (*resp)(struct fc_seq *, struct fc_frame *, void *); | 435 | |
345 | void (*destructor)(struct fc_seq *, void *); | 436 | void (*destructor)(struct fc_seq *, void *); |
346 | /* | 437 | |
347 | * arg is passed as void pointer to exchange | ||
348 | * resp and destructor handlers | ||
349 | */ | ||
350 | void *arg; | ||
351 | }; | 438 | }; |
352 | #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq) | 439 | #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq) |
353 | 440 | ||
354 | struct libfc_function_template { | ||
355 | 441 | ||
442 | struct libfc_function_template { | ||
356 | /* | 443 | /* |
357 | * Interface to send a FC frame | 444 | * Interface to send a FC frame |
358 | * | 445 | * |
359 | * STATUS: REQUIRED | 446 | * STATUS: REQUIRED |
360 | */ | 447 | */ |
361 | int (*frame_send)(struct fc_lport *lp, struct fc_frame *fp); | 448 | int (*frame_send)(struct fc_lport *, struct fc_frame *); |
362 | 449 | ||
363 | /* | 450 | /* |
364 | * Interface to send ELS/CT frames | 451 | * Interface to send ELS/CT frames |
365 | * | 452 | * |
366 | * STATUS: OPTIONAL | 453 | * STATUS: OPTIONAL |
367 | */ | 454 | */ |
368 | struct fc_seq *(*elsct_send)(struct fc_lport *lport, | 455 | struct fc_seq *(*elsct_send)(struct fc_lport *, u32 did, |
369 | u32 did, | 456 | struct fc_frame *, unsigned int op, |
370 | struct fc_frame *fp, | ||
371 | unsigned int op, | ||
372 | void (*resp)(struct fc_seq *, | 457 | void (*resp)(struct fc_seq *, |
373 | struct fc_frame *fp, | 458 | struct fc_frame *, void *arg), |
374 | void *arg), | ||
375 | void *arg, u32 timer_msec); | 459 | void *arg, u32 timer_msec); |
376 | 460 | ||
377 | /* | 461 | /* |
378 | * Send the FC frame payload using a new exchange and sequence. | 462 | * Send the FC frame payload using a new exchange and sequence. |
379 | * | 463 | * |
380 | * The frame pointer with some of the header's fields must be | ||
381 | * filled before calling exch_seq_send(), those fields are, | ||
382 | * | ||
383 | * - routing control | ||
384 | * - FC port did | ||
385 | * - FC port sid | ||
386 | * - FC header type | ||
387 | * - frame control | ||
388 | * - parameter or relative offset | ||
389 | * | ||
390 | * The exchange response handler is set in this routine to resp() | 464 | * The exchange response handler is set in this routine to resp() |
391 | * function pointer. It can be called in two scenarios: if a timeout | 465 | * function pointer. It can be called in two scenarios: if a timeout |
392 | * occurs or if a response frame is received for the exchange. The | 466 | * occurs or if a response frame is received for the exchange. The |
@@ -407,14 +481,13 @@ struct libfc_function_template { | |||
407 | * | 481 | * |
408 | * STATUS: OPTIONAL | 482 | * STATUS: OPTIONAL |
409 | */ | 483 | */ |
410 | struct fc_seq *(*exch_seq_send)(struct fc_lport *lp, | 484 | struct fc_seq *(*exch_seq_send)(struct fc_lport *, struct fc_frame *, |
411 | struct fc_frame *fp, | 485 | void (*resp)(struct fc_seq *, |
412 | void (*resp)(struct fc_seq *sp, | 486 | struct fc_frame *, |
413 | struct fc_frame *fp, | 487 | void *), |
414 | void *arg), | 488 | void (*destructor)(struct fc_seq *, |
415 | void (*destructor)(struct fc_seq *sp, | 489 | void *), |
416 | void *arg), | 490 | void *, unsigned int timer_msec); |
417 | void *arg, unsigned int timer_msec); | ||
418 | 491 | ||
419 | /* | 492 | /* |
420 | * Sets up the DDP context for a given exchange id on the given | 493 | * Sets up the DDP context for a given exchange id on the given |
@@ -422,22 +495,22 @@ struct libfc_function_template { | |||
422 | * | 495 | * |
423 | * STATUS: OPTIONAL | 496 | * STATUS: OPTIONAL |
424 | */ | 497 | */ |
425 | int (*ddp_setup)(struct fc_lport *lp, u16 xid, | 498 | int (*ddp_setup)(struct fc_lport *, u16, struct scatterlist *, |
426 | struct scatterlist *sgl, unsigned int sgc); | 499 | unsigned int); |
427 | /* | 500 | /* |
428 | * Completes the DDP transfer and returns the length of data DDPed | 501 | * Completes the DDP transfer and returns the length of data DDPed |
429 | * for the given exchange id. | 502 | * for the given exchange id. |
430 | * | 503 | * |
431 | * STATUS: OPTIONAL | 504 | * STATUS: OPTIONAL |
432 | */ | 505 | */ |
433 | int (*ddp_done)(struct fc_lport *lp, u16 xid); | 506 | int (*ddp_done)(struct fc_lport *, u16); |
434 | /* | 507 | /* |
435 | * Send a frame using an existing sequence and exchange. | 508 | * Send a frame using an existing sequence and exchange. |
436 | * | 509 | * |
437 | * STATUS: OPTIONAL | 510 | * STATUS: OPTIONAL |
438 | */ | 511 | */ |
439 | int (*seq_send)(struct fc_lport *lp, struct fc_seq *sp, | 512 | int (*seq_send)(struct fc_lport *, struct fc_seq *, |
440 | struct fc_frame *fp); | 513 | struct fc_frame *); |
441 | 514 | ||
442 | /* | 515 | /* |
443 | * Send an ELS response using infomation from a previous | 516 | * Send an ELS response using infomation from a previous |
@@ -445,8 +518,8 @@ struct libfc_function_template { | |||
445 | * | 518 | * |
446 | * STATUS: OPTIONAL | 519 | * STATUS: OPTIONAL |
447 | */ | 520 | */ |
448 | void (*seq_els_rsp_send)(struct fc_seq *sp, enum fc_els_cmd els_cmd, | 521 | void (*seq_els_rsp_send)(struct fc_seq *, enum fc_els_cmd, |
449 | struct fc_seq_els_data *els_data); | 522 | struct fc_seq_els_data *); |
450 | 523 | ||
451 | /* | 524 | /* |
452 | * Abort an exchange and sequence. Generally called because of a | 525 | * Abort an exchange and sequence. Generally called because of a |
@@ -458,7 +531,7 @@ struct libfc_function_template { | |||
458 | * | 531 | * |
459 | * STATUS: OPTIONAL | 532 | * STATUS: OPTIONAL |
460 | */ | 533 | */ |
461 | int (*seq_exch_abort)(const struct fc_seq *req_sp, | 534 | int (*seq_exch_abort)(const struct fc_seq *, |
462 | unsigned int timer_msec); | 535 | unsigned int timer_msec); |
463 | 536 | ||
464 | /* | 537 | /* |
@@ -467,14 +540,14 @@ struct libfc_function_template { | |||
467 | * | 540 | * |
468 | * STATUS: OPTIONAL | 541 | * STATUS: OPTIONAL |
469 | */ | 542 | */ |
470 | void (*exch_done)(struct fc_seq *sp); | 543 | void (*exch_done)(struct fc_seq *); |
471 | 544 | ||
472 | /* | 545 | /* |
473 | * Start a new sequence on the same exchange/sequence tuple. | 546 | * Start a new sequence on the same exchange/sequence tuple. |
474 | * | 547 | * |
475 | * STATUS: OPTIONAL | 548 | * STATUS: OPTIONAL |
476 | */ | 549 | */ |
477 | struct fc_seq *(*seq_start_next)(struct fc_seq *sp); | 550 | struct fc_seq *(*seq_start_next)(struct fc_seq *); |
478 | 551 | ||
479 | /* | 552 | /* |
480 | * Reset an exchange manager, completing all sequences and exchanges. | 553 | * Reset an exchange manager, completing all sequences and exchanges. |
@@ -483,8 +556,7 @@ struct libfc_function_template { | |||
483 | * | 556 | * |
484 | * STATUS: OPTIONAL | 557 | * STATUS: OPTIONAL |
485 | */ | 558 | */ |
486 | void (*exch_mgr_reset)(struct fc_lport *, | 559 | void (*exch_mgr_reset)(struct fc_lport *, u32 s_id, u32 d_id); |
487 | u32 s_id, u32 d_id); | ||
488 | 560 | ||
489 | /* | 561 | /* |
490 | * Flush the rport work queue. Generally used before shutdown. | 562 | * Flush the rport work queue. Generally used before shutdown. |
@@ -498,8 +570,8 @@ struct libfc_function_template { | |||
498 | * | 570 | * |
499 | * STATUS: OPTIONAL | 571 | * STATUS: OPTIONAL |
500 | */ | 572 | */ |
501 | void (*lport_recv)(struct fc_lport *lp, struct fc_seq *sp, | 573 | void (*lport_recv)(struct fc_lport *, struct fc_seq *, |
502 | struct fc_frame *fp); | 574 | struct fc_frame *); |
503 | 575 | ||
504 | /* | 576 | /* |
505 | * Reset the local port. | 577 | * Reset the local port. |
@@ -565,31 +637,31 @@ struct libfc_function_template { | |||
565 | * | 637 | * |
566 | * STATUS: OPTIONAL | 638 | * STATUS: OPTIONAL |
567 | */ | 639 | */ |
568 | int (*fcp_cmd_send)(struct fc_lport *lp, struct fc_fcp_pkt *fsp, | 640 | int (*fcp_cmd_send)(struct fc_lport *, struct fc_fcp_pkt *, |
569 | void (*resp)(struct fc_seq *, struct fc_frame *fp, | 641 | void (*resp)(struct fc_seq *, struct fc_frame *, |
570 | void *arg)); | 642 | void *)); |
571 | 643 | ||
572 | /* | 644 | /* |
573 | * Cleanup the FCP layer, used durring link down and reset | 645 | * Cleanup the FCP layer, used durring link down and reset |
574 | * | 646 | * |
575 | * STATUS: OPTIONAL | 647 | * STATUS: OPTIONAL |
576 | */ | 648 | */ |
577 | void (*fcp_cleanup)(struct fc_lport *lp); | 649 | void (*fcp_cleanup)(struct fc_lport *); |
578 | 650 | ||
579 | /* | 651 | /* |
580 | * Abort all I/O on a local port | 652 | * Abort all I/O on a local port |
581 | * | 653 | * |
582 | * STATUS: OPTIONAL | 654 | * STATUS: OPTIONAL |
583 | */ | 655 | */ |
584 | void (*fcp_abort_io)(struct fc_lport *lp); | 656 | void (*fcp_abort_io)(struct fc_lport *); |
585 | 657 | ||
586 | /* | 658 | /* |
587 | * Receive a request for the discovery layer. | 659 | * Receive a request for the discovery layer. |
588 | * | 660 | * |
589 | * STATUS: OPTIONAL | 661 | * STATUS: OPTIONAL |
590 | */ | 662 | */ |
591 | void (*disc_recv_req)(struct fc_seq *, | 663 | void (*disc_recv_req)(struct fc_seq *, struct fc_frame *, |
592 | struct fc_frame *, struct fc_lport *); | 664 | struct fc_lport *); |
593 | 665 | ||
594 | /* | 666 | /* |
595 | * Start discovery for a local port. | 667 | * Start discovery for a local port. |
@@ -618,133 +690,224 @@ struct libfc_function_template { | |||
618 | void (*disc_stop_final) (struct fc_lport *); | 690 | void (*disc_stop_final) (struct fc_lport *); |
619 | }; | 691 | }; |
620 | 692 | ||
621 | /* information used by the discovery layer */ | 693 | /** |
694 | * struct fc_disc - Discovery context | ||
695 | * @retry_count: Number of retries | ||
696 | * @pending: 1 if discovery is pending, 0 if not | ||
697 | * @requesting: 1 if discovery has been requested, 0 if not | ||
698 | * @seq_count: Number of sequences used for discovery | ||
699 | * @buf_len: Length of the discovery buffer | ||
700 | * @disc_id: Discovery ID | ||
701 | * @rports: List of discovered remote ports | ||
702 | * @lport: The local port that discovery is for | ||
703 | * @disc_mutex: Mutex that protects the discovery context | ||
704 | * @partial_buf: Partial name buffer (if names are returned | ||
705 | * in multiple frames) | ||
706 | * @disc_work: handle for delayed work context | ||
707 | * @disc_callback: Callback routine called when discovery completes | ||
708 | */ | ||
622 | struct fc_disc { | 709 | struct fc_disc { |
623 | unsigned char retry_count; | 710 | unsigned char retry_count; |
624 | unsigned char pending; | 711 | unsigned char pending; |
625 | unsigned char requested; | 712 | unsigned char requested; |
626 | unsigned short seq_count; | 713 | unsigned short seq_count; |
627 | unsigned char buf_len; | 714 | unsigned char buf_len; |
628 | u16 disc_id; | 715 | u16 disc_id; |
716 | |||
717 | struct list_head rports; | ||
718 | struct fc_lport *lport; | ||
719 | struct mutex disc_mutex; | ||
720 | struct fc_gpn_ft_resp partial_buf; | ||
721 | struct delayed_work disc_work; | ||
629 | 722 | ||
630 | void (*disc_callback)(struct fc_lport *, | 723 | void (*disc_callback)(struct fc_lport *, |
631 | enum fc_disc_event); | 724 | enum fc_disc_event); |
632 | |||
633 | struct list_head rports; | ||
634 | struct fc_lport *lport; | ||
635 | struct mutex disc_mutex; | ||
636 | struct fc_gpn_ft_resp partial_buf; /* partial name buffer */ | ||
637 | struct delayed_work disc_work; | ||
638 | }; | 725 | }; |
639 | 726 | ||
727 | /** | ||
728 | * struct fc_lport - Local port | ||
729 | * @host: The SCSI host associated with a local port | ||
730 | * @ema_list: Exchange manager anchor list | ||
731 | * @dns_rdata: The directory server remote port | ||
732 | * @ptp_rdata: Point to point remote port | ||
733 | * @scsi_priv: FCP layer internal data | ||
734 | * @disc: Discovery context | ||
735 | * @vports: Child vports if N_Port | ||
736 | * @vport: Parent vport if VN_Port | ||
737 | * @tt: Libfc function template | ||
738 | * @link_up: Link state (1 = link up, 0 = link down) | ||
739 | * @qfull: Queue state (1 queue is full, 0 queue is not full) | ||
740 | * @state: Identifies the state | ||
741 | * @boot_time: Timestamp indicating when the local port came online | ||
742 | * @host_stats: SCSI host statistics | ||
743 | * @dev_stats: FCoE device stats (TODO: libfc should not be | ||
744 | * FCoE aware) | ||
745 | * @retry_count: Number of retries in the current state | ||
746 | * @wwpn: World Wide Port Name | ||
747 | * @wwnn: World Wide Node Name | ||
748 | * @service_params: Common service parameters | ||
749 | * @e_d_tov: Error detection timeout value | ||
750 | * @r_a_tov: Resouce allocation timeout value | ||
751 | * @rnid_gen: RNID information | ||
752 | * @sg_supp: Indicates if scatter gather is supported | ||
753 | * @seq_offload: Indicates if sequence offload is supported | ||
754 | * @crc_offload: Indicates if CRC offload is supported | ||
755 | * @lro_enabled: Indicates if large receive offload is supported | ||
756 | * @does_npiv: Supports multiple vports | ||
757 | * @npiv_enabled: Switch/fabric allows NPIV | ||
758 | * @mfs: The maximum Fibre Channel payload size | ||
759 | * @max_retry_count: The maximum retry attempts | ||
760 | * @max_rport_retry_count: The maximum remote port retry attempts | ||
761 | * @lro_xid: The maximum XID for LRO | ||
762 | * @lso_max: The maximum large offload send size | ||
763 | * @fcts: FC-4 type mask | ||
764 | * @lp_mutex: Mutex to protect the local port | ||
765 | * @list: Handle for list of local ports | ||
766 | * @retry_work: Handle to local port for delayed retry context | ||
767 | */ | ||
640 | struct fc_lport { | 768 | struct fc_lport { |
641 | struct list_head list; | ||
642 | |||
643 | /* Associations */ | 769 | /* Associations */ |
644 | struct Scsi_Host *host; | 770 | struct Scsi_Host *host; |
645 | struct list_head ema_list; | 771 | struct list_head ema_list; |
646 | struct list_head vports; /* child vports if N_Port */ | 772 | struct fc_rport_priv *dns_rdata; |
647 | struct fc_vport *vport; /* parent vport if VN_Port */ | 773 | struct fc_rport_priv *ptp_rdata; |
648 | struct fc_rport_priv *dns_rp; | 774 | void *scsi_priv; |
649 | struct fc_rport_priv *ptp_rp; | 775 | struct fc_disc disc; |
650 | void *scsi_priv; | 776 | |
651 | struct fc_disc disc; | 777 | /* Virtual port information */ |
778 | struct list_head vports; | ||
779 | struct fc_vport *vport; | ||
652 | 780 | ||
653 | /* Operational Information */ | 781 | /* Operational Information */ |
654 | struct libfc_function_template tt; | 782 | struct libfc_function_template tt; |
655 | u8 link_up; | 783 | u8 link_up; |
656 | u8 qfull; | 784 | u8 qfull; |
657 | enum fc_lport_state state; | 785 | enum fc_lport_state state; |
658 | unsigned long boot_time; | 786 | unsigned long boot_time; |
659 | 787 | struct fc_host_statistics host_stats; | |
660 | struct fc_host_statistics host_stats; | 788 | struct fcoe_dev_stats *dev_stats; |
661 | struct fcoe_dev_stats *dev_stats; | 789 | u8 retry_count; |
662 | 790 | ||
663 | u64 wwpn; | 791 | /* Fabric information */ |
664 | u64 wwnn; | 792 | u64 wwpn; |
665 | u8 retry_count; | 793 | u64 wwnn; |
794 | unsigned int service_params; | ||
795 | unsigned int e_d_tov; | ||
796 | unsigned int r_a_tov; | ||
797 | struct fc_els_rnid_gen rnid_gen; | ||
666 | 798 | ||
667 | /* Capabilities */ | 799 | /* Capabilities */ |
668 | u32 sg_supp:1; /* scatter gather supported */ | 800 | u32 sg_supp:1; |
669 | u32 seq_offload:1; /* seq offload supported */ | 801 | u32 seq_offload:1; |
670 | u32 crc_offload:1; /* crc offload supported */ | 802 | u32 crc_offload:1; |
671 | u32 lro_enabled:1; /* large receive offload */ | 803 | u32 lro_enabled:1; |
672 | u32 does_npiv:1; /* supports multiple vports */ | 804 | u32 does_npiv:1; |
673 | u32 npiv_enabled:1; /* switch/fabric allows NPIV */ | 805 | u32 npiv_enabled:1; |
674 | u32 mfs; /* max FC payload size */ | 806 | u32 mfs; |
675 | unsigned int service_params; | 807 | u8 max_retry_count; |
676 | unsigned int e_d_tov; | 808 | u8 max_rport_retry_count; |
677 | unsigned int r_a_tov; | 809 | u16 link_speed; |
678 | u8 max_retry_count; | 810 | u16 link_supported_speeds; |
679 | u8 max_rport_retry_count; | 811 | u16 lro_xid; |
680 | u16 link_speed; | 812 | unsigned int lso_max; |
681 | u16 link_supported_speeds; | 813 | struct fc_ns_fts fcts; |
682 | u16 lro_xid; /* max xid for fcoe lro */ | ||
683 | unsigned int lso_max; /* max large send size */ | ||
684 | struct fc_ns_fts fcts; /* FC-4 type masks */ | ||
685 | struct fc_els_rnid_gen rnid_gen; /* RNID information */ | ||
686 | |||
687 | /* Semaphores */ | ||
688 | struct mutex lp_mutex; | ||
689 | 814 | ||
690 | /* Miscellaneous */ | 815 | /* Miscellaneous */ |
691 | struct delayed_work retry_work; | 816 | struct mutex lp_mutex; |
817 | struct list_head list; | ||
818 | struct delayed_work retry_work; | ||
692 | }; | 819 | }; |
693 | 820 | ||
694 | /* | 821 | /* |
695 | * FC_LPORT HELPER FUNCTIONS | 822 | * FC_LPORT HELPER FUNCTIONS |
696 | *****************************/ | 823 | *****************************/ |
697 | static inline int fc_lport_test_ready(struct fc_lport *lp) | 824 | |
825 | /** | ||
826 | * fc_lport_test_ready() - Determine if a local port is in the READY state | ||
827 | * @lport: The local port to test | ||
828 | */ | ||
829 | static inline int fc_lport_test_ready(struct fc_lport *lport) | ||
698 | { | 830 | { |
699 | return lp->state == LPORT_ST_READY; | 831 | return lport->state == LPORT_ST_READY; |
700 | } | 832 | } |
701 | 833 | ||
702 | static inline void fc_set_wwnn(struct fc_lport *lp, u64 wwnn) | 834 | /** |
835 | * fc_set_wwnn() - Set the World Wide Node Name of a local port | ||
836 | * @lport: The local port whose WWNN is to be set | ||
837 | * @wwnn: The new WWNN | ||
838 | */ | ||
839 | static inline void fc_set_wwnn(struct fc_lport *lport, u64 wwnn) | ||
703 | { | 840 | { |
704 | lp->wwnn = wwnn; | 841 | lport->wwnn = wwnn; |
705 | } | 842 | } |
706 | 843 | ||
707 | static inline void fc_set_wwpn(struct fc_lport *lp, u64 wwnn) | 844 | /** |
845 | * fc_set_wwpn() - Set the World Wide Port Name of a local port | ||
846 | * @lport: The local port whose WWPN is to be set | ||
847 | * @wwnn: The new WWPN | ||
848 | */ | ||
849 | static inline void fc_set_wwpn(struct fc_lport *lport, u64 wwnn) | ||
708 | { | 850 | { |
709 | lp->wwpn = wwnn; | 851 | lport->wwpn = wwnn; |
710 | } | 852 | } |
711 | 853 | ||
712 | static inline void fc_lport_state_enter(struct fc_lport *lp, | 854 | /** |
855 | * fc_lport_state_enter() - Change a local port's state | ||
856 | * @lport: The local port whose state is to change | ||
857 | * @state: The new state | ||
858 | */ | ||
859 | static inline void fc_lport_state_enter(struct fc_lport *lport, | ||
713 | enum fc_lport_state state) | 860 | enum fc_lport_state state) |
714 | { | 861 | { |
715 | if (state != lp->state) | 862 | if (state != lport->state) |
716 | lp->retry_count = 0; | 863 | lport->retry_count = 0; |
717 | lp->state = state; | 864 | lport->state = state; |
718 | } | 865 | } |
719 | 866 | ||
720 | static inline int fc_lport_init_stats(struct fc_lport *lp) | 867 | /** |
868 | * fc_lport_init_stats() - Allocate per-CPU statistics for a local port | ||
869 | * @lport: The local port whose statistics are to be initialized | ||
870 | */ | ||
871 | static inline int fc_lport_init_stats(struct fc_lport *lport) | ||
721 | { | 872 | { |
722 | /* allocate per cpu stats block */ | 873 | lport->dev_stats = alloc_percpu(struct fcoe_dev_stats); |
723 | lp->dev_stats = alloc_percpu(struct fcoe_dev_stats); | 874 | if (!lport->dev_stats) |
724 | if (!lp->dev_stats) | ||
725 | return -ENOMEM; | 875 | return -ENOMEM; |
726 | return 0; | 876 | return 0; |
727 | } | 877 | } |
728 | 878 | ||
729 | static inline void fc_lport_free_stats(struct fc_lport *lp) | 879 | /** |
880 | * fc_lport_free_stats() - Free memory for a local port's statistics | ||
881 | * @lport: The local port whose statistics are to be freed | ||
882 | */ | ||
883 | static inline void fc_lport_free_stats(struct fc_lport *lport) | ||
730 | { | 884 | { |
731 | free_percpu(lp->dev_stats); | 885 | free_percpu(lport->dev_stats); |
732 | } | 886 | } |
733 | 887 | ||
734 | static inline struct fcoe_dev_stats *fc_lport_get_stats(struct fc_lport *lp) | 888 | /** |
889 | * fc_lport_get_stats() - Get a local port's statistics | ||
890 | * @lport: The local port whose statistics are to be retreived | ||
891 | */ | ||
892 | static inline struct fcoe_dev_stats *fc_lport_get_stats(struct fc_lport *lport) | ||
735 | { | 893 | { |
736 | return per_cpu_ptr(lp->dev_stats, smp_processor_id()); | 894 | return per_cpu_ptr(lport->dev_stats, smp_processor_id()); |
737 | } | 895 | } |
738 | 896 | ||
739 | static inline void *lport_priv(const struct fc_lport *lp) | 897 | /** |
898 | * lport_priv() - Return the private data from a local port | ||
899 | * @lport: The local port whose private data is to be retreived | ||
900 | */ | ||
901 | static inline void *lport_priv(const struct fc_lport *lport) | ||
740 | { | 902 | { |
741 | return (void *)(lp + 1); | 903 | return (void *)(lport + 1); |
742 | } | 904 | } |
743 | 905 | ||
744 | /** | 906 | /** |
745 | * libfc_host_alloc() - Allocate a Scsi_Host with room for the fc_lport | 907 | * libfc_host_alloc() - Allocate a Scsi_Host with room for a local port and |
746 | * @sht: ptr to the scsi host templ | 908 | * LLD private data |
747 | * @priv_size: size of private data after fc_lport | 909 | * @sht: The SCSI host template |
910 | * @priv_size: Size of private data | ||
748 | * | 911 | * |
749 | * Returns: libfc lport | 912 | * Returns: libfc lport |
750 | */ | 913 | */ |
@@ -765,156 +928,73 @@ libfc_host_alloc(struct scsi_host_template *sht, int priv_size) | |||
765 | } | 928 | } |
766 | 929 | ||
767 | /* | 930 | /* |
768 | * LOCAL PORT LAYER | 931 | * FC_FCP HELPER FUNCTIONS |
769 | *****************************/ | 932 | *****************************/ |
770 | int fc_lport_init(struct fc_lport *lp); | 933 | static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp) |
771 | 934 | { | |
772 | /* | 935 | if (fsp && fsp->cmd) |
773 | * Destroy the specified local port by finding and freeing all | 936 | return fsp->cmd->sc_data_direction == DMA_FROM_DEVICE; |
774 | * fc_rports associated with it and then by freeing the fc_lport | 937 | return false; |
775 | * itself. | 938 | } |
776 | */ | ||
777 | int fc_lport_destroy(struct fc_lport *lp); | ||
778 | |||
779 | /* | ||
780 | * Logout the specified local port from the fabric | ||
781 | */ | ||
782 | int fc_fabric_logoff(struct fc_lport *lp); | ||
783 | |||
784 | /* | ||
785 | * Initiate the LP state machine. This handler will use fc_host_attr | ||
786 | * to store the FLOGI service parameters, so fc_host_attr must be | ||
787 | * initialized before calling this handler. | ||
788 | */ | ||
789 | int fc_fabric_login(struct fc_lport *lp); | ||
790 | 939 | ||
791 | /* | 940 | /* |
792 | * The link is up for the given local port. | 941 | * LOCAL PORT LAYER |
793 | */ | 942 | *****************************/ |
943 | int fc_lport_init(struct fc_lport *); | ||
944 | int fc_lport_destroy(struct fc_lport *); | ||
945 | int fc_fabric_logoff(struct fc_lport *); | ||
946 | int fc_fabric_login(struct fc_lport *); | ||
794 | void __fc_linkup(struct fc_lport *); | 947 | void __fc_linkup(struct fc_lport *); |
795 | void fc_linkup(struct fc_lport *); | 948 | void fc_linkup(struct fc_lport *); |
796 | |||
797 | /* | ||
798 | * Link is down for the given local port. | ||
799 | */ | ||
800 | void __fc_linkdown(struct fc_lport *); | 949 | void __fc_linkdown(struct fc_lport *); |
801 | void fc_linkdown(struct fc_lport *); | 950 | void fc_linkdown(struct fc_lport *); |
802 | 951 | void fc_vport_setlink(struct fc_lport *); | |
803 | /* | 952 | void fc_vports_linkchange(struct fc_lport *); |
804 | * Configure the local port. | ||
805 | */ | ||
806 | int fc_lport_config(struct fc_lport *); | 953 | int fc_lport_config(struct fc_lport *); |
807 | |||
808 | /* | ||
809 | * Reset the local port. | ||
810 | */ | ||
811 | int fc_lport_reset(struct fc_lport *); | 954 | int fc_lport_reset(struct fc_lport *); |
812 | 955 | int fc_set_mfs(struct fc_lport *, u32 mfs); | |
813 | /* | 956 | struct fc_lport *libfc_vport_create(struct fc_vport *, int privsize); |
814 | * Set the mfs or reset | 957 | struct fc_lport *fc_vport_id_lookup(struct fc_lport *, u32 port_id); |
815 | */ | 958 | int fc_lport_bsg_request(struct fc_bsg_job *); |
816 | int fc_set_mfs(struct fc_lport *lp, u32 mfs); | ||
817 | |||
818 | /* | ||
819 | * Allocate a new lport struct for an NPIV VN_Port | ||
820 | */ | ||
821 | struct fc_lport *libfc_vport_create(struct fc_vport *vport, int privsize); | ||
822 | |||
823 | /* | ||
824 | * Find an NPIV VN_Port by port ID | ||
825 | */ | ||
826 | struct fc_lport *fc_vport_id_lookup(struct fc_lport *n_port, u32 port_id); | ||
827 | |||
828 | /* | ||
829 | * NPIV VN_Port link state management | ||
830 | */ | ||
831 | void fc_vport_setlink(struct fc_lport *vn_port); | ||
832 | void fc_vports_linkchange(struct fc_lport *n_port); | ||
833 | |||
834 | /* | ||
835 | * Issue fc pass-thru request via bsg interface | ||
836 | */ | ||
837 | int fc_lport_bsg_request(struct fc_bsg_job *job); | ||
838 | |||
839 | 959 | ||
840 | /* | 960 | /* |
841 | * REMOTE PORT LAYER | 961 | * REMOTE PORT LAYER |
842 | *****************************/ | 962 | *****************************/ |
843 | int fc_rport_init(struct fc_lport *lp); | 963 | int fc_rport_init(struct fc_lport *); |
844 | void fc_rport_terminate_io(struct fc_rport *rp); | 964 | void fc_rport_terminate_io(struct fc_rport *); |
845 | 965 | ||
846 | /* | 966 | /* |
847 | * DISCOVERY LAYER | 967 | * DISCOVERY LAYER |
848 | *****************************/ | 968 | *****************************/ |
849 | int fc_disc_init(struct fc_lport *lp); | 969 | int fc_disc_init(struct fc_lport *); |
850 | |||
851 | 970 | ||
852 | /* | 971 | /* |
853 | * SCSI LAYER | 972 | * FCP LAYER |
854 | *****************************/ | 973 | *****************************/ |
855 | /* | ||
856 | * Initialize the SCSI block of libfc | ||
857 | */ | ||
858 | int fc_fcp_init(struct fc_lport *); | 974 | int fc_fcp_init(struct fc_lport *); |
975 | void fc_fcp_destroy(struct fc_lport *); | ||
859 | 976 | ||
860 | /* | 977 | /* |
861 | * This section provides an API which allows direct interaction | 978 | * SCSI INTERACTION LAYER |
862 | * with the SCSI-ml. Each of these functions satisfies a function | 979 | *****************************/ |
863 | * pointer defined in Scsi_Host and therefore is always called | 980 | int fc_queuecommand(struct scsi_cmnd *, |
864 | * directly from the SCSI-ml. | ||
865 | */ | ||
866 | int fc_queuecommand(struct scsi_cmnd *sc_cmd, | ||
867 | void (*done)(struct scsi_cmnd *)); | 981 | void (*done)(struct scsi_cmnd *)); |
868 | 982 | int fc_eh_abort(struct scsi_cmnd *); | |
869 | /* | 983 | int fc_eh_device_reset(struct scsi_cmnd *); |
870 | * Send an ABTS frame to the target device. The sc_cmd argument | 984 | int fc_eh_host_reset(struct scsi_cmnd *); |
871 | * is a pointer to the SCSI command to be aborted. | 985 | int fc_slave_alloc(struct scsi_device *); |
872 | */ | 986 | int fc_change_queue_depth(struct scsi_device *, int qdepth, int reason); |
873 | int fc_eh_abort(struct scsi_cmnd *sc_cmd); | 987 | int fc_change_queue_type(struct scsi_device *, int tag_type); |
874 | |||
875 | /* | ||
876 | * Reset a LUN by sending send the tm cmd to the target. | ||
877 | */ | ||
878 | int fc_eh_device_reset(struct scsi_cmnd *sc_cmd); | ||
879 | |||
880 | /* | ||
881 | * Reset the host adapter. | ||
882 | */ | ||
883 | int fc_eh_host_reset(struct scsi_cmnd *sc_cmd); | ||
884 | |||
885 | /* | ||
886 | * Check rport status. | ||
887 | */ | ||
888 | int fc_slave_alloc(struct scsi_device *sdev); | ||
889 | |||
890 | /* | ||
891 | * Adjust the queue depth. | ||
892 | */ | ||
893 | int fc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason); | ||
894 | |||
895 | /* | ||
896 | * Change the tag type. | ||
897 | */ | ||
898 | int fc_change_queue_type(struct scsi_device *sdev, int tag_type); | ||
899 | |||
900 | /* | ||
901 | * Free memory pools used by the FCP layer. | ||
902 | */ | ||
903 | void fc_fcp_destroy(struct fc_lport *); | ||
904 | 988 | ||
905 | /* | 989 | /* |
906 | * ELS/CT interface | 990 | * ELS/CT interface |
907 | *****************************/ | 991 | *****************************/ |
908 | /* | 992 | int fc_elsct_init(struct fc_lport *); |
909 | * Initializes ELS/CT interface | 993 | struct fc_seq *fc_elsct_send(struct fc_lport *, u32 did, |
910 | */ | 994 | struct fc_frame *, |
911 | int fc_elsct_init(struct fc_lport *lp); | ||
912 | struct fc_seq *fc_elsct_send(struct fc_lport *lport, | ||
913 | u32 did, | ||
914 | struct fc_frame *fp, | ||
915 | unsigned int op, | 995 | unsigned int op, |
916 | void (*resp)(struct fc_seq *, | 996 | void (*resp)(struct fc_seq *, |
917 | struct fc_frame *fp, | 997 | struct fc_frame *, |
918 | void *arg), | 998 | void *arg), |
919 | void *arg, u32 timer_msec); | 999 | void *arg, u32 timer_msec); |
920 | void fc_lport_flogi_resp(struct fc_seq *, struct fc_frame *, void *); | 1000 | void fc_lport_flogi_resp(struct fc_seq *, struct fc_frame *, void *); |
@@ -924,90 +1004,26 @@ void fc_lport_logo_resp(struct fc_seq *, struct fc_frame *, void *); | |||
924 | /* | 1004 | /* |
925 | * EXCHANGE MANAGER LAYER | 1005 | * EXCHANGE MANAGER LAYER |
926 | *****************************/ | 1006 | *****************************/ |
927 | /* | 1007 | int fc_exch_init(struct fc_lport *); |
928 | * Initializes Exchange Manager related | 1008 | struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *, |
929 | * function pointers in struct libfc_function_template. | 1009 | struct fc_exch_mgr *, |
930 | */ | ||
931 | int fc_exch_init(struct fc_lport *lp); | ||
932 | |||
933 | /* | ||
934 | * Adds Exchange Manager (EM) mp to lport. | ||
935 | * | ||
936 | * Adds specified mp to lport using struct fc_exch_mgr_anchor, | ||
937 | * the struct fc_exch_mgr_anchor allows same EM sharing by | ||
938 | * more than one lport with their specified match function, | ||
939 | * the match function is used in allocating exchange from | ||
940 | * added mp. | ||
941 | */ | ||
942 | struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *lport, | ||
943 | struct fc_exch_mgr *mp, | ||
944 | bool (*match)(struct fc_frame *)); | 1010 | bool (*match)(struct fc_frame *)); |
945 | 1011 | void fc_exch_mgr_del(struct fc_exch_mgr_anchor *); | |
946 | /* | ||
947 | * Deletes Exchange Manager (EM) from lport by removing | ||
948 | * its anchor ema from lport. | ||
949 | * | ||
950 | * If removed anchor ema was the last user of its associated EM | ||
951 | * then also destroys associated EM. | ||
952 | */ | ||
953 | void fc_exch_mgr_del(struct fc_exch_mgr_anchor *ema); | ||
954 | |||
955 | /* | ||
956 | * Clone an exchange manager list, getting reference holds for each EM. | ||
957 | * This is for use with NPIV and sharing the X_ID space between VN_Ports. | ||
958 | */ | ||
959 | int fc_exch_mgr_list_clone(struct fc_lport *src, struct fc_lport *dst); | 1012 | int fc_exch_mgr_list_clone(struct fc_lport *src, struct fc_lport *dst); |
960 | 1013 | struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *, enum fc_class class, | |
961 | /* | 1014 | u16 min_xid, u16 max_xid, |
962 | * Allocates an Exchange Manager (EM). | ||
963 | * | ||
964 | * The EM manages exchanges for their allocation and | ||
965 | * free, also allows exchange lookup for received | ||
966 | * frame. | ||
967 | * | ||
968 | * The class is used for initializing FC class of | ||
969 | * allocated exchange from EM. | ||
970 | * | ||
971 | * The min_xid and max_xid will limit new | ||
972 | * exchange ID (XID) within this range for | ||
973 | * a new exchange. | ||
974 | * The LLD may choose to have multiple EMs, | ||
975 | * e.g. one EM instance per CPU receive thread in LLD. | ||
976 | * | ||
977 | * Specified match function is used in allocating exchanges | ||
978 | * from newly allocated EM. | ||
979 | */ | ||
980 | struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp, | ||
981 | enum fc_class class, | ||
982 | u16 min_xid, | ||
983 | u16 max_xid, | ||
984 | bool (*match)(struct fc_frame *)); | 1015 | bool (*match)(struct fc_frame *)); |
985 | 1016 | void fc_exch_mgr_free(struct fc_lport *); | |
986 | /* | 1017 | void fc_exch_recv(struct fc_lport *, struct fc_frame *); |
987 | * Free all exchange managers of a lport. | ||
988 | */ | ||
989 | void fc_exch_mgr_free(struct fc_lport *lport); | ||
990 | |||
991 | /* | ||
992 | * Receive a frame on specified local port and exchange manager. | ||
993 | */ | ||
994 | void fc_exch_recv(struct fc_lport *lp, struct fc_frame *fp); | ||
995 | |||
996 | /* | ||
997 | * Reset all EMs of a lport, releasing its all sequences and | ||
998 | * exchanges. If sid is non-zero, then reset only exchanges | ||
999 | * we sourced from that FID. If did is non-zero, reset only | ||
1000 | * exchanges destined to that FID. | ||
1001 | */ | ||
1002 | void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id); | 1018 | void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id); |
1003 | 1019 | ||
1004 | /* | 1020 | /* |
1005 | * Functions for fc_functions_template | 1021 | * Functions for fc_functions_template |
1006 | */ | 1022 | */ |
1007 | void fc_get_host_speed(struct Scsi_Host *shost); | 1023 | void fc_get_host_speed(struct Scsi_Host *); |
1008 | void fc_get_host_port_type(struct Scsi_Host *shost); | 1024 | void fc_get_host_port_type(struct Scsi_Host *); |
1009 | void fc_get_host_port_state(struct Scsi_Host *shost); | 1025 | void fc_get_host_port_state(struct Scsi_Host *); |
1010 | void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout); | 1026 | void fc_set_rport_loss_tmo(struct fc_rport *, u32 timeout); |
1011 | struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *); | 1027 | struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *); |
1012 | 1028 | ||
1013 | #endif /* _LIBFC_H_ */ | 1029 | #endif /* _LIBFC_H_ */ |