libfc.h 25 KB

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