libfc.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  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. u32 xfer_contig_end; /* offset of end of contiguous xfer */
  222. u16 max_payload; /* max payload size in bytes */
  223. /*
  224. * scsi/fcp return status
  225. */
  226. u32 io_status; /* SCSI result upper 24 bits */
  227. u8 cdb_status;
  228. u8 status_code; /* FCP I/O status */
  229. /* bit 3 Underrun bit 2: overrun */
  230. u8 scsi_comp_flags;
  231. u32 req_flags; /* bit 0: read bit:1 write */
  232. u32 scsi_resid; /* residule length */
  233. struct fc_rport *rport; /* remote port pointer */
  234. struct fc_seq *seq_ptr; /* current sequence pointer */
  235. /*
  236. * Error Processing
  237. */
  238. u8 recov_retry; /* count of recovery retries */
  239. struct fc_seq *recov_seq; /* sequence for REC or SRR */
  240. };
  241. /*
  242. * Structure and function definitions for managing Fibre Channel Exchanges
  243. * and Sequences
  244. *
  245. * fc_exch holds state for one exchange and links to its active sequence.
  246. *
  247. * fc_seq holds the state for an individual sequence.
  248. */
  249. struct fc_exch_mgr;
  250. /*
  251. * Sequence.
  252. */
  253. struct fc_seq {
  254. u8 id; /* seq ID */
  255. u16 ssb_stat; /* status flags for sequence status block */
  256. u16 cnt; /* frames sent so far on sequence */
  257. u32 rec_data; /* FC-4 value for REC */
  258. };
  259. #define FC_EX_DONE (1 << 0) /* ep is completed */
  260. #define FC_EX_RST_CLEANUP (1 << 1) /* reset is forcing completion */
  261. /*
  262. * Exchange.
  263. *
  264. * Locking notes: The ex_lock protects following items:
  265. * state, esb_stat, f_ctl, seq.ssb_stat
  266. * seq_id
  267. * sequence allocation
  268. */
  269. struct fc_exch {
  270. struct fc_exch_mgr *em; /* exchange manager */
  271. u32 state; /* internal driver state */
  272. u16 xid; /* our exchange ID */
  273. struct list_head ex_list; /* free or busy list linkage */
  274. spinlock_t ex_lock; /* lock covering exchange state */
  275. atomic_t ex_refcnt; /* reference counter */
  276. struct delayed_work timeout_work; /* timer for upper level protocols */
  277. struct fc_lport *lp; /* fc device instance */
  278. u16 oxid; /* originator's exchange ID */
  279. u16 rxid; /* responder's exchange ID */
  280. u32 oid; /* originator's FCID */
  281. u32 sid; /* source FCID */
  282. u32 did; /* destination FCID */
  283. u32 esb_stat; /* exchange status for ESB */
  284. u32 r_a_tov; /* r_a_tov from rport (msec) */
  285. u8 seq_id; /* next sequence ID to use */
  286. u32 f_ctl; /* F_CTL flags for sequences */
  287. u8 fh_type; /* frame type */
  288. enum fc_class class; /* class of service */
  289. struct fc_seq seq; /* single sequence */
  290. /*
  291. * Handler for responses to this current exchange.
  292. */
  293. void (*resp)(struct fc_seq *, struct fc_frame *, void *);
  294. void (*destructor)(struct fc_seq *, void *);
  295. /*
  296. * arg is passed as void pointer to exchange
  297. * resp and destructor handlers
  298. */
  299. void *arg;
  300. };
  301. #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
  302. struct libfc_function_template {
  303. /*
  304. * Interface to send a FC frame
  305. *
  306. * STATUS: REQUIRED
  307. */
  308. int (*frame_send)(struct fc_lport *lp, struct fc_frame *fp);
  309. /*
  310. * Interface to send ELS/CT frames
  311. *
  312. * STATUS: OPTIONAL
  313. */
  314. struct fc_seq *(*elsct_send)(struct fc_lport *lport,
  315. struct fc_rport *rport,
  316. struct fc_frame *fp,
  317. unsigned int op,
  318. void (*resp)(struct fc_seq *,
  319. struct fc_frame *fp,
  320. void *arg),
  321. void *arg, u32 timer_msec);
  322. /*
  323. * Send the FC frame payload using a new exchange and sequence.
  324. *
  325. * The frame pointer with some of the header's fields must be
  326. * filled before calling exch_seq_send(), those fields are,
  327. *
  328. * - routing control
  329. * - FC port did
  330. * - FC port sid
  331. * - FC header type
  332. * - frame control
  333. * - parameter or relative offset
  334. *
  335. * The exchange response handler is set in this routine to resp()
  336. * function pointer. It can be called in two scenarios: if a timeout
  337. * occurs or if a response frame is received for the exchange. The
  338. * fc_frame pointer in response handler will also indicate timeout
  339. * as error using IS_ERR related macros.
  340. *
  341. * The exchange destructor handler is also set in this routine.
  342. * The destructor handler is invoked by EM layer when exchange
  343. * is about to free, this can be used by caller to free its
  344. * resources along with exchange free.
  345. *
  346. * The arg is passed back to resp and destructor handler.
  347. *
  348. * The timeout value (in msec) for an exchange is set if non zero
  349. * timer_msec argument is specified. The timer is canceled when
  350. * it fires or when the exchange is done. The exchange timeout handler
  351. * is registered by EM layer.
  352. *
  353. * STATUS: OPTIONAL
  354. */
  355. struct fc_seq *(*exch_seq_send)(struct fc_lport *lp,
  356. struct fc_frame *fp,
  357. void (*resp)(struct fc_seq *sp,
  358. struct fc_frame *fp,
  359. void *arg),
  360. void (*destructor)(struct fc_seq *sp,
  361. void *arg),
  362. void *arg, unsigned int timer_msec);
  363. /*
  364. * Send a frame using an existing sequence and exchange.
  365. *
  366. * STATUS: OPTIONAL
  367. */
  368. int (*seq_send)(struct fc_lport *lp, struct fc_seq *sp,
  369. struct fc_frame *fp);
  370. /*
  371. * Send an ELS response using infomation from a previous
  372. * exchange and sequence.
  373. *
  374. * STATUS: OPTIONAL
  375. */
  376. void (*seq_els_rsp_send)(struct fc_seq *sp, enum fc_els_cmd els_cmd,
  377. struct fc_seq_els_data *els_data);
  378. /*
  379. * Abort an exchange and sequence. Generally called because of a
  380. * exchange timeout or an abort from the upper layer.
  381. *
  382. * A timer_msec can be specified for abort timeout, if non-zero
  383. * timer_msec value is specified then exchange resp handler
  384. * will be called with timeout error if no response to abort.
  385. *
  386. * STATUS: OPTIONAL
  387. */
  388. int (*seq_exch_abort)(const struct fc_seq *req_sp,
  389. unsigned int timer_msec);
  390. /*
  391. * Indicate that an exchange/sequence tuple is complete and the memory
  392. * allocated for the related objects may be freed.
  393. *
  394. * STATUS: OPTIONAL
  395. */
  396. void (*exch_done)(struct fc_seq *sp);
  397. /*
  398. * Assigns a EM and a free XID for an new exchange and then
  399. * allocates a new exchange and sequence pair.
  400. * The fp can be used to determine free XID.
  401. *
  402. * STATUS: OPTIONAL
  403. */
  404. struct fc_exch *(*exch_get)(struct fc_lport *lp, struct fc_frame *fp);
  405. /*
  406. * Release previously assigned XID by exch_get API.
  407. * The LLD may implement this if XID is assigned by LLD
  408. * in exch_get().
  409. *
  410. * STATUS: OPTIONAL
  411. */
  412. void (*exch_put)(struct fc_lport *lp, struct fc_exch_mgr *mp,
  413. u16 ex_id);
  414. /*
  415. * Start a new sequence on the same exchange/sequence tuple.
  416. *
  417. * STATUS: OPTIONAL
  418. */
  419. struct fc_seq *(*seq_start_next)(struct fc_seq *sp);
  420. /*
  421. * Reset an exchange manager, completing all sequences and exchanges.
  422. * If s_id is non-zero, reset only exchanges originating from that FID.
  423. * If d_id is non-zero, reset only exchanges sending to that FID.
  424. *
  425. * STATUS: OPTIONAL
  426. */
  427. void (*exch_mgr_reset)(struct fc_lport *,
  428. u32 s_id, u32 d_id);
  429. /*
  430. * Flush the rport work queue. Generally used before shutdown.
  431. *
  432. * STATUS: OPTIONAL
  433. */
  434. void (*rport_flush_queue)(void);
  435. /*
  436. * Receive a frame for a local port.
  437. *
  438. * STATUS: OPTIONAL
  439. */
  440. void (*lport_recv)(struct fc_lport *lp, struct fc_seq *sp,
  441. struct fc_frame *fp);
  442. /*
  443. * Reset the local port.
  444. *
  445. * STATUS: OPTIONAL
  446. */
  447. int (*lport_reset)(struct fc_lport *);
  448. /*
  449. * Create a remote port
  450. */
  451. struct fc_rport *(*rport_create)(struct fc_disc_port *);
  452. /*
  453. * Initiates the RP state machine. It is called from the LP module.
  454. * This function will issue the following commands to the N_Port
  455. * identified by the FC ID provided.
  456. *
  457. * - PLOGI
  458. * - PRLI
  459. * - RTV
  460. *
  461. * STATUS: OPTIONAL
  462. */
  463. int (*rport_login)(struct fc_rport *rport);
  464. /*
  465. * Logoff, and remove the rport from the transport if
  466. * it had been added. This will send a LOGO to the target.
  467. *
  468. * STATUS: OPTIONAL
  469. */
  470. int (*rport_logoff)(struct fc_rport *rport);
  471. /*
  472. * Recieve a request from a remote port.
  473. *
  474. * STATUS: OPTIONAL
  475. */
  476. void (*rport_recv_req)(struct fc_seq *, struct fc_frame *,
  477. struct fc_rport *);
  478. /*
  479. * lookup an rport by it's port ID.
  480. *
  481. * STATUS: OPTIONAL
  482. */
  483. struct fc_rport *(*rport_lookup)(const struct fc_lport *, u32);
  484. /*
  485. * Send a fcp cmd from fsp pkt.
  486. * Called with the SCSI host lock unlocked and irqs disabled.
  487. *
  488. * The resp handler is called when FCP_RSP received.
  489. *
  490. * STATUS: OPTIONAL
  491. */
  492. int (*fcp_cmd_send)(struct fc_lport *lp, struct fc_fcp_pkt *fsp,
  493. void (*resp)(struct fc_seq *, struct fc_frame *fp,
  494. void *arg));
  495. /*
  496. * Cleanup the FCP layer, used durring link down and reset
  497. *
  498. * STATUS: OPTIONAL
  499. */
  500. void (*fcp_cleanup)(struct fc_lport *lp);
  501. /*
  502. * Abort all I/O on a local port
  503. *
  504. * STATUS: OPTIONAL
  505. */
  506. void (*fcp_abort_io)(struct fc_lport *lp);
  507. /*
  508. * Receive a request for the discovery layer.
  509. *
  510. * STATUS: OPTIONAL
  511. */
  512. void (*disc_recv_req)(struct fc_seq *,
  513. struct fc_frame *, struct fc_lport *);
  514. /*
  515. * Start discovery for a local port.
  516. *
  517. * STATUS: OPTIONAL
  518. */
  519. void (*disc_start)(void (*disc_callback)(struct fc_lport *,
  520. enum fc_disc_event),
  521. struct fc_lport *);
  522. /*
  523. * Stop discovery for a given lport. This will remove
  524. * all discovered rports
  525. *
  526. * STATUS: OPTIONAL
  527. */
  528. void (*disc_stop) (struct fc_lport *);
  529. /*
  530. * Stop discovery for a given lport. This will block
  531. * until all discovered rports are deleted from the
  532. * FC transport class
  533. *
  534. * STATUS: OPTIONAL
  535. */
  536. void (*disc_stop_final) (struct fc_lport *);
  537. };
  538. /* information used by the discovery layer */
  539. struct fc_disc {
  540. unsigned char retry_count;
  541. unsigned char delay;
  542. unsigned char pending;
  543. unsigned char requested;
  544. unsigned short seq_count;
  545. unsigned char buf_len;
  546. enum fc_disc_event event;
  547. void (*disc_callback)(struct fc_lport *,
  548. enum fc_disc_event);
  549. struct list_head rports;
  550. struct fc_lport *lport;
  551. struct mutex disc_mutex;
  552. struct fc_gpn_ft_resp partial_buf; /* partial name buffer */
  553. struct delayed_work disc_work;
  554. };
  555. struct fc_lport {
  556. struct list_head list;
  557. /* Associations */
  558. struct Scsi_Host *host;
  559. struct fc_exch_mgr *emp;
  560. struct fc_rport *dns_rp;
  561. struct fc_rport *ptp_rp;
  562. void *scsi_priv;
  563. struct fc_disc disc;
  564. /* Operational Information */
  565. struct libfc_function_template tt;
  566. u8 link_up;
  567. u8 qfull;
  568. enum fc_lport_state state;
  569. unsigned long boot_time;
  570. struct fc_host_statistics host_stats;
  571. struct fcoe_dev_stats *dev_stats[NR_CPUS];
  572. u64 wwpn;
  573. u64 wwnn;
  574. u8 retry_count;
  575. /* Capabilities */
  576. u32 sg_supp:1; /* scatter gather supported */
  577. u32 seq_offload:1; /* seq offload supported */
  578. u32 crc_offload:1; /* crc offload supported */
  579. u32 lro_enabled:1; /* large receive offload */
  580. u32 mfs; /* max FC payload size */
  581. unsigned int service_params;
  582. unsigned int e_d_tov;
  583. unsigned int r_a_tov;
  584. u8 max_retry_count;
  585. u16 link_speed;
  586. u16 link_supported_speeds;
  587. u16 lro_xid; /* max xid for fcoe lro */
  588. struct fc_ns_fts fcts; /* FC-4 type masks */
  589. struct fc_els_rnid_gen rnid_gen; /* RNID information */
  590. /* Semaphores */
  591. struct mutex lp_mutex;
  592. /* Miscellaneous */
  593. struct delayed_work retry_work;
  594. struct delayed_work disc_work;
  595. };
  596. /*
  597. * FC_LPORT HELPER FUNCTIONS
  598. *****************************/
  599. static inline void *lport_priv(const struct fc_lport *lp)
  600. {
  601. return (void *)(lp + 1);
  602. }
  603. static inline int fc_lport_test_ready(struct fc_lport *lp)
  604. {
  605. return lp->state == LPORT_ST_READY;
  606. }
  607. static inline void fc_set_wwnn(struct fc_lport *lp, u64 wwnn)
  608. {
  609. lp->wwnn = wwnn;
  610. }
  611. static inline void fc_set_wwpn(struct fc_lport *lp, u64 wwnn)
  612. {
  613. lp->wwpn = wwnn;
  614. }
  615. static inline void fc_lport_state_enter(struct fc_lport *lp,
  616. enum fc_lport_state state)
  617. {
  618. if (state != lp->state)
  619. lp->retry_count = 0;
  620. lp->state = state;
  621. }
  622. /*
  623. * LOCAL PORT LAYER
  624. *****************************/
  625. int fc_lport_init(struct fc_lport *lp);
  626. /*
  627. * Destroy the specified local port by finding and freeing all
  628. * fc_rports associated with it and then by freeing the fc_lport
  629. * itself.
  630. */
  631. int fc_lport_destroy(struct fc_lport *lp);
  632. /*
  633. * Logout the specified local port from the fabric
  634. */
  635. int fc_fabric_logoff(struct fc_lport *lp);
  636. /*
  637. * Initiate the LP state machine. This handler will use fc_host_attr
  638. * to store the FLOGI service parameters, so fc_host_attr must be
  639. * initialized before calling this handler.
  640. */
  641. int fc_fabric_login(struct fc_lport *lp);
  642. /*
  643. * The link is up for the given local port.
  644. */
  645. void fc_linkup(struct fc_lport *);
  646. /*
  647. * Link is down for the given local port.
  648. */
  649. void fc_linkdown(struct fc_lport *);
  650. /*
  651. * Configure the local port.
  652. */
  653. int fc_lport_config(struct fc_lport *);
  654. /*
  655. * Reset the local port.
  656. */
  657. int fc_lport_reset(struct fc_lport *);
  658. /*
  659. * Set the mfs or reset
  660. */
  661. int fc_set_mfs(struct fc_lport *lp, u32 mfs);
  662. /*
  663. * REMOTE PORT LAYER
  664. *****************************/
  665. int fc_rport_init(struct fc_lport *lp);
  666. void fc_rport_terminate_io(struct fc_rport *rp);
  667. /*
  668. * DISCOVERY LAYER
  669. *****************************/
  670. int fc_disc_init(struct fc_lport *lp);
  671. /*
  672. * SCSI LAYER
  673. *****************************/
  674. /*
  675. * Initialize the SCSI block of libfc
  676. */
  677. int fc_fcp_init(struct fc_lport *);
  678. /*
  679. * This section provides an API which allows direct interaction
  680. * with the SCSI-ml. Each of these functions satisfies a function
  681. * pointer defined in Scsi_Host and therefore is always called
  682. * directly from the SCSI-ml.
  683. */
  684. int fc_queuecommand(struct scsi_cmnd *sc_cmd,
  685. void (*done)(struct scsi_cmnd *));
  686. /*
  687. * complete processing of a fcp packet
  688. *
  689. * This function may sleep if a fsp timer is pending.
  690. * The host lock must not be held by caller.
  691. */
  692. void fc_fcp_complete(struct fc_fcp_pkt *fsp);
  693. /*
  694. * Send an ABTS frame to the target device. The sc_cmd argument
  695. * is a pointer to the SCSI command to be aborted.
  696. */
  697. int fc_eh_abort(struct scsi_cmnd *sc_cmd);
  698. /*
  699. * Reset a LUN by sending send the tm cmd to the target.
  700. */
  701. int fc_eh_device_reset(struct scsi_cmnd *sc_cmd);
  702. /*
  703. * Reset the host adapter.
  704. */
  705. int fc_eh_host_reset(struct scsi_cmnd *sc_cmd);
  706. /*
  707. * Check rport status.
  708. */
  709. int fc_slave_alloc(struct scsi_device *sdev);
  710. /*
  711. * Adjust the queue depth.
  712. */
  713. int fc_change_queue_depth(struct scsi_device *sdev, int qdepth);
  714. /*
  715. * Change the tag type.
  716. */
  717. int fc_change_queue_type(struct scsi_device *sdev, int tag_type);
  718. /*
  719. * Free memory pools used by the FCP layer.
  720. */
  721. void fc_fcp_destroy(struct fc_lport *);
  722. /*
  723. * ELS/CT interface
  724. *****************************/
  725. /*
  726. * Initializes ELS/CT interface
  727. */
  728. int fc_elsct_init(struct fc_lport *lp);
  729. /*
  730. * EXCHANGE MANAGER LAYER
  731. *****************************/
  732. /*
  733. * Initializes Exchange Manager related
  734. * function pointers in struct libfc_function_template.
  735. */
  736. int fc_exch_init(struct fc_lport *lp);
  737. /*
  738. * Allocates an Exchange Manager (EM).
  739. *
  740. * The EM manages exchanges for their allocation and
  741. * free, also allows exchange lookup for received
  742. * frame.
  743. *
  744. * The class is used for initializing FC class of
  745. * allocated exchange from EM.
  746. *
  747. * The min_xid and max_xid will limit new
  748. * exchange ID (XID) within this range for
  749. * a new exchange.
  750. * The LLD may choose to have multiple EMs,
  751. * e.g. one EM instance per CPU receive thread in LLD.
  752. * The LLD can use exch_get() of struct libfc_function_template
  753. * to specify XID for a new exchange within
  754. * a specified EM instance.
  755. *
  756. * The em_idx to uniquely identify an EM instance.
  757. */
  758. struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp,
  759. enum fc_class class,
  760. u16 min_xid,
  761. u16 max_xid);
  762. /*
  763. * Free an exchange manager.
  764. */
  765. void fc_exch_mgr_free(struct fc_exch_mgr *mp);
  766. /*
  767. * Receive a frame on specified local port and exchange manager.
  768. */
  769. void fc_exch_recv(struct fc_lport *lp, struct fc_exch_mgr *mp,
  770. struct fc_frame *fp);
  771. /*
  772. * This function is for exch_seq_send function pointer in
  773. * struct libfc_function_template, see comment block on
  774. * exch_seq_send for description of this function.
  775. */
  776. struct fc_seq *fc_exch_seq_send(struct fc_lport *lp,
  777. struct fc_frame *fp,
  778. void (*resp)(struct fc_seq *sp,
  779. struct fc_frame *fp,
  780. void *arg),
  781. void (*destructor)(struct fc_seq *sp,
  782. void *arg),
  783. void *arg, u32 timer_msec);
  784. /*
  785. * send a frame using existing sequence and exchange.
  786. */
  787. int fc_seq_send(struct fc_lport *lp, struct fc_seq *sp, struct fc_frame *fp);
  788. /*
  789. * Send ELS response using mainly infomation
  790. * in exchange and sequence in EM layer.
  791. */
  792. void fc_seq_els_rsp_send(struct fc_seq *sp, enum fc_els_cmd els_cmd,
  793. struct fc_seq_els_data *els_data);
  794. /*
  795. * This function is for seq_exch_abort function pointer in
  796. * struct libfc_function_template, see comment block on
  797. * seq_exch_abort for description of this function.
  798. */
  799. int fc_seq_exch_abort(const struct fc_seq *req_sp, unsigned int timer_msec);
  800. /*
  801. * Indicate that an exchange/sequence tuple is complete and the memory
  802. * allocated for the related objects may be freed.
  803. */
  804. void fc_exch_done(struct fc_seq *sp);
  805. /*
  806. * Assigns a EM and XID for a frame and then allocates
  807. * a new exchange and sequence pair.
  808. * The fp can be used to determine free XID.
  809. */
  810. struct fc_exch *fc_exch_get(struct fc_lport *lp, struct fc_frame *fp);
  811. /*
  812. * Allocate a new exchange and sequence pair.
  813. * if ex_id is zero then next free exchange id
  814. * from specified exchange manger mp will be assigned.
  815. */
  816. struct fc_exch *fc_exch_alloc(struct fc_exch_mgr *mp,
  817. struct fc_frame *fp, u16 ex_id);
  818. /*
  819. * Start a new sequence on the same exchange as the supplied sequence.
  820. */
  821. struct fc_seq *fc_seq_start_next(struct fc_seq *sp);
  822. /*
  823. * Reset an exchange manager, completing all sequences and exchanges.
  824. * If s_id is non-zero, reset only exchanges originating from that FID.
  825. * If d_id is non-zero, reset only exchanges sending to that FID.
  826. */
  827. void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id);
  828. /*
  829. * Functions for fc_functions_template
  830. */
  831. void fc_get_host_speed(struct Scsi_Host *shost);
  832. void fc_get_host_port_type(struct Scsi_Host *shost);
  833. void fc_get_host_port_state(struct Scsi_Host *shost);
  834. void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout);
  835. struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *);
  836. /*
  837. * module setup functions.
  838. */
  839. int fc_setup_exch_mgr(void);
  840. void fc_destroy_exch_mgr(void);
  841. int fc_setup_rport(void);
  842. void fc_destroy_rport(void);
  843. #endif /* _LIBFC_H_ */