libfc.h 26 KB

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