blob: 8b97877d42cf660ae1bb928888fa34794bfeaaf7 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
Jing Huang7725ccf2009-09-23 17:46:15 -07003 * 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
Jing Huangacdc79a2010-10-18 17:15:55 -070018/*
Jing Huang7725ccf2009-09-23 17:46:15 -070019 * Contains base driver definitions.
20 */
21
Jing Huangacdc79a2010-10-18 17:15:55 -070022/*
Jing Huang7725ccf2009-09-23 17:46:15 -070023 * bfa_drv.h Linux driver data structures.
24 */
25
26#ifndef __BFAD_DRV_H__
27#define __BFAD_DRV_H__
28
Maggie Zhangf16a1752010-12-09 19:12:32 -080029#include <linux/types.h>
Maggie Zhangf16a1752010-12-09 19:12:32 -080030#include <linux/pci.h>
31#include <linux/dma-mapping.h>
32#include <linux/idr.h>
33#include <linux/interrupt.h>
34#include <linux/cdev.h>
35#include <linux/fs.h>
36#include <linux/delay.h>
37#include <linux/vmalloc.h>
38#include <linux/workqueue.h>
39#include <linux/bitops.h>
Krishna Gudipati881c1b32012-08-22 19:52:02 -070040#include <linux/aer.h>
Maggie Zhangf16a1752010-12-09 19:12:32 -080041#include <scsi/scsi.h>
42#include <scsi/scsi_host.h>
43#include <scsi/scsi_tcq.h>
44#include <scsi/scsi_transport_fc.h>
45#include <scsi/scsi_transport.h>
Krishna Gudipatib85daaf2011-06-13 15:55:11 -070046#include <scsi/scsi_bsg_fc.h>
Krishna Gudipati5b7db7a2011-12-20 18:58:32 -080047#include <scsi/scsi_devinfo.h>
Jing Huang7725ccf2009-09-23 17:46:15 -070048
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070049#include "bfa_modules.h"
50#include "bfa_fcs.h"
51#include "bfa_defs_fcs.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070052
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070053#include "bfa_plog.h"
54#include "bfa_cs.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070055
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070056#define BFAD_DRIVER_NAME "bfa"
Jing Huang7725ccf2009-09-23 17:46:15 -070057#ifdef BFA_DRIVER_VERSION
58#define BFAD_DRIVER_VERSION BFA_DRIVER_VERSION
59#else
Vijaya Mohan Guvva2da11ad2013-11-21 01:37:50 -080060#define BFAD_DRIVER_VERSION "3.2.23.0"
Jing Huang7725ccf2009-09-23 17:46:15 -070061#endif
62
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070063#define BFAD_PROTO_NAME FCPI_NAME
Jing Huang7725ccf2009-09-23 17:46:15 -070064#define BFAD_IRQ_FLAGS IRQF_SHARED
65
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070066#ifndef FC_PORTSPEED_8GBIT
67#define FC_PORTSPEED_8GBIT 0x10
68#endif
69
Jing Huang7725ccf2009-09-23 17:46:15 -070070/*
71 * BFAD flags
72 */
73#define BFAD_MSIX_ON 0x00000001
74#define BFAD_HAL_INIT_DONE 0x00000002
75#define BFAD_DRV_INIT_DONE 0x00000004
76#define BFAD_CFG_PPORT_DONE 0x00000008
77#define BFAD_HAL_START_DONE 0x00000010
78#define BFAD_PORT_ONLINE 0x00000020
79#define BFAD_RPORT_ONLINE 0x00000040
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070080#define BFAD_FCS_INIT_DONE 0x00000080
81#define BFAD_HAL_INIT_FAIL 0x00000100
82#define BFAD_FC4_PROBE_DONE 0x00000200
Jing Huang7725ccf2009-09-23 17:46:15 -070083#define BFAD_PORT_DELETE 0x00000001
Krishna Gudipati61e62e22011-06-24 20:29:07 -070084#define BFAD_INTX_ON 0x00000400
Krishna Gudipati881c1b32012-08-22 19:52:02 -070085#define BFAD_EEH_BUSY 0x00000800
86#define BFAD_EEH_PCI_CHANNEL_IO_PERM_FAILURE 0x00001000
Jing Huang7725ccf2009-09-23 17:46:15 -070087/*
88 * BFAD related definition
89 */
90#define SCSI_SCAN_DELAY HZ
91#define BFAD_STOP_TIMEOUT 30
92#define BFAD_SUSPEND_TIMEOUT BFAD_STOP_TIMEOUT
93
94/*
95 * BFAD configuration parameter default values
96 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070097#define BFAD_LUN_QUEUE_DEPTH 32
98#define BFAD_IO_MAX_SGE SG_ALL
Krishna Gudipati61e62e22011-06-24 20:29:07 -070099#define BFAD_MIN_SECTORS 128 /* 64k */
100#define BFAD_MAX_SECTORS 0xFFFF /* 32 MB */
Jing Huang7725ccf2009-09-23 17:46:15 -0700101
102#define bfad_isr_t irq_handler_t
103
104#define MAX_MSIX_ENTRY 22
105
106struct bfad_msix_s {
107 struct bfad_s *bfad;
108 struct msix_entry msix;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700109 char name[32];
110};
111
112/*
113 * Only append to the enums defined here to avoid any versioning
114 * needed between trace utility and driver version
115 */
116enum {
117 BFA_TRC_LDRV_BFAD = 1,
118 BFA_TRC_LDRV_IM = 2,
Krishna Gudipatib85daaf2011-06-13 15:55:11 -0700119 BFA_TRC_LDRV_BSG = 3,
Jing Huang7725ccf2009-09-23 17:46:15 -0700120};
121
122enum bfad_port_pvb_type {
123 BFAD_PORT_PHYS_BASE = 0,
124 BFAD_PORT_PHYS_VPORT = 1,
125 BFAD_PORT_VF_BASE = 2,
126 BFAD_PORT_VF_VPORT = 3,
127};
128
129/*
130 * PORT data structure
131 */
132struct bfad_port_s {
133 struct list_head list_entry;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700134 struct bfad_s *bfad;
135 struct bfa_fcs_lport_s *fcs_port;
136 u32 roles;
137 s32 flags;
138 u32 supported_fc4s;
Jing Huang7725ccf2009-09-23 17:46:15 -0700139 enum bfad_port_pvb_type pvb_type;
140 struct bfad_im_port_s *im_port; /* IM specific data */
Jing Huangab2a9ba2010-07-08 20:02:55 -0700141 /* port debugfs specific data */
142 struct dentry *port_debugfs_root;
Jing Huang7725ccf2009-09-23 17:46:15 -0700143};
144
145/*
146 * VPORT data structure
147 */
148struct bfad_vport_s {
149 struct bfad_port_s drv_port;
150 struct bfa_fcs_vport_s fcs_vport;
151 struct completion *comp_del;
Jing Huangd9883542010-07-08 19:46:26 -0700152 struct list_head list_entry;
Jing Huang7725ccf2009-09-23 17:46:15 -0700153};
154
155/*
156 * VF data structure
157 */
158struct bfad_vf_s {
159 bfa_fcs_vf_t fcs_vf;
160 struct bfad_port_s base_port; /* base port for vf */
161 struct bfad_s *bfad;
162};
163
164struct bfad_cfg_param_s {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700165 u32 rport_del_timeout;
166 u32 ioc_queue_depth;
167 u32 lun_queue_depth;
168 u32 io_max_sge;
169 u32 binding_method;
170};
171
172union bfad_tmp_buf {
173 /* From struct bfa_adapter_attr_s */
174 char manufacturer[BFA_ADAPTER_MFG_NAME_LEN];
175 char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN];
176 char model[BFA_ADAPTER_MODEL_NAME_LEN];
177 char fw_ver[BFA_VERSION_LEN];
178 char optrom_ver[BFA_VERSION_LEN];
179
180 /* From struct bfa_ioc_pci_attr_s */
181 u8 chip_rev[BFA_IOC_CHIP_REV_LEN]; /* chip revision */
182
183 wwn_t wwn[BFA_FCS_MAX_LPORTS];
Jing Huang7725ccf2009-09-23 17:46:15 -0700184};
185
Jing Huang7725ccf2009-09-23 17:46:15 -0700186/*
187 * BFAD (PCI function) data structure
188 */
189struct bfad_s {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700190 bfa_sm_t sm; /* state machine */
Jing Huang7725ccf2009-09-23 17:46:15 -0700191 struct list_head list_entry;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700192 struct bfa_s bfa;
193 struct bfa_fcs_s bfa_fcs;
Jing Huang7725ccf2009-09-23 17:46:15 -0700194 struct pci_dev *pcidev;
195 const char *pci_name;
196 struct bfa_pcidev_s hal_pcidev;
197 struct bfa_ioc_pci_attr_s pci_attr;
Jing Huang7725ccf2009-09-23 17:46:15 -0700198 void __iomem *pci_bar0_kva;
Krishna Gudipati11189202011-06-13 15:50:35 -0700199 void __iomem *pci_bar2_kva;
Jing Huang7725ccf2009-09-23 17:46:15 -0700200 struct completion comp;
201 struct completion suspend;
Krishna Gudipati60138062011-06-24 20:25:15 -0700202 struct completion enable_comp;
Jing Huang7725ccf2009-09-23 17:46:15 -0700203 struct completion disable_comp;
204 bfa_boolean_t disable_active;
205 struct bfad_port_s pport; /* physical port of the BFAD */
206 struct bfa_meminfo_s meminfo;
207 struct bfa_iocfc_cfg_s ioc_cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700208 u32 inst_no; /* BFAD instance number */
209 u32 bfad_flags;
Jing Huang7725ccf2009-09-23 17:46:15 -0700210 spinlock_t bfad_lock;
Krishna Gudipatie6714322010-03-03 17:44:02 -0800211 struct task_struct *bfad_tsk;
Jing Huang7725ccf2009-09-23 17:46:15 -0700212 struct bfad_cfg_param_s cfg_data;
213 struct bfad_msix_s msix_tab[MAX_MSIX_ENTRY];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700214 int nvec;
215 char adapter_name[BFA_ADAPTER_SYM_NAME_LEN];
216 char port_name[BFA_ADAPTER_SYM_NAME_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700217 struct timer_list hal_tmo;
218 unsigned long hs_start;
219 struct bfad_im_s *im; /* IM specific data */
Jing Huang7725ccf2009-09-23 17:46:15 -0700220 struct bfa_trc_mod_s *trcmod;
Jing Huang7725ccf2009-09-23 17:46:15 -0700221 struct bfa_plog_s plog_buf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700222 int ref_count;
223 union bfad_tmp_buf tmp_buf;
Jing Huang7725ccf2009-09-23 17:46:15 -0700224 struct fc_host_statistics link_stats;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700225 struct list_head pbc_vport_list;
Jing Huangab2a9ba2010-07-08 20:02:55 -0700226 /* debugfs specific data */
227 char *regdata;
228 u32 reglen;
229 struct dentry *bfad_dentry_files[5];
Krishna Gudipati7826f302011-07-20 16:59:13 -0700230 struct list_head free_aen_q;
231 struct list_head active_aen_q;
232 struct bfa_aen_entry_s aen_list[BFA_AEN_MAX_ENTRY];
233 spinlock_t bfad_aen_spinlock;
Krishna Gudipati5b7db7a2011-12-20 18:58:32 -0800234 struct list_head vport_list;
Jing Huangd9883542010-07-08 19:46:26 -0700235};
236
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700237/* BFAD state machine events */
238enum bfad_sm_event {
239 BFAD_E_CREATE = 1,
240 BFAD_E_KTHREAD_CREATE_FAILED = 2,
241 BFAD_E_INIT = 3,
242 BFAD_E_INIT_SUCCESS = 4,
Vijaya Mohan Guvvada3e0be2013-11-21 01:37:33 -0800243 BFAD_E_HAL_INIT_FAILED = 5,
244 BFAD_E_INIT_FAILED = 6,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700245 BFAD_E_FCS_EXIT_COMP = 7,
246 BFAD_E_EXIT_COMP = 8,
247 BFAD_E_STOP = 9
Jing Huang7725ccf2009-09-23 17:46:15 -0700248};
249
250/*
251 * RPORT data structure
252 */
253struct bfad_rport_s {
254 struct bfa_fcs_rport_s fcs_rport;
255};
256
257struct bfad_buf_info {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700258 void *virt;
Jing Huang7725ccf2009-09-23 17:46:15 -0700259 dma_addr_t phys;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700260 u32 size;
Jing Huang7725ccf2009-09-23 17:46:15 -0700261};
262
263struct bfad_fcxp {
264 struct bfad_port_s *port;
265 struct bfa_rport_s *bfa_rport;
266 bfa_status_t req_status;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700267 u16 tag;
268 u16 rsp_len;
269 u16 rsp_maxlen;
270 u8 use_ireqbuf;
271 u8 use_irspbuf;
272 u32 num_req_sgles;
273 u32 num_rsp_sgles;
274 struct fchs_s fchs;
275 void *reqbuf_info;
276 void *rspbuf_info;
Jing Huang7725ccf2009-09-23 17:46:15 -0700277 struct bfa_sge_s *req_sge;
278 struct bfa_sge_s *rsp_sge;
279 fcxp_send_cb_t send_cbfn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700280 void *send_cbarg;
281 void *bfa_fcxp;
Jing Huang7725ccf2009-09-23 17:46:15 -0700282 struct completion comp;
283};
284
285struct bfad_hal_comp {
286 bfa_status_t status;
287 struct completion comp;
288};
289
Maggie Zhangf16a1752010-12-09 19:12:32 -0800290#define BFA_LOG(level, bfad, mask, fmt, arg...) \
291do { \
292 if (((mask) == 4) || (level[1] <= '4')) \
293 dev_printk(level, &((bfad)->pcidev)->dev, fmt, ##arg); \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700294} while (0)
295
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700296bfa_status_t bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
297 struct bfa_lport_cfg_s *port_cfg,
298 struct device *dev);
299bfa_status_t bfad_vf_create(struct bfad_s *bfad, u16 vf_id,
300 struct bfa_lport_cfg_s *port_cfg);
301bfa_status_t bfad_cfg_pport(struct bfad_s *bfad, enum bfa_lport_role role);
302bfa_status_t bfad_drv_init(struct bfad_s *bfad);
Krishna Gudipatie6714322010-03-03 17:44:02 -0800303bfa_status_t bfad_start_ops(struct bfad_s *bfad);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700304void bfad_drv_start(struct bfad_s *bfad);
305void bfad_uncfg_pport(struct bfad_s *bfad);
306void bfad_stop(struct bfad_s *bfad);
307void bfad_fcs_stop(struct bfad_s *bfad);
308void bfad_remove_intr(struct bfad_s *bfad);
309void bfad_hal_mem_release(struct bfad_s *bfad);
310void bfad_hcb_comp(void *arg, bfa_status_t status);
Jing Huang7725ccf2009-09-23 17:46:15 -0700311
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700312int bfad_setup_intr(struct bfad_s *bfad);
313void bfad_remove_intr(struct bfad_s *bfad);
Jing Huang7725ccf2009-09-23 17:46:15 -0700314void bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg);
315bfa_status_t bfad_hal_mem_alloc(struct bfad_s *bfad);
316void bfad_bfa_tmo(unsigned long data);
317void bfad_init_timer(struct bfad_s *bfad);
318int bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad);
319void bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad);
Jing Huang7725ccf2009-09-23 17:46:15 -0700320void bfad_drv_uninit(struct bfad_s *bfad);
Jing Huangab2a9ba2010-07-08 20:02:55 -0700321int bfad_worker(void *ptr);
322void bfad_debugfs_init(struct bfad_port_s *port);
323void bfad_debugfs_exit(struct bfad_port_s *port);
Krishna Gudipatie6714322010-03-03 17:44:02 -0800324
Jing Huang7725ccf2009-09-23 17:46:15 -0700325void bfad_pci_remove(struct pci_dev *pdev);
326int bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid);
Maggie Zhangf16a1752010-12-09 19:12:32 -0800327void bfad_rport_online_wait(struct bfad_s *bfad);
328int bfad_get_linkup_delay(struct bfad_s *bfad);
Jing Huang7725ccf2009-09-23 17:46:15 -0700329int bfad_install_msix_handler(struct bfad_s *bfad);
330
331extern struct idr bfad_im_port_index;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700332extern struct pci_device_id bfad_id_table[];
Jing Huang7725ccf2009-09-23 17:46:15 -0700333extern struct list_head bfad_list;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700334extern char *os_name;
335extern char *os_patch;
336extern char *host_name;
337extern int num_rports;
338extern int num_ios;
339extern int num_tms;
340extern int num_fcxps;
341extern int num_ufbufs;
342extern int reqq_size;
343extern int rspq_size;
344extern int num_sgpgs;
345extern int rport_del_timeout;
346extern int bfa_lun_queue_depth;
347extern int bfa_io_max_sge;
Jing Huang88166242010-12-09 17:11:53 -0800348extern int bfa_log_level;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700349extern int ioc_auto_recover;
350extern int bfa_linkup_delay;
351extern int msix_disable_cb;
352extern int msix_disable_ct;
353extern int fdmi_enable;
354extern int supported_fc4s;
355extern int pcie_max_read_reqsz;
Krishna Gudipati61e62e22011-06-24 20:29:07 -0700356extern int max_xfer_size;
Jing Huangab2a9ba2010-07-08 20:02:55 -0700357extern int bfa_debugfs_enable;
Jing Huang42b426e2010-03-19 11:07:09 -0700358extern struct mutex bfad_mutex;
Jing Huang7725ccf2009-09-23 17:46:15 -0700359
360#endif /* __BFAD_DRV_H__ */