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