libfc.h 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright(c) 2007 Intel Corporation. All rights reserved.
  4. *
  5. * Maintained at www.Open-FCoE.org
  6. */
  7. #ifndef _LIBFC_H_
  8. #define _LIBFC_H_
  9. #include <linux/timer.h>
  10. #include <linux/if.h>
  11. #include <linux/percpu.h>
  12. #include <linux/refcount.h>
  13. #include <scsi/scsi_transport.h>
  14. #include <scsi/scsi_transport_fc.h>
  15. #include <scsi/scsi_bsg_fc.h>
  16. #include <scsi/fc/fc_fcp.h>
  17. #include <scsi/fc/fc_ns.h>
  18. #include <scsi/fc/fc_ms.h>
  19. #include <scsi/fc/fc_els.h>
  20. #include <scsi/fc/fc_gs.h>
  21. #include <scsi/fc_frame.h>
  22. #define FC_FC4_PROV_SIZE (FC_TYPE_FCP + 1) /* size of tables */
  23. /*
  24. * libfc error codes
  25. */
  26. #define FC_NO_ERR 0 /* no error */
  27. #define FC_EX_TIMEOUT 1 /* Exchange timeout */
  28. #define FC_EX_CLOSED 2 /* Exchange closed */
  29. #define FC_EX_ALLOC_ERR 3 /* Exchange allocation failed */
  30. #define FC_EX_XMIT_ERR 4 /* Exchange transmit failed */
  31. #define FC_EX_ELS_RJT 5 /* ELS rejected */
  32. #define FC_EX_INV_LOGIN 6 /* Login not completed */
  33. #define FC_EX_SEQ_ERR 6 /* Exchange sequence error */
  34. /**
  35. * enum fc_lport_state - Local port states
  36. * @LPORT_ST_DISABLED: Disabled
  37. * @LPORT_ST_FLOGI: Fabric login (FLOGI) sent
  38. * @LPORT_ST_DNS: Waiting for name server remote port to become ready
  39. * @LPORT_ST_RPN_ID: Register port name by ID (RPN_ID) sent
  40. * @LPORT_ST_RFT_ID: Register Fibre Channel types by ID (RFT_ID) sent
  41. * @LPORT_ST_RFF_ID: Register FC-4 Features by ID (RFF_ID) sent
  42. * @LPORT_ST_FDMI: Waiting for mgmt server rport to become ready
  43. * @LPORT_ST_RHBA:
  44. * @LPORT_ST_SCR: State Change Register (SCR) sent
  45. * @LPORT_ST_READY: Ready for use
  46. * @LPORT_ST_LOGO: Local port logout (LOGO) sent
  47. * @LPORT_ST_RESET: Local port reset
  48. */
  49. enum fc_lport_state {
  50. LPORT_ST_DISABLED = 0,
  51. LPORT_ST_FLOGI,
  52. LPORT_ST_DNS,
  53. LPORT_ST_RNN_ID,
  54. LPORT_ST_RSNN_NN,
  55. LPORT_ST_RSPN_ID,
  56. LPORT_ST_RFT_ID,
  57. LPORT_ST_RFF_ID,
  58. LPORT_ST_FDMI,
  59. LPORT_ST_RHBA,
  60. LPORT_ST_RPA,
  61. LPORT_ST_DHBA,
  62. LPORT_ST_DPRT,
  63. LPORT_ST_SCR,
  64. LPORT_ST_READY,
  65. LPORT_ST_LOGO,
  66. LPORT_ST_RESET
  67. };
  68. enum fc_disc_event {
  69. DISC_EV_NONE = 0,
  70. DISC_EV_SUCCESS,
  71. DISC_EV_FAILED
  72. };
  73. /**
  74. * enum fc_rport_state - Remote port states
  75. * @RPORT_ST_INIT: Initialized
  76. * @RPORT_ST_FLOGI: Waiting for FLOGI completion for point-to-multipoint
  77. * @RPORT_ST_PLOGI_WAIT: Waiting for peer to login for point-to-multipoint
  78. * @RPORT_ST_PLOGI: Waiting for PLOGI completion
  79. * @RPORT_ST_PRLI: Waiting for PRLI completion
  80. * @RPORT_ST_RTV: Waiting for RTV completion
  81. * @RPORT_ST_READY: Ready for use
  82. * @RPORT_ST_ADISC: Discover Address sent
  83. * @RPORT_ST_DELETE: Remote port being deleted
  84. */
  85. enum fc_rport_state {
  86. RPORT_ST_INIT,
  87. RPORT_ST_FLOGI,
  88. RPORT_ST_PLOGI_WAIT,
  89. RPORT_ST_PLOGI,
  90. RPORT_ST_PRLI,
  91. RPORT_ST_RTV,
  92. RPORT_ST_READY,
  93. RPORT_ST_ADISC,
  94. RPORT_ST_DELETE,
  95. };
  96. /**
  97. * struct fc_disc_port - temporary discovery port to hold rport identifiers
  98. * @lp: Fibre Channel host port instance
  99. * @peers: Node for list management during discovery and RSCN processing
  100. * @rport_work: Work struct for starting the rport state machine
  101. * @port_id: Port ID of the discovered port
  102. */
  103. struct fc_disc_port {
  104. struct fc_lport *lp;
  105. struct list_head peers;
  106. struct work_struct rport_work;
  107. u32 port_id;
  108. };
  109. /**
  110. * enum fc_rport_event - Remote port events
  111. * @RPORT_EV_NONE: No event
  112. * @RPORT_EV_READY: Remote port is ready for use
  113. * @RPORT_EV_FAILED: State machine failed, remote port is not ready
  114. * @RPORT_EV_STOP: Remote port has been stopped
  115. * @RPORT_EV_LOGO: Remote port logout (LOGO) sent
  116. */
  117. enum fc_rport_event {
  118. RPORT_EV_NONE = 0,
  119. RPORT_EV_READY,
  120. RPORT_EV_FAILED,
  121. RPORT_EV_STOP,
  122. RPORT_EV_LOGO
  123. };
  124. struct fc_rport_priv;
  125. /**
  126. * struct fc_rport_operations - Operations for a remote port
  127. * @event_callback: Function to be called for remote port events
  128. */
  129. struct fc_rport_operations {
  130. void (*event_callback)(struct fc_lport *, struct fc_rport_priv *,
  131. enum fc_rport_event);
  132. };
  133. /**
  134. * struct fc_rport_libfc_priv - libfc internal information about a remote port
  135. * @local_port: The associated local port
  136. * @rp_state: Indicates READY for I/O or DELETE when blocked
  137. * @flags: REC and RETRY supported flags
  138. * @e_d_tov: Error detect timeout value (in msec)
  139. * @r_a_tov: Resource allocation timeout value (in msec)
  140. */
  141. struct fc_rport_libfc_priv {
  142. struct fc_lport *local_port;
  143. enum fc_rport_state rp_state;
  144. u16 flags;
  145. #define FC_RP_FLAGS_REC_SUPPORTED (1 << 0)
  146. #define FC_RP_FLAGS_RETRY (1 << 1)
  147. #define FC_RP_STARTED (1 << 2)
  148. #define FC_RP_FLAGS_CONF_REQ (1 << 3)
  149. unsigned int e_d_tov;
  150. unsigned int r_a_tov;
  151. };
  152. /**
  153. * struct fc_rport_priv - libfc remote port and discovery info
  154. * @local_port: The associated local port
  155. * @rport: The FC transport remote port
  156. * @kref: Reference counter
  157. * @rp_state: Enumeration that tracks progress of PLOGI, PRLI,
  158. * and RTV exchanges
  159. * @ids: The remote port identifiers and roles
  160. * @flags: STARTED, REC and RETRY_SUPPORTED flags
  161. * @max_seq: Maximum number of concurrent sequences
  162. * @disc_id: The discovery identifier
  163. * @maxframe_size: The maximum frame size
  164. * @retries: The retry count for the current state
  165. * @major_retries: The retry count for the entire PLOGI/PRLI state machine
  166. * @e_d_tov: Error detect timeout value (in msec)
  167. * @r_a_tov: Resource allocation timeout value (in msec)
  168. * @rp_mutex: The mutex that protects the remote port
  169. * @retry_work: Handle for retries
  170. * @event_callback: Callback when READY, FAILED or LOGO states complete
  171. * @prli_count: Count of open PRLI sessions in providers
  172. * @rcu: Structure used for freeing in an RCU-safe manner
  173. */
  174. struct fc_rport_priv {
  175. struct fc_lport *local_port;
  176. struct fc_rport *rport;
  177. struct kref kref;
  178. enum fc_rport_state rp_state;
  179. struct fc_rport_identifiers ids;
  180. u16 flags;
  181. u16 max_seq;
  182. u16 disc_id;
  183. u16 maxframe_size;
  184. unsigned int retries;
  185. unsigned int major_retries;
  186. unsigned int e_d_tov;
  187. unsigned int r_a_tov;
  188. struct mutex rp_mutex;
  189. struct delayed_work retry_work;
  190. enum fc_rport_event event;
  191. struct fc_rport_operations *ops;
  192. struct list_head peers;
  193. struct work_struct event_work;
  194. u32 supported_classes;
  195. u16 prli_count;
  196. struct rcu_head rcu;
  197. u16 sp_features;
  198. u8 spp_type;
  199. void (*lld_event_callback)(struct fc_lport *,
  200. struct fc_rport_priv *,
  201. enum fc_rport_event);
  202. };
  203. /**
  204. * struct fc_stats - fc stats structure
  205. * @SecondsSinceLastReset: Seconds since the last reset
  206. * @TxFrames: Number of transmitted frames
  207. * @TxWords: Number of transmitted words
  208. * @RxFrames: Number of received frames
  209. * @RxWords: Number of received words
  210. * @ErrorFrames: Number of received error frames
  211. * @DumpedFrames: Number of dumped frames
  212. * @FcpPktAllocFails: Number of fcp packet allocation failures
  213. * @FcpPktAborts: Number of fcp packet aborts
  214. * @FcpFrameAllocFails: Number of fcp frame allocation failures
  215. * @LinkFailureCount: Number of link failures
  216. * @LossOfSignalCount: Number for signal losses
  217. * @InvalidTxWordCount: Number of invalid transmitted words
  218. * @InvalidCRCCount: Number of invalid CRCs
  219. * @InputRequests: Number of input requests
  220. * @OutputRequests: Number of output requests
  221. * @ControlRequests: Number of control requests
  222. * @InputBytes: Number of received bytes
  223. * @OutputBytes: Number of transmitted bytes
  224. * @VLinkFailureCount: Number of virtual link failures
  225. * @MissDiscAdvCount: Number of missing FIP discovery advertisement
  226. */
  227. struct fc_stats {
  228. u64 SecondsSinceLastReset;
  229. u64 TxFrames;
  230. u64 TxWords;
  231. u64 RxFrames;
  232. u64 RxWords;
  233. u64 ErrorFrames;
  234. u64 DumpedFrames;
  235. u64 FcpPktAllocFails;
  236. u64 FcpPktAborts;
  237. u64 FcpFrameAllocFails;
  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. refcount_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. int timer_delay;
  323. u32 recov_retry;
  324. struct fc_seq *recov_seq;
  325. struct completion tm_done;
  326. } ____cacheline_aligned_in_smp;
  327. /*
  328. * @fsp should be tested and set under the scsi_pkt_queue lock
  329. */
  330. struct libfc_cmd_priv {
  331. struct fc_fcp_pkt *fsp;
  332. u32 resid_len;
  333. u8 status;
  334. };
  335. /*
  336. * Structure and function definitions for managing Fibre Channel Exchanges
  337. * and Sequences
  338. *
  339. * fc_exch holds state for one exchange and links to its active sequence.
  340. *
  341. * fc_seq holds the state for an individual sequence.
  342. */
  343. struct fc_exch_mgr;
  344. struct fc_exch_mgr_anchor;
  345. extern u16 fc_cpu_mask; /* cpu mask for possible cpus */
  346. /**
  347. * struct fc_seq - FC sequence
  348. * @id: The sequence ID
  349. * @ssb_stat: Status flags for the sequence status block (SSB)
  350. * @cnt: Number of frames sent so far
  351. * @rec_data: FC-4 value for REC
  352. */
  353. struct fc_seq {
  354. u8 id;
  355. u16 ssb_stat;
  356. u16 cnt;
  357. u32 rec_data;
  358. };
  359. #define FC_EX_DONE (1 << 0) /* ep is completed */
  360. #define FC_EX_RST_CLEANUP (1 << 1) /* reset is forcing completion */
  361. #define FC_EX_QUARANTINE (1 << 2) /* exch is quarantined */
  362. /**
  363. * struct fc_exch - Fibre Channel Exchange
  364. * @em: Exchange manager
  365. * @pool: Exchange pool
  366. * @state: The exchange's state
  367. * @xid: The exchange ID
  368. * @ex_list: Handle used by the EM to track free exchanges
  369. * @ex_lock: Lock that protects the exchange
  370. * @ex_refcnt: Reference count
  371. * @timeout_work: Handle for timeout handler
  372. * @lp: The local port that this exchange is on
  373. * @oxid: Originator's exchange ID
  374. * @rxid: Responder's exchange ID
  375. * @oid: Originator's FCID
  376. * @sid: Source FCID
  377. * @did: Destination FCID
  378. * @esb_stat: ESB exchange status
  379. * @r_a_tov: Resource allocation time out value (in msecs)
  380. * @seq_id: The next sequence ID to use
  381. * @encaps: encapsulation information for lower-level driver
  382. * @f_ctl: F_CTL flags for the sequence
  383. * @fh_type: The frame type
  384. * @class: The class of service
  385. * @seq: The sequence in use on this exchange
  386. * @resp_active: Number of tasks that are concurrently executing @resp().
  387. * @resp_task: If @resp_active > 0, either the task executing @resp(), the
  388. * task that has been interrupted to execute the soft-IRQ
  389. * executing @resp() or NULL if more than one task is executing
  390. * @resp concurrently.
  391. * @resp_wq: Waitqueue for the tasks waiting on @resp_active.
  392. * @resp: Callback for responses on this exchange
  393. * @destructor: Called when destroying the exchange
  394. * @arg: Passed as a void pointer to the resp() callback
  395. *
  396. * Locking notes: The ex_lock protects following items:
  397. * state, esb_stat, f_ctl, seq.ssb_stat
  398. * seq_id
  399. * sequence allocation
  400. */
  401. struct fc_exch {
  402. spinlock_t ex_lock;
  403. atomic_t ex_refcnt;
  404. enum fc_class class;
  405. struct fc_exch_mgr *em;
  406. struct fc_exch_pool *pool;
  407. struct list_head ex_list;
  408. struct fc_lport *lp;
  409. u32 esb_stat;
  410. u8 state;
  411. u8 fh_type;
  412. u8 seq_id;
  413. u8 encaps;
  414. u16 xid;
  415. u16 oxid;
  416. u16 rxid;
  417. u32 oid;
  418. u32 sid;
  419. u32 did;
  420. u32 r_a_tov;
  421. u32 f_ctl;
  422. struct fc_seq seq;
  423. int resp_active;
  424. struct task_struct *resp_task;
  425. wait_queue_head_t resp_wq;
  426. void (*resp)(struct fc_seq *, struct fc_frame *, void *);
  427. void *arg;
  428. void (*destructor)(struct fc_seq *, void *);
  429. struct delayed_work timeout_work;
  430. } ____cacheline_aligned_in_smp;
  431. #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
  432. struct libfc_function_template {
  433. /*
  434. * Interface to send a FC frame
  435. *
  436. * STATUS: REQUIRED
  437. */
  438. int (*frame_send)(struct fc_lport *, struct fc_frame *);
  439. /*
  440. * Interface to send ELS/CT frames
  441. *
  442. * STATUS: OPTIONAL
  443. */
  444. struct fc_seq *(*elsct_send)(struct fc_lport *, u32 did,
  445. struct fc_frame *, unsigned int op,
  446. void (*resp)(struct fc_seq *,
  447. struct fc_frame *, void *arg),
  448. void *arg, u32 timer_msec);
  449. /*
  450. * Sets up the DDP context for a given exchange id on the given
  451. * scatterlist if LLD supports DDP for large receive.
  452. *
  453. * STATUS: OPTIONAL
  454. */
  455. int (*ddp_setup)(struct fc_lport *, u16, struct scatterlist *,
  456. unsigned int);
  457. /*
  458. * Completes the DDP transfer and returns the length of data DDPed
  459. * for the given exchange id.
  460. *
  461. * STATUS: OPTIONAL
  462. */
  463. int (*ddp_done)(struct fc_lport *, u16);
  464. /*
  465. * Sets up the DDP context for a given exchange id on the given
  466. * scatterlist if LLD supports DDP for target.
  467. *
  468. * STATUS: OPTIONAL
  469. */
  470. int (*ddp_target)(struct fc_lport *, u16, struct scatterlist *,
  471. unsigned int);
  472. /*
  473. * Allow LLD to fill its own Link Error Status Block
  474. *
  475. * STATUS: OPTIONAL
  476. */
  477. void (*get_lesb)(struct fc_lport *, struct fc_els_lesb *lesb);
  478. /*
  479. * Reset an exchange manager, completing all sequences and exchanges.
  480. * If s_id is non-zero, reset only exchanges originating from that FID.
  481. * If d_id is non-zero, reset only exchanges sending to that FID.
  482. *
  483. * STATUS: OPTIONAL
  484. */
  485. void (*exch_mgr_reset)(struct fc_lport *, u32 s_id, u32 d_id);
  486. /*
  487. * Set the local port FC_ID.
  488. *
  489. * This may be provided by the LLD to allow it to be
  490. * notified when the local port is assigned a FC-ID.
  491. *
  492. * The frame, if non-NULL, is the incoming frame with the
  493. * FLOGI LS_ACC or FLOGI, and may contain the granted MAC
  494. * address for the LLD. The frame pointer may be NULL if
  495. * no MAC is associated with this assignment (LOGO or PLOGI).
  496. *
  497. * If FC_ID is non-zero, r_a_tov and e_d_tov must be valid.
  498. *
  499. * Note: this is called with the local port mutex held.
  500. *
  501. * STATUS: OPTIONAL
  502. */
  503. void (*lport_set_port_id)(struct fc_lport *, u32 port_id,
  504. struct fc_frame *);
  505. /*
  506. * Callback routine after the remote port is logged in
  507. *
  508. * STATUS: OPTIONAL
  509. */
  510. void (*rport_event_callback)(struct fc_lport *,
  511. struct fc_rport_priv *,
  512. enum fc_rport_event);
  513. /*
  514. * Send a fcp cmd from fsp pkt.
  515. * Called with the SCSI host lock unlocked and irqs disabled.
  516. *
  517. * The resp handler is called when FCP_RSP received.
  518. *
  519. * STATUS: OPTIONAL
  520. */
  521. int (*fcp_cmd_send)(struct fc_lport *, struct fc_fcp_pkt *,
  522. void (*resp)(struct fc_seq *, struct fc_frame *,
  523. void *));
  524. /*
  525. * Cleanup the FCP layer, used during link down and reset
  526. *
  527. * STATUS: OPTIONAL
  528. */
  529. void (*fcp_cleanup)(struct fc_lport *);
  530. /*
  531. * Abort all I/O on a local port
  532. *
  533. * STATUS: OPTIONAL
  534. */
  535. void (*fcp_abort_io)(struct fc_lport *);
  536. /*
  537. * Receive a request for the discovery layer.
  538. *
  539. * STATUS: OPTIONAL
  540. */
  541. void (*disc_recv_req)(struct fc_lport *, struct fc_frame *);
  542. /*
  543. * Start discovery for a local port.
  544. *
  545. * STATUS: OPTIONAL
  546. */
  547. void (*disc_start)(void (*disc_callback)(struct fc_lport *,
  548. enum fc_disc_event),
  549. struct fc_lport *);
  550. /*
  551. * Stop discovery for a given lport. This will remove
  552. * all discovered rports
  553. *
  554. * STATUS: OPTIONAL
  555. */
  556. void (*disc_stop) (struct fc_lport *);
  557. /*
  558. * Stop discovery for a given lport. This will block
  559. * until all discovered rports are deleted from the
  560. * FC transport class
  561. *
  562. * STATUS: OPTIONAL
  563. */
  564. void (*disc_stop_final) (struct fc_lport *);
  565. };
  566. /**
  567. * struct fc_disc - Discovery context
  568. * @retry_count: Number of retries
  569. * @pending: 1 if discovery is pending, 0 if not
  570. * @requested: 1 if discovery has been requested, 0 if not
  571. * @seq_count: Number of sequences used for discovery
  572. * @buf_len: Length of the discovery buffer
  573. * @disc_id: Discovery ID
  574. * @rports: List of discovered remote ports
  575. * @priv: Private pointer for use by discovery code
  576. * @disc_mutex: Mutex that protects the discovery context
  577. * @partial_buf: Partial name buffer (if names are returned
  578. * in multiple frames)
  579. * @disc_work: handle for delayed work context
  580. * @disc_callback: Callback routine called when discovery completes
  581. */
  582. struct fc_disc {
  583. unsigned char retry_count;
  584. unsigned char pending;
  585. unsigned char requested;
  586. unsigned short seq_count;
  587. unsigned char buf_len;
  588. u16 disc_id;
  589. struct list_head rports;
  590. void *priv;
  591. struct mutex disc_mutex;
  592. struct fc_gpn_ft_resp partial_buf;
  593. struct delayed_work disc_work;
  594. void (*disc_callback)(struct fc_lport *,
  595. enum fc_disc_event);
  596. };
  597. /*
  598. * Local port notifier and events.
  599. */
  600. extern struct blocking_notifier_head fc_lport_notifier_head;
  601. enum fc_lport_event {
  602. FC_LPORT_EV_ADD,
  603. FC_LPORT_EV_DEL,
  604. };
  605. /**
  606. * struct fc_lport - Local port
  607. * @host: The SCSI host associated with a local port
  608. * @ema_list: Exchange manager anchor list
  609. * @dns_rdata: The directory server remote port
  610. * @ms_rdata: The management server remote port
  611. * @ptp_rdata: Point to point remote port
  612. * @scsi_priv: FCP layer internal data
  613. * @disc: Discovery context
  614. * @vports: Child vports if N_Port
  615. * @vport: Parent vport if VN_Port
  616. * @tt: Libfc function template
  617. * @link_up: Link state (1 = link up, 0 = link down)
  618. * @qfull: Queue state (1 queue is full, 0 queue is not full)
  619. * @state: Identifies the state
  620. * @boot_time: Timestamp indicating when the local port came online
  621. * @host_stats: SCSI host statistics
  622. * @stats: FC local port stats (TODO separate libfc LLD stats)
  623. * @retry_count: Number of retries in the current state
  624. * @port_id: FC Port ID
  625. * @wwpn: World Wide Port Name
  626. * @wwnn: World Wide Node Name
  627. * @service_params: Common service parameters
  628. * @e_d_tov: Error detection timeout value
  629. * @r_a_tov: Resource allocation timeout value
  630. * @rnid_gen: RNID information
  631. * @sg_supp: Indicates if scatter gather is supported
  632. * @seq_offload: Indicates if sequence offload is supported
  633. * @crc_offload: Indicates if CRC offload is supported
  634. * @lro_enabled: Indicates if large receive offload is supported
  635. * @does_npiv: Supports multiple vports
  636. * @npiv_enabled: Switch/fabric allows NPIV
  637. * @mfs: The maximum Fibre Channel payload size
  638. * @max_retry_count: The maximum retry attempts
  639. * @max_rport_retry_count: The maximum remote port retry attempts
  640. * @rport_priv_size: Size needed by driver after struct fc_rport_priv
  641. * @lro_xid: The maximum XID for LRO
  642. * @lso_max: The maximum large offload send size
  643. * @fcts: FC-4 type mask
  644. * @lp_mutex: Mutex to protect the local port
  645. * @list: Linkage on list of vport peers
  646. * @retry_work: Handle to local port for delayed retry context
  647. * @prov: Pointers available for use by passive FC-4 providers
  648. * @lport_list: Linkage on module-wide list of local ports
  649. */
  650. struct fc_lport {
  651. /* Associations */
  652. struct Scsi_Host *host;
  653. struct list_head ema_list;
  654. struct fc_rport_priv *dns_rdata;
  655. struct fc_rport_priv *ms_rdata;
  656. struct fc_rport_priv *ptp_rdata;
  657. void *scsi_priv;
  658. struct fc_disc disc;
  659. /* Virtual port information */
  660. struct list_head vports;
  661. struct fc_vport *vport;
  662. /* Operational Information */
  663. struct libfc_function_template tt;
  664. u8 link_up;
  665. u8 qfull;
  666. u16 vlan;
  667. enum fc_lport_state state;
  668. unsigned long boot_time;
  669. struct fc_host_statistics host_stats;
  670. struct fc_stats __percpu *stats;
  671. u8 retry_count;
  672. /* Fabric information */
  673. u32 port_id;
  674. u64 wwpn;
  675. u64 wwnn;
  676. unsigned int service_params;
  677. unsigned int e_d_tov;
  678. unsigned int r_a_tov;
  679. struct fc_els_rnid_gen rnid_gen;
  680. /* Capabilities */
  681. u32 sg_supp:1;
  682. u32 seq_offload:1;
  683. u32 crc_offload:1;
  684. u32 lro_enabled:1;
  685. u32 does_npiv:1;
  686. u32 npiv_enabled:1;
  687. u32 point_to_multipoint:1;
  688. u32 fdmi_enabled:1;
  689. u32 mfs;
  690. u8 max_retry_count;
  691. u8 max_rport_retry_count;
  692. u16 rport_priv_size;
  693. u16 link_speed;
  694. u16 link_supported_speeds;
  695. u16 lro_xid;
  696. unsigned int lso_max;
  697. struct fc_ns_fts fcts;
  698. /* Miscellaneous */
  699. struct mutex lp_mutex;
  700. struct list_head list;
  701. struct delayed_work retry_work;
  702. void *prov[FC_FC4_PROV_SIZE];
  703. struct list_head lport_list;
  704. };
  705. /**
  706. * struct fc4_prov - FC-4 provider registration
  707. * @prli: Handler for incoming PRLI
  708. * @prlo: Handler for session reset
  709. * @recv: Handler for incoming request
  710. * @module: Pointer to module. May be NULL.
  711. */
  712. struct fc4_prov {
  713. int (*prli)(struct fc_rport_priv *, u32 spp_len,
  714. const struct fc_els_spp *spp_in,
  715. struct fc_els_spp *spp_out);
  716. void (*prlo)(struct fc_rport_priv *);
  717. void (*recv)(struct fc_lport *, struct fc_frame *);
  718. struct module *module;
  719. };
  720. /*
  721. * Register FC-4 provider with libfc.
  722. */
  723. int fc_fc4_register_provider(enum fc_fh_type type, struct fc4_prov *);
  724. void fc_fc4_deregister_provider(enum fc_fh_type type, struct fc4_prov *);
  725. /*
  726. * FC_LPORT HELPER FUNCTIONS
  727. *****************************/
  728. /**
  729. * fc_lport_test_ready() - Determine if a local port is in the READY state
  730. * @lport: The local port to test
  731. */
  732. static inline int fc_lport_test_ready(struct fc_lport *lport)
  733. {
  734. return lport->state == LPORT_ST_READY;
  735. }
  736. /**
  737. * fc_set_wwnn() - Set the World Wide Node Name of a local port
  738. * @lport: The local port whose WWNN is to be set
  739. * @wwnn: The new WWNN
  740. */
  741. static inline void fc_set_wwnn(struct fc_lport *lport, u64 wwnn)
  742. {
  743. lport->wwnn = wwnn;
  744. }
  745. /**
  746. * fc_set_wwpn() - Set the World Wide Port Name of a local port
  747. * @lport: The local port whose WWPN is to be set
  748. * @wwpn: The new WWPN
  749. */
  750. static inline void fc_set_wwpn(struct fc_lport *lport, u64 wwpn)
  751. {
  752. lport->wwpn = wwpn;
  753. }
  754. /**
  755. * fc_lport_state_enter() - Change a local port's state
  756. * @lport: The local port whose state is to change
  757. * @state: The new state
  758. */
  759. static inline void fc_lport_state_enter(struct fc_lport *lport,
  760. enum fc_lport_state state)
  761. {
  762. if (state != lport->state)
  763. lport->retry_count = 0;
  764. lport->state = state;
  765. }
  766. /**
  767. * fc_lport_init_stats() - Allocate per-CPU statistics for a local port
  768. * @lport: The local port whose statistics are to be initialized
  769. */
  770. static inline int fc_lport_init_stats(struct fc_lport *lport)
  771. {
  772. lport->stats = alloc_percpu(struct fc_stats);
  773. if (!lport->stats)
  774. return -ENOMEM;
  775. return 0;
  776. }
  777. /**
  778. * fc_lport_free_stats() - Free memory for a local port's statistics
  779. * @lport: The local port whose statistics are to be freed
  780. */
  781. static inline void fc_lport_free_stats(struct fc_lport *lport)
  782. {
  783. free_percpu(lport->stats);
  784. }
  785. /**
  786. * lport_priv() - Return the private data from a local port
  787. * @lport: The local port whose private data is to be retrieved
  788. */
  789. static inline void *lport_priv(const struct fc_lport *lport)
  790. {
  791. return (void *)(lport + 1);
  792. }
  793. /**
  794. * libfc_host_alloc() - Allocate a Scsi_Host with room for a local port and
  795. * LLD private data
  796. * @sht: The SCSI host template
  797. * @priv_size: Size of private data
  798. *
  799. * Returns: libfc lport
  800. */
  801. static inline struct fc_lport *
  802. libfc_host_alloc(struct scsi_host_template *sht, int priv_size)
  803. {
  804. struct fc_lport *lport;
  805. struct Scsi_Host *shost;
  806. shost = scsi_host_alloc(sht, sizeof(*lport) + priv_size);
  807. if (!shost)
  808. return NULL;
  809. lport = shost_priv(shost);
  810. lport->host = shost;
  811. INIT_LIST_HEAD(&lport->ema_list);
  812. INIT_LIST_HEAD(&lport->vports);
  813. return lport;
  814. }
  815. /*
  816. * FC_FCP HELPER FUNCTIONS
  817. *****************************/
  818. static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp)
  819. {
  820. if (fsp && fsp->cmd)
  821. return fsp->cmd->sc_data_direction == DMA_FROM_DEVICE;
  822. return false;
  823. }
  824. /*
  825. * LOCAL PORT LAYER
  826. *****************************/
  827. int fc_lport_init(struct fc_lport *);
  828. int fc_lport_destroy(struct fc_lport *);
  829. int fc_fabric_logoff(struct fc_lport *);
  830. int fc_fabric_login(struct fc_lport *);
  831. void __fc_linkup(struct fc_lport *);
  832. void fc_linkup(struct fc_lport *);
  833. void __fc_linkdown(struct fc_lport *);
  834. void fc_linkdown(struct fc_lport *);
  835. void fc_vport_setlink(struct fc_lport *);
  836. void fc_vports_linkchange(struct fc_lport *);
  837. int fc_lport_config(struct fc_lport *);
  838. int fc_lport_reset(struct fc_lport *);
  839. void fc_lport_recv(struct fc_lport *lport, struct fc_frame *fp);
  840. int fc_set_mfs(struct fc_lport *, u32 mfs);
  841. struct fc_lport *libfc_vport_create(struct fc_vport *, int privsize);
  842. struct fc_lport *fc_vport_id_lookup(struct fc_lport *, u32 port_id);
  843. int fc_lport_bsg_request(struct bsg_job *);
  844. void fc_lport_set_local_id(struct fc_lport *, u32 port_id);
  845. void fc_lport_iterate(void (*func)(struct fc_lport *, void *), void *);
  846. /*
  847. * REMOTE PORT LAYER
  848. *****************************/
  849. void fc_rport_terminate_io(struct fc_rport *);
  850. struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
  851. u32 port_id);
  852. struct fc_rport_priv *fc_rport_create(struct fc_lport *, u32);
  853. void fc_rport_destroy(struct kref *kref);
  854. int fc_rport_login(struct fc_rport_priv *rdata);
  855. int fc_rport_logoff(struct fc_rport_priv *rdata);
  856. void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp);
  857. void fc_rport_flush_queue(void);
  858. /*
  859. * DISCOVERY LAYER
  860. *****************************/
  861. void fc_disc_init(struct fc_lport *);
  862. void fc_disc_config(struct fc_lport *, void *);
  863. static inline struct fc_lport *fc_disc_lport(struct fc_disc *disc)
  864. {
  865. return container_of(disc, struct fc_lport, disc);
  866. }
  867. /*
  868. * FCP LAYER
  869. *****************************/
  870. int fc_fcp_init(struct fc_lport *);
  871. void fc_fcp_destroy(struct fc_lport *);
  872. /*
  873. * SCSI INTERACTION LAYER
  874. *****************************/
  875. int fc_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
  876. int fc_eh_abort(struct scsi_cmnd *);
  877. int fc_eh_device_reset(struct scsi_cmnd *);
  878. int fc_eh_host_reset(struct scsi_cmnd *);
  879. int fc_slave_alloc(struct scsi_device *);
  880. /*
  881. * ELS/CT interface
  882. *****************************/
  883. int fc_elsct_init(struct fc_lport *);
  884. struct fc_seq *fc_elsct_send(struct fc_lport *, u32 did,
  885. struct fc_frame *,
  886. unsigned int op,
  887. void (*resp)(struct fc_seq *,
  888. struct fc_frame *,
  889. void *arg),
  890. void *arg, u32 timer_msec);
  891. void fc_lport_flogi_resp(struct fc_seq *, struct fc_frame *, void *);
  892. void fc_lport_logo_resp(struct fc_seq *, struct fc_frame *, void *);
  893. void fc_fill_reply_hdr(struct fc_frame *, const struct fc_frame *,
  894. enum fc_rctl, u32 parm_offset);
  895. void fc_fill_hdr(struct fc_frame *, const struct fc_frame *,
  896. enum fc_rctl, u32 f_ctl, u16 seq_cnt, u32 parm_offset);
  897. /*
  898. * EXCHANGE MANAGER LAYER
  899. *****************************/
  900. int fc_exch_init(struct fc_lport *);
  901. void fc_exch_update_stats(struct fc_lport *lport);
  902. struct fc_seq *fc_exch_seq_send(struct fc_lport *lport,
  903. struct fc_frame *fp,
  904. void (*resp)(struct fc_seq *,
  905. struct fc_frame *fp,
  906. void *arg),
  907. void (*destructor)(struct fc_seq *, void *),
  908. void *arg, u32 timer_msec);
  909. void fc_seq_els_rsp_send(struct fc_frame *, enum fc_els_cmd,
  910. struct fc_seq_els_data *);
  911. struct fc_seq *fc_seq_start_next(struct fc_seq *sp);
  912. void fc_seq_set_resp(struct fc_seq *sp,
  913. void (*resp)(struct fc_seq *, struct fc_frame *, void *),
  914. void *arg);
  915. struct fc_seq *fc_seq_assign(struct fc_lport *lport, struct fc_frame *fp);
  916. void fc_seq_release(struct fc_seq *sp);
  917. struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *,
  918. struct fc_exch_mgr *,
  919. bool (*match)(struct fc_frame *));
  920. void fc_exch_mgr_del(struct fc_exch_mgr_anchor *);
  921. int fc_exch_mgr_list_clone(struct fc_lport *src, struct fc_lport *dst);
  922. struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *, enum fc_class class,
  923. u16 min_xid, u16 max_xid,
  924. bool (*match)(struct fc_frame *));
  925. void fc_exch_mgr_free(struct fc_lport *);
  926. void fc_exch_recv(struct fc_lport *, struct fc_frame *);
  927. void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id);
  928. int fc_seq_send(struct fc_lport *lport, struct fc_seq *sp, struct fc_frame *fp);
  929. int fc_seq_exch_abort(const struct fc_seq *, unsigned int timer_msec);
  930. void fc_exch_done(struct fc_seq *sp);
  931. /*
  932. * Functions for fc_functions_template
  933. */
  934. void fc_get_host_speed(struct Scsi_Host *);
  935. void fc_get_host_port_state(struct Scsi_Host *);
  936. void fc_set_rport_loss_tmo(struct fc_rport *, u32 timeout);
  937. struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *);
  938. #endif /* _LIBFC_H_ */