libfc.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  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. * Mandatory Fields
  305. *
  306. * These handlers must be implemented by the LLD.
  307. */
  308. /*
  309. * Interface to send a FC frame
  310. */
  311. int (*frame_send)(struct fc_lport *lp, struct fc_frame *fp);
  312. /**
  313. * Optional Fields
  314. *
  315. * The LLD may choose to implement any of the following handlers.
  316. * If LLD doesn't specify hander and leaves its pointer NULL then
  317. * the default libfc function will be used for that handler.
  318. */
  319. /**
  320. * ELS/CT interfaces
  321. */
  322. /*
  323. * elsct_send - sends ELS/CT frame
  324. */
  325. struct fc_seq *(*elsct_send)(struct fc_lport *lport,
  326. struct fc_rport *rport,
  327. struct fc_frame *fp,
  328. unsigned int op,
  329. void (*resp)(struct fc_seq *,
  330. struct fc_frame *fp,
  331. void *arg),
  332. void *arg, u32 timer_msec);
  333. /**
  334. * Exhance Manager interfaces
  335. */
  336. /*
  337. * Send the FC frame payload using a new exchange and sequence.
  338. *
  339. * The frame pointer with some of the header's fields must be
  340. * filled before calling exch_seq_send(), those fields are,
  341. *
  342. * - routing control
  343. * - FC port did
  344. * - FC port sid
  345. * - FC header type
  346. * - frame control
  347. * - parameter or relative offset
  348. *
  349. * The exchange response handler is set in this routine to resp()
  350. * function pointer. It can be called in two scenarios: if a timeout
  351. * occurs or if a response frame is received for the exchange. The
  352. * fc_frame pointer in response handler will also indicate timeout
  353. * as error using IS_ERR related macros.
  354. *
  355. * The exchange destructor handler is also set in this routine.
  356. * The destructor handler is invoked by EM layer when exchange
  357. * is about to free, this can be used by caller to free its
  358. * resources along with exchange free.
  359. *
  360. * The arg is passed back to resp and destructor handler.
  361. *
  362. * The timeout value (in msec) for an exchange is set if non zero
  363. * timer_msec argument is specified. The timer is canceled when
  364. * it fires or when the exchange is done. The exchange timeout handler
  365. * is registered by EM layer.
  366. */
  367. struct fc_seq *(*exch_seq_send)(struct fc_lport *lp,
  368. struct fc_frame *fp,
  369. void (*resp)(struct fc_seq *sp,
  370. struct fc_frame *fp,
  371. void *arg),
  372. void (*destructor)(struct fc_seq *sp,
  373. void *arg),
  374. void *arg, unsigned int timer_msec);
  375. /*
  376. * send a frame using existing sequence and exchange.
  377. */
  378. int (*seq_send)(struct fc_lport *lp, struct fc_seq *sp,
  379. struct fc_frame *fp);
  380. /*
  381. * Send ELS response using mainly infomation
  382. * in exchange and sequence in EM layer.
  383. */
  384. void (*seq_els_rsp_send)(struct fc_seq *sp, enum fc_els_cmd els_cmd,
  385. struct fc_seq_els_data *els_data);
  386. /*
  387. * Abort an exchange and sequence. Generally called because of a
  388. * exchange timeout or an abort from the upper layer.
  389. *
  390. * A timer_msec can be specified for abort timeout, if non-zero
  391. * timer_msec value is specified then exchange resp handler
  392. * will be called with timeout error if no response to abort.
  393. */
  394. int (*seq_exch_abort)(const struct fc_seq *req_sp,
  395. unsigned int timer_msec);
  396. /*
  397. * Indicate that an exchange/sequence tuple is complete and the memory
  398. * allocated for the related objects may be freed.
  399. */
  400. void (*exch_done)(struct fc_seq *sp);
  401. /*
  402. * Assigns a EM and a free XID for an new exchange and then
  403. * allocates a new exchange and sequence pair.
  404. * The fp can be used to determine free XID.
  405. */
  406. struct fc_exch *(*exch_get)(struct fc_lport *lp, struct fc_frame *fp);
  407. /*
  408. * Release previously assigned XID by exch_get API.
  409. * The LLD may implement this if XID is assigned by LLD
  410. * in exch_get().
  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. struct fc_seq *(*seq_start_next)(struct fc_seq *sp);
  418. /*
  419. * Reset an exchange manager, completing all sequences and exchanges.
  420. * If s_id is non-zero, reset only exchanges originating from that FID.
  421. * If d_id is non-zero, reset only exchanges sending to that FID.
  422. */
  423. void (*exch_mgr_reset)(struct fc_lport *,
  424. u32 s_id, u32 d_id);
  425. void (*rport_flush_queue)(void);
  426. /**
  427. * Local Port interfaces
  428. */
  429. /*
  430. * Receive a frame to a local port.
  431. */
  432. void (*lport_recv)(struct fc_lport *lp, struct fc_seq *sp,
  433. struct fc_frame *fp);
  434. int (*lport_reset)(struct fc_lport *);
  435. /**
  436. * Remote Port interfaces
  437. */
  438. /*
  439. * Initiates the RP state machine. It is called from the LP module.
  440. * This function will issue the following commands to the N_Port
  441. * identified by the FC ID provided.
  442. *
  443. * - PLOGI
  444. * - PRLI
  445. * - RTV
  446. */
  447. int (*rport_login)(struct fc_rport *rport);
  448. /*
  449. * Logoff, and remove the rport from the transport if
  450. * it had been added. This will send a LOGO to the target.
  451. */
  452. int (*rport_logoff)(struct fc_rport *rport);
  453. /*
  454. * Recieve a request from a remote port.
  455. */
  456. void (*rport_recv_req)(struct fc_seq *, struct fc_frame *,
  457. struct fc_rport *);
  458. struct fc_rport *(*rport_lookup)(const struct fc_lport *, u32);
  459. /**
  460. * FCP interfaces
  461. */
  462. /*
  463. * Send a fcp cmd from fsp pkt.
  464. * Called with the SCSI host lock unlocked and irqs disabled.
  465. *
  466. * The resp handler is called when FCP_RSP received.
  467. *
  468. */
  469. int (*fcp_cmd_send)(struct fc_lport *lp, struct fc_fcp_pkt *fsp,
  470. void (*resp)(struct fc_seq *, struct fc_frame *fp,
  471. void *arg));
  472. /*
  473. * Used at least durring linkdown and reset
  474. */
  475. void (*fcp_cleanup)(struct fc_lport *lp);
  476. /*
  477. * Abort all I/O on a local port
  478. */
  479. void (*fcp_abort_io)(struct fc_lport *lp);
  480. /**
  481. * Discovery interfaces
  482. */
  483. void (*disc_recv_req)(struct fc_seq *,
  484. struct fc_frame *, struct fc_lport *);
  485. /*
  486. * Start discovery for a local port.
  487. */
  488. void (*disc_start)(void (*disc_callback)(struct fc_lport *,
  489. enum fc_disc_event),
  490. struct fc_lport *);
  491. /*
  492. * Stop discovery for a given lport. This will remove
  493. * all discovered rports
  494. */
  495. void (*disc_stop) (struct fc_lport *);
  496. /*
  497. * Stop discovery for a given lport. This will block
  498. * until all discovered rports are deleted from the
  499. * FC transport class
  500. */
  501. void (*disc_stop_final) (struct fc_lport *);
  502. };
  503. /* information used by the discovery layer */
  504. struct fc_disc {
  505. unsigned char retry_count;
  506. unsigned char delay;
  507. unsigned char pending;
  508. unsigned char requested;
  509. unsigned short seq_count;
  510. unsigned char buf_len;
  511. enum fc_disc_event event;
  512. void (*disc_callback)(struct fc_lport *,
  513. enum fc_disc_event);
  514. struct list_head rports;
  515. struct fc_lport *lport;
  516. struct mutex disc_mutex;
  517. struct fc_gpn_ft_resp partial_buf; /* partial name buffer */
  518. struct delayed_work disc_work;
  519. };
  520. struct fc_lport {
  521. struct list_head list;
  522. /* Associations */
  523. struct Scsi_Host *host;
  524. struct fc_exch_mgr *emp;
  525. struct fc_rport *dns_rp;
  526. struct fc_rport *ptp_rp;
  527. void *scsi_priv;
  528. struct fc_disc disc;
  529. /* Operational Information */
  530. struct libfc_function_template tt;
  531. u8 link_up;
  532. u8 qfull;
  533. enum fc_lport_state state;
  534. unsigned long boot_time;
  535. struct fc_host_statistics host_stats;
  536. struct fcoe_dev_stats *dev_stats[NR_CPUS];
  537. u64 wwpn;
  538. u64 wwnn;
  539. u8 retry_count;
  540. /* Capabilities */
  541. u32 sg_supp:1; /* scatter gather supported */
  542. u32 seq_offload:1; /* seq offload supported */
  543. u32 crc_offload:1; /* crc offload supported */
  544. u32 lro_enabled:1; /* large receive offload */
  545. u32 mfs; /* max FC payload size */
  546. unsigned int service_params;
  547. unsigned int e_d_tov;
  548. unsigned int r_a_tov;
  549. u8 max_retry_count;
  550. u16 link_speed;
  551. u16 link_supported_speeds;
  552. u16 lro_xid; /* max xid for fcoe lro */
  553. struct fc_ns_fts fcts; /* FC-4 type masks */
  554. struct fc_els_rnid_gen rnid_gen; /* RNID information */
  555. /* Semaphores */
  556. struct mutex lp_mutex;
  557. /* Miscellaneous */
  558. struct delayed_work retry_work;
  559. struct delayed_work disc_work;
  560. };
  561. /**
  562. * FC_LPORT HELPER FUNCTIONS
  563. *****************************/
  564. static inline void *lport_priv(const struct fc_lport *lp)
  565. {
  566. return (void *)(lp + 1);
  567. }
  568. static inline int fc_lport_test_ready(struct fc_lport *lp)
  569. {
  570. return lp->state == LPORT_ST_READY;
  571. }
  572. static inline void fc_set_wwnn(struct fc_lport *lp, u64 wwnn)
  573. {
  574. lp->wwnn = wwnn;
  575. }
  576. static inline void fc_set_wwpn(struct fc_lport *lp, u64 wwnn)
  577. {
  578. lp->wwpn = wwnn;
  579. }
  580. static inline void fc_lport_state_enter(struct fc_lport *lp,
  581. enum fc_lport_state state)
  582. {
  583. if (state != lp->state)
  584. lp->retry_count = 0;
  585. lp->state = state;
  586. }
  587. /**
  588. * LOCAL PORT LAYER
  589. *****************************/
  590. int fc_lport_init(struct fc_lport *lp);
  591. /*
  592. * Destroy the specified local port by finding and freeing all
  593. * fc_rports associated with it and then by freeing the fc_lport
  594. * itself.
  595. */
  596. int fc_lport_destroy(struct fc_lport *lp);
  597. /*
  598. * Logout the specified local port from the fabric
  599. */
  600. int fc_fabric_logoff(struct fc_lport *lp);
  601. /*
  602. * Initiate the LP state machine. This handler will use fc_host_attr
  603. * to store the FLOGI service parameters, so fc_host_attr must be
  604. * initialized before calling this handler.
  605. */
  606. int fc_fabric_login(struct fc_lport *lp);
  607. /*
  608. * The link is up for the given local port.
  609. */
  610. void fc_linkup(struct fc_lport *);
  611. /*
  612. * Link is down for the given local port.
  613. */
  614. void fc_linkdown(struct fc_lport *);
  615. /*
  616. * Configure the local port.
  617. */
  618. int fc_lport_config(struct fc_lport *);
  619. /*
  620. * Reset the local port.
  621. */
  622. int fc_lport_reset(struct fc_lport *);
  623. /*
  624. * Set the mfs or reset
  625. */
  626. int fc_set_mfs(struct fc_lport *lp, u32 mfs);
  627. /**
  628. * REMOTE PORT LAYER
  629. *****************************/
  630. int fc_rport_init(struct fc_lport *lp);
  631. void fc_rport_terminate_io(struct fc_rport *rp);
  632. /**
  633. * DISCOVERY LAYER
  634. *****************************/
  635. int fc_disc_init(struct fc_lport *lp);
  636. /**
  637. * SCSI LAYER
  638. *****************************/
  639. /*
  640. * Initialize the SCSI block of libfc
  641. */
  642. int fc_fcp_init(struct fc_lport *);
  643. /*
  644. * This section provides an API which allows direct interaction
  645. * with the SCSI-ml. Each of these functions satisfies a function
  646. * pointer defined in Scsi_Host and therefore is always called
  647. * directly from the SCSI-ml.
  648. */
  649. int fc_queuecommand(struct scsi_cmnd *sc_cmd,
  650. void (*done)(struct scsi_cmnd *));
  651. /*
  652. * complete processing of a fcp packet
  653. *
  654. * This function may sleep if a fsp timer is pending.
  655. * The host lock must not be held by caller.
  656. */
  657. void fc_fcp_complete(struct fc_fcp_pkt *fsp);
  658. /*
  659. * Send an ABTS frame to the target device. The sc_cmd argument
  660. * is a pointer to the SCSI command to be aborted.
  661. */
  662. int fc_eh_abort(struct scsi_cmnd *sc_cmd);
  663. /*
  664. * Reset a LUN by sending send the tm cmd to the target.
  665. */
  666. int fc_eh_device_reset(struct scsi_cmnd *sc_cmd);
  667. /*
  668. * Reset the host adapter.
  669. */
  670. int fc_eh_host_reset(struct scsi_cmnd *sc_cmd);
  671. /*
  672. * Check rport status.
  673. */
  674. int fc_slave_alloc(struct scsi_device *sdev);
  675. /*
  676. * Adjust the queue depth.
  677. */
  678. int fc_change_queue_depth(struct scsi_device *sdev, int qdepth);
  679. /*
  680. * Change the tag type.
  681. */
  682. int fc_change_queue_type(struct scsi_device *sdev, int tag_type);
  683. /*
  684. * Free memory pools used by the FCP layer.
  685. */
  686. void fc_fcp_destroy(struct fc_lport *);
  687. /**
  688. * ELS/CT interface
  689. *****************************/
  690. /*
  691. * Initializes ELS/CT interface
  692. */
  693. int fc_elsct_init(struct fc_lport *lp);
  694. /**
  695. * EXCHANGE MANAGER LAYER
  696. *****************************/
  697. /*
  698. * Initializes Exchange Manager related
  699. * function pointers in struct libfc_function_template.
  700. */
  701. int fc_exch_init(struct fc_lport *lp);
  702. /*
  703. * Allocates an Exchange Manager (EM).
  704. *
  705. * The EM manages exchanges for their allocation and
  706. * free, also allows exchange lookup for received
  707. * frame.
  708. *
  709. * The class is used for initializing FC class of
  710. * allocated exchange from EM.
  711. *
  712. * The min_xid and max_xid will limit new
  713. * exchange ID (XID) within this range for
  714. * a new exchange.
  715. * The LLD may choose to have multiple EMs,
  716. * e.g. one EM instance per CPU receive thread in LLD.
  717. * The LLD can use exch_get() of struct libfc_function_template
  718. * to specify XID for a new exchange within
  719. * a specified EM instance.
  720. *
  721. * The em_idx to uniquely identify an EM instance.
  722. */
  723. struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp,
  724. enum fc_class class,
  725. u16 min_xid,
  726. u16 max_xid);
  727. /*
  728. * Free an exchange manager.
  729. */
  730. void fc_exch_mgr_free(struct fc_exch_mgr *mp);
  731. /*
  732. * Receive a frame on specified local port and exchange manager.
  733. */
  734. void fc_exch_recv(struct fc_lport *lp, struct fc_exch_mgr *mp,
  735. struct fc_frame *fp);
  736. /*
  737. * This function is for exch_seq_send function pointer in
  738. * struct libfc_function_template, see comment block on
  739. * exch_seq_send for description of this function.
  740. */
  741. struct fc_seq *fc_exch_seq_send(struct fc_lport *lp,
  742. struct fc_frame *fp,
  743. void (*resp)(struct fc_seq *sp,
  744. struct fc_frame *fp,
  745. void *arg),
  746. void (*destructor)(struct fc_seq *sp,
  747. void *arg),
  748. void *arg, u32 timer_msec);
  749. /*
  750. * send a frame using existing sequence and exchange.
  751. */
  752. int fc_seq_send(struct fc_lport *lp, struct fc_seq *sp, struct fc_frame *fp);
  753. /*
  754. * Send ELS response using mainly infomation
  755. * in exchange and sequence in EM layer.
  756. */
  757. void fc_seq_els_rsp_send(struct fc_seq *sp, enum fc_els_cmd els_cmd,
  758. struct fc_seq_els_data *els_data);
  759. /*
  760. * This function is for seq_exch_abort function pointer in
  761. * struct libfc_function_template, see comment block on
  762. * seq_exch_abort for description of this function.
  763. */
  764. int fc_seq_exch_abort(const struct fc_seq *req_sp, unsigned int timer_msec);
  765. /*
  766. * Indicate that an exchange/sequence tuple is complete and the memory
  767. * allocated for the related objects may be freed.
  768. */
  769. void fc_exch_done(struct fc_seq *sp);
  770. /*
  771. * Assigns a EM and XID for a frame and then allocates
  772. * a new exchange and sequence pair.
  773. * The fp can be used to determine free XID.
  774. */
  775. struct fc_exch *fc_exch_get(struct fc_lport *lp, struct fc_frame *fp);
  776. /*
  777. * Allocate a new exchange and sequence pair.
  778. * if ex_id is zero then next free exchange id
  779. * from specified exchange manger mp will be assigned.
  780. */
  781. struct fc_exch *fc_exch_alloc(struct fc_exch_mgr *mp,
  782. struct fc_frame *fp, u16 ex_id);
  783. /*
  784. * Start a new sequence on the same exchange as the supplied sequence.
  785. */
  786. struct fc_seq *fc_seq_start_next(struct fc_seq *sp);
  787. /*
  788. * Reset an exchange manager, completing all sequences and exchanges.
  789. * If s_id is non-zero, reset only exchanges originating from that FID.
  790. * If d_id is non-zero, reset only exchanges sending to that FID.
  791. */
  792. void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id);
  793. /*
  794. * Functions for fc_functions_template
  795. */
  796. void fc_get_host_speed(struct Scsi_Host *shost);
  797. void fc_get_host_port_type(struct Scsi_Host *shost);
  798. void fc_get_host_port_state(struct Scsi_Host *shost);
  799. void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout);
  800. struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *);
  801. /*
  802. * module setup functions.
  803. */
  804. int fc_setup_exch_mgr(void);
  805. void fc_destroy_exch_mgr(void);
  806. int fc_setup_rport(void);
  807. void fc_destroy_rport(void);
  808. #endif /* _LIBFC_H_ */