bfad_drv.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
  4. * Copyright (c) 2014- QLogic Corporation.
  5. * All rights reserved
  6. * www.qlogic.com
  7. *
  8. * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
  9. */
  10. /*
  11. * Contains base driver definitions.
  12. */
  13. /*
  14. * bfa_drv.h Linux driver data structures.
  15. */
  16. #ifndef __BFAD_DRV_H__
  17. #define __BFAD_DRV_H__
  18. #include <linux/types.h>
  19. #include <linux/pci.h>
  20. #include <linux/dma-mapping.h>
  21. #include <linux/idr.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/cdev.h>
  24. #include <linux/fs.h>
  25. #include <linux/delay.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/workqueue.h>
  28. #include <linux/bitops.h>
  29. #include <linux/aer.h>
  30. #include <scsi/scsi.h>
  31. #include <scsi/scsi_host.h>
  32. #include <scsi/scsi_tcq.h>
  33. #include <scsi/scsi_transport_fc.h>
  34. #include <scsi/scsi_transport.h>
  35. #include <scsi/scsi_bsg_fc.h>
  36. #include <scsi/scsi_devinfo.h>
  37. #include "bfa_modules.h"
  38. #include "bfa_fcs.h"
  39. #include "bfa_defs_fcs.h"
  40. #include "bfa_plog.h"
  41. #include "bfa_cs.h"
  42. #define BFAD_DRIVER_NAME "bfa"
  43. #ifdef BFA_DRIVER_VERSION
  44. #define BFAD_DRIVER_VERSION BFA_DRIVER_VERSION
  45. #else
  46. #define BFAD_DRIVER_VERSION "3.2.25.1"
  47. #endif
  48. #define BFAD_PROTO_NAME FCPI_NAME
  49. #define BFAD_IRQ_FLAGS IRQF_SHARED
  50. #ifndef FC_PORTSPEED_8GBIT
  51. #define FC_PORTSPEED_8GBIT 0x10
  52. #endif
  53. /*
  54. * BFAD flags
  55. */
  56. #define BFAD_MSIX_ON 0x00000001
  57. #define BFAD_HAL_INIT_DONE 0x00000002
  58. #define BFAD_DRV_INIT_DONE 0x00000004
  59. #define BFAD_CFG_PPORT_DONE 0x00000008
  60. #define BFAD_HAL_START_DONE 0x00000010
  61. #define BFAD_PORT_ONLINE 0x00000020
  62. #define BFAD_RPORT_ONLINE 0x00000040
  63. #define BFAD_FCS_INIT_DONE 0x00000080
  64. #define BFAD_HAL_INIT_FAIL 0x00000100
  65. #define BFAD_FC4_PROBE_DONE 0x00000200
  66. #define BFAD_PORT_DELETE 0x00000001
  67. #define BFAD_INTX_ON 0x00000400
  68. #define BFAD_EEH_BUSY 0x00000800
  69. #define BFAD_EEH_PCI_CHANNEL_IO_PERM_FAILURE 0x00001000
  70. /*
  71. * BFAD related definition
  72. */
  73. #define SCSI_SCAN_DELAY HZ
  74. #define BFAD_STOP_TIMEOUT 30
  75. #define BFAD_SUSPEND_TIMEOUT BFAD_STOP_TIMEOUT
  76. /*
  77. * BFAD configuration parameter default values
  78. */
  79. #define BFAD_LUN_QUEUE_DEPTH 32
  80. #define BFAD_IO_MAX_SGE SG_ALL
  81. #define BFAD_MIN_SECTORS 128 /* 64k */
  82. #define BFAD_MAX_SECTORS 0xFFFF /* 32 MB */
  83. #define bfad_isr_t irq_handler_t
  84. #define MAX_MSIX_ENTRY 22
  85. struct bfad_msix_s {
  86. struct bfad_s *bfad;
  87. struct msix_entry msix;
  88. char name[32];
  89. };
  90. /*
  91. * Only append to the enums defined here to avoid any versioning
  92. * needed between trace utility and driver version
  93. */
  94. enum {
  95. BFA_TRC_LDRV_BFAD = 1,
  96. BFA_TRC_LDRV_IM = 2,
  97. BFA_TRC_LDRV_BSG = 3,
  98. };
  99. enum bfad_port_pvb_type {
  100. BFAD_PORT_PHYS_BASE = 0,
  101. BFAD_PORT_PHYS_VPORT = 1,
  102. BFAD_PORT_VF_BASE = 2,
  103. BFAD_PORT_VF_VPORT = 3,
  104. };
  105. /*
  106. * PORT data structure
  107. */
  108. struct bfad_port_s {
  109. struct list_head list_entry;
  110. struct bfad_s *bfad;
  111. struct bfa_fcs_lport_s *fcs_port;
  112. u32 roles;
  113. s32 flags;
  114. u32 supported_fc4s;
  115. enum bfad_port_pvb_type pvb_type;
  116. struct bfad_im_port_s *im_port; /* IM specific data */
  117. /* port debugfs specific data */
  118. struct dentry *port_debugfs_root;
  119. };
  120. /*
  121. * VPORT data structure
  122. */
  123. struct bfad_vport_s {
  124. struct bfad_port_s drv_port;
  125. struct bfa_fcs_vport_s fcs_vport;
  126. struct completion *comp_del;
  127. struct list_head list_entry;
  128. };
  129. /*
  130. * VF data structure
  131. */
  132. struct bfad_vf_s {
  133. bfa_fcs_vf_t fcs_vf;
  134. struct bfad_port_s base_port; /* base port for vf */
  135. struct bfad_s *bfad;
  136. };
  137. struct bfad_cfg_param_s {
  138. u32 rport_del_timeout;
  139. u32 ioc_queue_depth;
  140. u32 lun_queue_depth;
  141. u32 io_max_sge;
  142. u32 binding_method;
  143. };
  144. union bfad_tmp_buf {
  145. /* From struct bfa_adapter_attr_s */
  146. char manufacturer[BFA_ADAPTER_MFG_NAME_LEN];
  147. char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN];
  148. char model[BFA_ADAPTER_MODEL_NAME_LEN];
  149. char fw_ver[BFA_VERSION_LEN];
  150. char optrom_ver[BFA_VERSION_LEN];
  151. /* From struct bfa_ioc_pci_attr_s */
  152. u8 chip_rev[BFA_IOC_CHIP_REV_LEN]; /* chip revision */
  153. wwn_t wwn[BFA_FCS_MAX_LPORTS];
  154. };
  155. /*
  156. * BFAD (PCI function) data structure
  157. */
  158. struct bfad_s {
  159. bfa_sm_t sm; /* state machine */
  160. struct list_head list_entry;
  161. struct bfa_s bfa;
  162. struct bfa_fcs_s bfa_fcs;
  163. struct pci_dev *pcidev;
  164. const char *pci_name;
  165. struct bfa_pcidev_s hal_pcidev;
  166. struct bfa_ioc_pci_attr_s pci_attr;
  167. void __iomem *pci_bar0_kva;
  168. void __iomem *pci_bar2_kva;
  169. struct completion comp;
  170. struct completion suspend;
  171. struct completion enable_comp;
  172. struct completion disable_comp;
  173. bfa_boolean_t disable_active;
  174. struct bfad_port_s pport; /* physical port of the BFAD */
  175. struct bfa_meminfo_s meminfo;
  176. struct bfa_iocfc_cfg_s ioc_cfg;
  177. u32 inst_no; /* BFAD instance number */
  178. u32 bfad_flags;
  179. spinlock_t bfad_lock;
  180. struct task_struct *bfad_tsk;
  181. struct bfad_cfg_param_s cfg_data;
  182. struct bfad_msix_s msix_tab[MAX_MSIX_ENTRY];
  183. int nvec;
  184. char adapter_name[BFA_ADAPTER_SYM_NAME_LEN];
  185. char port_name[BFA_ADAPTER_SYM_NAME_LEN];
  186. struct timer_list hal_tmo;
  187. unsigned long hs_start;
  188. struct bfad_im_s *im; /* IM specific data */
  189. struct bfa_trc_mod_s *trcmod;
  190. struct bfa_plog_s plog_buf;
  191. int ref_count;
  192. union bfad_tmp_buf tmp_buf;
  193. struct fc_host_statistics link_stats;
  194. struct list_head pbc_vport_list;
  195. /* debugfs specific data */
  196. char *regdata;
  197. u32 reglen;
  198. struct dentry *bfad_dentry_files[5];
  199. struct list_head free_aen_q;
  200. struct list_head active_aen_q;
  201. struct bfa_aen_entry_s aen_list[BFA_AEN_MAX_ENTRY];
  202. spinlock_t bfad_aen_spinlock;
  203. struct list_head vport_list;
  204. };
  205. /* BFAD state machine events */
  206. enum bfad_sm_event {
  207. BFAD_E_CREATE = 1,
  208. BFAD_E_KTHREAD_CREATE_FAILED = 2,
  209. BFAD_E_INIT = 3,
  210. BFAD_E_INIT_SUCCESS = 4,
  211. BFAD_E_HAL_INIT_FAILED = 5,
  212. BFAD_E_INIT_FAILED = 6,
  213. BFAD_E_FCS_EXIT_COMP = 7,
  214. BFAD_E_EXIT_COMP = 8,
  215. BFAD_E_STOP = 9
  216. };
  217. /*
  218. * RPORT data structure
  219. */
  220. struct bfad_rport_s {
  221. struct bfa_fcs_rport_s fcs_rport;
  222. };
  223. struct bfad_buf_info {
  224. void *virt;
  225. dma_addr_t phys;
  226. u32 size;
  227. };
  228. struct bfad_fcxp {
  229. struct bfad_port_s *port;
  230. struct bfa_rport_s *bfa_rport;
  231. bfa_status_t req_status;
  232. u16 tag;
  233. u16 rsp_len;
  234. u16 rsp_maxlen;
  235. u8 use_ireqbuf;
  236. u8 use_irspbuf;
  237. u32 num_req_sgles;
  238. u32 num_rsp_sgles;
  239. struct fchs_s fchs;
  240. void *reqbuf_info;
  241. void *rspbuf_info;
  242. struct bfa_sge_s *req_sge;
  243. struct bfa_sge_s *rsp_sge;
  244. fcxp_send_cb_t send_cbfn;
  245. void *send_cbarg;
  246. void *bfa_fcxp;
  247. struct completion comp;
  248. };
  249. struct bfad_hal_comp {
  250. bfa_status_t status;
  251. struct completion comp;
  252. };
  253. #define BFA_LOG(level, bfad, mask, fmt, arg...) \
  254. do { \
  255. if (((mask) == 4) || (level[1] <= '4')) \
  256. dev_printk(level, &((bfad)->pcidev)->dev, fmt, ##arg); \
  257. } while (0)
  258. bfa_status_t bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
  259. struct bfa_lport_cfg_s *port_cfg,
  260. struct device *dev);
  261. bfa_status_t bfad_vf_create(struct bfad_s *bfad, u16 vf_id,
  262. struct bfa_lport_cfg_s *port_cfg);
  263. bfa_status_t bfad_cfg_pport(struct bfad_s *bfad, enum bfa_lport_role role);
  264. bfa_status_t bfad_drv_init(struct bfad_s *bfad);
  265. bfa_status_t bfad_start_ops(struct bfad_s *bfad);
  266. void bfad_drv_start(struct bfad_s *bfad);
  267. void bfad_uncfg_pport(struct bfad_s *bfad);
  268. void bfad_stop(struct bfad_s *bfad);
  269. void bfad_fcs_stop(struct bfad_s *bfad);
  270. void bfad_remove_intr(struct bfad_s *bfad);
  271. void bfad_hal_mem_release(struct bfad_s *bfad);
  272. void bfad_hcb_comp(void *arg, bfa_status_t status);
  273. int bfad_setup_intr(struct bfad_s *bfad);
  274. void bfad_remove_intr(struct bfad_s *bfad);
  275. void bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg);
  276. bfa_status_t bfad_hal_mem_alloc(struct bfad_s *bfad);
  277. void bfad_bfa_tmo(struct timer_list *t);
  278. void bfad_init_timer(struct bfad_s *bfad);
  279. int bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad);
  280. void bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad);
  281. void bfad_drv_uninit(struct bfad_s *bfad);
  282. int bfad_worker(void *ptr);
  283. void bfad_debugfs_init(struct bfad_port_s *port);
  284. void bfad_debugfs_exit(struct bfad_port_s *port);
  285. void bfad_pci_remove(struct pci_dev *pdev);
  286. int bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid);
  287. void bfad_rport_online_wait(struct bfad_s *bfad);
  288. int bfad_get_linkup_delay(struct bfad_s *bfad);
  289. int bfad_install_msix_handler(struct bfad_s *bfad);
  290. extern struct idr bfad_im_port_index;
  291. extern struct pci_device_id bfad_id_table[];
  292. extern struct list_head bfad_list;
  293. extern char *os_name;
  294. extern char *os_patch;
  295. extern char *host_name;
  296. extern int num_rports;
  297. extern int num_ios;
  298. extern int num_tms;
  299. extern int num_fcxps;
  300. extern int num_ufbufs;
  301. extern int reqq_size;
  302. extern int rspq_size;
  303. extern int num_sgpgs;
  304. extern int rport_del_timeout;
  305. extern int bfa_lun_queue_depth;
  306. extern int bfa_io_max_sge;
  307. extern int bfa_log_level;
  308. extern int ioc_auto_recover;
  309. extern int bfa_linkup_delay;
  310. extern int msix_disable_cb;
  311. extern int msix_disable_ct;
  312. extern int fdmi_enable;
  313. extern int supported_fc4s;
  314. extern int pcie_max_read_reqsz;
  315. extern int max_xfer_size;
  316. extern int bfa_debugfs_enable;
  317. extern struct mutex bfad_mutex;
  318. #endif /* __BFAD_DRV_H__ */