libfc.h 34 KB

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