blob: 1a632069c40289301e5c558c5026a7c3e4b8ec44 [file] [log] [blame]
Robert Love42e9a922008-12-09 15:10:17 -08001/*
2 * Copyright(c) 2007 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * Maintained at www.Open-FCoE.org
18 */
19
20#ifndef _LIBFC_H_
21#define _LIBFC_H_
22
23#include <linux/timer.h>
24#include <linux/if.h>
Robert Love582b45b2009-03-31 15:51:50 -070025#include <linux/percpu.h>
Robert Love42e9a922008-12-09 15:10:17 -080026
27#include <scsi/scsi_transport.h>
28#include <scsi/scsi_transport_fc.h>
29
30#include <scsi/fc/fc_fcp.h>
31#include <scsi/fc/fc_ns.h>
32#include <scsi/fc/fc_els.h>
33#include <scsi/fc/fc_gs.h>
34
35#include <scsi/fc_frame.h>
36
Robert Love42e9a922008-12-09 15:10:17 -080037/*
38 * libfc error codes
39 */
40#define FC_NO_ERR 0 /* no error */
41#define FC_EX_TIMEOUT 1 /* Exchange timeout */
42#define FC_EX_CLOSED 2 /* Exchange closed */
43
44/* some helpful macros */
45
46#define ntohll(x) be64_to_cpu(x)
47#define htonll(x) cpu_to_be64(x)
48
49#define ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
50
51#define hton24(p, v) do { \
52 p[0] = (((v) >> 16) & 0xFF); \
53 p[1] = (((v) >> 8) & 0xFF); \
54 p[2] = ((v) & 0xFF); \
55 } while (0)
56
57/*
58 * FC HBA status
59 */
Robert Love42e9a922008-12-09 15:10:17 -080060enum fc_lport_state {
Joe Eykholtb1d9fd52009-07-29 17:04:22 -070061 LPORT_ST_DISABLED = 0,
Robert Love42e9a922008-12-09 15:10:17 -080062 LPORT_ST_FLOGI,
63 LPORT_ST_DNS,
Chris Leechc9c7bd72009-11-03 11:46:51 -080064 LPORT_ST_RNN_ID,
Chris Leech5baa17c2009-11-03 11:46:56 -080065 LPORT_ST_RSNN_NN,
Robert Love42e9a922008-12-09 15:10:17 -080066 LPORT_ST_RFT_ID,
67 LPORT_ST_SCR,
68 LPORT_ST_READY,
69 LPORT_ST_LOGO,
70 LPORT_ST_RESET
71};
72
73enum fc_disc_event {
74 DISC_EV_NONE = 0,
75 DISC_EV_SUCCESS,
76 DISC_EV_FAILED
77};
78
79enum fc_rport_state {
Robert Love42e9a922008-12-09 15:10:17 -080080 RPORT_ST_INIT, /* initialized */
81 RPORT_ST_PLOGI, /* waiting for PLOGI completion */
82 RPORT_ST_PRLI, /* waiting for PRLI completion */
83 RPORT_ST_RTV, /* waiting for RTV completion */
84 RPORT_ST_READY, /* ready for use */
85 RPORT_ST_LOGO, /* port logout sent */
Joe Eykholt370c3bd2009-08-25 14:03:47 -070086 RPORT_ST_ADISC, /* Discover Address sent */
Joe Eykholt14194052009-07-29 17:04:43 -070087 RPORT_ST_DELETE, /* port being deleted */
Joe Eykholtb4a9c7e2009-10-21 16:28:30 -070088 RPORT_ST_RESTART, /* remote port being deleted and will restart */
Robert Love42e9a922008-12-09 15:10:17 -080089};
90
Robert Love42e9a922008-12-09 15:10:17 -080091/**
92 * struct fc_disc_port - temporary discovery port to hold rport identifiers
Robert Love9737e6a2009-08-25 14:02:59 -070093 * @lp: Fibre Channel host port instance
94 * @peers: Node for list management during discovery and RSCN processing
95 * @rport_work: Work struct for starting the rport state machine
96 * @port_id: Port ID of the discovered port
Robert Love42e9a922008-12-09 15:10:17 -080097 */
98struct fc_disc_port {
99 struct fc_lport *lp;
100 struct list_head peers;
Robert Love42e9a922008-12-09 15:10:17 -0800101 struct work_struct rport_work;
Robert Love9737e6a2009-08-25 14:02:59 -0700102 u32 port_id;
Robert Love42e9a922008-12-09 15:10:17 -0800103};
104
105enum fc_rport_event {
106 RPORT_EV_NONE = 0,
Joe Eykholt4c0f62b2009-08-25 14:01:12 -0700107 RPORT_EV_READY,
Robert Love42e9a922008-12-09 15:10:17 -0800108 RPORT_EV_FAILED,
109 RPORT_EV_STOP,
110 RPORT_EV_LOGO
111};
112
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700113struct fc_rport_priv;
114
Robert Love42e9a922008-12-09 15:10:17 -0800115struct fc_rport_operations {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700116 void (*event_callback)(struct fc_lport *, struct fc_rport_priv *,
Robert Love42e9a922008-12-09 15:10:17 -0800117 enum fc_rport_event);
118};
119
120/**
121 * struct fc_rport_libfc_priv - libfc internal information about a remote port
122 * @local_port: Fibre Channel host port instance
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700123 * @rp_state: indicates READY for I/O or DELETE when blocked.
124 * @flags: REC and RETRY supported flags
125 * @e_d_tov: error detect timeout value (in msec)
126 * @r_a_tov: resource allocation timeout value (in msec)
127 */
128struct fc_rport_libfc_priv {
129 struct fc_lport *local_port;
130 enum fc_rport_state rp_state;
131 u16 flags;
132 #define FC_RP_FLAGS_REC_SUPPORTED (1 << 0)
133 #define FC_RP_FLAGS_RETRY (1 << 1)
134 unsigned int e_d_tov;
135 unsigned int r_a_tov;
136};
137
138/**
139 * struct fc_rport_priv - libfc rport and discovery info about a remote port
140 * @local_port: Fibre Channel host port instance
Joe Eykholtf211fa52009-08-25 14:01:01 -0700141 * @rport: transport remote port
142 * @kref: reference counter
Robert Love42e9a922008-12-09 15:10:17 -0800143 * @rp_state: state tracks progress of PLOGI, PRLI, and RTV exchanges
Joe Eykholtf211fa52009-08-25 14:01:01 -0700144 * @ids: remote port identifiers and roles
Robert Love42e9a922008-12-09 15:10:17 -0800145 * @flags: REC and RETRY supported flags
146 * @max_seq: maximum number of concurrent sequences
Joe Eykholt0f6c614982009-08-25 14:02:11 -0700147 * @disc_id: discovery identifier
Joe Eykholtf211fa52009-08-25 14:01:01 -0700148 * @maxframe_size: maximum frame size
Robert Love42e9a922008-12-09 15:10:17 -0800149 * @retries: retry count in current state
150 * @e_d_tov: error detect timeout value (in msec)
151 * @r_a_tov: resource allocation timeout value (in msec)
152 * @rp_mutex: mutex protects rport
153 * @retry_work:
154 * @event_callback: Callback for rport READY, FAILED or LOGO
155 */
Joe Eykholt9e9d0452009-08-25 14:01:18 -0700156struct fc_rport_priv {
Robert Love42e9a922008-12-09 15:10:17 -0800157 struct fc_lport *local_port;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700158 struct fc_rport *rport;
159 struct kref kref;
Robert Love42e9a922008-12-09 15:10:17 -0800160 enum fc_rport_state rp_state;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700161 struct fc_rport_identifiers ids;
Robert Love42e9a922008-12-09 15:10:17 -0800162 u16 flags;
Robert Love42e9a922008-12-09 15:10:17 -0800163 u16 max_seq;
Joe Eykholt0f6c614982009-08-25 14:02:11 -0700164 u16 disc_id;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700165 u16 maxframe_size;
Robert Love42e9a922008-12-09 15:10:17 -0800166 unsigned int retries;
167 unsigned int e_d_tov;
168 unsigned int r_a_tov;
Robert Love42e9a922008-12-09 15:10:17 -0800169 struct mutex rp_mutex;
170 struct delayed_work retry_work;
171 enum fc_rport_event event;
172 struct fc_rport_operations *ops;
173 struct list_head peers;
174 struct work_struct event_work;
Joe Eykholtf211fa52009-08-25 14:01:01 -0700175 u32 supported_classes;
Robert Love42e9a922008-12-09 15:10:17 -0800176};
177
Robert Love42e9a922008-12-09 15:10:17 -0800178/*
179 * fcoe stats structure
180 */
181struct fcoe_dev_stats {
182 u64 SecondsSinceLastReset;
183 u64 TxFrames;
184 u64 TxWords;
185 u64 RxFrames;
186 u64 RxWords;
187 u64 ErrorFrames;
188 u64 DumpedFrames;
189 u64 LinkFailureCount;
190 u64 LossOfSignalCount;
191 u64 InvalidTxWordCount;
192 u64 InvalidCRCCount;
193 u64 InputRequests;
194 u64 OutputRequests;
195 u64 ControlRequests;
196 u64 InputMegabytes;
197 u64 OutputMegabytes;
198};
199
200/*
201 * els data is used for passing ELS respone specific
202 * data to send ELS response mainly using infomation
203 * in exchange and sequence in EM layer.
204 */
205struct fc_seq_els_data {
206 struct fc_frame *fp;
207 enum fc_els_rjt_reason reason;
208 enum fc_els_rjt_explan explan;
209};
210
211/*
212 * FCP request structure, one for each scsi cmd request
213 */
214struct fc_fcp_pkt {
215 /*
216 * housekeeping stuff
217 */
218 struct fc_lport *lp; /* handle to hba struct */
219 u16 state; /* scsi_pkt state state */
220 u16 tgt_flags; /* target flags */
221 atomic_t ref_cnt; /* fcp pkt ref count */
222 spinlock_t scsi_pkt_lock; /* Must be taken before the host lock
223 * if both are held at the same time */
224 /*
225 * SCSI I/O related stuff
226 */
227 struct scsi_cmnd *cmd; /* scsi command pointer. set/clear
228 * under host lock */
229 struct list_head list; /* tracks queued commands. access under
230 * host lock */
231 /*
232 * timeout related stuff
233 */
234 struct timer_list timer; /* command timer */
235 struct completion tm_done;
236 int wait_for_comp;
237 unsigned long start_time; /* start jiffie */
238 unsigned long end_time; /* end jiffie */
239 unsigned long last_pkt_time; /* jiffies of last frame received */
240
241 /*
242 * scsi cmd and data transfer information
243 */
244 u32 data_len;
245 /*
246 * transport related veriables
247 */
248 struct fcp_cmnd cdb_cmd;
249 size_t xfer_len;
Yi Zoub277d2a2009-02-27 14:07:21 -0800250 u16 xfer_ddp; /* this xfer is ddped */
Robert Love42e9a922008-12-09 15:10:17 -0800251 u32 xfer_contig_end; /* offset of end of contiguous xfer */
252 u16 max_payload; /* max payload size in bytes */
253
254 /*
255 * scsi/fcp return status
256 */
257 u32 io_status; /* SCSI result upper 24 bits */
258 u8 cdb_status;
259 u8 status_code; /* FCP I/O status */
260 /* bit 3 Underrun bit 2: overrun */
261 u8 scsi_comp_flags;
262 u32 req_flags; /* bit 0: read bit:1 write */
263 u32 scsi_resid; /* residule length */
264
265 struct fc_rport *rport; /* remote port pointer */
266 struct fc_seq *seq_ptr; /* current sequence pointer */
267 /*
268 * Error Processing
269 */
270 u8 recov_retry; /* count of recovery retries */
271 struct fc_seq *recov_seq; /* sequence for REC or SRR */
272};
Yi Zoub277d2a2009-02-27 14:07:21 -0800273/*
274 * FC_FCP HELPER FUNCTIONS
275 *****************************/
276static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp)
277{
278 if (fsp && fsp->cmd)
279 return fsp->cmd->sc_data_direction == DMA_FROM_DEVICE;
280 return false;
281}
Robert Love42e9a922008-12-09 15:10:17 -0800282
283/*
284 * Structure and function definitions for managing Fibre Channel Exchanges
285 * and Sequences
286 *
287 * fc_exch holds state for one exchange and links to its active sequence.
288 *
289 * fc_seq holds the state for an individual sequence.
290 */
291
292struct fc_exch_mgr;
Vasu Dev96316092009-07-29 17:05:00 -0700293struct fc_exch_mgr_anchor;
Vasu Deve4bc50b2009-08-25 13:58:47 -0700294extern u16 fc_cpu_mask; /* cpu mask for possible cpus */
Robert Love42e9a922008-12-09 15:10:17 -0800295
296/*
297 * Sequence.
298 */
299struct fc_seq {
300 u8 id; /* seq ID */
301 u16 ssb_stat; /* status flags for sequence status block */
302 u16 cnt; /* frames sent so far on sequence */
303 u32 rec_data; /* FC-4 value for REC */
304};
305
306#define FC_EX_DONE (1 << 0) /* ep is completed */
307#define FC_EX_RST_CLEANUP (1 << 1) /* reset is forcing completion */
308
309/*
310 * Exchange.
311 *
312 * Locking notes: The ex_lock protects following items:
313 * state, esb_stat, f_ctl, seq.ssb_stat
314 * seq_id
315 * sequence allocation
316 */
317struct fc_exch {
318 struct fc_exch_mgr *em; /* exchange manager */
Vasu Devb2f00912009-08-25 13:58:53 -0700319 struct fc_exch_pool *pool; /* per cpu exches pool */
Robert Love42e9a922008-12-09 15:10:17 -0800320 u32 state; /* internal driver state */
321 u16 xid; /* our exchange ID */
322 struct list_head ex_list; /* free or busy list linkage */
323 spinlock_t ex_lock; /* lock covering exchange state */
324 atomic_t ex_refcnt; /* reference counter */
325 struct delayed_work timeout_work; /* timer for upper level protocols */
326 struct fc_lport *lp; /* fc device instance */
327 u16 oxid; /* originator's exchange ID */
328 u16 rxid; /* responder's exchange ID */
329 u32 oid; /* originator's FCID */
330 u32 sid; /* source FCID */
331 u32 did; /* destination FCID */
332 u32 esb_stat; /* exchange status for ESB */
333 u32 r_a_tov; /* r_a_tov from rport (msec) */
334 u8 seq_id; /* next sequence ID to use */
335 u32 f_ctl; /* F_CTL flags for sequences */
336 u8 fh_type; /* frame type */
337 enum fc_class class; /* class of service */
338 struct fc_seq seq; /* single sequence */
339 /*
340 * Handler for responses to this current exchange.
341 */
342 void (*resp)(struct fc_seq *, struct fc_frame *, void *);
343 void (*destructor)(struct fc_seq *, void *);
344 /*
345 * arg is passed as void pointer to exchange
346 * resp and destructor handlers
347 */
348 void *arg;
349};
350#define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
351
352struct libfc_function_template {
353
Robert Love42e9a922008-12-09 15:10:17 -0800354 /*
355 * Interface to send a FC frame
Robert Love0ae4d4a2009-02-27 10:55:39 -0800356 *
357 * STATUS: REQUIRED
Robert Love42e9a922008-12-09 15:10:17 -0800358 */
359 int (*frame_send)(struct fc_lport *lp, struct fc_frame *fp);
360
Robert Love42e9a922008-12-09 15:10:17 -0800361 /*
Robert Love0ae4d4a2009-02-27 10:55:39 -0800362 * Interface to send ELS/CT frames
363 *
364 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800365 */
366 struct fc_seq *(*elsct_send)(struct fc_lport *lport,
Joe Eykholta46f3272009-08-25 14:00:55 -0700367 u32 did,
Robert Love42e9a922008-12-09 15:10:17 -0800368 struct fc_frame *fp,
369 unsigned int op,
370 void (*resp)(struct fc_seq *,
371 struct fc_frame *fp,
372 void *arg),
373 void *arg, u32 timer_msec);
Robert Love42e9a922008-12-09 15:10:17 -0800374
375 /*
376 * Send the FC frame payload using a new exchange and sequence.
377 *
378 * The frame pointer with some of the header's fields must be
379 * filled before calling exch_seq_send(), those fields are,
380 *
381 * - routing control
382 * - FC port did
383 * - FC port sid
384 * - FC header type
385 * - frame control
386 * - parameter or relative offset
387 *
388 * The exchange response handler is set in this routine to resp()
389 * function pointer. It can be called in two scenarios: if a timeout
390 * occurs or if a response frame is received for the exchange. The
391 * fc_frame pointer in response handler will also indicate timeout
392 * as error using IS_ERR related macros.
393 *
394 * The exchange destructor handler is also set in this routine.
395 * The destructor handler is invoked by EM layer when exchange
396 * is about to free, this can be used by caller to free its
397 * resources along with exchange free.
398 *
399 * The arg is passed back to resp and destructor handler.
400 *
401 * The timeout value (in msec) for an exchange is set if non zero
402 * timer_msec argument is specified. The timer is canceled when
403 * it fires or when the exchange is done. The exchange timeout handler
404 * is registered by EM layer.
Robert Love0ae4d4a2009-02-27 10:55:39 -0800405 *
406 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800407 */
408 struct fc_seq *(*exch_seq_send)(struct fc_lport *lp,
409 struct fc_frame *fp,
410 void (*resp)(struct fc_seq *sp,
411 struct fc_frame *fp,
412 void *arg),
413 void (*destructor)(struct fc_seq *sp,
414 void *arg),
415 void *arg, unsigned int timer_msec);
416
417 /*
Yi Zoub277d2a2009-02-27 14:07:21 -0800418 * Sets up the DDP context for a given exchange id on the given
419 * scatterlist if LLD supports DDP for large receive.
420 *
421 * STATUS: OPTIONAL
422 */
423 int (*ddp_setup)(struct fc_lport *lp, u16 xid,
424 struct scatterlist *sgl, unsigned int sgc);
425 /*
426 * Completes the DDP transfer and returns the length of data DDPed
427 * for the given exchange id.
428 *
429 * STATUS: OPTIONAL
430 */
431 int (*ddp_done)(struct fc_lport *lp, u16 xid);
432 /*
Robert Love0ae4d4a2009-02-27 10:55:39 -0800433 * Send a frame using an existing sequence and exchange.
434 *
435 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800436 */
437 int (*seq_send)(struct fc_lport *lp, struct fc_seq *sp,
438 struct fc_frame *fp);
439
440 /*
Robert Love0ae4d4a2009-02-27 10:55:39 -0800441 * Send an ELS response using infomation from a previous
442 * exchange and sequence.
443 *
444 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800445 */
446 void (*seq_els_rsp_send)(struct fc_seq *sp, enum fc_els_cmd els_cmd,
447 struct fc_seq_els_data *els_data);
448
449 /*
450 * Abort an exchange and sequence. Generally called because of a
451 * exchange timeout or an abort from the upper layer.
452 *
453 * A timer_msec can be specified for abort timeout, if non-zero
454 * timer_msec value is specified then exchange resp handler
455 * will be called with timeout error if no response to abort.
Robert Love0ae4d4a2009-02-27 10:55:39 -0800456 *
457 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800458 */
459 int (*seq_exch_abort)(const struct fc_seq *req_sp,
460 unsigned int timer_msec);
461
462 /*
463 * Indicate that an exchange/sequence tuple is complete and the memory
464 * allocated for the related objects may be freed.
Robert Love0ae4d4a2009-02-27 10:55:39 -0800465 *
466 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800467 */
468 void (*exch_done)(struct fc_seq *sp);
469
470 /*
Robert Love42e9a922008-12-09 15:10:17 -0800471 * Start a new sequence on the same exchange/sequence tuple.
Robert Love0ae4d4a2009-02-27 10:55:39 -0800472 *
473 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800474 */
475 struct fc_seq *(*seq_start_next)(struct fc_seq *sp);
476
477 /*
478 * Reset an exchange manager, completing all sequences and exchanges.
479 * If s_id is non-zero, reset only exchanges originating from that FID.
480 * If d_id is non-zero, reset only exchanges sending to that FID.
Robert Love0ae4d4a2009-02-27 10:55:39 -0800481 *
482 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800483 */
Abhijeet Joglekar1f6ff362009-02-27 10:54:35 -0800484 void (*exch_mgr_reset)(struct fc_lport *,
Robert Love42e9a922008-12-09 15:10:17 -0800485 u32 s_id, u32 d_id);
486
Robert Love0ae4d4a2009-02-27 10:55:39 -0800487 /*
488 * Flush the rport work queue. Generally used before shutdown.
489 *
490 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800491 */
Robert Love0ae4d4a2009-02-27 10:55:39 -0800492 void (*rport_flush_queue)(void);
Robert Love42e9a922008-12-09 15:10:17 -0800493
494 /*
Robert Love0ae4d4a2009-02-27 10:55:39 -0800495 * Receive a frame for a local port.
496 *
497 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800498 */
499 void (*lport_recv)(struct fc_lport *lp, struct fc_seq *sp,
500 struct fc_frame *fp);
501
Robert Love0ae4d4a2009-02-27 10:55:39 -0800502 /*
503 * Reset the local port.
504 *
505 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800506 */
Robert Love0ae4d4a2009-02-27 10:55:39 -0800507 int (*lport_reset)(struct fc_lport *);
Robert Love42e9a922008-12-09 15:10:17 -0800508
509 /*
Robert Love9737e6a2009-08-25 14:02:59 -0700510 * Create a remote port with a given port ID
511 *
512 * STATUS: OPTIONAL
Robert Love5101ff92009-02-27 10:55:18 -0800513 */
Robert Love9737e6a2009-08-25 14:02:59 -0700514 struct fc_rport_priv *(*rport_create)(struct fc_lport *, u32);
Robert Love5101ff92009-02-27 10:55:18 -0800515
516 /*
Robert Love42e9a922008-12-09 15:10:17 -0800517 * Initiates the RP state machine. It is called from the LP module.
518 * This function will issue the following commands to the N_Port
519 * identified by the FC ID provided.
520 *
521 * - PLOGI
522 * - PRLI
523 * - RTV
Robert Love0ae4d4a2009-02-27 10:55:39 -0800524 *
525 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800526 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700527 int (*rport_login)(struct fc_rport_priv *);
Robert Love42e9a922008-12-09 15:10:17 -0800528
529 /*
530 * Logoff, and remove the rport from the transport if
531 * it had been added. This will send a LOGO to the target.
Robert Love0ae4d4a2009-02-27 10:55:39 -0800532 *
533 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800534 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700535 int (*rport_logoff)(struct fc_rport_priv *);
Robert Love42e9a922008-12-09 15:10:17 -0800536
537 /*
538 * Recieve a request from a remote port.
Robert Love0ae4d4a2009-02-27 10:55:39 -0800539 *
540 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800541 */
542 void (*rport_recv_req)(struct fc_seq *, struct fc_frame *,
Joe Eykholt131203a2009-08-25 14:03:10 -0700543 struct fc_lport *);
Robert Love42e9a922008-12-09 15:10:17 -0800544
Robert Love0ae4d4a2009-02-27 10:55:39 -0800545 /*
546 * lookup an rport by it's port ID.
547 *
548 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800549 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700550 struct fc_rport_priv *(*rport_lookup)(const struct fc_lport *, u32);
Robert Love42e9a922008-12-09 15:10:17 -0800551
552 /*
Joe Eykholtf211fa52009-08-25 14:01:01 -0700553 * Destroy an rport after final kref_put().
554 * The argument is a pointer to the kref inside the fc_rport_priv.
555 */
556 void (*rport_destroy)(struct kref *);
557
558 /*
Robert Love42e9a922008-12-09 15:10:17 -0800559 * Send a fcp cmd from fsp pkt.
560 * Called with the SCSI host lock unlocked and irqs disabled.
561 *
562 * The resp handler is called when FCP_RSP received.
563 *
Robert Love0ae4d4a2009-02-27 10:55:39 -0800564 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800565 */
566 int (*fcp_cmd_send)(struct fc_lport *lp, struct fc_fcp_pkt *fsp,
567 void (*resp)(struct fc_seq *, struct fc_frame *fp,
568 void *arg));
569
570 /*
Robert Love0ae4d4a2009-02-27 10:55:39 -0800571 * Cleanup the FCP layer, used durring link down and reset
572 *
573 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800574 */
575 void (*fcp_cleanup)(struct fc_lport *lp);
576
577 /*
578 * Abort all I/O on a local port
Robert Love0ae4d4a2009-02-27 10:55:39 -0800579 *
580 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800581 */
582 void (*fcp_abort_io)(struct fc_lport *lp);
583
Robert Love0ae4d4a2009-02-27 10:55:39 -0800584 /*
585 * Receive a request for the discovery layer.
586 *
587 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800588 */
Robert Love42e9a922008-12-09 15:10:17 -0800589 void (*disc_recv_req)(struct fc_seq *,
590 struct fc_frame *, struct fc_lport *);
591
592 /*
593 * Start discovery for a local port.
Robert Love0ae4d4a2009-02-27 10:55:39 -0800594 *
595 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800596 */
597 void (*disc_start)(void (*disc_callback)(struct fc_lport *,
598 enum fc_disc_event),
599 struct fc_lport *);
600
601 /*
602 * Stop discovery for a given lport. This will remove
603 * all discovered rports
Robert Love0ae4d4a2009-02-27 10:55:39 -0800604 *
605 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800606 */
607 void (*disc_stop) (struct fc_lport *);
608
609 /*
610 * Stop discovery for a given lport. This will block
611 * until all discovered rports are deleted from the
612 * FC transport class
Robert Love0ae4d4a2009-02-27 10:55:39 -0800613 *
614 * STATUS: OPTIONAL
Robert Love42e9a922008-12-09 15:10:17 -0800615 */
616 void (*disc_stop_final) (struct fc_lport *);
617};
618
619/* information used by the discovery layer */
620struct fc_disc {
621 unsigned char retry_count;
Robert Love42e9a922008-12-09 15:10:17 -0800622 unsigned char pending;
623 unsigned char requested;
624 unsigned short seq_count;
625 unsigned char buf_len;
Joe Eykholt0f6c614982009-08-25 14:02:11 -0700626 u16 disc_id;
Robert Love42e9a922008-12-09 15:10:17 -0800627
628 void (*disc_callback)(struct fc_lport *,
629 enum fc_disc_event);
630
631 struct list_head rports;
632 struct fc_lport *lport;
633 struct mutex disc_mutex;
634 struct fc_gpn_ft_resp partial_buf; /* partial name buffer */
635 struct delayed_work disc_work;
636};
637
638struct fc_lport {
639 struct list_head list;
640
641 /* Associations */
642 struct Scsi_Host *host;
Vasu Dev96316092009-07-29 17:05:00 -0700643 struct list_head ema_list;
Chris Leech174e1eb2009-11-03 11:46:14 -0800644 struct list_head vports; /* child vports if N_Port */
645 struct fc_vport *vport; /* parent vport if VN_Port */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700646 struct fc_rport_priv *dns_rp;
647 struct fc_rport_priv *ptp_rp;
Robert Love42e9a922008-12-09 15:10:17 -0800648 void *scsi_priv;
649 struct fc_disc disc;
650
651 /* Operational Information */
652 struct libfc_function_template tt;
Vasu Devbc0e17f2009-02-27 10:54:57 -0800653 u8 link_up;
654 u8 qfull;
Robert Love42e9a922008-12-09 15:10:17 -0800655 enum fc_lport_state state;
656 unsigned long boot_time;
657
658 struct fc_host_statistics host_stats;
Robert Love582b45b2009-03-31 15:51:50 -0700659 struct fcoe_dev_stats *dev_stats;
660
Robert Love42e9a922008-12-09 15:10:17 -0800661 u64 wwpn;
662 u64 wwnn;
663 u8 retry_count;
664
665 /* Capabilities */
666 u32 sg_supp:1; /* scatter gather supported */
667 u32 seq_offload:1; /* seq offload supported */
668 u32 crc_offload:1; /* crc offload supported */
669 u32 lro_enabled:1; /* large receive offload */
Chris Leech174e1eb2009-11-03 11:46:14 -0800670 u32 does_npiv:1; /* supports multiple vports */
671 u32 npiv_enabled:1; /* switch/fabric allows NPIV */
Robert Love42e9a922008-12-09 15:10:17 -0800672 u32 mfs; /* max FC payload size */
673 unsigned int service_params;
674 unsigned int e_d_tov;
675 unsigned int r_a_tov;
676 u8 max_retry_count;
Abhijeet Joglekara3666952009-05-01 10:01:26 -0700677 u8 max_rport_retry_count;
Robert Love42e9a922008-12-09 15:10:17 -0800678 u16 link_speed;
679 u16 link_supported_speeds;
680 u16 lro_xid; /* max xid for fcoe lro */
Yi Zouea1e9a92009-02-27 14:07:04 -0800681 unsigned int lso_max; /* max large send size */
Robert Love42e9a922008-12-09 15:10:17 -0800682 struct fc_ns_fts fcts; /* FC-4 type masks */
683 struct fc_els_rnid_gen rnid_gen; /* RNID information */
684
685 /* Semaphores */
686 struct mutex lp_mutex;
687
688 /* Miscellaneous */
689 struct delayed_work retry_work;
Robert Love42e9a922008-12-09 15:10:17 -0800690};
691
Robert Love34f42a02009-02-27 10:55:45 -0800692/*
Robert Love42e9a922008-12-09 15:10:17 -0800693 * FC_LPORT HELPER FUNCTIONS
694 *****************************/
Robert Love42e9a922008-12-09 15:10:17 -0800695static inline int fc_lport_test_ready(struct fc_lport *lp)
696{
697 return lp->state == LPORT_ST_READY;
698}
699
700static inline void fc_set_wwnn(struct fc_lport *lp, u64 wwnn)
701{
702 lp->wwnn = wwnn;
703}
704
705static inline void fc_set_wwpn(struct fc_lport *lp, u64 wwnn)
706{
707 lp->wwpn = wwnn;
708}
709
710static inline void fc_lport_state_enter(struct fc_lport *lp,
711 enum fc_lport_state state)
712{
713 if (state != lp->state)
714 lp->retry_count = 0;
715 lp->state = state;
716}
717
Robert Love582b45b2009-03-31 15:51:50 -0700718static inline int fc_lport_init_stats(struct fc_lport *lp)
719{
720 /* allocate per cpu stats block */
721 lp->dev_stats = alloc_percpu(struct fcoe_dev_stats);
722 if (!lp->dev_stats)
723 return -ENOMEM;
724 return 0;
725}
726
727static inline void fc_lport_free_stats(struct fc_lport *lp)
728{
729 free_percpu(lp->dev_stats);
730}
731
732static inline struct fcoe_dev_stats *fc_lport_get_stats(struct fc_lport *lp)
733{
734 return per_cpu_ptr(lp->dev_stats, smp_processor_id());
735}
736
Vasu Deva0a25da2009-03-17 11:42:29 -0700737static inline void *lport_priv(const struct fc_lport *lp)
738{
739 return (void *)(lp + 1);
740}
741
742/**
743 * libfc_host_alloc() - Allocate a Scsi_Host with room for the fc_lport
744 * @sht: ptr to the scsi host templ
745 * @priv_size: size of private data after fc_lport
746 *
Chris Leech86221962009-11-03 11:46:08 -0800747 * Returns: libfc lport
Vasu Deva0a25da2009-03-17 11:42:29 -0700748 */
Chris Leech86221962009-11-03 11:46:08 -0800749static inline struct fc_lport *
Vasu Deva0a25da2009-03-17 11:42:29 -0700750libfc_host_alloc(struct scsi_host_template *sht, int priv_size)
751{
Chris Leech86221962009-11-03 11:46:08 -0800752 struct fc_lport *lport;
753 struct Scsi_Host *shost;
754
755 shost = scsi_host_alloc(sht, sizeof(*lport) + priv_size);
756 if (!shost)
757 return NULL;
758 lport = shost_priv(shost);
759 lport->host = shost;
760 INIT_LIST_HEAD(&lport->ema_list);
Chris Leech174e1eb2009-11-03 11:46:14 -0800761 INIT_LIST_HEAD(&lport->vports);
Chris Leech86221962009-11-03 11:46:08 -0800762 return lport;
Vasu Deva0a25da2009-03-17 11:42:29 -0700763}
Robert Love42e9a922008-12-09 15:10:17 -0800764
Robert Love34f42a02009-02-27 10:55:45 -0800765/*
Robert Love42e9a922008-12-09 15:10:17 -0800766 * LOCAL PORT LAYER
767 *****************************/
768int fc_lport_init(struct fc_lport *lp);
769
770/*
771 * Destroy the specified local port by finding and freeing all
772 * fc_rports associated with it and then by freeing the fc_lport
773 * itself.
774 */
775int fc_lport_destroy(struct fc_lport *lp);
776
777/*
778 * Logout the specified local port from the fabric
779 */
780int fc_fabric_logoff(struct fc_lport *lp);
781
782/*
783 * Initiate the LP state machine. This handler will use fc_host_attr
784 * to store the FLOGI service parameters, so fc_host_attr must be
785 * initialized before calling this handler.
786 */
787int fc_fabric_login(struct fc_lport *lp);
788
789/*
790 * The link is up for the given local port.
791 */
Chris Leech8faecdd2009-11-03 11:46:19 -0800792void __fc_linkup(struct fc_lport *);
Robert Love42e9a922008-12-09 15:10:17 -0800793void fc_linkup(struct fc_lport *);
794
795/*
796 * Link is down for the given local port.
797 */
Chris Leech8faecdd2009-11-03 11:46:19 -0800798void __fc_linkdown(struct fc_lport *);
Robert Love42e9a922008-12-09 15:10:17 -0800799void fc_linkdown(struct fc_lport *);
800
801/*
Robert Love42e9a922008-12-09 15:10:17 -0800802 * Configure the local port.
803 */
804int fc_lport_config(struct fc_lport *);
805
806/*
807 * Reset the local port.
808 */
809int fc_lport_reset(struct fc_lport *);
810
811/*
812 * Set the mfs or reset
813 */
814int fc_set_mfs(struct fc_lport *lp, u32 mfs);
815
Chris Leech174e1eb2009-11-03 11:46:14 -0800816/*
817 * Allocate a new lport struct for an NPIV VN_Port
818 */
819struct fc_lport *libfc_vport_create(struct fc_vport *vport, int privsize);
820
821/*
822 * Find an NPIV VN_Port by port ID
823 */
824struct fc_lport *fc_vport_id_lookup(struct fc_lport *n_port, u32 port_id);
Robert Love42e9a922008-12-09 15:10:17 -0800825
Robert Love34f42a02009-02-27 10:55:45 -0800826/*
Chris Leech8faecdd2009-11-03 11:46:19 -0800827 * NPIV VN_Port link state management
828 */
829void fc_vport_setlink(struct fc_lport *vn_port);
830void fc_vports_linkchange(struct fc_lport *n_port);
831
832/*
Robert Love42e9a922008-12-09 15:10:17 -0800833 * REMOTE PORT LAYER
834 *****************************/
835int fc_rport_init(struct fc_lport *lp);
836void fc_rport_terminate_io(struct fc_rport *rp);
837
Robert Love34f42a02009-02-27 10:55:45 -0800838/*
Robert Love42e9a922008-12-09 15:10:17 -0800839 * DISCOVERY LAYER
840 *****************************/
841int fc_disc_init(struct fc_lport *lp);
842
843
Robert Love34f42a02009-02-27 10:55:45 -0800844/*
Robert Love42e9a922008-12-09 15:10:17 -0800845 * SCSI LAYER
846 *****************************/
847/*
848 * Initialize the SCSI block of libfc
849 */
850int fc_fcp_init(struct fc_lport *);
851
852/*
853 * This section provides an API which allows direct interaction
854 * with the SCSI-ml. Each of these functions satisfies a function
855 * pointer defined in Scsi_Host and therefore is always called
856 * directly from the SCSI-ml.
857 */
858int fc_queuecommand(struct scsi_cmnd *sc_cmd,
859 void (*done)(struct scsi_cmnd *));
860
861/*
Robert Love42e9a922008-12-09 15:10:17 -0800862 * Send an ABTS frame to the target device. The sc_cmd argument
863 * is a pointer to the SCSI command to be aborted.
864 */
865int fc_eh_abort(struct scsi_cmnd *sc_cmd);
866
867/*
868 * Reset a LUN by sending send the tm cmd to the target.
869 */
870int fc_eh_device_reset(struct scsi_cmnd *sc_cmd);
871
872/*
873 * Reset the host adapter.
874 */
875int fc_eh_host_reset(struct scsi_cmnd *sc_cmd);
876
877/*
878 * Check rport status.
879 */
880int fc_slave_alloc(struct scsi_device *sdev);
881
882/*
883 * Adjust the queue depth.
884 */
Mike Christiee881a172009-10-15 17:46:39 -0700885int fc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason);
Robert Love42e9a922008-12-09 15:10:17 -0800886
887/*
888 * Change the tag type.
889 */
890int fc_change_queue_type(struct scsi_device *sdev, int tag_type);
891
892/*
893 * Free memory pools used by the FCP layer.
894 */
895void fc_fcp_destroy(struct fc_lport *);
896
Robert Love34f42a02009-02-27 10:55:45 -0800897/*
Robert Love42e9a922008-12-09 15:10:17 -0800898 * ELS/CT interface
899 *****************************/
900/*
901 * Initializes ELS/CT interface
902 */
903int fc_elsct_init(struct fc_lport *lp);
Chris Leech11b56182009-11-03 11:46:29 -0800904struct fc_seq *fc_elsct_send(struct fc_lport *lport,
905 u32 did,
906 struct fc_frame *fp,
907 unsigned int op,
908 void (*resp)(struct fc_seq *,
909 struct fc_frame *fp,
910 void *arg),
911 void *arg, u32 timer_msec);
912void fc_lport_flogi_resp(struct fc_seq *, struct fc_frame *, void *);
913void fc_lport_logo_resp(struct fc_seq *, struct fc_frame *, void *);
Robert Love42e9a922008-12-09 15:10:17 -0800914
915
Robert Love34f42a02009-02-27 10:55:45 -0800916/*
Robert Love42e9a922008-12-09 15:10:17 -0800917 * EXCHANGE MANAGER LAYER
918 *****************************/
919/*
920 * Initializes Exchange Manager related
921 * function pointers in struct libfc_function_template.
922 */
923int fc_exch_init(struct fc_lport *lp);
924
925/*
Vasu Dev96316092009-07-29 17:05:00 -0700926 * Adds Exchange Manager (EM) mp to lport.
927 *
928 * Adds specified mp to lport using struct fc_exch_mgr_anchor,
929 * the struct fc_exch_mgr_anchor allows same EM sharing by
930 * more than one lport with their specified match function,
931 * the match function is used in allocating exchange from
932 * added mp.
933 */
934struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *lport,
935 struct fc_exch_mgr *mp,
936 bool (*match)(struct fc_frame *));
937
938/*
939 * Deletes Exchange Manager (EM) from lport by removing
940 * its anchor ema from lport.
941 *
942 * If removed anchor ema was the last user of its associated EM
943 * then also destroys associated EM.
944 */
945void fc_exch_mgr_del(struct fc_exch_mgr_anchor *ema);
946
947/*
Chris Leech174e1eb2009-11-03 11:46:14 -0800948 * Clone an exchange manager list, getting reference holds for each EM.
949 * This is for use with NPIV and sharing the X_ID space between VN_Ports.
950 */
951int fc_exch_mgr_list_clone(struct fc_lport *src, struct fc_lport *dst);
952
953/*
Robert Love42e9a922008-12-09 15:10:17 -0800954 * Allocates an Exchange Manager (EM).
955 *
956 * The EM manages exchanges for their allocation and
957 * free, also allows exchange lookup for received
958 * frame.
959 *
960 * The class is used for initializing FC class of
961 * allocated exchange from EM.
962 *
963 * The min_xid and max_xid will limit new
964 * exchange ID (XID) within this range for
965 * a new exchange.
966 * The LLD may choose to have multiple EMs,
967 * e.g. one EM instance per CPU receive thread in LLD.
Robert Love42e9a922008-12-09 15:10:17 -0800968 *
Vasu Dev52ff8782009-07-29 17:05:10 -0700969 * Specified match function is used in allocating exchanges
970 * from newly allocated EM.
Robert Love42e9a922008-12-09 15:10:17 -0800971 */
972struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp,
973 enum fc_class class,
974 u16 min_xid,
Vasu Dev52ff8782009-07-29 17:05:10 -0700975 u16 max_xid,
976 bool (*match)(struct fc_frame *));
Robert Love42e9a922008-12-09 15:10:17 -0800977
978/*
Vasu Dev52ff8782009-07-29 17:05:10 -0700979 * Free all exchange managers of a lport.
Robert Love42e9a922008-12-09 15:10:17 -0800980 */
Vasu Dev52ff8782009-07-29 17:05:10 -0700981void fc_exch_mgr_free(struct fc_lport *lport);
Robert Love42e9a922008-12-09 15:10:17 -0800982
983/*
984 * Receive a frame on specified local port and exchange manager.
985 */
Vasu Dev52ff8782009-07-29 17:05:10 -0700986void fc_exch_recv(struct fc_lport *lp, struct fc_frame *fp);
Robert Love42e9a922008-12-09 15:10:17 -0800987
988/*
Vasu Devb2f00912009-08-25 13:58:53 -0700989 * Reset all EMs of a lport, releasing its all sequences and
990 * exchanges. If sid is non-zero, then reset only exchanges
991 * we sourced from that FID. If did is non-zero, reset only
992 * exchanges destined to that FID.
Robert Love42e9a922008-12-09 15:10:17 -0800993 */
Abhijeet Joglekar1f6ff362009-02-27 10:54:35 -0800994void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id);
Robert Love42e9a922008-12-09 15:10:17 -0800995
996/*
997 * Functions for fc_functions_template
998 */
999void fc_get_host_speed(struct Scsi_Host *shost);
1000void fc_get_host_port_type(struct Scsi_Host *shost);
1001void fc_get_host_port_state(struct Scsi_Host *shost);
1002void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout);
1003struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *);
1004
Robert Love42e9a922008-12-09 15:10:17 -08001005#endif /* _LIBFC_H_ */