libfc.h 31 KB

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