libfc.h 32 KB

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