libfc.h 25 KB

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