libfc.h 32 KB

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