libfc.h 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  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. * Structure and function definitions for managing Fibre Channel Exchanges
  329. * and Sequences
  330. *
  331. * fc_exch holds state for one exchange and links to its active sequence.
  332. *
  333. * fc_seq holds the state for an individual sequence.
  334. */
  335. struct fc_exch_mgr;
  336. struct fc_exch_mgr_anchor;
  337. extern u16 fc_cpu_mask; /* cpu mask for possible cpus */
  338. /**
  339. * struct fc_seq - FC sequence
  340. * @id: The sequence ID
  341. * @ssb_stat: Status flags for the sequence status block (SSB)
  342. * @cnt: Number of frames sent so far
  343. * @rec_data: FC-4 value for REC
  344. */
  345. struct fc_seq {
  346. u8 id;
  347. u16 ssb_stat;
  348. u16 cnt;
  349. u32 rec_data;
  350. };
  351. #define FC_EX_DONE (1 << 0) /* ep is completed */
  352. #define FC_EX_RST_CLEANUP (1 << 1) /* reset is forcing completion */
  353. #define FC_EX_QUARANTINE (1 << 2) /* exch is quarantined */
  354. /**
  355. * struct fc_exch - Fibre Channel Exchange
  356. * @em: Exchange manager
  357. * @pool: Exchange pool
  358. * @state: The exchange's state
  359. * @xid: The exchange ID
  360. * @ex_list: Handle used by the EM to track free exchanges
  361. * @ex_lock: Lock that protects the exchange
  362. * @ex_refcnt: Reference count
  363. * @timeout_work: Handle for timeout handler
  364. * @lp: The local port that this exchange is on
  365. * @oxid: Originator's exchange ID
  366. * @rxid: Responder's exchange ID
  367. * @oid: Originator's FCID
  368. * @sid: Source FCID
  369. * @did: Destination FCID
  370. * @esb_stat: ESB exchange status
  371. * @r_a_tov: Resouce allocation time out value (in msecs)
  372. * @seq_id: The next sequence ID to use
  373. * @encaps: encapsulation information for lower-level driver
  374. * @f_ctl: F_CTL flags for the sequence
  375. * @fh_type: The frame type
  376. * @class: The class of service
  377. * @seq: The sequence in use on this exchange
  378. * @resp_active: Number of tasks that are concurrently executing @resp().
  379. * @resp_task: If @resp_active > 0, either the task executing @resp(), the
  380. * task that has been interrupted to execute the soft-IRQ
  381. * executing @resp() or NULL if more than one task is executing
  382. * @resp concurrently.
  383. * @resp_wq: Waitqueue for the tasks waiting on @resp_active.
  384. * @resp: Callback for responses on this exchange
  385. * @destructor: Called when destroying the exchange
  386. * @arg: Passed as a void pointer to the resp() callback
  387. *
  388. * Locking notes: The ex_lock protects following items:
  389. * state, esb_stat, f_ctl, seq.ssb_stat
  390. * seq_id
  391. * sequence allocation
  392. */
  393. struct fc_exch {
  394. spinlock_t ex_lock;
  395. atomic_t ex_refcnt;
  396. enum fc_class class;
  397. struct fc_exch_mgr *em;
  398. struct fc_exch_pool *pool;
  399. struct list_head ex_list;
  400. struct fc_lport *lp;
  401. u32 esb_stat;
  402. u8 state;
  403. u8 fh_type;
  404. u8 seq_id;
  405. u8 encaps;
  406. u16 xid;
  407. u16 oxid;
  408. u16 rxid;
  409. u32 oid;
  410. u32 sid;
  411. u32 did;
  412. u32 r_a_tov;
  413. u32 f_ctl;
  414. struct fc_seq seq;
  415. int resp_active;
  416. struct task_struct *resp_task;
  417. wait_queue_head_t resp_wq;
  418. void (*resp)(struct fc_seq *, struct fc_frame *, void *);
  419. void *arg;
  420. void (*destructor)(struct fc_seq *, void *);
  421. struct delayed_work timeout_work;
  422. } ____cacheline_aligned_in_smp;
  423. #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
  424. struct libfc_function_template {
  425. /*
  426. * Interface to send a FC frame
  427. *
  428. * STATUS: REQUIRED
  429. */
  430. int (*frame_send)(struct fc_lport *, struct fc_frame *);
  431. /*
  432. * Interface to send ELS/CT frames
  433. *
  434. * STATUS: OPTIONAL
  435. */
  436. struct fc_seq *(*elsct_send)(struct fc_lport *, u32 did,
  437. struct fc_frame *, unsigned int op,
  438. void (*resp)(struct fc_seq *,
  439. struct fc_frame *, void *arg),
  440. void *arg, u32 timer_msec);
  441. /*
  442. * Sets up the DDP context for a given exchange id on the given
  443. * scatterlist if LLD supports DDP for large receive.
  444. *
  445. * STATUS: OPTIONAL
  446. */
  447. int (*ddp_setup)(struct fc_lport *, u16, struct scatterlist *,
  448. unsigned int);
  449. /*
  450. * Completes the DDP transfer and returns the length of data DDPed
  451. * for the given exchange id.
  452. *
  453. * STATUS: OPTIONAL
  454. */
  455. int (*ddp_done)(struct fc_lport *, u16);
  456. /*
  457. * Sets up the DDP context for a given exchange id on the given
  458. * scatterlist if LLD supports DDP for target.
  459. *
  460. * STATUS: OPTIONAL
  461. */
  462. int (*ddp_target)(struct fc_lport *, u16, struct scatterlist *,
  463. unsigned int);
  464. /*
  465. * Allow LLD to fill its own Link Error Status Block
  466. *
  467. * STATUS: OPTIONAL
  468. */
  469. void (*get_lesb)(struct fc_lport *, struct fc_els_lesb *lesb);
  470. /*
  471. * Reset an exchange manager, completing all sequences and exchanges.
  472. * If s_id is non-zero, reset only exchanges originating from that FID.
  473. * If d_id is non-zero, reset only exchanges sending to that FID.
  474. *
  475. * STATUS: OPTIONAL
  476. */
  477. void (*exch_mgr_reset)(struct fc_lport *, u32 s_id, u32 d_id);
  478. /*
  479. * Set the local port FC_ID.
  480. *
  481. * This may be provided by the LLD to allow it to be
  482. * notified when the local port is assigned a FC-ID.
  483. *
  484. * The frame, if non-NULL, is the incoming frame with the
  485. * FLOGI LS_ACC or FLOGI, and may contain the granted MAC
  486. * address for the LLD. The frame pointer may be NULL if
  487. * no MAC is associated with this assignment (LOGO or PLOGI).
  488. *
  489. * If FC_ID is non-zero, r_a_tov and e_d_tov must be valid.
  490. *
  491. * Note: this is called with the local port mutex held.
  492. *
  493. * STATUS: OPTIONAL
  494. */
  495. void (*lport_set_port_id)(struct fc_lport *, u32 port_id,
  496. struct fc_frame *);
  497. /*
  498. * Callback routine after the remote port is logged in
  499. *
  500. * STATUS: OPTIONAL
  501. */
  502. void (*rport_event_callback)(struct fc_lport *,
  503. struct fc_rport_priv *,
  504. enum fc_rport_event);
  505. /*
  506. * Send a fcp cmd from fsp pkt.
  507. * Called with the SCSI host lock unlocked and irqs disabled.
  508. *
  509. * The resp handler is called when FCP_RSP received.
  510. *
  511. * STATUS: OPTIONAL
  512. */
  513. int (*fcp_cmd_send)(struct fc_lport *, struct fc_fcp_pkt *,
  514. void (*resp)(struct fc_seq *, struct fc_frame *,
  515. void *));
  516. /*
  517. * Cleanup the FCP layer, used during link down and reset
  518. *
  519. * STATUS: OPTIONAL
  520. */
  521. void (*fcp_cleanup)(struct fc_lport *);
  522. /*
  523. * Abort all I/O on a local port
  524. *
  525. * STATUS: OPTIONAL
  526. */
  527. void (*fcp_abort_io)(struct fc_lport *);
  528. /*
  529. * Receive a request for the discovery layer.
  530. *
  531. * STATUS: OPTIONAL
  532. */
  533. void (*disc_recv_req)(struct fc_lport *, struct fc_frame *);
  534. /*
  535. * Start discovery for a local port.
  536. *
  537. * STATUS: OPTIONAL
  538. */
  539. void (*disc_start)(void (*disc_callback)(struct fc_lport *,
  540. enum fc_disc_event),
  541. struct fc_lport *);
  542. /*
  543. * Stop discovery for a given lport. This will remove
  544. * all discovered rports
  545. *
  546. * STATUS: OPTIONAL
  547. */
  548. void (*disc_stop) (struct fc_lport *);
  549. /*
  550. * Stop discovery for a given lport. This will block
  551. * until all discovered rports are deleted from the
  552. * FC transport class
  553. *
  554. * STATUS: OPTIONAL
  555. */
  556. void (*disc_stop_final) (struct fc_lport *);
  557. };
  558. /**
  559. * struct fc_disc - Discovery context
  560. * @retry_count: Number of retries
  561. * @pending: 1 if discovery is pending, 0 if not
  562. * @requested: 1 if discovery has been requested, 0 if not
  563. * @seq_count: Number of sequences used for discovery
  564. * @buf_len: Length of the discovery buffer
  565. * @disc_id: Discovery ID
  566. * @rports: List of discovered remote ports
  567. * @priv: Private pointer for use by discovery code
  568. * @disc_mutex: Mutex that protects the discovery context
  569. * @partial_buf: Partial name buffer (if names are returned
  570. * in multiple frames)
  571. * @disc_work: handle for delayed work context
  572. * @disc_callback: Callback routine called when discovery completes
  573. */
  574. struct fc_disc {
  575. unsigned char retry_count;
  576. unsigned char pending;
  577. unsigned char requested;
  578. unsigned short seq_count;
  579. unsigned char buf_len;
  580. u16 disc_id;
  581. struct list_head rports;
  582. void *priv;
  583. struct mutex disc_mutex;
  584. struct fc_gpn_ft_resp partial_buf;
  585. struct delayed_work disc_work;
  586. void (*disc_callback)(struct fc_lport *,
  587. enum fc_disc_event);
  588. };
  589. /*
  590. * Local port notifier and events.
  591. */
  592. extern struct blocking_notifier_head fc_lport_notifier_head;
  593. enum fc_lport_event {
  594. FC_LPORT_EV_ADD,
  595. FC_LPORT_EV_DEL,
  596. };
  597. /**
  598. * struct fc_lport - Local port
  599. * @host: The SCSI host associated with a local port
  600. * @ema_list: Exchange manager anchor list
  601. * @dns_rdata: The directory server remote port
  602. * @ms_rdata: The management server remote port
  603. * @ptp_rdata: Point to point remote port
  604. * @scsi_priv: FCP layer internal data
  605. * @disc: Discovery context
  606. * @vports: Child vports if N_Port
  607. * @vport: Parent vport if VN_Port
  608. * @tt: Libfc function template
  609. * @link_up: Link state (1 = link up, 0 = link down)
  610. * @qfull: Queue state (1 queue is full, 0 queue is not full)
  611. * @state: Identifies the state
  612. * @boot_time: Timestamp indicating when the local port came online
  613. * @host_stats: SCSI host statistics
  614. * @stats: FC local port stats (TODO separate libfc LLD stats)
  615. * @retry_count: Number of retries in the current state
  616. * @port_id: FC Port ID
  617. * @wwpn: World Wide Port Name
  618. * @wwnn: World Wide Node Name
  619. * @service_params: Common service parameters
  620. * @e_d_tov: Error detection timeout value
  621. * @r_a_tov: Resouce allocation timeout value
  622. * @rnid_gen: RNID information
  623. * @sg_supp: Indicates if scatter gather is supported
  624. * @seq_offload: Indicates if sequence offload is supported
  625. * @crc_offload: Indicates if CRC offload is supported
  626. * @lro_enabled: Indicates if large receive offload is supported
  627. * @does_npiv: Supports multiple vports
  628. * @npiv_enabled: Switch/fabric allows NPIV
  629. * @mfs: The maximum Fibre Channel payload size
  630. * @max_retry_count: The maximum retry attempts
  631. * @max_rport_retry_count: The maximum remote port retry attempts
  632. * @rport_priv_size: Size needed by driver after struct fc_rport_priv
  633. * @lro_xid: The maximum XID for LRO
  634. * @lso_max: The maximum large offload send size
  635. * @fcts: FC-4 type mask
  636. * @lp_mutex: Mutex to protect the local port
  637. * @list: Linkage on list of vport peers
  638. * @retry_work: Handle to local port for delayed retry context
  639. * @prov: Pointers available for use by passive FC-4 providers
  640. * @lport_list: Linkage on module-wide list of local ports
  641. */
  642. struct fc_lport {
  643. /* Associations */
  644. struct Scsi_Host *host;
  645. struct list_head ema_list;
  646. struct fc_rport_priv *dns_rdata;
  647. struct fc_rport_priv *ms_rdata;
  648. struct fc_rport_priv *ptp_rdata;
  649. void *scsi_priv;
  650. struct fc_disc disc;
  651. /* Virtual port information */
  652. struct list_head vports;
  653. struct fc_vport *vport;
  654. /* Operational Information */
  655. struct libfc_function_template tt;
  656. u8 link_up;
  657. u8 qfull;
  658. u16 vlan;
  659. enum fc_lport_state state;
  660. unsigned long boot_time;
  661. struct fc_host_statistics host_stats;
  662. struct fc_stats __percpu *stats;
  663. u8 retry_count;
  664. /* Fabric information */
  665. u32 port_id;
  666. u64 wwpn;
  667. u64 wwnn;
  668. unsigned int service_params;
  669. unsigned int e_d_tov;
  670. unsigned int r_a_tov;
  671. struct fc_els_rnid_gen rnid_gen;
  672. /* Capabilities */
  673. u32 sg_supp:1;
  674. u32 seq_offload:1;
  675. u32 crc_offload:1;
  676. u32 lro_enabled:1;
  677. u32 does_npiv:1;
  678. u32 npiv_enabled:1;
  679. u32 point_to_multipoint:1;
  680. u32 fdmi_enabled:1;
  681. u32 mfs;
  682. u8 max_retry_count;
  683. u8 max_rport_retry_count;
  684. u16 rport_priv_size;
  685. u16 link_speed;
  686. u16 link_supported_speeds;
  687. u16 lro_xid;
  688. unsigned int lso_max;
  689. struct fc_ns_fts fcts;
  690. /* Miscellaneous */
  691. struct mutex lp_mutex;
  692. struct list_head list;
  693. struct delayed_work retry_work;
  694. void *prov[FC_FC4_PROV_SIZE];
  695. struct list_head lport_list;
  696. };
  697. /**
  698. * struct fc4_prov - FC-4 provider registration
  699. * @prli: Handler for incoming PRLI
  700. * @prlo: Handler for session reset
  701. * @recv: Handler for incoming request
  702. * @module: Pointer to module. May be NULL.
  703. */
  704. struct fc4_prov {
  705. int (*prli)(struct fc_rport_priv *, u32 spp_len,
  706. const struct fc_els_spp *spp_in,
  707. struct fc_els_spp *spp_out);
  708. void (*prlo)(struct fc_rport_priv *);
  709. void (*recv)(struct fc_lport *, struct fc_frame *);
  710. struct module *module;
  711. };
  712. /*
  713. * Register FC-4 provider with libfc.
  714. */
  715. int fc_fc4_register_provider(enum fc_fh_type type, struct fc4_prov *);
  716. void fc_fc4_deregister_provider(enum fc_fh_type type, struct fc4_prov *);
  717. /*
  718. * FC_LPORT HELPER FUNCTIONS
  719. *****************************/
  720. /**
  721. * fc_lport_test_ready() - Determine if a local port is in the READY state
  722. * @lport: The local port to test
  723. */
  724. static inline int fc_lport_test_ready(struct fc_lport *lport)
  725. {
  726. return lport->state == LPORT_ST_READY;
  727. }
  728. /**
  729. * fc_set_wwnn() - Set the World Wide Node Name of a local port
  730. * @lport: The local port whose WWNN is to be set
  731. * @wwnn: The new WWNN
  732. */
  733. static inline void fc_set_wwnn(struct fc_lport *lport, u64 wwnn)
  734. {
  735. lport->wwnn = wwnn;
  736. }
  737. /**
  738. * fc_set_wwpn() - Set the World Wide Port Name of a local port
  739. * @lport: The local port whose WWPN is to be set
  740. * @wwpn: The new WWPN
  741. */
  742. static inline void fc_set_wwpn(struct fc_lport *lport, u64 wwpn)
  743. {
  744. lport->wwpn = wwpn;
  745. }
  746. /**
  747. * fc_lport_state_enter() - Change a local port's state
  748. * @lport: The local port whose state is to change
  749. * @state: The new state
  750. */
  751. static inline void fc_lport_state_enter(struct fc_lport *lport,
  752. enum fc_lport_state state)
  753. {
  754. if (state != lport->state)
  755. lport->retry_count = 0;
  756. lport->state = state;
  757. }
  758. /**
  759. * fc_lport_init_stats() - Allocate per-CPU statistics for a local port
  760. * @lport: The local port whose statistics are to be initialized
  761. */
  762. static inline int fc_lport_init_stats(struct fc_lport *lport)
  763. {
  764. lport->stats = alloc_percpu(struct fc_stats);
  765. if (!lport->stats)
  766. return -ENOMEM;
  767. return 0;
  768. }
  769. /**
  770. * fc_lport_free_stats() - Free memory for a local port's statistics
  771. * @lport: The local port whose statistics are to be freed
  772. */
  773. static inline void fc_lport_free_stats(struct fc_lport *lport)
  774. {
  775. free_percpu(lport->stats);
  776. }
  777. /**
  778. * lport_priv() - Return the private data from a local port
  779. * @lport: The local port whose private data is to be retreived
  780. */
  781. static inline void *lport_priv(const struct fc_lport *lport)
  782. {
  783. return (void *)(lport + 1);
  784. }
  785. /**
  786. * libfc_host_alloc() - Allocate a Scsi_Host with room for a local port and
  787. * LLD private data
  788. * @sht: The SCSI host template
  789. * @priv_size: Size of private data
  790. *
  791. * Returns: libfc lport
  792. */
  793. static inline struct fc_lport *
  794. libfc_host_alloc(struct scsi_host_template *sht, int priv_size)
  795. {
  796. struct fc_lport *lport;
  797. struct Scsi_Host *shost;
  798. shost = scsi_host_alloc(sht, sizeof(*lport) + priv_size);
  799. if (!shost)
  800. return NULL;
  801. lport = shost_priv(shost);
  802. lport->host = shost;
  803. INIT_LIST_HEAD(&lport->ema_list);
  804. INIT_LIST_HEAD(&lport->vports);
  805. return lport;
  806. }
  807. /*
  808. * FC_FCP HELPER FUNCTIONS
  809. *****************************/
  810. static inline bool fc_fcp_is_read(const struct fc_fcp_pkt *fsp)
  811. {
  812. if (fsp && fsp->cmd)
  813. return fsp->cmd->sc_data_direction == DMA_FROM_DEVICE;
  814. return false;
  815. }
  816. /*
  817. * LOCAL PORT LAYER
  818. *****************************/
  819. int fc_lport_init(struct fc_lport *);
  820. int fc_lport_destroy(struct fc_lport *);
  821. int fc_fabric_logoff(struct fc_lport *);
  822. int fc_fabric_login(struct fc_lport *);
  823. void __fc_linkup(struct fc_lport *);
  824. void fc_linkup(struct fc_lport *);
  825. void __fc_linkdown(struct fc_lport *);
  826. void fc_linkdown(struct fc_lport *);
  827. void fc_vport_setlink(struct fc_lport *);
  828. void fc_vports_linkchange(struct fc_lport *);
  829. int fc_lport_config(struct fc_lport *);
  830. int fc_lport_reset(struct fc_lport *);
  831. void fc_lport_recv(struct fc_lport *lport, struct fc_frame *fp);
  832. int fc_set_mfs(struct fc_lport *, u32 mfs);
  833. struct fc_lport *libfc_vport_create(struct fc_vport *, int privsize);
  834. struct fc_lport *fc_vport_id_lookup(struct fc_lport *, u32 port_id);
  835. int fc_lport_bsg_request(struct bsg_job *);
  836. void fc_lport_set_local_id(struct fc_lport *, u32 port_id);
  837. void fc_lport_iterate(void (*func)(struct fc_lport *, void *), void *);
  838. /*
  839. * REMOTE PORT LAYER
  840. *****************************/
  841. void fc_rport_terminate_io(struct fc_rport *);
  842. struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
  843. u32 port_id);
  844. struct fc_rport_priv *fc_rport_create(struct fc_lport *, u32);
  845. void fc_rport_destroy(struct kref *kref);
  846. int fc_rport_login(struct fc_rport_priv *rdata);
  847. int fc_rport_logoff(struct fc_rport_priv *rdata);
  848. void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp);
  849. void fc_rport_flush_queue(void);
  850. /*
  851. * DISCOVERY LAYER
  852. *****************************/
  853. void fc_disc_init(struct fc_lport *);
  854. void fc_disc_config(struct fc_lport *, void *);
  855. static inline struct fc_lport *fc_disc_lport(struct fc_disc *disc)
  856. {
  857. return container_of(disc, struct fc_lport, disc);
  858. }
  859. /*
  860. * FCP LAYER
  861. *****************************/
  862. int fc_fcp_init(struct fc_lport *);
  863. void fc_fcp_destroy(struct fc_lport *);
  864. /*
  865. * SCSI INTERACTION LAYER
  866. *****************************/
  867. int fc_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
  868. int fc_eh_abort(struct scsi_cmnd *);
  869. int fc_eh_device_reset(struct scsi_cmnd *);
  870. int fc_eh_host_reset(struct scsi_cmnd *);
  871. int fc_slave_alloc(struct scsi_device *);
  872. /*
  873. * ELS/CT interface
  874. *****************************/
  875. int fc_elsct_init(struct fc_lport *);
  876. struct fc_seq *fc_elsct_send(struct fc_lport *, u32 did,
  877. struct fc_frame *,
  878. unsigned int op,
  879. void (*resp)(struct fc_seq *,
  880. struct fc_frame *,
  881. void *arg),
  882. void *arg, u32 timer_msec);
  883. void fc_lport_flogi_resp(struct fc_seq *, struct fc_frame *, void *);
  884. void fc_lport_logo_resp(struct fc_seq *, struct fc_frame *, void *);
  885. void fc_fill_reply_hdr(struct fc_frame *, const struct fc_frame *,
  886. enum fc_rctl, u32 parm_offset);
  887. void fc_fill_hdr(struct fc_frame *, const struct fc_frame *,
  888. enum fc_rctl, u32 f_ctl, u16 seq_cnt, u32 parm_offset);
  889. /*
  890. * EXCHANGE MANAGER LAYER
  891. *****************************/
  892. int fc_exch_init(struct fc_lport *);
  893. void fc_exch_update_stats(struct fc_lport *lport);
  894. struct fc_seq *fc_exch_seq_send(struct fc_lport *lport,
  895. struct fc_frame *fp,
  896. void (*resp)(struct fc_seq *,
  897. struct fc_frame *fp,
  898. void *arg),
  899. void (*destructor)(struct fc_seq *, void *),
  900. void *arg, u32 timer_msec);
  901. void fc_seq_els_rsp_send(struct fc_frame *, enum fc_els_cmd,
  902. struct fc_seq_els_data *);
  903. struct fc_seq *fc_seq_start_next(struct fc_seq *sp);
  904. void fc_seq_set_resp(struct fc_seq *sp,
  905. void (*resp)(struct fc_seq *, struct fc_frame *, void *),
  906. void *arg);
  907. struct fc_seq *fc_seq_assign(struct fc_lport *lport, struct fc_frame *fp);
  908. void fc_seq_release(struct fc_seq *sp);
  909. struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *,
  910. struct fc_exch_mgr *,
  911. bool (*match)(struct fc_frame *));
  912. void fc_exch_mgr_del(struct fc_exch_mgr_anchor *);
  913. int fc_exch_mgr_list_clone(struct fc_lport *src, struct fc_lport *dst);
  914. struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *, enum fc_class class,
  915. u16 min_xid, u16 max_xid,
  916. bool (*match)(struct fc_frame *));
  917. void fc_exch_mgr_free(struct fc_lport *);
  918. void fc_exch_recv(struct fc_lport *, struct fc_frame *);
  919. void fc_exch_mgr_reset(struct fc_lport *, u32 s_id, u32 d_id);
  920. int fc_seq_send(struct fc_lport *lport, struct fc_seq *sp, struct fc_frame *fp);
  921. int fc_seq_exch_abort(const struct fc_seq *, unsigned int timer_msec);
  922. void fc_exch_done(struct fc_seq *sp);
  923. /*
  924. * Functions for fc_functions_template
  925. */
  926. void fc_get_host_speed(struct Scsi_Host *);
  927. void fc_get_host_port_state(struct Scsi_Host *);
  928. void fc_set_rport_loss_tmo(struct fc_rport *, u32 timeout);
  929. struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *);
  930. #endif /* _LIBFC_H_ */