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