libfc.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  1. /*
  2. * Copyright(c) 2007 Intel Corporation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  16. *
  17. * Maintained at www.Open-FCoE.org
  18. */
  19. #ifndef _LIBFC_H_
  20. #define _LIBFC_H_
  21. #include <linux/timer.h>
  22. #include <linux/if.h>
  23. #include <linux/percpu.h>
  24. #include <scsi/scsi_transport.h>
  25. #include <scsi/scsi_transport_fc.h>
  26. #include <scsi/scsi_bsg_fc.h>
  27. #include <scsi/fc/fc_fcp.h>
  28. #include <scsi/fc/fc_ns.h>
  29. #include <scsi/fc/fc_ms.h>
  30. #include <scsi/fc/fc_els.h>
  31. #include <scsi/fc/fc_gs.h>
  32. #include <scsi/fc_frame.h>
  33. #define FC_FC4_PROV_SIZE (FC_TYPE_FCP + 1) /* size of tables */
  34. /*
  35. * libfc error codes
  36. */
  37. #define FC_NO_ERR 0 /* no error */
  38. #define FC_EX_TIMEOUT 1 /* Exchange timeout */
  39. #define FC_EX_CLOSED 2 /* Exchange closed */
  40. /**
  41. * enum fc_lport_state - Local port states
  42. * @LPORT_ST_DISABLED: Disabled
  43. * @LPORT_ST_FLOGI: Fabric login (FLOGI) sent
  44. * @LPORT_ST_DNS: Waiting for name server remote port to become ready
  45. * @LPORT_ST_RPN_ID: Register port name by ID (RPN_ID) sent
  46. * @LPORT_ST_RFT_ID: Register Fibre Channel types by ID (RFT_ID) sent
  47. * @LPORT_ST_RFF_ID: Register FC-4 Features by ID (RFF_ID) sent
  48. * @LPORT_ST_FDMI: Waiting for mgmt server rport to become ready
  49. * @LPORT_ST_RHBA:
  50. * @LPORT_ST_SCR: State Change Register (SCR) sent
  51. * @LPORT_ST_READY: Ready for use
  52. * @LPORT_ST_LOGO: Local port logout (LOGO) sent
  53. * @LPORT_ST_RESET: Local port reset
  54. */
  55. enum fc_lport_state {
  56. LPORT_ST_DISABLED = 0,
  57. LPORT_ST_FLOGI,
  58. LPORT_ST_DNS,
  59. LPORT_ST_RNN_ID,
  60. LPORT_ST_RSNN_NN,
  61. LPORT_ST_RSPN_ID,
  62. LPORT_ST_RFT_ID,
  63. LPORT_ST_RFF_ID,
  64. LPORT_ST_FDMI,
  65. LPORT_ST_RHBA,
  66. LPORT_ST_RPA,
  67. LPORT_ST_DHBA,
  68. LPORT_ST_DPRT,
  69. LPORT_ST_SCR,
  70. LPORT_ST_READY,
  71. LPORT_ST_LOGO,
  72. LPORT_ST_RESET
  73. };
  74. enum fc_disc_event {
  75. DISC_EV_NONE = 0,
  76. DISC_EV_SUCCESS,
  77. DISC_EV_FAILED
  78. };
  79. /**
  80. * enum fc_rport_state - Remote port states
  81. * @RPORT_ST_INIT: Initialized
  82. * @RPORT_ST_FLOGI: Waiting for FLOGI completion for point-to-multipoint
  83. * @RPORT_ST_PLOGI_WAIT: Waiting for peer to login for point-to-multipoint
  84. * @RPORT_ST_PLOGI: Waiting for PLOGI completion
  85. * @RPORT_ST_PRLI: Waiting for PRLI completion
  86. * @RPORT_ST_RTV: Waiting for RTV completion
  87. * @RPORT_ST_READY: Ready for use
  88. * @RPORT_ST_ADISC: Discover Address sent
  89. * @RPORT_ST_DELETE: Remote port being deleted
  90. */
  91. enum fc_rport_state {
  92. RPORT_ST_INIT,
  93. RPORT_ST_FLOGI,
  94. RPORT_ST_PLOGI_WAIT,
  95. RPORT_ST_PLOGI,
  96. RPORT_ST_PRLI,
  97. RPORT_ST_RTV,
  98. RPORT_ST_READY,
  99. RPORT_ST_ADISC,
  100. RPORT_ST_DELETE,
  101. };
  102. /**
  103. * struct fc_disc_port - temporary discovery port to hold rport identifiers
  104. * @lp: Fibre Channel host port instance
  105. * @peers: Node for list management during discovery and RSCN processing
  106. * @rport_work: Work struct for starting the rport state machine
  107. * @port_id: Port ID of the discovered port
  108. */
  109. struct fc_disc_port {
  110. struct fc_lport *lp;
  111. struct list_head peers;
  112. struct work_struct rport_work;
  113. u32 port_id;
  114. };
  115. /**
  116. * enum fc_rport_event - Remote port events
  117. * @RPORT_EV_NONE: No event
  118. * @RPORT_EV_READY: Remote port is ready for use
  119. * @RPORT_EV_FAILED: State machine failed, remote port is not ready
  120. * @RPORT_EV_STOP: Remote port has been stopped
  121. * @RPORT_EV_LOGO: Remote port logout (LOGO) sent
  122. */
  123. enum fc_rport_event {
  124. RPORT_EV_NONE = 0,
  125. RPORT_EV_READY,
  126. RPORT_EV_FAILED,
  127. RPORT_EV_STOP,
  128. RPORT_EV_LOGO
  129. };
  130. struct fc_rport_priv;
  131. /**
  132. * struct fc_rport_operations - Operations for a remote port
  133. * @event_callback: Function to be called for remote port events
  134. */
  135. struct fc_rport_operations {
  136. void (*event_callback)(struct fc_lport *, struct fc_rport_priv *,
  137. enum fc_rport_event);
  138. };
  139. /**
  140. * struct fc_rport_libfc_priv - libfc internal information about a remote port
  141. * @local_port: The associated local port
  142. * @rp_state: Indicates READY for I/O or DELETE when blocked
  143. * @flags: REC and RETRY supported flags
  144. * @e_d_tov: Error detect timeout value (in msec)
  145. * @r_a_tov: Resource allocation timeout value (in msec)
  146. */
  147. struct fc_rport_libfc_priv {
  148. struct fc_lport *local_port;
  149. enum fc_rport_state rp_state;
  150. u16 flags;
  151. #define FC_RP_FLAGS_REC_SUPPORTED (1 << 0)
  152. #define FC_RP_FLAGS_RETRY (1 << 1)
  153. #define FC_RP_STARTED (1 << 2)
  154. #define FC_RP_FLAGS_CONF_REQ (1 << 3)
  155. unsigned int e_d_tov;
  156. unsigned int r_a_tov;
  157. };
  158. /**
  159. * struct fc_rport_priv - libfc remote port and discovery info
  160. * @local_port: The associated local port
  161. * @rport: The FC transport remote port
  162. * @kref: Reference counter
  163. * @rp_state: Enumeration that tracks progress of PLOGI, PRLI,
  164. * and RTV exchanges
  165. * @ids: The remote port identifiers and roles
  166. * @flags: STARTED, REC and RETRY_SUPPORTED flags
  167. * @max_seq: Maximum number of concurrent sequences
  168. * @disc_id: The discovery identifier
  169. * @maxframe_size: The maximum frame size
  170. * @retries: The retry count for the current state
  171. * @major_retries: The retry count for the entire PLOGI/PRLI state machine
  172. * @e_d_tov: Error detect timeout value (in msec)
  173. * @r_a_tov: Resource allocation timeout value (in msec)
  174. * @rp_mutex: The mutex that protects the remote port
  175. * @retry_work: Handle for retries
  176. * @event_callback: Callback when READY, FAILED or LOGO states complete
  177. * @prli_count: Count of open PRLI sessions in providers
  178. * @rcu: Structure used for freeing in an RCU-safe manner
  179. */
  180. struct fc_rport_priv {
  181. struct fc_lport *local_port;
  182. struct fc_rport *rport;
  183. struct kref kref;
  184. enum fc_rport_state rp_state;
  185. struct fc_rport_identifiers ids;
  186. u16 flags;
  187. u16 max_seq;
  188. u16 disc_id;
  189. u16 maxframe_size;
  190. unsigned int retries;
  191. unsigned int major_retries;
  192. unsigned int e_d_tov;
  193. unsigned int r_a_tov;
  194. struct mutex rp_mutex;
  195. struct delayed_work retry_work;
  196. enum fc_rport_event event;
  197. struct fc_rport_operations *ops;
  198. struct list_head peers;
  199. struct work_struct event_work;
  200. u32 supported_classes;
  201. u16 prli_count;
  202. struct rcu_head rcu;
  203. u16 sp_features;
  204. u8 spp_type;
  205. void (*lld_event_callback)(struct fc_lport *,
  206. struct fc_rport_priv *,
  207. enum fc_rport_event);
  208. };
  209. /**
  210. * struct fcoe_dev_stats - fcoe stats structure
  211. * @SecondsSinceLastReset: Seconds since the last reset
  212. * @TxFrames: Number of transmitted frames
  213. * @TxWords: Number of transmitted words
  214. * @RxFrames: Number of received frames
  215. * @RxWords: Number of received words
  216. * @ErrorFrames: Number of received error frames
  217. * @DumpedFrames: Number of dumped frames
  218. * @LinkFailureCount: Number of link failures
  219. * @LossOfSignalCount: Number for signal losses
  220. * @InvalidTxWordCount: Number of invalid transmitted words
  221. * @InvalidCRCCount: Number of invalid CRCs
  222. * @InputRequests: Number of input requests
  223. * @OutputRequests: Number of output requests
  224. * @ControlRequests: Number of control requests
  225. * @InputBytes: Number of received bytes
  226. * @OutputBytes: Number of transmitted bytes
  227. * @VLinkFailureCount: Number of virtual link failures
  228. * @MissDiscAdvCount: Number of missing FIP discovery advertisement
  229. */
  230. struct fcoe_dev_stats {
  231. u64 SecondsSinceLastReset;
  232. u64 TxFrames;
  233. u64 TxWords;
  234. u64 RxFrames;
  235. u64 RxWords;
  236. u64 ErrorFrames;
  237. u64 DumpedFrames;
  238. u64 LinkFailureCount;
  239. u64 LossOfSignalCount;
  240. u64 InvalidTxWordCount;
  241. u64 InvalidCRCCount;
  242. u64 InputRequests;
  243. u64 OutputRequests;
  244. u64 ControlRequests;
  245. u64 InputBytes;
  246. u64 OutputBytes;
  247. u64 VLinkFailureCount;
  248. u64 MissDiscAdvCount;
  249. };
  250. /**
  251. * struct fc_seq_els_data - ELS data used for passing ELS specific responses
  252. * @reason: The reason for rejection
  253. * @explan: The explanation of the rejection
  254. *
  255. * Mainly used by the exchange manager layer.
  256. */
  257. struct fc_seq_els_data {
  258. enum fc_els_rjt_reason reason;
  259. enum fc_els_rjt_explan explan;
  260. };
  261. /**
  262. * struct fc_fcp_pkt - FCP request structure (one for each scsi_cmnd request)
  263. * @lp: The associated local port
  264. * @state: The state of the I/O
  265. * @ref_cnt: Reference count
  266. * @scsi_pkt_lock: Lock to protect the SCSI packet (must be taken before the
  267. * host_lock if both are to be held at the same time)
  268. * @cmd: The SCSI command (set and clear with the host_lock held)
  269. * @list: Tracks queued commands (accessed with the host_lock held)
  270. * @timer: The command timer
  271. * @tm_done: Completion indicator
  272. * @wait_for_comp: Indicator to wait for completion of the I/O (in jiffies)
  273. * @data_len: The length of the data
  274. * @cdb_cmd: The CDB command
  275. * @xfer_len: The transfer length
  276. * @xfer_ddp: Indicates if this transfer used DDP (XID of the exchange
  277. * will be set here if DDP was setup)
  278. * @xfer_contig_end: The offset into the buffer if the buffer is contiguous
  279. * (Tx and Rx)
  280. * @max_payload: The maximum payload size (in bytes)
  281. * @io_status: SCSI result (upper 24 bits)
  282. * @cdb_status: CDB status
  283. * @status_code: FCP I/O status
  284. * @scsi_comp_flags: Completion flags (bit 3 Underrun bit 2: overrun)
  285. * @req_flags: Request flags (bit 0: read bit:1 write)
  286. * @scsi_resid: SCSI residule length
  287. * @rport: The remote port that the SCSI command is targeted at
  288. * @seq_ptr: The sequence that will carry the SCSI command
  289. * @recov_retry: Number of recovery retries
  290. * @recov_seq: The sequence for REC or SRR
  291. */
  292. struct fc_fcp_pkt {
  293. spinlock_t scsi_pkt_lock;
  294. atomic_t ref_cnt;
  295. /* SCSI command and data transfer information */
  296. u32 data_len;
  297. /* SCSI I/O related information */
  298. struct scsi_cmnd *cmd;
  299. struct list_head list;
  300. /* Housekeeping information */
  301. struct fc_lport *lp;
  302. u8 state;
  303. /* SCSI/FCP return status */
  304. u8 cdb_status;
  305. u8 status_code;
  306. u8 scsi_comp_flags;
  307. u32 io_status;
  308. u32 req_flags;
  309. u32 scsi_resid;
  310. /* Transport related veriables */
  311. size_t xfer_len;
  312. struct fcp_cmnd cdb_cmd;
  313. u32 xfer_contig_end;
  314. u16 max_payload;
  315. u16 xfer_ddp;
  316. /* Associated structures */
  317. struct fc_rport *rport;
  318. struct fc_seq *seq_ptr;
  319. /* Timeout/error related information */
  320. struct timer_list timer;
  321. int wait_for_comp;
  322. u32 recov_retry;
  323. struct fc_seq *recov_seq;
  324. struct completion tm_done;
  325. } ____cacheline_aligned_in_smp;
  326. /*
  327. * Structure and function definitions for managing Fibre Channel Exchanges
  328. * and Sequences
  329. *
  330. * fc_exch holds state for one exchange and links to its active sequence.
  331. *
  332. * fc_seq holds the state for an individual sequence.
  333. */
  334. struct fc_exch_mgr;
  335. struct fc_exch_mgr_anchor;
  336. extern u16 fc_cpu_mask; /* cpu mask for possible cpus */
  337. /**
  338. * struct fc_seq - FC sequence
  339. * @id: The sequence ID
  340. * @ssb_stat: Status flags for the sequence status block (SSB)
  341. * @cnt: Number of frames sent so far
  342. * @rec_data: FC-4 value for REC
  343. */
  344. struct fc_seq {
  345. u8 id;
  346. u16 ssb_stat;
  347. u16 cnt;
  348. u32 rec_data;
  349. };
  350. #define FC_EX_DONE (1 << 0) /* ep is completed */
  351. #define FC_EX_RST_CLEANUP (1 << 1) /* reset is forcing completion */
  352. /**
  353. * struct fc_exch - Fibre Channel Exchange
  354. * @em: Exchange manager
  355. * @pool: Exchange pool
  356. * @state: The exchange's state
  357. * @xid: The exchange ID
  358. * @ex_list: Handle used by the EM to track free exchanges
  359. * @ex_lock: Lock that protects the exchange
  360. * @ex_refcnt: Reference count
  361. * @timeout_work: Handle for timeout handler
  362. * @lp: The local port that this exchange is on
  363. * @oxid: Originator's exchange ID
  364. * @rxid: Responder's exchange ID
  365. * @oid: Originator's FCID
  366. * @sid: Source FCID
  367. * @did: Destination FCID
  368. * @esb_stat: ESB exchange status
  369. * @r_a_tov: Resouce allocation time out value (in msecs)
  370. * @seq_id: The next sequence ID to use
  371. * @encaps: encapsulation information for lower-level driver
  372. * @f_ctl: F_CTL flags for the sequence
  373. * @fh_type: The frame type
  374. * @class: The class of service
  375. * @seq: The sequence in use on this exchange
  376. * @resp: Callback for responses on this exchange
  377. * @destructor: Called when destroying the exchange
  378. * @arg: Passed as a void pointer to the resp() callback
  379. *
  380. * Locking notes: The ex_lock protects following items:
  381. * state, esb_stat, f_ctl, seq.ssb_stat
  382. * seq_id
  383. * sequence allocation
  384. */
  385. struct fc_exch {
  386. spinlock_t ex_lock;
  387. atomic_t ex_refcnt;
  388. enum fc_class class;
  389. struct fc_exch_mgr *em;
  390. struct fc_exch_pool *pool;
  391. struct list_head ex_list;
  392. struct fc_lport *lp;
  393. u32 esb_stat;
  394. u8 state;
  395. u8 fh_type;
  396. u8 seq_id;
  397. u8 encaps;
  398. u16 xid;
  399. u16 oxid;
  400. u16 rxid;
  401. u32 oid;
  402. u32 sid;
  403. u32 did;
  404. u32 r_a_tov;
  405. u32 f_ctl;
  406. struct fc_seq seq;
  407. void (*resp)(struct fc_seq *, struct fc_frame *, void *);
  408. void *arg;
  409. void (*destructor)(struct fc_seq *, void *);
  410. struct delayed_work timeout_work;
  411. } ____cacheline_aligned_in_smp;
  412. #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
  413. struct libfc_function_template {
  414. /*
  415. * Interface to send a FC frame
  416. *
  417. * STATUS: REQUIRED
  418. */
  419. int (*frame_send)(struct fc_lport *, struct fc_frame *);
  420. /*
  421. * Interface to send ELS/CT frames
  422. *
  423. * STATUS: OPTIONAL
  424. */
  425. struct fc_seq *(*elsct_send)(struct fc_lport *, u32 did,
  426. struct fc_frame *, unsigned int op,
  427. void (*resp)(struct fc_seq *,
  428. struct fc_frame *, void *arg),
  429. void *arg, u32 timer_msec);
  430. /*
  431. * Send the FC frame payload using a new exchange and sequence.
  432. *
  433. * The exchange response handler is set in this routine to resp()
  434. * function pointer. It can be called in two scenarios: if a timeout
  435. * occurs or if a response frame is received for the exchange. The
  436. * fc_frame pointer in response handler will also indicate timeout
  437. * as error using IS_ERR related macros.
  438. *
  439. * The exchange destructor handler is also set in this routine.
  440. * The destructor handler is invoked by EM layer when exchange
  441. * is about to free, this can be used by caller to free its
  442. * resources along with exchange free.
  443. *
  444. * The arg is passed back to resp and destructor handler.
  445. *
  446. * The timeout value (in msec) for an exchange is set if non zero
  447. * timer_msec argument is specified. The timer is canceled when
  448. * it fires or when the exchange is done. The exchange timeout handler
  449. * is registered by EM layer.
  450. *
  451. * STATUS: OPTIONAL
  452. */
  453. struct fc_seq *(*exch_seq_send)(struct fc_lport *, struct fc_frame *,
  454. void (*resp)(struct fc_seq *,
  455. struct fc_frame *,
  456. void *),
  457. void (*destructor)(struct fc_seq *,
  458. void *),
  459. void *, unsigned int timer_msec);
  460. /*
  461. * Sets up the DDP context for a given exchange id on the given
  462. * scatterlist if LLD supports DDP for large receive.
  463. *
  464. * STATUS: OPTIONAL
  465. */
  466. int (*ddp_setup)(struct fc_lport *, u16, struct scatterlist *,
  467. unsigned int);
  468. /*
  469. * Completes the DDP transfer and returns the length of data DDPed
  470. * for the given exchange id.
  471. *
  472. * STATUS: OPTIONAL
  473. */
  474. int (*ddp_done)(struct fc_lport *, u16);
  475. /*
  476. * Sets up the DDP context for a given exchange id on the given
  477. * scatterlist if LLD supports DDP for FCoE target.
  478. *
  479. * STATUS: OPTIONAL
  480. */
  481. int (*ddp_target)(struct fc_lport *, u16, struct scatterlist *,
  482. unsigned int);
  483. /*
  484. * Allow LLD to fill its own Link Error Status Block
  485. *
  486. * STATUS: OPTIONAL
  487. */
  488. void (*get_lesb)(struct fc_lport *, struct fc_els_lesb *lesb);
  489. /*
  490. * Send a frame using an existing sequence and exchange.
  491. *
  492. * STATUS: OPTIONAL
  493. */
  494. int (*seq_send)(struct fc_lport *, struct fc_seq *,
  495. struct fc_frame *);
  496. /*
  497. * Send an ELS response using information from the received frame.
  498. *
  499. * STATUS: OPTIONAL
  500. */
  501. void (*seq_els_rsp_send)(struct fc_frame *, enum fc_els_cmd,
  502. struct fc_seq_els_data *);
  503. /*
  504. * Abort an exchange and sequence. Generally called because of a
  505. * exchange timeout or an abort from the upper layer.
  506. *
  507. * A timer_msec can be specified for abort timeout, if non-zero
  508. * timer_msec value is specified then exchange resp handler
  509. * will be called with timeout error if no response to abort.
  510. *
  511. * STATUS: OPTIONAL
  512. */
  513. int (*seq_exch_abort)(const struct fc_seq *,
  514. unsigned int timer_msec);
  515. /*
  516. * Indicate that an exchange/sequence tuple is complete and the memory
  517. * allocated for the related objects may be freed.
  518. *
  519. * STATUS: OPTIONAL
  520. */
  521. void (*exch_done)(struct fc_seq *);
  522. /*
  523. * Start a new sequence on the same exchange/sequence tuple.
  524. *
  525. * STATUS: OPTIONAL
  526. */
  527. struct fc_seq *(*seq_start_next)(struct fc_seq *);
  528. /*
  529. * Set a response handler for the exchange of the sequence.
  530. *
  531. * STATUS: OPTIONAL
  532. */
  533. void (*seq_set_resp)(struct fc_seq *sp,
  534. void (*resp)(struct fc_seq *, struct fc_frame *,
  535. void *),
  536. void *arg);
  537. /*
  538. * Assign a sequence for an incoming request frame.
  539. *
  540. * STATUS: OPTIONAL
  541. */
  542. struct fc_seq *(*seq_assign)(struct fc_lport *, struct fc_frame *);
  543. /*
  544. * Release the reference on the sequence returned by seq_assign().
  545. *
  546. * STATUS: OPTIONAL
  547. */
  548. void (*seq_release)(struct fc_seq *);
  549. /*
  550. * Reset an exchange manager, completing all sequences and exchanges.
  551. * If s_id is non-zero, reset only exchanges originating from that FID.
  552. * If d_id is non-zero, reset only exchanges sending to that FID.
  553. *
  554. * STATUS: OPTIONAL
  555. */
  556. void (*exch_mgr_reset)(struct fc_lport *, u32 s_id, u32 d_id);
  557. /*
  558. * Flush the rport work queue. Generally used before shutdown.
  559. *
  560. * STATUS: OPTIONAL
  561. */
  562. void (*rport_flush_queue)(void);
  563. /*
  564. * Receive a frame for a local port.
  565. *
  566. * STATUS: OPTIONAL
  567. */
  568. void (*lport_recv)(struct fc_lport *, struct fc_frame *);
  569. /*
  570. * Reset the local port.
  571. *
  572. * STATUS: OPTIONAL
  573. */
  574. int (*lport_reset)(struct fc_lport *);
  575. /*
  576. * Set the local port FC_ID.
  577. *
  578. * This may be provided by the LLD to allow it to be
  579. * notified when the local port is assigned a FC-ID.
  580. *
  581. * The frame, if non-NULL, is the incoming frame with the
  582. * FLOGI LS_ACC or FLOGI, and may contain the granted MAC
  583. * address for the LLD. The frame pointer may be NULL if
  584. * no MAC is associated with this assignment (LOGO or PLOGI).
  585. *
  586. * If FC_ID is non-zero, r_a_tov and e_d_tov must be valid.
  587. *
  588. * Note: this is called with the local port mutex held.
  589. *
  590. * STATUS: OPTIONAL
  591. */
  592. void (*lport_set_port_id)(struct fc_lport *, u32 port_id,
  593. struct fc_frame *);
  594. /*
  595. * Create a remote port with a given port ID
  596. *
  597. * STATUS: OPTIONAL
  598. */
  599. struct fc_rport_priv *(*rport_create)(struct fc_lport *, u32);
  600. /*
  601. * Initiates the RP state machine. It is called from the LP module.
  602. * This function will issue the following commands to the N_Port
  603. * identified by the FC ID provided.
  604. *
  605. * - PLOGI
  606. * - PRLI
  607. * - RTV
  608. *
  609. * STATUS: OPTIONAL
  610. */
  611. int (*rport_login)(struct fc_rport_priv *);
  612. /*
  613. * Logoff, and remove the rport from the transport if
  614. * it had been added. This will send a LOGO to the target.
  615. *
  616. * STATUS: OPTIONAL
  617. */
  618. int (*rport_logoff)(struct fc_rport_priv *);
  619. /*
  620. * Receive a request from a remote port.
  621. *
  622. * STATUS: OPTIONAL
  623. */
  624. void (*rport_recv_req)(struct fc_lport *, struct fc_frame *);
  625. /*
  626. * lookup an rport by it's port ID.
  627. *
  628. * STATUS: OPTIONAL
  629. */
  630. struct fc_rport_priv *(*rport_lookup)(const struct fc_lport *, u32);
  631. /*
  632. * Destroy an rport after final kref_put().
  633. * The argument is a pointer to the kref inside the fc_rport_priv.
  634. */
  635. void (*rport_destroy)(struct kref *);
  636. /*
  637. * Callback routine after the remote port is logged in
  638. *
  639. * STATUS: OPTIONAL
  640. */
  641. void (*rport_event_callback)(struct fc_lport *,
  642. struct fc_rport_priv *,
  643. enum fc_rport_event);
  644. /*
  645. * Send a fcp cmd from fsp pkt.
  646. * Called with the SCSI host lock unlocked and irqs disabled.
  647. *
  648. * The resp handler is called when FCP_RSP received.
  649. *
  650. * STATUS: OPTIONAL
  651. */
  652. int (*fcp_cmd_send)(struct fc_lport *, struct fc_fcp_pkt *,
  653. void (*resp)(struct fc_seq *, struct fc_frame *,
  654. void *));
  655. /*
  656. * Cleanup the FCP layer, used during link down and reset
  657. *
  658. * STATUS: OPTIONAL
  659. */
  660. void (*fcp_cleanup)(struct fc_lport *);
  661. /*
  662. * Abort all I/O on a local port
  663. *
  664. * STATUS: OPTIONAL
  665. */
  666. void (*fcp_abort_io)(struct fc_lport *);
  667. /*
  668. * Receive a request for the discovery layer.
  669. *
  670. * STATUS: OPTIONAL
  671. */
  672. void (*disc_recv_req)(struct fc_lport *, struct fc_frame *);
  673. /*
  674. * Start discovery for a local port.
  675. *
  676. * STATUS: OPTIONAL
  677. */
  678. void (*disc_start)(void (*disc_callback)(struct fc_lport *,
  679. enum fc_disc_event),
  680. struct fc_lport *);
  681. /*
  682. * Stop discovery for a given lport. This will remove
  683. * all discovered rports
  684. *
  685. * STATUS: OPTIONAL
  686. */
  687. void (*disc_stop) (struct fc_lport *);
  688. /*
  689. * Stop discovery for a given lport. This will block
  690. * until all discovered rports are deleted from the
  691. * FC transport class
  692. *
  693. * STATUS: OPTIONAL
  694. */
  695. void (*disc_stop_final) (struct fc_lport *);
  696. };
  697. /**
  698. * struct fc_disc - Discovery context
  699. * @retry_count: Number of retries
  700. * @pending: 1 if discovery is pending, 0 if not
  701. * @requested: 1 if discovery has been requested, 0 if not
  702. * @seq_count: Number of sequences used for discovery
  703. * @buf_len: Length of the discovery buffer
  704. * @disc_id: Discovery ID
  705. * @rports: List of discovered remote ports
  706. * @priv: Private pointer for use by discovery code
  707. * @disc_mutex: Mutex that protects the discovery context
  708. * @partial_buf: Partial name buffer (if names are returned
  709. * in multiple frames)
  710. * @disc_work: handle for delayed work context
  711. * @disc_callback: Callback routine called when discovery completes
  712. */
  713. struct fc_disc {
  714. unsigned char retry_count;
  715. unsigned char pending;
  716. unsigned char requested;
  717. unsigned short seq_count;
  718. unsigned char buf_len;
  719. u16 disc_id;
  720. struct list_head rports;
  721. void *priv;
  722. struct mutex disc_mutex;
  723. struct fc_gpn_ft_resp partial_buf;
  724. struct delayed_work disc_work;
  725. void (*disc_callback)(struct fc_lport *,
  726. enum fc_disc_event);
  727. };
  728. /*
  729. * Local port notifier and events.
  730. */
  731. extern struct blocking_notifier_head fc_lport_notifier_head;
  732. enum fc_lport_event {
  733. FC_LPORT_EV_ADD,
  734. FC_LPORT_EV_DEL,
  735. };
  736. /**
  737. * struct fc_lport - Local port
  738. * @host: The SCSI host associated with a local port
  739. * @ema_list: Exchange manager anchor list
  740. * @dns_rdata: The directory server remote port
  741. * @ms_rdata: The management server remote port
  742. * @ptp_rdata: Point to point remote port
  743. * @scsi_priv: FCP layer internal data
  744. * @disc: Discovery context
  745. * @vports: Child vports if N_Port
  746. * @vport: Parent vport if VN_Port
  747. * @tt: Libfc function template
  748. * @link_up: Link state (1 = link up, 0 = link down)
  749. * @qfull: Queue state (1 queue is full, 0 queue is not full)
  750. * @state: Identifies the state
  751. * @boot_time: Timestamp indicating when the local port came online
  752. * @host_stats: SCSI host statistics
  753. * @dev_stats: FCoE device stats (TODO: libfc should not be
  754. * FCoE aware)
  755. * @retry_count: Number of retries in the current state
  756. * @port_id: FC Port ID
  757. * @wwpn: World Wide Port Name
  758. * @wwnn: World Wide Node Name
  759. * @service_params: Common service parameters
  760. * @e_d_tov: Error detection timeout value
  761. * @r_a_tov: Resouce allocation timeout value
  762. * @rnid_gen: RNID information
  763. * @sg_supp: Indicates if scatter gather is supported
  764. * @seq_offload: Indicates if sequence offload is supported
  765. * @crc_offload: Indicates if CRC offload is supported
  766. * @lro_enabled: Indicates if large receive offload is supported
  767. * @does_npiv: Supports multiple vports
  768. * @npiv_enabled: Switch/fabric allows NPIV
  769. * @mfs: The maximum Fibre Channel payload size
  770. * @max_retry_count: The maximum retry attempts
  771. * @max_rport_retry_count: The maximum remote port retry attempts
  772. * @rport_priv_size: Size needed by driver after struct fc_rport_priv
  773. * @lro_xid: The maximum XID for LRO
  774. * @lso_max: The maximum large offload send size
  775. * @fcts: FC-4 type mask
  776. * @lp_mutex: Mutex to protect the local port
  777. * @list: Linkage on list of vport peers
  778. * @retry_work: Handle to local port for delayed retry context
  779. * @prov: Pointers available for use by passive FC-4 providers
  780. * @lport_list: Linkage on module-wide list of local ports
  781. */
  782. struct fc_lport {
  783. /* Associations */
  784. struct Scsi_Host *host;
  785. struct list_head ema_list;
  786. struct fc_rport_priv *dns_rdata;
  787. struct fc_rport_priv *ms_rdata;
  788. struct fc_rport_priv *ptp_rdata;
  789. void *scsi_priv;
  790. struct fc_disc disc;
  791. /* Virtual port information */
  792. struct list_head vports;
  793. struct fc_vport *vport;
  794. /* Operational Information */
  795. struct libfc_function_template tt;
  796. u8 link_up;
  797. u8 qfull;
  798. enum fc_lport_state state;
  799. unsigned long boot_time;
  800. struct fc_host_statistics host_stats;
  801. struct fcoe_dev_stats __percpu *dev_stats;
  802. u8 retry_count;
  803. /* Fabric information */
  804. u32 port_id;
  805. u64 wwpn;
  806. u64 wwnn;
  807. unsigned int service_params;
  808. unsigned int e_d_tov;
  809. unsigned int r_a_tov;
  810. struct fc_els_rnid_gen rnid_gen;
  811. /* Capabilities */
  812. u32 sg_supp:1;
  813. u32 seq_offload:1;
  814. u32 crc_offload:1;
  815. u32 lro_enabled:1;
  816. u32 does_npiv:1;
  817. u32 npiv_enabled:1;
  818. u32 point_to_multipoint:1;
  819. u32 fdmi_enabled:1;
  820. u32 mfs;
  821. u8 max_retry_count;
  822. u8 max_rport_retry_count;
  823. u16 rport_priv_size;
  824. u16 link_speed;
  825. u16 link_supported_speeds;
  826. u16 lro_xid;
  827. unsigned int lso_max;
  828. struct fc_ns_fts fcts;
  829. /* Miscellaneous */
  830. struct mutex lp_mutex;
  831. struct list_head list;
  832. struct delayed_work retry_work;
  833. void *prov[FC_FC4_PROV_SIZE];
  834. struct list_head lport_list;
  835. };
  836. /**
  837. * struct fc4_prov - FC-4 provider registration
  838. * @prli: Handler for incoming PRLI
  839. * @prlo: Handler for session reset
  840. * @recv: Handler for incoming request
  841. * @module: Pointer to module. May be NULL.
  842. */
  843. struct fc4_prov {
  844. int (*prli)(struct fc_rport_priv *, u32 spp_len,
  845. const struct fc_els_spp *spp_in,
  846. struct fc_els_spp *spp_out);
  847. void (*prlo)(struct fc_rport_priv *);
  848. void (*recv)(struct fc_lport *, struct fc_frame *);
  849. struct module *module;
  850. };
  851. /*
  852. * Register FC-4 provider with libfc.
  853. */
  854. int fc_fc4_register_provider(enum fc_fh_type type, struct fc4_prov *);
  855. void fc_fc4_deregister_provider(enum fc_fh_type type, struct fc4_prov *);
  856. /*
  857. * FC_LPORT HELPER FUNCTIONS
  858. *****************************/
  859. /**
  860. * fc_lport_test_ready() - Determine if a local port is in the READY state
  861. * @lport: The local port to test
  862. */
  863. static inline int fc_lport_test_ready(struct fc_lport *lport)
  864. {
  865. return lport->state == LPORT_ST_READY;
  866. }
  867. /**
  868. * fc_set_wwnn() - Set the World Wide Node Name of a local port
  869. * @lport: The local port whose WWNN is to be set
  870. * @wwnn: The new WWNN
  871. */
  872. static inline void fc_set_wwnn(struct fc_lport *lport, u64 wwnn)
  873. {
  874. lport->wwnn = wwnn;
  875. }
  876. /**
  877. * fc_set_wwpn() - Set the World Wide Port Name of a local port
  878. * @lport: The local port whose WWPN is to be set
  879. * @wwnn: The new WWPN
  880. */
  881. static inline void fc_set_wwpn(struct fc_lport *lport, u64 wwnn)
  882. {
  883. lport->wwpn = wwnn;
  884. }
  885. /**
  886. * fc_lport_state_enter() - Change a local port's state
  887. * @lport: The local port whose state is to change
  888. * @state: The new state
  889. */
  890. static inline void fc_lport_state_enter(struct fc_lport *lport,
  891. enum fc_lport_state state)
  892. {
  893. if (state != lport->state)
  894. lport->retry_count = 0;
  895. lport->state = state;
  896. }
  897. /**
  898. * fc_lport_init_stats() - Allocate per-CPU statistics for a local port
  899. * @lport: The local port whose statistics are to be initialized
  900. */
  901. static inline int fc_lport_init_stats(struct fc_lport *lport)
  902. {
  903. lport->dev_stats = alloc_percpu(struct fcoe_dev_stats);
  904. if (!lport->dev_stats)
  905. return -ENOMEM;
  906. return 0;
  907. }
  908. /**
  909. * fc_lport_free_stats() - Free memory for a local port's statistics
  910. * @lport: The local port whose statistics are to be freed
  911. */
  912. static inline void fc_lport_free_stats(struct fc_lport *lport)
  913. {
  914. free_percpu(lport->dev_stats);
  915. }
  916. /**
  917. * lport_priv() - Return the private data from a local port
  918. * @lport: The local port whose private data is to be retreived
  919. */
  920. static inline void *lport_priv(const struct fc_lport *lport)
  921. {
  922. return (void *)(lport + 1);
  923. }
  924. /**
  925. * libfc_host_alloc() - Allocate a Scsi_Host with room for a local port and
  926. * LLD private data
  927. * @sht: The SCSI host template
  928. * @priv_size: Size of private data
  929. *
  930. * Returns: libfc lport
  931. */
  932. static inline struct fc_lport *
  933. libfc_host_alloc(struct scsi_host_template *sht, int priv_size)
  934. {
  935. struct fc_lport *lport;
  936. struct Scsi_Host *shost;
  937. shost = scsi_host_alloc(sht, sizeof(*lport) + priv_size);
  938. if (!shost)
  939. return NULL;
  940. lport = shost_priv(shost);
  941. lport->host = shost;
  942. INIT_LIST_HEAD(&lport->ema_list);
  943. INIT_LIST_HEAD(&lport->vports);
  944. return lport;
  945. }
  946. /*
  947. * FC_FCP HELPER FUNCTIONS
  948. *****************************/
  949. static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp)
  950. {
  951. if (fsp && fsp->cmd)
  952. return fsp->cmd->sc_data_direction == DMA_FROM_DEVICE;
  953. return false;
  954. }
  955. /*
  956. * LOCAL PORT LAYER
  957. *****************************/
  958. int fc_lport_init(struct fc_lport *);
  959. int fc_lport_destroy(struct fc_lport *);
  960. int fc_fabric_logoff(struct fc_lport *);
  961. int fc_fabric_login(struct fc_lport *);
  962. void __fc_linkup(struct fc_lport *);
  963. void fc_linkup(struct fc_lport *);
  964. void __fc_linkdown(struct fc_lport *);
  965. void fc_linkdown(struct fc_lport *);
  966. void fc_vport_setlink(struct fc_lport *);
  967. void fc_vports_linkchange(struct fc_lport *);
  968. int fc_lport_config(struct fc_lport *);
  969. int fc_lport_reset(struct fc_lport *);
  970. int fc_set_mfs(struct fc_lport *, u32 mfs);
  971. struct fc_lport *libfc_vport_create(struct fc_vport *, int privsize);
  972. struct fc_lport *fc_vport_id_lookup(struct fc_lport *, u32 port_id);
  973. int fc_lport_bsg_request(struct fc_bsg_job *);
  974. void fc_lport_set_local_id(struct fc_lport *, u32 port_id);
  975. void fc_lport_iterate(void (*func)(struct fc_lport *, void *), void *);
  976. /*
  977. * REMOTE PORT LAYER
  978. *****************************/
  979. int fc_rport_init(struct fc_lport *);
  980. void fc_rport_terminate_io(struct fc_rport *);
  981. /*
  982. * DISCOVERY LAYER
  983. *****************************/
  984. int fc_disc_init(struct fc_lport *);
  985. static inline struct fc_lport *fc_disc_lport(struct fc_disc *disc)
  986. {
  987. return container_of(disc, struct fc_lport, disc);
  988. }
  989. /*
  990. * FCP LAYER
  991. *****************************/
  992. int fc_fcp_init(struct fc_lport *);
  993. void fc_fcp_destroy(struct fc_lport *);
  994. /*
  995. * SCSI INTERACTION LAYER
  996. *****************************/
  997. int fc_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
  998. int fc_eh_abort(struct scsi_cmnd *);
  999. int fc_eh_device_reset(struct scsi_cmnd *);
  1000. int fc_eh_host_reset(struct scsi_cmnd *);
  1001. int fc_slave_alloc(struct scsi_device *);
  1002. int fc_change_queue_depth(struct scsi_device *, int qdepth, int reason);
  1003. int fc_change_queue_type(struct scsi_device *, int tag_type);
  1004. /*
  1005. * ELS/CT interface
  1006. *****************************/
  1007. int fc_elsct_init(struct fc_lport *);
  1008. struct fc_seq *fc_elsct_send(struct fc_lport *, u32 did,
  1009. struct fc_frame *,
  1010. unsigned int op,
  1011. void (*resp)(struct fc_seq *,
  1012. struct fc_frame *,
  1013. void *arg),
  1014. void *arg, u32 timer_msec);
  1015. void fc_lport_flogi_resp(struct fc_seq *, struct fc_frame *, void *);
  1016. void fc_lport_logo_resp(struct fc_seq *, struct fc_frame *, void *);
  1017. void fc_fill_reply_hdr(struct fc_frame *, const struct fc_frame *,
  1018. enum fc_rctl, u32 parm_offset);
  1019. void fc_fill_hdr(struct fc_frame *, const struct fc_frame *,
  1020. enum fc_rctl, u32 f_ctl, u16 seq_cnt, u32 parm_offset);
  1021. /*
  1022. * EXCHANGE MANAGER LAYER
  1023. *****************************/
  1024. int fc_exch_init(struct fc_lport *);
  1025. struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *,
  1026. struct fc_exch_mgr *,
  1027. bool (*match)(struct fc_frame *));
  1028. void fc_exch_mgr_del(struct fc_exch_mgr_anchor *);
  1029. int fc_exch_mgr_list_clone(struct fc_lport *src, struct fc_lport *dst);
  1030. struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *, enum fc_class class,
  1031. u16 min_xid, u16 max_xid,
  1032. bool (*match)(struct fc_frame *));
  1033. void fc_exch_mgr_free(struct fc_lport *);
  1034. void fc_exch_recv(struct fc_lport *, struct fc_frame *);
  1035. void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id);
  1036. /*
  1037. * Functions for fc_functions_template
  1038. */
  1039. void fc_get_host_speed(struct Scsi_Host *);
  1040. void fc_get_host_port_state(struct Scsi_Host *);
  1041. void fc_set_rport_loss_tmo(struct fc_rport *, u32 timeout);
  1042. struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *);
  1043. #endif /* _LIBFC_H_ */