libfc.h 24 KB

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