fnic_fdls.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2008 Cisco Systems, Inc. All rights reserved.
  4. * Copyright 2007 Nuova Systems, Inc. All rights reserved.
  5. */
  6. #ifndef _FNIC_FDLS_H_
  7. #define _FNIC_FDLS_H_
  8. #include "fnic_stats.h"
  9. #include "fdls_fc.h"
  10. /* FDLS - Fabric discovery and login services
  11. * -> VLAN discovery
  12. * -> retry every retry delay seconds until it succeeds.
  13. * <- List of VLANs
  14. *
  15. * -> Solicitation
  16. * <- Solicitation response (Advertisement)
  17. *
  18. * -> FCF selection & FLOGI ( FLOGI timeout - 2 * E_D_TOV)
  19. * <- FLOGI response
  20. *
  21. * -> FCF keep alive
  22. * <- FCF keep alive
  23. *
  24. * -> PLOGI to FFFFFC (DNS) (PLOGI timeout - 2 * R_A_TOV)
  25. * -> ABTS if timeout (ABTS tomeout - 2 * R_A_TOV)
  26. * <- PLOGI response
  27. * -> Retry PLOGI to FFFFFC (DNS) - Number of retries from vnic.cfg
  28. *
  29. * -> SCR to FFFFFC (DNS) (SCR timeout - 2 * R_A_TOV)
  30. * -> ABTS if timeout (ABTS tomeout - 2 * R_A_TOV)
  31. * <- SCR response
  32. * -> Retry SCR - Number of retries 2
  33. *
  34. * -> GPN_FT to FFFFFC (GPN_FT timeout - 2 * R_A_TOV)a
  35. * -> Retry on BUSY until it succeeds
  36. * -> Retry on BUSY until it succeeds
  37. * -> 2 retries on timeout
  38. *
  39. * -> RFT_ID to FFFFFC (DNS) (RFT_ID timeout - 3 * R_A_TOV)
  40. * -> ABTS if timeout (ABTS tomeout - 2 * R_A_TOV)
  41. * -> Retry RFT_ID to FFFFFC (DNS) (Number of retries 2 )
  42. * -> Ignore if both retires fail.
  43. *
  44. * Session establishment with targets
  45. * For each PWWN
  46. * -> PLOGI to FCID of that PWWN (PLOGI timeout 2 * R_A_TOV)
  47. * -> ABTS if timeout (ABTS tomeout - 2 * R_A_TOV)
  48. * <- PLOGI response
  49. * -> Retry PLOGI. Num retries using vnic.cfg
  50. *
  51. * -> PRLI to FCID of that PWWN (PRLI timeout 2 * R_A_TOV)
  52. * -> ABTS if timeout (ABTS tomeout - 2 * R_A_TOV)
  53. * <- PRLI response
  54. * -> Retry PRLI. Num retries using vnic.cfg
  55. *
  56. */
  57. #define FDLS_RETRY_COUNT 2
  58. /*
  59. * OXID encoding:
  60. * bits 0-8: oxid idx - allocated from poool
  61. * bits 9-13: oxid frame code from fnic_oxid_frame_type_e
  62. * bits 14-15: all zeros
  63. */
  64. #define FNIC_OXID_POOL_SZ (512) /* always power of 2 */
  65. #define FNIC_OXID_ENCODE(idx, frame_type) (frame_type | idx)
  66. #define FNIC_FRAME_MASK 0xFE00
  67. #define FNIC_FRAME_TYPE(oxid) (oxid & FNIC_FRAME_MASK)
  68. #define FNIC_OXID_IDX(oxid) ((oxid) & (FNIC_OXID_POOL_SZ - 1))
  69. #define OXID_RECLAIM_TOV(iport) (2 * iport->r_a_tov) /* in milliseconds */
  70. #define FNIC_FDLS_FABRIC_ABORT_ISSUED 0x1
  71. #define FNIC_FDLS_FPMA_LEARNT 0x2
  72. /* tport flags */
  73. #define FNIC_FDLS_TPORT_IN_GPN_FT_LIST 0x1
  74. #define FNIC_FDLS_TGT_ABORT_ISSUED 0x2
  75. #define FNIC_FDLS_TPORT_SEND_ADISC 0x4
  76. #define FNIC_FDLS_RETRY_FRAME 0x8
  77. #define FNIC_FDLS_TPORT_BUSY 0x10
  78. #define FNIC_FDLS_TPORT_TERMINATING 0x20
  79. #define FNIC_FDLS_TPORT_DELETED 0x40
  80. #define FNIC_FDLS_SCSI_REGISTERED 0x200
  81. /* Retry supported by rport(returned by prli service parameters) */
  82. #define FDLS_FC_RP_FLAGS_RETRY 0x1
  83. #define fdls_set_state(_fdls_fabric, _state) ((_fdls_fabric)->state = _state)
  84. #define fdls_get_state(_fdls_fabric) ((_fdls_fabric)->state)
  85. #define FNIC_FDMI_ACTIVE 0x8
  86. #define FNIC_FIRST_LINK_UP 0x2
  87. #define fdls_set_tport_state(_tport, _state) (_tport->state = _state)
  88. #define fdls_get_tport_state(_tport) (_tport->state)
  89. #define FNIC_PORTSPEED_10GBIT 1
  90. #define FNIC_FRAME_HT_ROOM (2148)
  91. #define FNIC_FCOE_FRAME_MAXSZ (2112)
  92. #define FNIC_FRAME_TYPE_FABRIC_FLOGI 0x1000
  93. #define FNIC_FRAME_TYPE_FABRIC_PLOGI 0x1200
  94. #define FNIC_FRAME_TYPE_FABRIC_RPN 0x1400
  95. #define FNIC_FRAME_TYPE_FABRIC_RFT 0x1600
  96. #define FNIC_FRAME_TYPE_FABRIC_RFF 0x1800
  97. #define FNIC_FRAME_TYPE_FABRIC_SCR 0x1A00
  98. #define FNIC_FRAME_TYPE_FABRIC_GPN_FT 0x1C00
  99. #define FNIC_FRAME_TYPE_FABRIC_LOGO 0x1E00
  100. #define FNIC_FRAME_TYPE_FDMI_PLOGI 0x2000
  101. #define FNIC_FRAME_TYPE_FDMI_RHBA 0x2200
  102. #define FNIC_FRAME_TYPE_FDMI_RPA 0x2400
  103. #define FNIC_FRAME_TYPE_TGT_PLOGI 0x2600
  104. #define FNIC_FRAME_TYPE_TGT_PRLI 0x2800
  105. #define FNIC_FRAME_TYPE_TGT_ADISC 0x2A00
  106. #define FNIC_FRAME_TYPE_TGT_LOGO 0x2C00
  107. struct fnic_fip_fcf_s {
  108. uint16_t vlan_id;
  109. uint8_t fcf_mac[6];
  110. uint8_t fcf_priority;
  111. uint32_t fka_adv_period;
  112. uint8_t ka_disabled;
  113. };
  114. enum fnic_fdls_state_e {
  115. FDLS_STATE_INIT = 0,
  116. FDLS_STATE_LINKDOWN,
  117. FDLS_STATE_FABRIC_LOGO,
  118. FDLS_STATE_FLOGO_DONE,
  119. FDLS_STATE_FABRIC_FLOGI,
  120. FDLS_STATE_FABRIC_PLOGI,
  121. FDLS_STATE_RPN_ID,
  122. FDLS_STATE_REGISTER_FC4_TYPES,
  123. FDLS_STATE_REGISTER_FC4_FEATURES,
  124. FDLS_STATE_SCR,
  125. FDLS_STATE_GPN_FT,
  126. FDLS_STATE_TGT_DISCOVERY,
  127. FDLS_STATE_RSCN_GPN_FT,
  128. FDLS_STATE_SEND_GPNFT
  129. };
  130. struct fnic_fdls_fabric_s {
  131. enum fnic_fdls_state_e state;
  132. uint32_t flags;
  133. struct list_head tport_list; /* List of discovered tports */
  134. struct timer_list retry_timer;
  135. int del_timer_inprogress;
  136. int del_fdmi_timer_inprogress;
  137. int retry_counter;
  138. int timer_pending;
  139. int fdmi_retry;
  140. struct timer_list fdmi_timer;
  141. int fdmi_pending;
  142. };
  143. struct fnic_fdls_fip_s {
  144. uint32_t state;
  145. uint32_t flogi_retry;
  146. };
  147. /* Message to tport_event_handler */
  148. enum fnic_tgt_msg_id {
  149. TGT_EV_NONE = 0,
  150. TGT_EV_RPORT_ADD,
  151. TGT_EV_RPORT_DEL,
  152. TGT_EV_TPORT_DELETE,
  153. TGT_EV_REMOVE
  154. };
  155. struct fnic_tport_event_s {
  156. struct list_head links;
  157. enum fnic_tgt_msg_id event;
  158. void *arg1;
  159. };
  160. enum fdls_tgt_state_e {
  161. FDLS_TGT_STATE_INIT = 0,
  162. FDLS_TGT_STATE_PLOGI,
  163. FDLS_TGT_STATE_PRLI,
  164. FDLS_TGT_STATE_READY,
  165. FDLS_TGT_STATE_LOGO_RECEIVED,
  166. FDLS_TGT_STATE_ADISC,
  167. FDL_TGT_STATE_PLOGO,
  168. FDLS_TGT_STATE_OFFLINING,
  169. FDLS_TGT_STATE_OFFLINE
  170. };
  171. struct fnic_tport_s {
  172. struct list_head links; /* To link the tports */
  173. enum fdls_tgt_state_e state;
  174. uint32_t flags;
  175. uint32_t fcid;
  176. uint64_t wwpn;
  177. uint64_t wwnn;
  178. uint16_t active_oxid;
  179. uint16_t tgt_flags;
  180. atomic_t in_flight; /* io counter */
  181. uint16_t max_payload_size;
  182. uint16_t r_a_tov;
  183. uint16_t e_d_tov;
  184. uint16_t lun0_delay;
  185. int max_concur_seqs;
  186. uint32_t fcp_csp;
  187. struct timer_list retry_timer;
  188. int del_timer_inprogress;
  189. int retry_counter;
  190. int timer_pending;
  191. unsigned int num_pending_cmds;
  192. int nexus_restart_count;
  193. int exch_reset_in_progress;
  194. void *iport;
  195. struct work_struct tport_del_work;
  196. struct completion *tport_del_done;
  197. struct fc_rport *rport;
  198. char str_wwpn[20];
  199. char str_wwnn[20];
  200. };
  201. /* OXID pool related structures */
  202. struct reclaim_entry_s {
  203. struct list_head links;
  204. /* oxid that needs to be freed after 2*r_a_tov */
  205. uint16_t oxid_idx;
  206. /* in jiffies. Use this to waiting time */
  207. unsigned long expires;
  208. unsigned long *bitmap;
  209. };
  210. /* used for allocating oxids for fabric and fdmi requests */
  211. struct fnic_oxid_pool_s {
  212. DECLARE_BITMAP(bitmap, FNIC_OXID_POOL_SZ);
  213. int sz; /* size of the pool or block */
  214. int next_idx; /* used for cycling through the oxid pool */
  215. /* retry schedule free */
  216. DECLARE_BITMAP(pending_schedule_free, FNIC_OXID_POOL_SZ);
  217. struct delayed_work schedule_oxid_free_retry;
  218. /* List of oxids that need to be freed and reclaimed.
  219. * This list is shared by all the oxid pools
  220. */
  221. struct list_head oxid_reclaim_list;
  222. /* Work associated with reclaim list */
  223. struct delayed_work oxid_reclaim_work;
  224. };
  225. /* iport */
  226. enum fnic_iport_state_e {
  227. FNIC_IPORT_STATE_INIT = 0,
  228. FNIC_IPORT_STATE_LINK_WAIT,
  229. FNIC_IPORT_STATE_FIP,
  230. FNIC_IPORT_STATE_FABRIC_DISC,
  231. FNIC_IPORT_STATE_READY
  232. };
  233. struct fnic_iport_s {
  234. enum fnic_iport_state_e state;
  235. struct fnic *fnic;
  236. uint64_t boot_time;
  237. uint32_t flags;
  238. int usefip;
  239. uint8_t hwmac[6]; /* HW MAC Addr */
  240. uint8_t fpma[6]; /* Fabric Provided MA */
  241. uint8_t fcfmac[6]; /* MAC addr of Fabric */
  242. uint16_t vlan_id;
  243. uint32_t fcid;
  244. /* oxid pool */
  245. struct fnic_oxid_pool_s oxid_pool;
  246. /*
  247. * fabric reqs are serialized and only one req at a time.
  248. * Tracking the oxid for sending abort
  249. */
  250. uint16_t active_oxid_fabric_req;
  251. /* fdmi only */
  252. uint16_t active_oxid_fdmi_plogi;
  253. uint16_t active_oxid_fdmi_rhba;
  254. uint16_t active_oxid_fdmi_rpa;
  255. struct fnic_fip_fcf_s selected_fcf;
  256. struct fnic_fdls_fip_s fip;
  257. struct fnic_fdls_fabric_s fabric;
  258. struct list_head tport_list;
  259. struct list_head tport_list_pending_del;
  260. /* list of tports for which we are yet to send PLOGO */
  261. struct list_head inprocess_tport_list;
  262. struct list_head deleted_tport_list;
  263. struct work_struct tport_event_work;
  264. uint32_t e_d_tov; /* msec */
  265. uint32_t r_a_tov; /* msec */
  266. uint32_t link_supported_speeds;
  267. uint32_t max_flogi_retries;
  268. uint32_t max_plogi_retries;
  269. uint32_t plogi_timeout;
  270. uint32_t service_params;
  271. uint64_t wwpn;
  272. uint64_t wwnn;
  273. uint16_t max_payload_size;
  274. spinlock_t deleted_tport_lst_lock;
  275. struct completion *flogi_reg_done;
  276. struct fnic_iport_stats iport_stats;
  277. char str_wwpn[20];
  278. char str_wwnn[20];
  279. };
  280. struct rport_dd_data_s {
  281. struct fnic_tport_s *tport;
  282. struct fnic_iport_s *iport;
  283. };
  284. enum fnic_recv_frame_type_e {
  285. FNIC_FABRIC_FLOGI_RSP = 1,
  286. FNIC_FABRIC_PLOGI_RSP,
  287. FNIC_FABRIC_RPN_RSP,
  288. FNIC_FABRIC_RFT_RSP,
  289. FNIC_FABRIC_RFF_RSP,
  290. FNIC_FABRIC_SCR_RSP,
  291. FNIC_FABRIC_GPN_FT_RSP,
  292. FNIC_FABRIC_BLS_ABTS_RSP,
  293. FNIC_FDMI_PLOGI_RSP,
  294. FNIC_FDMI_REG_HBA_RSP,
  295. FNIC_FDMI_RPA_RSP,
  296. FNIC_FDMI_BLS_ABTS_RSP,
  297. FNIC_FABRIC_LOGO_RSP,
  298. /* responses to target requests */
  299. FNIC_TPORT_PLOGI_RSP,
  300. FNIC_TPORT_PRLI_RSP,
  301. FNIC_TPORT_ADISC_RSP,
  302. FNIC_TPORT_BLS_ABTS_RSP,
  303. FNIC_TPORT_LOGO_RSP,
  304. /* unsolicited requests */
  305. FNIC_BLS_ABTS_REQ,
  306. FNIC_ELS_PLOGI_REQ,
  307. FNIC_ELS_RSCN_REQ,
  308. FNIC_ELS_LOGO_REQ,
  309. FNIC_ELS_ECHO_REQ,
  310. FNIC_ELS_ADISC,
  311. FNIC_ELS_RLS,
  312. FNIC_ELS_RRQ,
  313. FNIC_ELS_UNSUPPORTED_REQ,
  314. };
  315. enum fnic_port_speeds {
  316. DCEM_PORTSPEED_NONE = 0,
  317. DCEM_PORTSPEED_1G = 1000,
  318. DCEM_PORTSPEED_2G = 2000,
  319. DCEM_PORTSPEED_4G = 4000,
  320. DCEM_PORTSPEED_8G = 8000,
  321. DCEM_PORTSPEED_10G = 10000,
  322. DCEM_PORTSPEED_16G = 16000,
  323. DCEM_PORTSPEED_20G = 20000,
  324. DCEM_PORTSPEED_25G = 25000,
  325. DCEM_PORTSPEED_32G = 32000,
  326. DCEM_PORTSPEED_40G = 40000,
  327. DCEM_PORTSPEED_4x10G = 41000,
  328. DCEM_PORTSPEED_50G = 50000,
  329. DCEM_PORTSPEED_64G = 64000,
  330. DCEM_PORTSPEED_100G = 100000,
  331. DCEM_PORTSPEED_128G = 128000,
  332. };
  333. /* Function Declarations */
  334. /* fdls_disc.c */
  335. void fnic_fdls_disc_init(struct fnic_iport_s *iport);
  336. void fnic_fdls_disc_start(struct fnic_iport_s *iport);
  337. void fnic_fdls_recv_frame(struct fnic_iport_s *iport, void *rx_frame,
  338. int len, int fchdr_offset);
  339. void fnic_fdls_link_down(struct fnic_iport_s *iport);
  340. int fdls_init_frame_pool(struct fnic_iport_s *iport);
  341. uint8_t *fdls_alloc_frame(struct fnic_iport_s *iport);
  342. uint16_t fdls_alloc_oxid(struct fnic_iport_s *iport, int oxid_frame_type,
  343. uint16_t *active_oxid);
  344. void fdls_free_oxid(struct fnic_iport_s *iport,
  345. uint16_t oxid, uint16_t *active_oxid);
  346. void fdls_tgt_logout(struct fnic_iport_s *iport,
  347. struct fnic_tport_s *tport);
  348. void fnic_del_fabric_timer_sync(struct fnic *fnic);
  349. void fnic_del_tport_timer_sync(struct fnic *fnic,
  350. struct fnic_tport_s *tport);
  351. void fdls_send_fabric_logo(struct fnic_iport_s *iport);
  352. int fnic_fdls_validate_and_get_frame_type(struct fnic_iport_s *iport,
  353. struct fc_frame_header *fchdr);
  354. void fdls_send_tport_abts(struct fnic_iport_s *iport,
  355. struct fnic_tport_s *tport);
  356. bool fdls_delete_tport(struct fnic_iport_s *iport,
  357. struct fnic_tport_s *tport);
  358. void fdls_fdmi_timer_callback(struct timer_list *t);
  359. void fdls_fdmi_retry_plogi(struct fnic_iport_s *iport);
  360. /* fnic_fcs.c */
  361. void fnic_fdls_init(struct fnic *fnic, int usefip);
  362. void fnic_send_fcoe_frame(struct fnic_iport_s *iport, void *frame,
  363. int frame_size);
  364. void fnic_fcoe_send_vlan_req(struct fnic *fnic);
  365. int fnic_send_fip_frame(struct fnic_iport_s *iport,
  366. void *frame, int frame_size);
  367. void fnic_fdls_learn_fcoe_macs(struct fnic_iport_s *iport, void *rx_frame,
  368. uint8_t *fcid);
  369. void fnic_fdls_add_tport(struct fnic_iport_s *iport,
  370. struct fnic_tport_s *tport, unsigned long flags);
  371. void fnic_fdls_remove_tport(struct fnic_iport_s *iport,
  372. struct fnic_tport_s *tport,
  373. unsigned long flags);
  374. /* fip.c */
  375. void fnic_fcoe_send_vlan_req(struct fnic *fnic);
  376. void fnic_common_fip_cleanup(struct fnic *fnic);
  377. int fdls_fip_recv_frame(struct fnic *fnic, void *frame);
  378. void fnic_handle_fcs_ka_timer(struct timer_list *t);
  379. void fnic_handle_enode_ka_timer(struct timer_list *t);
  380. void fnic_handle_vn_ka_timer(struct timer_list *t);
  381. void fnic_handle_fip_timer(struct timer_list *t);
  382. extern void fdls_fabric_timer_callback(struct timer_list *t);
  383. /* fnic_scsi.c */
  384. void fnic_scsi_fcpio_reset(struct fnic *fnic);
  385. extern void fdls_fabric_timer_callback(struct timer_list *t);
  386. void fnic_rport_exch_reset(struct fnic *fnic, u32 fcid);
  387. int fnic_fdls_register_portid(struct fnic_iport_s *iport, u32 port_id,
  388. void *fp);
  389. struct fnic_tport_s *fnic_find_tport_by_fcid(struct fnic_iport_s *iport,
  390. uint32_t fcid);
  391. struct fnic_tport_s *fnic_find_tport_by_wwpn(struct fnic_iport_s *iport,
  392. uint64_t wwpn);
  393. #endif /* _FNIC_FDLS_H_ */