libfc.h 32 KB

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