bfad_drv.h 9.2 KB

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