libfc.h 31 KB

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