bfad_drv.h 9.0 KB

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