blob: 5e19a5f820ec6d515773ec942ff4ba1d9184608e [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>
40#include <scsi/scsi.h>
41#include <scsi/scsi_host.h>
42#include <scsi/scsi_tcq.h>
43#include <scsi/scsi_transport_fc.h>
44#include <scsi/scsi_transport.h>
Krishna Gudipatib85daaf2011-06-13 15:55:11 -070045#include <scsi/scsi_bsg_fc.h>
Jing Huang7725ccf2009-09-23 17:46:15 -070046
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070047#include "bfa_modules.h"
48#include "bfa_fcs.h"
49#include "bfa_defs_fcs.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070050
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070051#include "bfa_plog.h"
52#include "bfa_cs.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070053
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070054#define BFAD_DRIVER_NAME "bfa"
Jing Huang7725ccf2009-09-23 17:46:15 -070055#ifdef BFA_DRIVER_VERSION
56#define BFAD_DRIVER_VERSION BFA_DRIVER_VERSION
57#else
Krishna Gudipati154fbf02011-07-20 17:04:44 -070058#define BFAD_DRIVER_VERSION "3.0.2.2"
Jing Huang7725ccf2009-09-23 17:46:15 -070059#endif
60
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070061#define BFAD_PROTO_NAME FCPI_NAME
Jing Huang7725ccf2009-09-23 17:46:15 -070062#define BFAD_IRQ_FLAGS IRQF_SHARED
63
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070064#ifndef FC_PORTSPEED_8GBIT
65#define FC_PORTSPEED_8GBIT 0x10
66#endif
67
Jing Huang7725ccf2009-09-23 17:46:15 -070068/*
69 * BFAD flags
70 */
71#define BFAD_MSIX_ON 0x00000001
72#define BFAD_HAL_INIT_DONE 0x00000002
73#define BFAD_DRV_INIT_DONE 0x00000004
74#define BFAD_CFG_PPORT_DONE 0x00000008
75#define BFAD_HAL_START_DONE 0x00000010
76#define BFAD_PORT_ONLINE 0x00000020
77#define BFAD_RPORT_ONLINE 0x00000040
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070078#define BFAD_FCS_INIT_DONE 0x00000080
79#define BFAD_HAL_INIT_FAIL 0x00000100
80#define BFAD_FC4_PROBE_DONE 0x00000200
Jing Huang7725ccf2009-09-23 17:46:15 -070081#define BFAD_PORT_DELETE 0x00000001
Krishna Gudipati61e62e22011-06-24 20:29:07 -070082#define BFAD_INTX_ON 0x00000400
Jing Huang7725ccf2009-09-23 17:46:15 -070083/*
84 * BFAD related definition
85 */
86#define SCSI_SCAN_DELAY HZ
87#define BFAD_STOP_TIMEOUT 30
88#define BFAD_SUSPEND_TIMEOUT BFAD_STOP_TIMEOUT
89
90/*
91 * BFAD configuration parameter default values
92 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070093#define BFAD_LUN_QUEUE_DEPTH 32
94#define BFAD_IO_MAX_SGE SG_ALL
Krishna Gudipati61e62e22011-06-24 20:29:07 -070095#define BFAD_MIN_SECTORS 128 /* 64k */
96#define BFAD_MAX_SECTORS 0xFFFF /* 32 MB */
Jing Huang7725ccf2009-09-23 17:46:15 -070097
98#define bfad_isr_t irq_handler_t
99
100#define MAX_MSIX_ENTRY 22
101
102struct bfad_msix_s {
103 struct bfad_s *bfad;
104 struct msix_entry msix;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700105 char name[32];
106};
107
108/*
109 * Only append to the enums defined here to avoid any versioning
110 * needed between trace utility and driver version
111 */
112enum {
113 BFA_TRC_LDRV_BFAD = 1,
114 BFA_TRC_LDRV_IM = 2,
Krishna Gudipatib85daaf2011-06-13 15:55:11 -0700115 BFA_TRC_LDRV_BSG = 3,
Jing Huang7725ccf2009-09-23 17:46:15 -0700116};
117
118enum bfad_port_pvb_type {
119 BFAD_PORT_PHYS_BASE = 0,
120 BFAD_PORT_PHYS_VPORT = 1,
121 BFAD_PORT_VF_BASE = 2,
122 BFAD_PORT_VF_VPORT = 3,
123};
124
125/*
126 * PORT data structure
127 */
128struct bfad_port_s {
129 struct list_head list_entry;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700130 struct bfad_s *bfad;
131 struct bfa_fcs_lport_s *fcs_port;
132 u32 roles;
133 s32 flags;
134 u32 supported_fc4s;
Jing Huang7725ccf2009-09-23 17:46:15 -0700135 enum bfad_port_pvb_type pvb_type;
136 struct bfad_im_port_s *im_port; /* IM specific data */
Jing Huangab2a9ba2010-07-08 20:02:55 -0700137 /* port debugfs specific data */
138 struct dentry *port_debugfs_root;
Jing Huang7725ccf2009-09-23 17:46:15 -0700139};
140
141/*
142 * VPORT data structure
143 */
144struct bfad_vport_s {
145 struct bfad_port_s drv_port;
146 struct bfa_fcs_vport_s fcs_vport;
147 struct completion *comp_del;
Jing Huangd9883542010-07-08 19:46:26 -0700148 struct list_head list_entry;
Jing Huang7725ccf2009-09-23 17:46:15 -0700149};
150
151/*
152 * VF data structure
153 */
154struct bfad_vf_s {
155 bfa_fcs_vf_t fcs_vf;
156 struct bfad_port_s base_port; /* base port for vf */
157 struct bfad_s *bfad;
158};
159
160struct bfad_cfg_param_s {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700161 u32 rport_del_timeout;
162 u32 ioc_queue_depth;
163 u32 lun_queue_depth;
164 u32 io_max_sge;
165 u32 binding_method;
166};
167
168union bfad_tmp_buf {
169 /* From struct bfa_adapter_attr_s */
170 char manufacturer[BFA_ADAPTER_MFG_NAME_LEN];
171 char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN];
172 char model[BFA_ADAPTER_MODEL_NAME_LEN];
173 char fw_ver[BFA_VERSION_LEN];
174 char optrom_ver[BFA_VERSION_LEN];
175
176 /* From struct bfa_ioc_pci_attr_s */
177 u8 chip_rev[BFA_IOC_CHIP_REV_LEN]; /* chip revision */
178
179 wwn_t wwn[BFA_FCS_MAX_LPORTS];
Jing Huang7725ccf2009-09-23 17:46:15 -0700180};
181
Jing Huang7725ccf2009-09-23 17:46:15 -0700182/*
183 * BFAD (PCI function) data structure
184 */
185struct bfad_s {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700186 bfa_sm_t sm; /* state machine */
Jing Huang7725ccf2009-09-23 17:46:15 -0700187 struct list_head list_entry;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700188 struct bfa_s bfa;
189 struct bfa_fcs_s bfa_fcs;
Jing Huang7725ccf2009-09-23 17:46:15 -0700190 struct pci_dev *pcidev;
191 const char *pci_name;
192 struct bfa_pcidev_s hal_pcidev;
193 struct bfa_ioc_pci_attr_s pci_attr;
Jing Huang7725ccf2009-09-23 17:46:15 -0700194 void __iomem *pci_bar0_kva;
Krishna Gudipati11189202011-06-13 15:50:35 -0700195 void __iomem *pci_bar2_kva;
Jing Huang7725ccf2009-09-23 17:46:15 -0700196 struct completion comp;
197 struct completion suspend;
Krishna Gudipati60138062011-06-24 20:25:15 -0700198 struct completion enable_comp;
Jing Huang7725ccf2009-09-23 17:46:15 -0700199 struct completion disable_comp;
200 bfa_boolean_t disable_active;
201 struct bfad_port_s pport; /* physical port of the BFAD */
202 struct bfa_meminfo_s meminfo;
203 struct bfa_iocfc_cfg_s ioc_cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700204 u32 inst_no; /* BFAD instance number */
205 u32 bfad_flags;
Jing Huang7725ccf2009-09-23 17:46:15 -0700206 spinlock_t bfad_lock;
Krishna Gudipatie6714322010-03-03 17:44:02 -0800207 struct task_struct *bfad_tsk;
Jing Huang7725ccf2009-09-23 17:46:15 -0700208 struct bfad_cfg_param_s cfg_data;
209 struct bfad_msix_s msix_tab[MAX_MSIX_ENTRY];
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700210 int nvec;
211 char adapter_name[BFA_ADAPTER_SYM_NAME_LEN];
212 char port_name[BFA_ADAPTER_SYM_NAME_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700213 struct timer_list hal_tmo;
214 unsigned long hs_start;
215 struct bfad_im_s *im; /* IM specific data */
Jing Huang7725ccf2009-09-23 17:46:15 -0700216 struct bfa_trc_mod_s *trcmod;
Jing Huang7725ccf2009-09-23 17:46:15 -0700217 struct bfa_plog_s plog_buf;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700218 int ref_count;
219 union bfad_tmp_buf tmp_buf;
Jing Huang7725ccf2009-09-23 17:46:15 -0700220 struct fc_host_statistics link_stats;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700221 struct list_head pbc_vport_list;
Jing Huangab2a9ba2010-07-08 20:02:55 -0700222 /* debugfs specific data */
223 char *regdata;
224 u32 reglen;
225 struct dentry *bfad_dentry_files[5];
Krishna Gudipati7826f302011-07-20 16:59:13 -0700226 struct list_head free_aen_q;
227 struct list_head active_aen_q;
228 struct bfa_aen_entry_s aen_list[BFA_AEN_MAX_ENTRY];
229 spinlock_t bfad_aen_spinlock;
Jing Huangd9883542010-07-08 19:46:26 -0700230};
231
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700232/* BFAD state machine events */
233enum bfad_sm_event {
234 BFAD_E_CREATE = 1,
235 BFAD_E_KTHREAD_CREATE_FAILED = 2,
236 BFAD_E_INIT = 3,
237 BFAD_E_INIT_SUCCESS = 4,
238 BFAD_E_INIT_FAILED = 5,
239 BFAD_E_INTR_INIT_FAILED = 6,
240 BFAD_E_FCS_EXIT_COMP = 7,
241 BFAD_E_EXIT_COMP = 8,
242 BFAD_E_STOP = 9
Jing Huang7725ccf2009-09-23 17:46:15 -0700243};
244
245/*
246 * RPORT data structure
247 */
248struct bfad_rport_s {
249 struct bfa_fcs_rport_s fcs_rport;
250};
251
252struct bfad_buf_info {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700253 void *virt;
Jing Huang7725ccf2009-09-23 17:46:15 -0700254 dma_addr_t phys;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700255 u32 size;
Jing Huang7725ccf2009-09-23 17:46:15 -0700256};
257
258struct bfad_fcxp {
259 struct bfad_port_s *port;
260 struct bfa_rport_s *bfa_rport;
261 bfa_status_t req_status;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700262 u16 tag;
263 u16 rsp_len;
264 u16 rsp_maxlen;
265 u8 use_ireqbuf;
266 u8 use_irspbuf;
267 u32 num_req_sgles;
268 u32 num_rsp_sgles;
269 struct fchs_s fchs;
270 void *reqbuf_info;
271 void *rspbuf_info;
Jing Huang7725ccf2009-09-23 17:46:15 -0700272 struct bfa_sge_s *req_sge;
273 struct bfa_sge_s *rsp_sge;
274 fcxp_send_cb_t send_cbfn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700275 void *send_cbarg;
276 void *bfa_fcxp;
Jing Huang7725ccf2009-09-23 17:46:15 -0700277 struct completion comp;
278};
279
280struct bfad_hal_comp {
281 bfa_status_t status;
282 struct completion comp;
283};
284
Maggie Zhangf16a1752010-12-09 19:12:32 -0800285#define BFA_LOG(level, bfad, mask, fmt, arg...) \
286do { \
287 if (((mask) == 4) || (level[1] <= '4')) \
288 dev_printk(level, &((bfad)->pcidev)->dev, fmt, ##arg); \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700289} while (0)
290
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700291bfa_status_t bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
292 struct bfa_lport_cfg_s *port_cfg,
293 struct device *dev);
294bfa_status_t bfad_vf_create(struct bfad_s *bfad, u16 vf_id,
295 struct bfa_lport_cfg_s *port_cfg);
296bfa_status_t bfad_cfg_pport(struct bfad_s *bfad, enum bfa_lport_role role);
297bfa_status_t bfad_drv_init(struct bfad_s *bfad);
Krishna Gudipatie6714322010-03-03 17:44:02 -0800298bfa_status_t bfad_start_ops(struct bfad_s *bfad);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700299void bfad_drv_start(struct bfad_s *bfad);
300void bfad_uncfg_pport(struct bfad_s *bfad);
301void bfad_stop(struct bfad_s *bfad);
302void bfad_fcs_stop(struct bfad_s *bfad);
303void bfad_remove_intr(struct bfad_s *bfad);
304void bfad_hal_mem_release(struct bfad_s *bfad);
305void bfad_hcb_comp(void *arg, bfa_status_t status);
Jing Huang7725ccf2009-09-23 17:46:15 -0700306
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700307int bfad_setup_intr(struct bfad_s *bfad);
308void bfad_remove_intr(struct bfad_s *bfad);
Jing Huang7725ccf2009-09-23 17:46:15 -0700309void bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg);
310bfa_status_t bfad_hal_mem_alloc(struct bfad_s *bfad);
311void bfad_bfa_tmo(unsigned long data);
312void bfad_init_timer(struct bfad_s *bfad);
313int bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad);
314void bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad);
Jing Huang7725ccf2009-09-23 17:46:15 -0700315void bfad_drv_uninit(struct bfad_s *bfad);
Jing Huangab2a9ba2010-07-08 20:02:55 -0700316int bfad_worker(void *ptr);
317void bfad_debugfs_init(struct bfad_port_s *port);
318void bfad_debugfs_exit(struct bfad_port_s *port);
Krishna Gudipatie6714322010-03-03 17:44:02 -0800319
Jing Huang7725ccf2009-09-23 17:46:15 -0700320void bfad_pci_remove(struct pci_dev *pdev);
321int bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid);
Maggie Zhangf16a1752010-12-09 19:12:32 -0800322void bfad_rport_online_wait(struct bfad_s *bfad);
323int bfad_get_linkup_delay(struct bfad_s *bfad);
Jing Huang7725ccf2009-09-23 17:46:15 -0700324int bfad_install_msix_handler(struct bfad_s *bfad);
325
326extern struct idr bfad_im_port_index;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700327extern struct pci_device_id bfad_id_table[];
Jing Huang7725ccf2009-09-23 17:46:15 -0700328extern struct list_head bfad_list;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700329extern char *os_name;
330extern char *os_patch;
331extern char *host_name;
332extern int num_rports;
333extern int num_ios;
334extern int num_tms;
335extern int num_fcxps;
336extern int num_ufbufs;
337extern int reqq_size;
338extern int rspq_size;
339extern int num_sgpgs;
340extern int rport_del_timeout;
341extern int bfa_lun_queue_depth;
342extern int bfa_io_max_sge;
Jing Huang88166242010-12-09 17:11:53 -0800343extern int bfa_log_level;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700344extern int ioc_auto_recover;
345extern int bfa_linkup_delay;
346extern int msix_disable_cb;
347extern int msix_disable_ct;
348extern int fdmi_enable;
349extern int supported_fc4s;
350extern int pcie_max_read_reqsz;
Krishna Gudipati61e62e22011-06-24 20:29:07 -0700351extern int max_xfer_size;
Jing Huangab2a9ba2010-07-08 20:02:55 -0700352extern int bfa_debugfs_enable;
Jing Huang42b426e2010-03-19 11:07:09 -0700353extern struct mutex bfad_mutex;
Jing Huang7725ccf2009-09-23 17:46:15 -0700354
355#endif /* __BFAD_DRV_H__ */