libfc.h 32 KB

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