efclib.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2021 Broadcom. All Rights Reserved. The term
  4. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
  5. */
  6. #ifndef __EFCLIB_H__
  7. #define __EFCLIB_H__
  8. #include "scsi/fc/fc_els.h"
  9. #include "scsi/fc/fc_fs.h"
  10. #include "scsi/fc/fc_ns.h"
  11. #include "scsi/fc/fc_gs.h"
  12. #include "scsi/fc_frame.h"
  13. #include "../include/efc_common.h"
  14. #include "../libefc_sli/sli4.h"
  15. #define EFC_SERVICE_PARMS_LENGTH 120
  16. #define EFC_NAME_LENGTH 32
  17. #define EFC_SM_NAME_LENGTH 64
  18. #define EFC_DISPLAY_BUS_INFO_LENGTH 16
  19. #define EFC_WWN_LENGTH 32
  20. #define EFC_FC_ELS_DEFAULT_RETRIES 3
  21. /* Timeouts */
  22. #define EFC_FC_ELS_SEND_DEFAULT_TIMEOUT 0
  23. #define EFC_FC_FLOGI_TIMEOUT_SEC 5
  24. #define EFC_SHUTDOWN_TIMEOUT_USEC 30000000
  25. /* Return values for calls from base driver to libefc */
  26. #define EFC_SCSI_CALL_COMPLETE 0
  27. #define EFC_SCSI_CALL_ASYNC 1
  28. /* Local port topology */
  29. enum efc_nport_topology {
  30. EFC_NPORT_TOPO_UNKNOWN = 0,
  31. EFC_NPORT_TOPO_FABRIC,
  32. EFC_NPORT_TOPO_P2P,
  33. EFC_NPORT_TOPO_FC_AL,
  34. };
  35. #define enable_target_rscn(efc) 1
  36. enum efc_node_shutd_rsn {
  37. EFC_NODE_SHUTDOWN_DEFAULT = 0,
  38. EFC_NODE_SHUTDOWN_EXPLICIT_LOGO,
  39. EFC_NODE_SHUTDOWN_IMPLICIT_LOGO,
  40. };
  41. enum efc_node_send_ls_acc {
  42. EFC_NODE_SEND_LS_ACC_NONE = 0,
  43. EFC_NODE_SEND_LS_ACC_PLOGI,
  44. EFC_NODE_SEND_LS_ACC_PRLI,
  45. };
  46. #define EFC_LINK_STATUS_UP 0
  47. #define EFC_LINK_STATUS_DOWN 1
  48. enum efc_sm_event;
  49. /* State machine context header */
  50. struct efc_sm_ctx {
  51. void (*current_state)(struct efc_sm_ctx *ctx,
  52. enum efc_sm_event evt, void *arg);
  53. const char *description;
  54. void *app;
  55. };
  56. /* Description of discovered Fabric Domain */
  57. struct efc_domain_record {
  58. u32 index;
  59. u32 priority;
  60. u8 address[6];
  61. u8 wwn[8];
  62. union {
  63. u8 vlan[512];
  64. u8 loop[128];
  65. } map;
  66. u32 speed;
  67. u32 fc_id;
  68. bool is_loop;
  69. bool is_nport;
  70. };
  71. /* Domain events */
  72. enum efc_hw_domain_event {
  73. EFC_HW_DOMAIN_ALLOC_OK,
  74. EFC_HW_DOMAIN_ALLOC_FAIL,
  75. EFC_HW_DOMAIN_ATTACH_OK,
  76. EFC_HW_DOMAIN_ATTACH_FAIL,
  77. EFC_HW_DOMAIN_FREE_OK,
  78. EFC_HW_DOMAIN_FREE_FAIL,
  79. EFC_HW_DOMAIN_LOST,
  80. EFC_HW_DOMAIN_FOUND,
  81. EFC_HW_DOMAIN_CHANGED,
  82. };
  83. /**
  84. * Fibre Channel port object
  85. *
  86. * @list_entry: nport list entry
  87. * @ref: reference count, each node takes a reference
  88. * @release: function to free nport object
  89. * @efc: pointer back to efc
  90. * @instance_index: unique instance index value
  91. * @display_name: port display name
  92. * @is_vport: Is NPIV port
  93. * @free_req_pending: pending request to free resources
  94. * @attached: mark attached if reg VPI succeeds
  95. * @p2p_winner: TRUE if we're the point-to-point winner
  96. * @domain: pointer back to domain
  97. * @wwpn: port wwpn
  98. * @wwnn: port wwnn
  99. * @tgt_data: target backend private port data
  100. * @ini_data: initiator backend private port data
  101. * @indicator: VPI
  102. * @fc_id: port FC address
  103. * @dma: memory for Service Parameters
  104. * @wwnn_str: wwpn string
  105. * @sli_wwpn: SLI provided wwpn
  106. * @sli_wwnn: SLI provided wwnn
  107. * @sm: nport state machine context
  108. * @lookup: fc_id to node lookup object
  109. * @enable_ini: SCSI initiator enabled for this port
  110. * @enable_tgt: SCSI target enabled for this port
  111. * @enable_rscn: port will be expecting RSCN
  112. * @shutting_down: nport in process of shutting down
  113. * @p2p_port_id: our port id for point-to-point
  114. * @topology: topology: fabric/p2p/unknown
  115. * @service_params: login parameters
  116. * @p2p_remote_port_id: remote node's port id for point-to-point
  117. */
  118. struct efc_nport {
  119. struct list_head list_entry;
  120. struct kref ref;
  121. void (*release)(struct kref *arg);
  122. struct efc *efc;
  123. u32 instance_index;
  124. char display_name[EFC_NAME_LENGTH];
  125. bool is_vport;
  126. bool free_req_pending;
  127. bool attached;
  128. bool attaching;
  129. bool p2p_winner;
  130. struct efc_domain *domain;
  131. u64 wwpn;
  132. u64 wwnn;
  133. void *tgt_data;
  134. void *ini_data;
  135. u32 indicator;
  136. u32 fc_id;
  137. struct efc_dma dma;
  138. u8 wwnn_str[EFC_WWN_LENGTH];
  139. __be64 sli_wwpn;
  140. __be64 sli_wwnn;
  141. struct efc_sm_ctx sm;
  142. struct xarray lookup;
  143. bool enable_ini;
  144. bool enable_tgt;
  145. bool enable_rscn;
  146. bool shutting_down;
  147. u32 p2p_port_id;
  148. enum efc_nport_topology topology;
  149. u8 service_params[EFC_SERVICE_PARMS_LENGTH];
  150. u32 p2p_remote_port_id;
  151. };
  152. /**
  153. * Fibre Channel domain object
  154. *
  155. * This object is a container for the various SLI components needed
  156. * to connect to the domain of a FC or FCoE switch
  157. * @efc: pointer back to efc
  158. * @instance_index: unique instance index value
  159. * @display_name: Node display name
  160. * @nport_list: linked list of nports associated with this domain
  161. * @ref: Reference count, each nport takes a reference
  162. * @release: Function to free domain object
  163. * @ini_domain: initiator backend private domain data
  164. * @tgt_domain: target backend private domain data
  165. * @sm: state machine context
  166. * @fcf: FC Forwarder table index
  167. * @fcf_indicator: FCFI
  168. * @indicator: VFI
  169. * @nport_count: Number of nports allocated
  170. * @dma: memory for Service Parameters
  171. * @fcf_wwn: WWN for FCF/switch
  172. * @drvsm: driver domain sm context
  173. * @attached: set true after attach completes
  174. * @is_fc: is FC
  175. * @is_loop: is loop topology
  176. * @is_nlport: is public loop
  177. * @domain_found_pending:A domain found is pending, drec is updated
  178. * @req_domain_free: True if domain object should be free'd
  179. * @req_accept_frames: set in domain state machine to enable frames
  180. * @domain_notify_pend: Set in domain SM to avoid duplicate node event post
  181. * @pending_drec: Pending drec if a domain found is pending
  182. * @service_params: any nports service parameters
  183. * @flogi_service_params:Fabric/P2p service parameters from FLOGI
  184. * @lookup: d_id to node lookup object
  185. * @nport: Pointer to first (physical) SLI port
  186. */
  187. struct efc_domain {
  188. struct efc *efc;
  189. char display_name[EFC_NAME_LENGTH];
  190. struct list_head nport_list;
  191. struct kref ref;
  192. void (*release)(struct kref *arg);
  193. void *ini_domain;
  194. void *tgt_domain;
  195. /* Declarations private to HW/SLI */
  196. u32 fcf;
  197. u32 fcf_indicator;
  198. u32 indicator;
  199. u32 nport_count;
  200. struct efc_dma dma;
  201. /* Declarations private to FC trannport */
  202. u64 fcf_wwn;
  203. struct efc_sm_ctx drvsm;
  204. bool attached;
  205. bool is_fc;
  206. bool is_loop;
  207. bool is_nlport;
  208. bool domain_found_pending;
  209. bool req_domain_free;
  210. bool req_accept_frames;
  211. bool domain_notify_pend;
  212. struct efc_domain_record pending_drec;
  213. u8 service_params[EFC_SERVICE_PARMS_LENGTH];
  214. u8 flogi_service_params[EFC_SERVICE_PARMS_LENGTH];
  215. struct xarray lookup;
  216. struct efc_nport *nport;
  217. };
  218. /**
  219. * Remote Node object
  220. *
  221. * This object represents a connection between the SLI port and another
  222. * Nx_Port on the fabric. Note this can be either a well known port such
  223. * as a F_Port (i.e. ff:ff:fe) or another N_Port.
  224. * @indicator: RPI
  225. * @fc_id: FC address
  226. * @attached: true if attached
  227. * @nport: associated SLI port
  228. * @node: associated node
  229. */
  230. struct efc_remote_node {
  231. u32 indicator;
  232. u32 index;
  233. u32 fc_id;
  234. bool attached;
  235. struct efc_nport *nport;
  236. void *node;
  237. };
  238. /**
  239. * FC Node object
  240. * @efc: pointer back to efc structure
  241. * @display_name: Node display name
  242. * @nort: Assosiated nport pointer.
  243. * @hold_frames: hold incoming frames if true
  244. * @els_io_enabled: Enable allocating els ios for this node
  245. * @els_ios_lock: lock to protect the els ios list
  246. * @els_ios_list: ELS I/O's for this node
  247. * @ini_node: backend initiator private node data
  248. * @tgt_node: backend target private node data
  249. * @rnode: Remote node
  250. * @sm: state machine context
  251. * @evtdepth: current event posting nesting depth
  252. * @req_free: this node is to be free'd
  253. * @attached: node is attached (REGLOGIN complete)
  254. * @fcp_enabled: node is enabled to handle FCP
  255. * @rscn_pending: for name server node RSCN is pending
  256. * @send_plogi: send PLOGI accept, upon completion of node attach
  257. * @send_plogi_acc: TRUE if io_alloc() is enabled.
  258. * @send_ls_acc: type of LS acc to send
  259. * @ls_acc_io: SCSI IO for LS acc
  260. * @ls_acc_oxid: OX_ID for pending accept
  261. * @ls_acc_did: D_ID for pending accept
  262. * @shutdown_reason: reason for node shutdown
  263. * @sparm_dma_buf: service parameters buffer
  264. * @service_params: plogi/acc frame from remote device
  265. * @pend_frames_lock: lock for inbound pending frames list
  266. * @pend_frames: inbound pending frames list
  267. * @pend_frames_processed:count of frames processed in hold frames interval
  268. * @ox_id_in_use: used to verify one at a time us of ox_id
  269. * @els_retries_remaining:for ELS, number of retries remaining
  270. * @els_req_cnt: number of outstanding ELS requests
  271. * @els_cmpl_cnt: number of outstanding ELS completions
  272. * @abort_cnt: Abort counter for debugging purpos
  273. * @current_state_name: current node state
  274. * @prev_state_name: previous node state
  275. * @current_evt: current event
  276. * @prev_evt: previous event
  277. * @targ: node is target capable
  278. * @init: node is init capable
  279. * @refound: Handle node refound case when node is being deleted
  280. * @els_io_pend_list: list of pending (not yet processed) ELS IOs
  281. * @els_io_active_list: list of active (processed) ELS IOs
  282. * @nodedb_state: Node debugging, saved state
  283. * @gidpt_delay_timer: GIDPT delay timer
  284. * @time_last_gidpt_msec:Start time of last target RSCN GIDPT
  285. * @wwnn: remote port WWNN
  286. * @wwpn: remote port WWPN
  287. */
  288. struct efc_node {
  289. struct efc *efc;
  290. char display_name[EFC_NAME_LENGTH];
  291. struct efc_nport *nport;
  292. struct kref ref;
  293. void (*release)(struct kref *arg);
  294. bool hold_frames;
  295. bool els_io_enabled;
  296. bool send_plogi_acc;
  297. bool send_plogi;
  298. bool rscn_pending;
  299. bool fcp_enabled;
  300. bool attached;
  301. bool req_free;
  302. spinlock_t els_ios_lock;
  303. struct list_head els_ios_list;
  304. void *ini_node;
  305. void *tgt_node;
  306. struct efc_remote_node rnode;
  307. /* Declarations private to FC trannport */
  308. struct efc_sm_ctx sm;
  309. u32 evtdepth;
  310. enum efc_node_send_ls_acc send_ls_acc;
  311. void *ls_acc_io;
  312. u32 ls_acc_oxid;
  313. u32 ls_acc_did;
  314. enum efc_node_shutd_rsn shutdown_reason;
  315. bool targ;
  316. bool init;
  317. bool refound;
  318. struct efc_dma sparm_dma_buf;
  319. u8 service_params[EFC_SERVICE_PARMS_LENGTH];
  320. spinlock_t pend_frames_lock;
  321. struct list_head pend_frames;
  322. u32 pend_frames_processed;
  323. u32 ox_id_in_use;
  324. u32 els_retries_remaining;
  325. u32 els_req_cnt;
  326. u32 els_cmpl_cnt;
  327. u32 abort_cnt;
  328. char current_state_name[EFC_SM_NAME_LENGTH];
  329. char prev_state_name[EFC_SM_NAME_LENGTH];
  330. int current_evt;
  331. int prev_evt;
  332. void (*nodedb_state)(struct efc_sm_ctx *ctx,
  333. enum efc_sm_event evt, void *arg);
  334. struct timer_list gidpt_delay_timer;
  335. u64 time_last_gidpt_msec;
  336. char wwnn[EFC_WWN_LENGTH];
  337. char wwpn[EFC_WWN_LENGTH];
  338. };
  339. /**
  340. * NPIV port
  341. *
  342. * Collection of the information required to restore a virtual port across
  343. * link events
  344. * @wwnn: node name
  345. * @wwpn: port name
  346. * @fc_id: port id
  347. * @tgt_data: target backend pointer
  348. * @ini_data: initiator backend pointe
  349. * @nport: Used to match record after attaching for update
  350. *
  351. */
  352. struct efc_vport {
  353. struct list_head list_entry;
  354. u64 wwnn;
  355. u64 wwpn;
  356. u32 fc_id;
  357. bool enable_tgt;
  358. bool enable_ini;
  359. void *tgt_data;
  360. void *ini_data;
  361. struct efc_nport *nport;
  362. };
  363. #define node_printf(node, fmt, args...) \
  364. efc_log_info(node->efc, "[%s] " fmt, node->display_name, ##args)
  365. /* Node SM IO Context Callback structure */
  366. struct efc_node_cb {
  367. int status;
  368. int ext_status;
  369. struct efc_hw_rq_buffer *header;
  370. struct efc_hw_rq_buffer *payload;
  371. struct efc_dma els_rsp;
  372. /* Actual length of data received */
  373. int rsp_len;
  374. };
  375. struct efc_hw_rq_buffer {
  376. u16 rqindex;
  377. struct efc_dma dma;
  378. };
  379. /**
  380. * FC sequence object
  381. *
  382. * Defines a general FC sequence object
  383. * @hw: HW that owns this sequence
  384. * @fcfi: FCFI associated with sequence
  385. * @header: Received frame header
  386. * @payload: Received frame header
  387. * @hw_priv: HW private context
  388. */
  389. struct efc_hw_sequence {
  390. struct list_head list_entry;
  391. void *hw;
  392. u8 fcfi;
  393. struct efc_hw_rq_buffer *header;
  394. struct efc_hw_rq_buffer *payload;
  395. void *hw_priv;
  396. };
  397. enum efc_disc_io_type {
  398. EFC_DISC_IO_ELS_REQ,
  399. EFC_DISC_IO_ELS_RESP,
  400. EFC_DISC_IO_CT_REQ,
  401. EFC_DISC_IO_CT_RESP
  402. };
  403. struct efc_io_els_params {
  404. u32 s_id;
  405. u16 ox_id;
  406. u8 timeout;
  407. };
  408. struct efc_io_ct_params {
  409. u8 r_ctl;
  410. u8 type;
  411. u8 df_ctl;
  412. u8 timeout;
  413. u16 ox_id;
  414. };
  415. union efc_disc_io_param {
  416. struct efc_io_els_params els;
  417. struct efc_io_ct_params ct;
  418. };
  419. struct efc_disc_io {
  420. struct efc_dma req; /* send buffer */
  421. struct efc_dma rsp; /* receive buffer */
  422. enum efc_disc_io_type io_type; /* EFC_DISC_IO_TYPE enum*/
  423. u16 xmit_len; /* Length of els request*/
  424. u16 rsp_len; /* Max length of rsps to be rcvd */
  425. u32 rpi; /* Registered RPI */
  426. u32 vpi; /* VPI for this nport */
  427. u32 s_id;
  428. u32 d_id;
  429. bool rpi_registered; /* if false, use tmp RPI */
  430. union efc_disc_io_param iparam;
  431. };
  432. /* Return value indiacating the sequence can not be freed */
  433. #define EFC_HW_SEQ_HOLD 0
  434. /* Return value indiacating the sequence can be freed */
  435. #define EFC_HW_SEQ_FREE 1
  436. struct libefc_function_template {
  437. /*Sport*/
  438. int (*new_nport)(struct efc *efc, struct efc_nport *sp);
  439. void (*del_nport)(struct efc *efc, struct efc_nport *sp);
  440. /*Scsi Node*/
  441. int (*scsi_new_node)(struct efc *efc, struct efc_node *n);
  442. int (*scsi_del_node)(struct efc *efc, struct efc_node *n, int reason);
  443. int (*issue_mbox_rqst)(void *efct, void *buf, void *cb, void *arg);
  444. /*Send ELS IO*/
  445. int (*send_els)(struct efc *efc, struct efc_disc_io *io);
  446. /*Send BLS IO*/
  447. int (*send_bls)(struct efc *efc, u32 type, struct sli_bls_params *bls);
  448. /*Free HW frame*/
  449. int (*hw_seq_free)(struct efc *efc, struct efc_hw_sequence *seq);
  450. };
  451. #define EFC_LOG_LIB 0x01
  452. #define EFC_LOG_NODE 0x02
  453. #define EFC_LOG_PORT 0x04
  454. #define EFC_LOG_DOMAIN 0x08
  455. #define EFC_LOG_ELS 0x10
  456. #define EFC_LOG_DOMAIN_SM 0x20
  457. #define EFC_LOG_SM 0x40
  458. /* efc library port structure */
  459. struct efc {
  460. void *base;
  461. struct pci_dev *pci;
  462. struct sli4 *sli;
  463. u32 fcfi;
  464. u64 req_wwpn;
  465. u64 req_wwnn;
  466. u64 def_wwpn;
  467. u64 def_wwnn;
  468. u64 max_xfer_size;
  469. mempool_t *node_pool;
  470. struct dma_pool *node_dma_pool;
  471. u32 nodes_count;
  472. u32 link_status;
  473. struct list_head vport_list;
  474. /* lock to protect the vport list */
  475. spinlock_t vport_lock;
  476. struct libefc_function_template tt;
  477. /* lock to protect the discovery library.
  478. * Refer to efclib.c for more details.
  479. */
  480. spinlock_t lock;
  481. bool enable_ini;
  482. bool enable_tgt;
  483. u32 log_level;
  484. struct efc_domain *domain;
  485. void (*domain_free_cb)(struct efc *efc, void *arg);
  486. void *domain_free_cb_arg;
  487. u64 tgt_rscn_delay_msec;
  488. u64 tgt_rscn_period_msec;
  489. bool external_loopback;
  490. u32 nodedb_mask;
  491. u32 logmask;
  492. mempool_t *els_io_pool;
  493. atomic_t els_io_alloc_failed_count;
  494. /* hold pending frames */
  495. bool hold_frames;
  496. /* lock to protect pending frames list access */
  497. spinlock_t pend_frames_lock;
  498. struct list_head pend_frames;
  499. /* count of pending frames that were processed */
  500. u32 pend_frames_processed;
  501. };
  502. /*
  503. * EFC library registration
  504. * **********************************/
  505. int efcport_init(struct efc *efc);
  506. void efcport_destroy(struct efc *efc);
  507. /*
  508. * EFC Domain
  509. * **********************************/
  510. int efc_domain_cb(void *arg, int event, void *data);
  511. void
  512. efc_register_domain_free_cb(struct efc *efc,
  513. void (*callback)(struct efc *efc, void *arg),
  514. void *arg);
  515. /*
  516. * EFC nport
  517. * **********************************/
  518. void efc_nport_cb(void *arg, int event, void *data);
  519. struct efc_vport *
  520. efc_vport_create_spec(struct efc *efc, u64 wwnn, u64 wwpn, u32 fc_id,
  521. bool enable_ini, bool enable_tgt,
  522. void *tgt_data, void *ini_data);
  523. int efc_nport_vport_new(struct efc_domain *domain, u64 wwpn,
  524. u64 wwnn, u32 fc_id, bool ini, bool tgt,
  525. void *tgt_data, void *ini_data);
  526. int efc_nport_vport_del(struct efc *efc, struct efc_domain *domain,
  527. u64 wwpn, u64 wwnn);
  528. void efc_vport_del_all(struct efc *efc);
  529. /*
  530. * EFC Node
  531. * **********************************/
  532. int efc_remote_node_cb(void *arg, int event, void *data);
  533. void efc_node_fcid_display(u32 fc_id, char *buffer, u32 buf_len);
  534. void efc_node_post_shutdown(struct efc_node *node, void *arg);
  535. u64 efc_node_get_wwpn(struct efc_node *node);
  536. /*
  537. * EFC FCP/ELS/CT interface
  538. * **********************************/
  539. void efc_dispatch_frame(struct efc *efc, struct efc_hw_sequence *seq);
  540. void efc_disc_io_complete(struct efc_disc_io *io, u32 len, u32 status,
  541. u32 ext_status);
  542. /*
  543. * EFC SCSI INTERACTION LAYER
  544. * **********************************/
  545. void efc_scsi_sess_reg_complete(struct efc_node *node, u32 status);
  546. void efc_scsi_del_initiator_complete(struct efc *efc, struct efc_node *node);
  547. void efc_scsi_del_target_complete(struct efc *efc, struct efc_node *node);
  548. void efc_scsi_io_list_empty(struct efc *efc, struct efc_node *node);
  549. #endif /* __EFCLIB_H__ */