blob: 2f9213b257a4a231854e4d3043774647951187e4 [file] [log] [blame]
Thomas Gleixner52fa7bf2019-05-29 07:18:06 -07001// SPDX-License-Identifier: GPL-2.0-only
Jing Huang7725ccf2009-09-23 17:46:15 -07002/*
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05003 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
4 * Copyright (c) 2014- QLogic Corporation.
Jing Huang7725ccf2009-09-23 17:46:15 -07005 * All rights reserved
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05006 * www.qlogic.com
Jing Huang7725ccf2009-09-23 17:46:15 -07007 *
Anil Gurumurthy31e1d562015-11-26 03:54:46 -05008 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
Jing Huang7725ccf2009-09-23 17:46:15 -07009 */
10
Jing Huang5fbe25c2010-10-18 17:17:23 -070011/*
Jing Huang7725ccf2009-09-23 17:46:15 -070012 * bfad.c Linux driver PCI interface module.
13 */
Jing Huang7725ccf2009-09-23 17:46:15 -070014#include <linux/module.h>
Krishna Gudipatie6714322010-03-03 17:44:02 -080015#include <linux/kthread.h>
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070016#include <linux/errno.h>
17#include <linux/sched.h>
18#include <linux/init.h>
19#include <linux/fs.h>
20#include <linux/pci.h>
21#include <linux/firmware.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080022#include <linux/uaccess.h>
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070023#include <asm/fcntl.h>
24
Jing Huang7725ccf2009-09-23 17:46:15 -070025#include "bfad_drv.h"
26#include "bfad_im.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070027#include "bfa_fcs.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070028#include "bfa_defs.h"
29#include "bfa.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070030
31BFA_TRC_FILE(LDRV, BFAD);
Jing Huang42b426e2010-03-19 11:07:09 -070032DEFINE_MUTEX(bfad_mutex);
Jing Huang7725ccf2009-09-23 17:46:15 -070033LIST_HEAD(bfad_list);
Jing Huang7725ccf2009-09-23 17:46:15 -070034
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070035static int bfad_inst;
36static int num_sgpgs_parm;
37int supported_fc4s;
38char *host_name, *os_name, *os_patch;
39int num_rports, num_ios, num_tms;
40int num_fcxps, num_ufbufs;
41int reqq_size, rspq_size, num_sgpgs;
42int rport_del_timeout = BFA_FCS_RPORT_DEF_DEL_TIMEOUT;
43int bfa_lun_queue_depth = BFAD_LUN_QUEUE_DEPTH;
44int bfa_io_max_sge = BFAD_IO_MAX_SGE;
Jing Huang88166242010-12-09 17:11:53 -080045int bfa_log_level = 3; /* WARNING log level */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070046int ioc_auto_recover = BFA_TRUE;
47int bfa_linkup_delay = -1;
48int fdmi_enable = BFA_TRUE;
49int pcie_max_read_reqsz;
Jing Huangab2a9ba2010-07-08 20:02:55 -070050int bfa_debugfs_enable = 1;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070051int msix_disable_cb = 0, msix_disable_ct = 0;
Krishna Gudipati61e62e22011-06-24 20:29:07 -070052int max_xfer_size = BFAD_MAX_SECTORS >> 1;
Krishna Gudipati61ba4392012-08-22 19:52:58 -070053int max_rport_logins = BFA_FCS_MAX_RPORT_LOGINS;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070054
Jing Huang61338a02011-04-13 11:44:03 -070055/* Firmware releated */
Krishna Gudipati11189202011-06-13 15:50:35 -070056u32 bfi_image_cb_size, bfi_image_ct_size, bfi_image_ct2_size;
57u32 *bfi_image_cb, *bfi_image_ct, *bfi_image_ct2;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070058
Benjamin Poirier2d1148f2016-12-23 20:40:19 -080059#define BFAD_FW_FILE_CB "cbfw-3.2.5.1.bin"
60#define BFAD_FW_FILE_CT "ctfw-3.2.5.1.bin"
61#define BFAD_FW_FILE_CT2 "ct2fw-3.2.5.1.bin"
Jing Huang61338a02011-04-13 11:44:03 -070062
63static u32 *bfad_load_fwimg(struct pci_dev *pdev);
64static void bfad_free_fwimg(void);
65static void bfad_read_firmware(struct pci_dev *pdev, u32 **bfi_image,
66 u32 *bfi_image_size, char *fw_name);
67
Maggie52f94b62010-11-29 18:21:32 -080068static const char *msix_name_ct[] = {
Krishna Gudipati11189202011-06-13 15:50:35 -070069 "ctrl",
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070070 "cpe0", "cpe1", "cpe2", "cpe3",
Krishna Gudipati11189202011-06-13 15:50:35 -070071 "rme0", "rme1", "rme2", "rme3" };
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070072
Maggie52f94b62010-11-29 18:21:32 -080073static const char *msix_name_cb[] = {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070074 "cpe0", "cpe1", "cpe2", "cpe3",
75 "rme0", "rme1", "rme2", "rme3",
76 "eemc", "elpu0", "elpu1", "epss", "mlpu" };
77
Krishna Gudipati11189202011-06-13 15:50:35 -070078MODULE_FIRMWARE(BFAD_FW_FILE_CB);
79MODULE_FIRMWARE(BFAD_FW_FILE_CT);
80MODULE_FIRMWARE(BFAD_FW_FILE_CT2);
Jing Huang7725ccf2009-09-23 17:46:15 -070081
82module_param(os_name, charp, S_IRUGO | S_IWUSR);
Jing Huang604158ad2010-07-08 19:59:49 -070083MODULE_PARM_DESC(os_name, "OS name of the hba host machine");
Jing Huang7725ccf2009-09-23 17:46:15 -070084module_param(os_patch, charp, S_IRUGO | S_IWUSR);
Jing Huang604158ad2010-07-08 19:59:49 -070085MODULE_PARM_DESC(os_patch, "OS patch level of the hba host machine");
Jing Huang7725ccf2009-09-23 17:46:15 -070086module_param(host_name, charp, S_IRUGO | S_IWUSR);
Jing Huang604158ad2010-07-08 19:59:49 -070087MODULE_PARM_DESC(host_name, "Hostname of the hba host machine");
Jing Huang7725ccf2009-09-23 17:46:15 -070088module_param(num_rports, int, S_IRUGO | S_IWUSR);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070089MODULE_PARM_DESC(num_rports, "Max number of rports supported per port "
90 "(physical/logical), default=1024");
Jing Huang7725ccf2009-09-23 17:46:15 -070091module_param(num_ios, int, S_IRUGO | S_IWUSR);
Jing Huang604158ad2010-07-08 19:59:49 -070092MODULE_PARM_DESC(num_ios, "Max number of ioim requests, default=2000");
Jing Huang7725ccf2009-09-23 17:46:15 -070093module_param(num_tms, int, S_IRUGO | S_IWUSR);
Jing Huang604158ad2010-07-08 19:59:49 -070094MODULE_PARM_DESC(num_tms, "Max number of task im requests, default=128");
Jing Huang7725ccf2009-09-23 17:46:15 -070095module_param(num_fcxps, int, S_IRUGO | S_IWUSR);
Jing Huang604158ad2010-07-08 19:59:49 -070096MODULE_PARM_DESC(num_fcxps, "Max number of fcxp requests, default=64");
Jing Huang7725ccf2009-09-23 17:46:15 -070097module_param(num_ufbufs, int, S_IRUGO | S_IWUSR);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070098MODULE_PARM_DESC(num_ufbufs, "Max number of unsolicited frame "
99 "buffers, default=64");
Jing Huang7725ccf2009-09-23 17:46:15 -0700100module_param(reqq_size, int, S_IRUGO | S_IWUSR);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700101MODULE_PARM_DESC(reqq_size, "Max number of request queue elements, "
102 "default=256");
Jing Huang7725ccf2009-09-23 17:46:15 -0700103module_param(rspq_size, int, S_IRUGO | S_IWUSR);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700104MODULE_PARM_DESC(rspq_size, "Max number of response queue elements, "
105 "default=64");
Jing Huang7725ccf2009-09-23 17:46:15 -0700106module_param(num_sgpgs, int, S_IRUGO | S_IWUSR);
Jing Huang604158ad2010-07-08 19:59:49 -0700107MODULE_PARM_DESC(num_sgpgs, "Number of scatter/gather pages, default=2048");
Jing Huang7725ccf2009-09-23 17:46:15 -0700108module_param(rport_del_timeout, int, S_IRUGO | S_IWUSR);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700109MODULE_PARM_DESC(rport_del_timeout, "Rport delete timeout, default=90 secs, "
110 "Range[>0]");
Jing Huang7725ccf2009-09-23 17:46:15 -0700111module_param(bfa_lun_queue_depth, int, S_IRUGO | S_IWUSR);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700112MODULE_PARM_DESC(bfa_lun_queue_depth, "Lun queue depth, default=32, Range[>0]");
Jing Huang7725ccf2009-09-23 17:46:15 -0700113module_param(bfa_io_max_sge, int, S_IRUGO | S_IWUSR);
Jing Huang604158ad2010-07-08 19:59:49 -0700114MODULE_PARM_DESC(bfa_io_max_sge, "Max io scatter/gather elements, default=255");
Jing Huang88166242010-12-09 17:11:53 -0800115module_param(bfa_log_level, int, S_IRUGO | S_IWUSR);
116MODULE_PARM_DESC(bfa_log_level, "Driver log level, default=3, "
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700117 "Range[Critical:1|Error:2|Warning:3|Info:4]");
Jing Huang7725ccf2009-09-23 17:46:15 -0700118module_param(ioc_auto_recover, int, S_IRUGO | S_IWUSR);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700119MODULE_PARM_DESC(ioc_auto_recover, "IOC auto recovery, default=1, "
120 "Range[off:0|on:1]");
Jing Huang7725ccf2009-09-23 17:46:15 -0700121module_param(bfa_linkup_delay, int, S_IRUGO | S_IWUSR);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700122MODULE_PARM_DESC(bfa_linkup_delay, "Link up delay, default=30 secs for "
123 "boot port. Otherwise 10 secs in RHEL4 & 0 for "
124 "[RHEL5, SLES10, ESX40] Range[>0]");
125module_param(msix_disable_cb, int, S_IRUGO | S_IWUSR);
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500126MODULE_PARM_DESC(msix_disable_cb, "Disable Message Signaled Interrupts for QLogic-415/425/815/825 cards, default=0 Range[false:0|true:1]");
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700127module_param(msix_disable_ct, int, S_IRUGO | S_IWUSR);
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500128MODULE_PARM_DESC(msix_disable_ct, "Disable Message Signaled Interrupts if possible for QLogic-1010/1020/804/1007/902/1741 cards, default=0, Range[false:0|true:1]");
Jing Huang604158ad2010-07-08 19:59:49 -0700129module_param(fdmi_enable, int, S_IRUGO | S_IWUSR);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700130MODULE_PARM_DESC(fdmi_enable, "Enables fdmi registration, default=1, "
131 "Range[false:0|true:1]");
132module_param(pcie_max_read_reqsz, int, S_IRUGO | S_IWUSR);
133MODULE_PARM_DESC(pcie_max_read_reqsz, "PCIe max read request size, default=0 "
134 "(use system setting), Range[128|256|512|1024|2048|4096]");
Jing Huangab2a9ba2010-07-08 20:02:55 -0700135module_param(bfa_debugfs_enable, int, S_IRUGO | S_IWUSR);
136MODULE_PARM_DESC(bfa_debugfs_enable, "Enables debugfs feature, default=1,"
137 " Range[false:0|true:1]");
Krishna Gudipati61e62e22011-06-24 20:29:07 -0700138module_param(max_xfer_size, int, S_IRUGO | S_IWUSR);
139MODULE_PARM_DESC(max_xfer_size, "default=32MB,"
140 " Range[64k|128k|256k|512k|1024k|2048k]");
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700141module_param(max_rport_logins, int, S_IRUGO | S_IWUSR);
142MODULE_PARM_DESC(max_rport_logins, "Max number of logins to initiator and target rports on a port (physical/logical), default=1024");
Jing Huang7725ccf2009-09-23 17:46:15 -0700143
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700144static void
145bfad_sm_uninit(struct bfad_s *bfad, enum bfad_sm_event event);
146static void
147bfad_sm_created(struct bfad_s *bfad, enum bfad_sm_event event);
148static void
149bfad_sm_initializing(struct bfad_s *bfad, enum bfad_sm_event event);
150static void
151bfad_sm_operational(struct bfad_s *bfad, enum bfad_sm_event event);
152static void
153bfad_sm_stopping(struct bfad_s *bfad, enum bfad_sm_event event);
154static void
155bfad_sm_failed(struct bfad_s *bfad, enum bfad_sm_event event);
156static void
157bfad_sm_fcs_exit(struct bfad_s *bfad, enum bfad_sm_event event);
158
Jing Huang5fbe25c2010-10-18 17:17:23 -0700159/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700160 * Beginning state for the driver instance, awaiting the pci_probe event
Jing Huang7725ccf2009-09-23 17:46:15 -0700161 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700162static void
163bfad_sm_uninit(struct bfad_s *bfad, enum bfad_sm_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700164{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700165 bfa_trc(bfad, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700166
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700167 switch (event) {
168 case BFAD_E_CREATE:
169 bfa_sm_set_state(bfad, bfad_sm_created);
170 bfad->bfad_tsk = kthread_create(bfad_worker, (void *) bfad,
171 "%s", "bfad_worker");
172 if (IS_ERR(bfad->bfad_tsk)) {
173 printk(KERN_INFO "bfad[%d]: Kernel thread "
174 "creation failed!\n", bfad->inst_no);
175 bfa_sm_send_event(bfad, BFAD_E_KTHREAD_CREATE_FAILED);
176 }
177 bfa_sm_send_event(bfad, BFAD_E_INIT);
178 break;
Jing Huang7725ccf2009-09-23 17:46:15 -0700179
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700180 case BFAD_E_STOP:
181 /* Ignore stop; already in uninit */
182 break;
Jing Huang7725ccf2009-09-23 17:46:15 -0700183
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700184 default:
185 bfa_sm_fault(bfad, event);
186 }
187}
Krishna Gudipatie6714322010-03-03 17:44:02 -0800188
Jing Huang5fbe25c2010-10-18 17:17:23 -0700189/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700190 * Driver Instance is created, awaiting event INIT to initialize the bfad
191 */
192static void
193bfad_sm_created(struct bfad_s *bfad, enum bfad_sm_event event)
194{
195 unsigned long flags;
Vijaya Mohan Guvvada3e0be2013-11-21 01:37:33 -0800196 bfa_status_t ret;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700197
198 bfa_trc(bfad, event);
199
200 switch (event) {
201 case BFAD_E_INIT:
202 bfa_sm_set_state(bfad, bfad_sm_initializing);
203
204 init_completion(&bfad->comp);
205
206 /* Enable Interrupt and wait bfa_init completion */
207 if (bfad_setup_intr(bfad)) {
208 printk(KERN_WARNING "bfad%d: bfad_setup_intr failed\n",
209 bfad->inst_no);
Vijaya Mohan Guvvada3e0be2013-11-21 01:37:33 -0800210 bfa_sm_send_event(bfad, BFAD_E_INIT_FAILED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700211 break;
212 }
213
214 spin_lock_irqsave(&bfad->bfad_lock, flags);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800215 bfa_iocfc_init(&bfad->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700216 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
217
218 /* Set up interrupt handler for each vectors */
219 if ((bfad->bfad_flags & BFAD_MSIX_ON) &&
220 bfad_install_msix_handler(bfad)) {
221 printk(KERN_WARNING "%s: install_msix failed, bfad%d\n",
222 __func__, bfad->inst_no);
223 }
224
225 bfad_init_timer(bfad);
226
227 wait_for_completion(&bfad->comp);
228
229 if ((bfad->bfad_flags & BFAD_HAL_INIT_DONE)) {
230 bfa_sm_send_event(bfad, BFAD_E_INIT_SUCCESS);
231 } else {
Krishna Gudipati7c38c052011-04-14 16:50:35 -0700232 printk(KERN_WARNING
233 "bfa %s: bfa init failed\n",
234 bfad->pci_name);
Vijaya Mohan Guvvada3e0be2013-11-21 01:37:33 -0800235 spin_lock_irqsave(&bfad->bfad_lock, flags);
236 bfa_fcs_init(&bfad->bfa_fcs);
237 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
238
239 ret = bfad_cfg_pport(bfad, BFA_LPORT_ROLE_FCP_IM);
240 if (ret != BFA_STATUS_OK) {
241 init_completion(&bfad->comp);
242
243 spin_lock_irqsave(&bfad->bfad_lock, flags);
244 bfad->pport.flags |= BFAD_PORT_DELETE;
245 bfa_fcs_exit(&bfad->bfa_fcs);
246 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
247
248 wait_for_completion(&bfad->comp);
249
250 bfa_sm_send_event(bfad, BFAD_E_INIT_FAILED);
251 break;
252 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700253 bfad->bfad_flags |= BFAD_HAL_INIT_FAIL;
Vijaya Mohan Guvvada3e0be2013-11-21 01:37:33 -0800254 bfa_sm_send_event(bfad, BFAD_E_HAL_INIT_FAILED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700255 }
256
257 break;
258
259 case BFAD_E_KTHREAD_CREATE_FAILED:
260 bfa_sm_set_state(bfad, bfad_sm_uninit);
261 break;
262
263 default:
264 bfa_sm_fault(bfad, event);
265 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700266}
267
268static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700269bfad_sm_initializing(struct bfad_s *bfad, enum bfad_sm_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700270{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700271 int retval;
272 unsigned long flags;
273
274 bfa_trc(bfad, event);
275
276 switch (event) {
277 case BFAD_E_INIT_SUCCESS:
278 kthread_stop(bfad->bfad_tsk);
279 spin_lock_irqsave(&bfad->bfad_lock, flags);
280 bfad->bfad_tsk = NULL;
281 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
282
283 retval = bfad_start_ops(bfad);
Vijaya Mohan Guvvada3e0be2013-11-21 01:37:33 -0800284 if (retval != BFA_STATUS_OK) {
285 bfa_sm_set_state(bfad, bfad_sm_failed);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700286 break;
Vijaya Mohan Guvvada3e0be2013-11-21 01:37:33 -0800287 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700288 bfa_sm_set_state(bfad, bfad_sm_operational);
289 break;
290
Vijaya Mohan Guvvada3e0be2013-11-21 01:37:33 -0800291 case BFAD_E_INIT_FAILED:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700292 bfa_sm_set_state(bfad, bfad_sm_uninit);
293 kthread_stop(bfad->bfad_tsk);
294 spin_lock_irqsave(&bfad->bfad_lock, flags);
295 bfad->bfad_tsk = NULL;
296 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
297 break;
298
Vijaya Mohan Guvvada3e0be2013-11-21 01:37:33 -0800299 case BFAD_E_HAL_INIT_FAILED:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700300 bfa_sm_set_state(bfad, bfad_sm_failed);
301 break;
302 default:
303 bfa_sm_fault(bfad, event);
304 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700305}
306
307static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700308bfad_sm_failed(struct bfad_s *bfad, enum bfad_sm_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700309{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700310 int retval;
Jing Huang7725ccf2009-09-23 17:46:15 -0700311
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700312 bfa_trc(bfad, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700313
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700314 switch (event) {
315 case BFAD_E_INIT_SUCCESS:
316 retval = bfad_start_ops(bfad);
317 if (retval != BFA_STATUS_OK)
318 break;
319 bfa_sm_set_state(bfad, bfad_sm_operational);
320 break;
Jing Huang7725ccf2009-09-23 17:46:15 -0700321
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700322 case BFAD_E_STOP:
Vijaya Mohan Guvvada3e0be2013-11-21 01:37:33 -0800323 bfa_sm_set_state(bfad, bfad_sm_fcs_exit);
324 bfa_sm_send_event(bfad, BFAD_E_FCS_EXIT_COMP);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700325 break;
Jing Huang7725ccf2009-09-23 17:46:15 -0700326
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700327 case BFAD_E_EXIT_COMP:
328 bfa_sm_set_state(bfad, bfad_sm_uninit);
329 bfad_remove_intr(bfad);
330 del_timer_sync(&bfad->hal_tmo);
331 break;
Jing Huang7725ccf2009-09-23 17:46:15 -0700332
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700333 default:
334 bfa_sm_fault(bfad, event);
335 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700336}
337
338static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700339bfad_sm_operational(struct bfad_s *bfad, enum bfad_sm_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700340{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700341 bfa_trc(bfad, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700342
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700343 switch (event) {
344 case BFAD_E_STOP:
345 bfa_sm_set_state(bfad, bfad_sm_fcs_exit);
346 bfad_fcs_stop(bfad);
347 break;
Jing Huang7725ccf2009-09-23 17:46:15 -0700348
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700349 default:
350 bfa_sm_fault(bfad, event);
351 }
352}
353
354static void
355bfad_sm_fcs_exit(struct bfad_s *bfad, enum bfad_sm_event event)
356{
357 bfa_trc(bfad, event);
358
359 switch (event) {
360 case BFAD_E_FCS_EXIT_COMP:
361 bfa_sm_set_state(bfad, bfad_sm_stopping);
362 bfad_stop(bfad);
363 break;
364
365 default:
366 bfa_sm_fault(bfad, event);
367 }
368}
369
370static void
371bfad_sm_stopping(struct bfad_s *bfad, enum bfad_sm_event event)
372{
373 bfa_trc(bfad, event);
374
375 switch (event) {
376 case BFAD_E_EXIT_COMP:
377 bfa_sm_set_state(bfad, bfad_sm_uninit);
378 bfad_remove_intr(bfad);
379 del_timer_sync(&bfad->hal_tmo);
380 bfad_im_probe_undo(bfad);
381 bfad->bfad_flags &= ~BFAD_FC4_PROBE_DONE;
382 bfad_uncfg_pport(bfad);
383 break;
384
385 default:
386 bfa_sm_fault(bfad, event);
387 break;
388 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700389}
390
Jing Huang5fbe25c2010-10-18 17:17:23 -0700391/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700392 * BFA callbacks
393 */
394void
395bfad_hcb_comp(void *arg, bfa_status_t status)
396{
397 struct bfad_hal_comp *fcomp = (struct bfad_hal_comp *)arg;
398
399 fcomp->status = status;
400 complete(&fcomp->comp);
401}
402
Jing Huang5fbe25c2010-10-18 17:17:23 -0700403/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700404 * bfa_init callback
405 */
406void
407bfa_cb_init(void *drv, bfa_status_t init_status)
408{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700409 struct bfad_s *bfad = drv;
Jing Huang7725ccf2009-09-23 17:46:15 -0700410
Krishna Gudipatie6714322010-03-03 17:44:02 -0800411 if (init_status == BFA_STATUS_OK) {
Jing Huang7725ccf2009-09-23 17:46:15 -0700412 bfad->bfad_flags |= BFAD_HAL_INIT_DONE;
413
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700414 /*
415 * If BFAD_HAL_INIT_FAIL flag is set:
Krishna Gudipatie6714322010-03-03 17:44:02 -0800416 * Wake up the kernel thread to start
417 * the bfad operations after HAL init done
418 */
419 if ((bfad->bfad_flags & BFAD_HAL_INIT_FAIL)) {
420 bfad->bfad_flags &= ~BFAD_HAL_INIT_FAIL;
421 wake_up_process(bfad->bfad_tsk);
422 }
423 }
424
Jing Huang7725ccf2009-09-23 17:46:15 -0700425 complete(&bfad->comp);
426}
427
Jing Huang5fbe25c2010-10-18 17:17:23 -0700428/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700429 * BFA_FCS callbacks
430 */
Jing Huang7725ccf2009-09-23 17:46:15 -0700431struct bfad_port_s *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700432bfa_fcb_lport_new(struct bfad_s *bfad, struct bfa_fcs_lport_s *port,
433 enum bfa_lport_role roles, struct bfad_vf_s *vf_drv,
Jing Huang7725ccf2009-09-23 17:46:15 -0700434 struct bfad_vport_s *vp_drv)
435{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700436 bfa_status_t rc;
437 struct bfad_port_s *port_drv;
Jing Huang7725ccf2009-09-23 17:46:15 -0700438
439 if (!vp_drv && !vf_drv) {
440 port_drv = &bfad->pport;
441 port_drv->pvb_type = BFAD_PORT_PHYS_BASE;
442 } else if (!vp_drv && vf_drv) {
443 port_drv = &vf_drv->base_port;
444 port_drv->pvb_type = BFAD_PORT_VF_BASE;
445 } else if (vp_drv && !vf_drv) {
446 port_drv = &vp_drv->drv_port;
447 port_drv->pvb_type = BFAD_PORT_PHYS_VPORT;
448 } else {
449 port_drv = &vp_drv->drv_port;
450 port_drv->pvb_type = BFAD_PORT_VF_VPORT;
451 }
452
453 port_drv->fcs_port = port;
454 port_drv->roles = roles;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700455
456 if (roles & BFA_LPORT_ROLE_FCP_IM) {
457 rc = bfad_im_port_new(bfad, port_drv);
458 if (rc != BFA_STATUS_OK) {
459 bfad_im_port_delete(bfad, port_drv);
460 port_drv = NULL;
461 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700462 }
463
464 return port_drv;
465}
466
Jing Huang5fbe25c2010-10-18 17:17:23 -0700467/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700468 * FCS RPORT alloc callback, after successful PLOGI by FCS
469 */
470bfa_status_t
471bfa_fcb_rport_alloc(struct bfad_s *bfad, struct bfa_fcs_rport_s **rport,
472 struct bfad_rport_s **rport_drv)
473{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700474 bfa_status_t rc = BFA_STATUS_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700475
476 *rport_drv = kzalloc(sizeof(struct bfad_rport_s), GFP_ATOMIC);
477 if (*rport_drv == NULL) {
478 rc = BFA_STATUS_ENOMEM;
479 goto ext;
480 }
481
482 *rport = &(*rport_drv)->fcs_rport;
483
484ext:
485 return rc;
486}
487
Jing Huang5fbe25c2010-10-18 17:17:23 -0700488/*
Jing Huangd9883542010-07-08 19:46:26 -0700489 * FCS PBC VPORT Create
490 */
491void
492bfa_fcb_pbc_vport_create(struct bfad_s *bfad, struct bfi_pbc_vport_s pbc_vport)
493{
Jing Huang7725ccf2009-09-23 17:46:15 -0700494
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700495 struct bfa_lport_cfg_s port_cfg = {0};
496 struct bfad_vport_s *vport;
497 int rc;
Jing Huangd9883542010-07-08 19:46:26 -0700498
Alexey Khoroshilovdc6d2a02014-04-18 00:58:42 -0700499 vport = kzalloc(sizeof(struct bfad_vport_s), GFP_ATOMIC);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700500 if (!vport) {
Jing Huangd9883542010-07-08 19:46:26 -0700501 bfa_trc(bfad, 0);
502 return;
503 }
504
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700505 vport->drv_port.bfad = bfad;
506 port_cfg.roles = BFA_LPORT_ROLE_FCP_IM;
507 port_cfg.pwwn = pbc_vport.vp_pwwn;
508 port_cfg.nwwn = pbc_vport.vp_nwwn;
509 port_cfg.preboot_vp = BFA_TRUE;
Jing Huangd9883542010-07-08 19:46:26 -0700510
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700511 rc = bfa_fcs_pbc_vport_create(&vport->fcs_vport, &bfad->bfa_fcs, 0,
512 &port_cfg, vport);
Jing Huangd9883542010-07-08 19:46:26 -0700513
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700514 if (rc != BFA_STATUS_OK) {
515 bfa_trc(bfad, 0);
516 return;
517 }
518
519 list_add_tail(&vport->list_entry, &bfad->pbc_vport_list);
Jing Huangd9883542010-07-08 19:46:26 -0700520}
Jing Huang7725ccf2009-09-23 17:46:15 -0700521
522void
523bfad_hal_mem_release(struct bfad_s *bfad)
524{
Jing Huang7725ccf2009-09-23 17:46:15 -0700525 struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo;
Krishna Gudipati45070252011-06-24 20:24:29 -0700526 struct bfa_mem_dma_s *dma_info, *dma_elem;
527 struct bfa_mem_kva_s *kva_info, *kva_elem;
528 struct list_head *dm_qe, *km_qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700529
Krishna Gudipati45070252011-06-24 20:24:29 -0700530 dma_info = &hal_meminfo->dma_info;
531 kva_info = &hal_meminfo->kva_info;
532
533 /* Iterate through the KVA meminfo queue */
534 list_for_each(km_qe, &kva_info->qe) {
535 kva_elem = (struct bfa_mem_kva_s *) km_qe;
536 vfree(kva_elem->kva);
537 }
538
539 /* Iterate through the DMA meminfo queue */
540 list_for_each(dm_qe, &dma_info->qe) {
541 dma_elem = (struct bfa_mem_dma_s *) dm_qe;
542 dma_free_coherent(&bfad->pcidev->dev,
543 dma_elem->mem_len, dma_elem->kva,
544 (dma_addr_t) dma_elem->dma);
Jing Huang7725ccf2009-09-23 17:46:15 -0700545 }
546
547 memset(hal_meminfo, 0, sizeof(struct bfa_meminfo_s));
548}
549
550void
551bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg)
552{
553 if (num_rports > 0)
554 bfa_cfg->fwcfg.num_rports = num_rports;
555 if (num_ios > 0)
556 bfa_cfg->fwcfg.num_ioim_reqs = num_ios;
557 if (num_tms > 0)
558 bfa_cfg->fwcfg.num_tskim_reqs = num_tms;
Krishna Gudipati45070252011-06-24 20:24:29 -0700559 if (num_fcxps > 0 && num_fcxps <= BFA_FCXP_MAX)
Jing Huang7725ccf2009-09-23 17:46:15 -0700560 bfa_cfg->fwcfg.num_fcxp_reqs = num_fcxps;
Krishna Gudipati45070252011-06-24 20:24:29 -0700561 if (num_ufbufs > 0 && num_ufbufs <= BFA_UF_MAX)
Jing Huang7725ccf2009-09-23 17:46:15 -0700562 bfa_cfg->fwcfg.num_uf_bufs = num_ufbufs;
563 if (reqq_size > 0)
564 bfa_cfg->drvcfg.num_reqq_elems = reqq_size;
565 if (rspq_size > 0)
566 bfa_cfg->drvcfg.num_rspq_elems = rspq_size;
Krishna Gudipati45070252011-06-24 20:24:29 -0700567 if (num_sgpgs > 0 && num_sgpgs <= BFA_SGPG_MAX)
Jing Huang7725ccf2009-09-23 17:46:15 -0700568 bfa_cfg->drvcfg.num_sgpgs = num_sgpgs;
569
570 /*
571 * populate the hal values back to the driver for sysfs use.
572 * otherwise, the default values will be shown as 0 in sysfs
573 */
574 num_rports = bfa_cfg->fwcfg.num_rports;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700575 num_ios = bfa_cfg->fwcfg.num_ioim_reqs;
576 num_tms = bfa_cfg->fwcfg.num_tskim_reqs;
577 num_fcxps = bfa_cfg->fwcfg.num_fcxp_reqs;
Jing Huang7725ccf2009-09-23 17:46:15 -0700578 num_ufbufs = bfa_cfg->fwcfg.num_uf_bufs;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700579 reqq_size = bfa_cfg->drvcfg.num_reqq_elems;
580 rspq_size = bfa_cfg->drvcfg.num_rspq_elems;
581 num_sgpgs = bfa_cfg->drvcfg.num_sgpgs;
Jing Huang7725ccf2009-09-23 17:46:15 -0700582}
583
584bfa_status_t
585bfad_hal_mem_alloc(struct bfad_s *bfad)
586{
587 struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo;
Krishna Gudipati45070252011-06-24 20:24:29 -0700588 struct bfa_mem_dma_s *dma_info, *dma_elem;
589 struct bfa_mem_kva_s *kva_info, *kva_elem;
590 struct list_head *dm_qe, *km_qe;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700591 bfa_status_t rc = BFA_STATUS_OK;
Krishna Gudipati45070252011-06-24 20:24:29 -0700592 dma_addr_t phys_addr;
Jing Huang7725ccf2009-09-23 17:46:15 -0700593
594 bfa_cfg_get_default(&bfad->ioc_cfg);
Jing Huang7725ccf2009-09-23 17:46:15 -0700595 bfad_update_hal_cfg(&bfad->ioc_cfg);
596 bfad->cfg_data.ioc_queue_depth = bfad->ioc_cfg.fwcfg.num_ioim_reqs;
Krishna Gudipati45070252011-06-24 20:24:29 -0700597 bfa_cfg_get_meminfo(&bfad->ioc_cfg, hal_meminfo, &bfad->bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -0700598
Krishna Gudipati45070252011-06-24 20:24:29 -0700599 dma_info = &hal_meminfo->dma_info;
600 kva_info = &hal_meminfo->kva_info;
Jing Huang7725ccf2009-09-23 17:46:15 -0700601
Krishna Gudipati45070252011-06-24 20:24:29 -0700602 /* Iterate through the KVA meminfo queue */
603 list_for_each(km_qe, &kva_info->qe) {
604 kva_elem = (struct bfa_mem_kva_s *) km_qe;
Himanshu Jhabde70f32017-12-30 20:58:31 +0530605 kva_elem->kva = vzalloc(kva_elem->mem_len);
Krishna Gudipati45070252011-06-24 20:24:29 -0700606 if (kva_elem->kva == NULL) {
607 bfad_hal_mem_release(bfad);
608 rc = BFA_STATUS_ENOMEM;
609 goto ext;
Jing Huang7725ccf2009-09-23 17:46:15 -0700610 }
Krishna Gudipati45070252011-06-24 20:24:29 -0700611 }
612
613 /* Iterate through the DMA meminfo queue */
614 list_for_each(dm_qe, &dma_info->qe) {
615 dma_elem = (struct bfa_mem_dma_s *) dm_qe;
616 dma_elem->kva = dma_alloc_coherent(&bfad->pcidev->dev,
617 dma_elem->mem_len,
618 &phys_addr, GFP_KERNEL);
619 if (dma_elem->kva == NULL) {
620 bfad_hal_mem_release(bfad);
621 rc = BFA_STATUS_ENOMEM;
622 goto ext;
623 }
624 dma_elem->dma = phys_addr;
625 memset(dma_elem->kva, 0, dma_elem->mem_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700626 }
627ext:
628 return rc;
629}
630
Jing Huang5fbe25c2010-10-18 17:17:23 -0700631/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700632 * Create a vport under a vf.
633 */
634bfa_status_t
635bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700636 struct bfa_lport_cfg_s *port_cfg, struct device *dev)
Jing Huang7725ccf2009-09-23 17:46:15 -0700637{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700638 struct bfad_vport_s *vport;
639 int rc = BFA_STATUS_OK;
640 unsigned long flags;
Jing Huang7725ccf2009-09-23 17:46:15 -0700641 struct completion fcomp;
642
643 vport = kzalloc(sizeof(struct bfad_vport_s), GFP_KERNEL);
644 if (!vport) {
645 rc = BFA_STATUS_ENOMEM;
646 goto ext;
647 }
648
649 vport->drv_port.bfad = bfad;
650 spin_lock_irqsave(&bfad->bfad_lock, flags);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700651 rc = bfa_fcs_vport_create(&vport->fcs_vport, &bfad->bfa_fcs, vf_id,
652 port_cfg, vport);
Jing Huang7725ccf2009-09-23 17:46:15 -0700653 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
654
655 if (rc != BFA_STATUS_OK)
656 goto ext_free_vport;
657
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700658 if (port_cfg->roles & BFA_LPORT_ROLE_FCP_IM) {
Jing Huangb5042932010-03-19 11:05:39 -0700659 rc = bfad_im_scsi_host_alloc(bfad, vport->drv_port.im_port,
660 dev);
Jing Huang7725ccf2009-09-23 17:46:15 -0700661 if (rc != BFA_STATUS_OK)
662 goto ext_free_fcs_vport;
663 }
664
665 spin_lock_irqsave(&bfad->bfad_lock, flags);
666 bfa_fcs_vport_start(&vport->fcs_vport);
Krishna Gudipati5b7db7a2011-12-20 18:58:32 -0800667 list_add_tail(&vport->list_entry, &bfad->vport_list);
Jing Huang7725ccf2009-09-23 17:46:15 -0700668 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
669
670 return BFA_STATUS_OK;
671
672ext_free_fcs_vport:
673 spin_lock_irqsave(&bfad->bfad_lock, flags);
674 vport->comp_del = &fcomp;
675 init_completion(vport->comp_del);
676 bfa_fcs_vport_delete(&vport->fcs_vport);
677 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
678 wait_for_completion(vport->comp_del);
679ext_free_vport:
680 kfree(vport);
681ext:
682 return rc;
683}
684
Jing Huang7725ccf2009-09-23 17:46:15 -0700685void
Kees Cooke99e88a2017-10-16 14:43:17 -0700686bfad_bfa_tmo(struct timer_list *t)
Jing Huang7725ccf2009-09-23 17:46:15 -0700687{
Kees Cooke99e88a2017-10-16 14:43:17 -0700688 struct bfad_s *bfad = from_timer(bfad, t, hal_tmo);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700689 unsigned long flags;
690 struct list_head doneq;
Jing Huang7725ccf2009-09-23 17:46:15 -0700691
692 spin_lock_irqsave(&bfad->bfad_lock, flags);
693
Maggie Zhangf7f738122010-12-09 19:08:43 -0800694 bfa_timer_beat(&bfad->bfa.timer_mod);
Jing Huang7725ccf2009-09-23 17:46:15 -0700695
696 bfa_comp_deq(&bfad->bfa, &doneq);
697 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
698
699 if (!list_empty(&doneq)) {
700 bfa_comp_process(&bfad->bfa, &doneq);
701 spin_lock_irqsave(&bfad->bfad_lock, flags);
702 bfa_comp_free(&bfad->bfa, &doneq);
703 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
704 }
705
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700706 mod_timer(&bfad->hal_tmo,
707 jiffies + msecs_to_jiffies(BFA_TIMER_FREQ));
Jing Huang7725ccf2009-09-23 17:46:15 -0700708}
709
710void
711bfad_init_timer(struct bfad_s *bfad)
712{
Kees Cooke99e88a2017-10-16 14:43:17 -0700713 timer_setup(&bfad->hal_tmo, bfad_bfa_tmo, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700714
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700715 mod_timer(&bfad->hal_tmo,
716 jiffies + msecs_to_jiffies(BFA_TIMER_FREQ));
Jing Huang7725ccf2009-09-23 17:46:15 -0700717}
718
719int
720bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad)
721{
Hannes Reinecke11ea3822019-02-18 08:34:23 +0100722 int rc = -ENODEV;
Jing Huang7725ccf2009-09-23 17:46:15 -0700723
724 if (pci_enable_device(pdev)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700725 printk(KERN_ERR "pci_enable_device fail %p\n", pdev);
Jing Huang7725ccf2009-09-23 17:46:15 -0700726 goto out;
727 }
728
729 if (pci_request_regions(pdev, BFAD_DRIVER_NAME))
730 goto out_disable_device;
731
732 pci_set_master(pdev);
733
Hannes Reinecke11ea3822019-02-18 08:34:23 +0100734 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
735 if (rc)
736 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
737
738 if (rc) {
739 rc = -ENODEV;
Christoph Hellwiga69b0802018-10-18 15:10:14 +0200740 printk(KERN_ERR "dma_set_mask_and_coherent fail %p\n", pdev);
741 goto out_release_region;
Krishna Gudipati10a07372011-06-24 20:23:38 -0700742 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700743
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700744 /* Enable PCIE Advanced Error Recovery (AER) if kernel supports */
745 pci_enable_pcie_error_reporting(pdev);
746
Jing Huangb3522f02010-03-19 11:06:44 -0700747 bfad->pci_bar0_kva = pci_iomap(pdev, 0, pci_resource_len(pdev, 0));
Krishna Gudipati11189202011-06-13 15:50:35 -0700748 bfad->pci_bar2_kva = pci_iomap(pdev, 2, pci_resource_len(pdev, 2));
Jing Huang7725ccf2009-09-23 17:46:15 -0700749
750 if (bfad->pci_bar0_kva == NULL) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700751 printk(KERN_ERR "Fail to map bar0\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700752 goto out_release_region;
753 }
754
755 bfad->hal_pcidev.pci_slot = PCI_SLOT(pdev->devfn);
756 bfad->hal_pcidev.pci_func = PCI_FUNC(pdev->devfn);
757 bfad->hal_pcidev.pci_bar_kva = bfad->pci_bar0_kva;
758 bfad->hal_pcidev.device_id = pdev->device;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700759 bfad->hal_pcidev.ssid = pdev->subsystem_device;
Jing Huang7725ccf2009-09-23 17:46:15 -0700760 bfad->pci_name = pci_name(pdev);
761
762 bfad->pci_attr.vendor_id = pdev->vendor;
763 bfad->pci_attr.device_id = pdev->device;
764 bfad->pci_attr.ssid = pdev->subsystem_device;
765 bfad->pci_attr.ssvid = pdev->subsystem_vendor;
766 bfad->pci_attr.pcifn = PCI_FUNC(pdev->devfn);
767
768 bfad->pcidev = pdev;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700769
770 /* Adjust PCIe Maximum Read Request Size */
Yijing Wangc0102c02013-09-05 15:55:25 +0800771 if (pci_is_pcie(pdev) && pcie_max_read_reqsz) {
772 if (pcie_max_read_reqsz >= 128 &&
773 pcie_max_read_reqsz <= 4096 &&
774 is_power_of_2(pcie_max_read_reqsz)) {
775 int max_rq = pcie_get_readrq(pdev);
776 printk(KERN_WARNING "BFA[%s]: "
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700777 "pcie_max_read_request_size is %d, "
Yijing Wangc0102c02013-09-05 15:55:25 +0800778 "reset to %d\n", bfad->pci_name, max_rq,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700779 pcie_max_read_reqsz);
Yijing Wangc0102c02013-09-05 15:55:25 +0800780 pcie_set_readrq(pdev, pcie_max_read_reqsz);
781 } else {
782 printk(KERN_WARNING "BFA[%s]: invalid "
783 "pcie_max_read_request_size %d ignored\n",
784 bfad->pci_name, pcie_max_read_reqsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700785 }
786 }
787
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700788 pci_save_state(pdev);
789
Jing Huang7725ccf2009-09-23 17:46:15 -0700790 return 0;
791
792out_release_region:
793 pci_release_regions(pdev);
794out_disable_device:
795 pci_disable_device(pdev);
796out:
797 return rc;
798}
799
800void
801bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad)
802{
Jing Huang7725ccf2009-09-23 17:46:15 -0700803 pci_iounmap(pdev, bfad->pci_bar0_kva);
Krishna Gudipati11189202011-06-13 15:50:35 -0700804 pci_iounmap(pdev, bfad->pci_bar2_kva);
Jing Huang7725ccf2009-09-23 17:46:15 -0700805 pci_release_regions(pdev);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700806 /* Disable PCIE Advanced Error Recovery (AER) */
807 pci_disable_pcie_error_reporting(pdev);
Jing Huang7725ccf2009-09-23 17:46:15 -0700808 pci_disable_device(pdev);
Jing Huang7725ccf2009-09-23 17:46:15 -0700809}
810
Jing Huang7725ccf2009-09-23 17:46:15 -0700811bfa_status_t
812bfad_drv_init(struct bfad_s *bfad)
813{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700814 bfa_status_t rc;
815 unsigned long flags;
Jing Huang7725ccf2009-09-23 17:46:15 -0700816
817 bfad->cfg_data.rport_del_timeout = rport_del_timeout;
818 bfad->cfg_data.lun_queue_depth = bfa_lun_queue_depth;
819 bfad->cfg_data.io_max_sge = bfa_io_max_sge;
820 bfad->cfg_data.binding_method = FCP_PWWN_BINDING;
821
822 rc = bfad_hal_mem_alloc(bfad);
823 if (rc != BFA_STATUS_OK) {
824 printk(KERN_WARNING "bfad%d bfad_hal_mem_alloc failure\n",
825 bfad->inst_no);
826 printk(KERN_WARNING
Anil Gurumurthy31e1d562015-11-26 03:54:46 -0500827 "Not enough memory to attach all QLogic BR-series HBA ports. System may need more memory.\n");
Vijaya Mohan Guvvada3e0be2013-11-21 01:37:33 -0800828 return BFA_STATUS_FAILED;
Jing Huang7725ccf2009-09-23 17:46:15 -0700829 }
830
Maggie Zhangf7f738122010-12-09 19:08:43 -0800831 bfad->bfa.trcmod = bfad->trcmod;
832 bfad->bfa.plog = &bfad->plog_buf;
Jing Huang7725ccf2009-09-23 17:46:15 -0700833 bfa_plog_init(&bfad->plog_buf);
834 bfa_plog_str(&bfad->plog_buf, BFA_PL_MID_DRVR, BFA_PL_EID_DRIVER_START,
835 0, "Driver Attach");
836
837 bfa_attach(&bfad->bfa, bfad, &bfad->ioc_cfg, &bfad->meminfo,
838 &bfad->hal_pcidev);
839
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700840 /* FCS INIT */
Jing Huang7725ccf2009-09-23 17:46:15 -0700841 spin_lock_irqsave(&bfad->bfad_lock, flags);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800842 bfad->bfa_fcs.trcmod = bfad->trcmod;
Krishna Gudipati82794a22010-03-03 17:43:30 -0800843 bfa_fcs_attach(&bfad->bfa_fcs, &bfad->bfa, bfad, BFA_FALSE);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800844 bfad->bfa_fcs.fdmi_enabled = fdmi_enable;
Jing Huang7725ccf2009-09-23 17:46:15 -0700845 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
846
847 bfad->bfad_flags |= BFAD_DRV_INIT_DONE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700848
Jing Huang7725ccf2009-09-23 17:46:15 -0700849 return BFA_STATUS_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700850}
851
852void
853bfad_drv_uninit(struct bfad_s *bfad)
854{
Krishna Gudipatie6714322010-03-03 17:44:02 -0800855 unsigned long flags;
856
857 spin_lock_irqsave(&bfad->bfad_lock, flags);
858 init_completion(&bfad->comp);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800859 bfa_iocfc_stop(&bfad->bfa);
Krishna Gudipatie6714322010-03-03 17:44:02 -0800860 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
861 wait_for_completion(&bfad->comp);
862
Jing Huang7725ccf2009-09-23 17:46:15 -0700863 del_timer_sync(&bfad->hal_tmo);
864 bfa_isr_disable(&bfad->bfa);
865 bfa_detach(&bfad->bfa);
866 bfad_remove_intr(bfad);
Jing Huang7725ccf2009-09-23 17:46:15 -0700867 bfad_hal_mem_release(bfad);
Krishna Gudipatie6714322010-03-03 17:44:02 -0800868
869 bfad->bfad_flags &= ~BFAD_DRV_INIT_DONE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700870}
871
872void
873bfad_drv_start(struct bfad_s *bfad)
874{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700875 unsigned long flags;
Jing Huang7725ccf2009-09-23 17:46:15 -0700876
877 spin_lock_irqsave(&bfad->bfad_lock, flags);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800878 bfa_iocfc_start(&bfad->bfa);
Krishna Gudipati75332a72011-06-13 15:54:31 -0700879 bfa_fcs_pbc_vport_init(&bfad->bfa_fcs);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800880 bfa_fcs_fabric_modstart(&bfad->bfa_fcs);
Jing Huang7725ccf2009-09-23 17:46:15 -0700881 bfad->bfad_flags |= BFAD_HAL_START_DONE;
882 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
883
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700884 if (bfad->im)
885 flush_workqueue(bfad->im->drv_workq);
Jing Huang7725ccf2009-09-23 17:46:15 -0700886}
887
888void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700889bfad_fcs_stop(struct bfad_s *bfad)
Jing Huang7725ccf2009-09-23 17:46:15 -0700890{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700891 unsigned long flags;
Jing Huang7725ccf2009-09-23 17:46:15 -0700892
893 spin_lock_irqsave(&bfad->bfad_lock, flags);
894 init_completion(&bfad->comp);
895 bfad->pport.flags |= BFAD_PORT_DELETE;
896 bfa_fcs_exit(&bfad->bfa_fcs);
897 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
898 wait_for_completion(&bfad->comp);
899
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700900 bfa_sm_send_event(bfad, BFAD_E_FCS_EXIT_COMP);
901}
902
903void
904bfad_stop(struct bfad_s *bfad)
905{
906 unsigned long flags;
907
Jing Huang7725ccf2009-09-23 17:46:15 -0700908 spin_lock_irqsave(&bfad->bfad_lock, flags);
909 init_completion(&bfad->comp);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800910 bfa_iocfc_stop(&bfad->bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -0700911 bfad->bfad_flags &= ~BFAD_HAL_START_DONE;
912 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
913 wait_for_completion(&bfad->comp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700914
915 bfa_sm_send_event(bfad, BFAD_E_EXIT_COMP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700916}
917
918bfa_status_t
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700919bfad_cfg_pport(struct bfad_s *bfad, enum bfa_lport_role role)
Jing Huang7725ccf2009-09-23 17:46:15 -0700920{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700921 int rc = BFA_STATUS_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700922
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700923 /* Allocate scsi_host for the physical port */
924 if ((supported_fc4s & BFA_LPORT_ROLE_FCP_IM) &&
925 (role & BFA_LPORT_ROLE_FCP_IM)) {
Jing Huang7725ccf2009-09-23 17:46:15 -0700926 if (bfad->pport.im_port == NULL) {
927 rc = BFA_STATUS_FAILED;
928 goto out;
929 }
930
Jing Huangb5042932010-03-19 11:05:39 -0700931 rc = bfad_im_scsi_host_alloc(bfad, bfad->pport.im_port,
932 &bfad->pcidev->dev);
Jing Huang7725ccf2009-09-23 17:46:15 -0700933 if (rc != BFA_STATUS_OK)
934 goto out;
935
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700936 bfad->pport.roles |= BFA_LPORT_ROLE_FCP_IM;
Jing Huang7725ccf2009-09-23 17:46:15 -0700937 }
938
939 bfad->bfad_flags |= BFAD_CFG_PPORT_DONE;
940
941out:
942 return rc;
943}
944
945void
946bfad_uncfg_pport(struct bfad_s *bfad)
947{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700948 if ((supported_fc4s & BFA_LPORT_ROLE_FCP_IM) &&
949 (bfad->pport.roles & BFA_LPORT_ROLE_FCP_IM)) {
Jing Huang7725ccf2009-09-23 17:46:15 -0700950 bfad_im_scsi_host_free(bfad, bfad->pport.im_port);
951 bfad_im_port_clean(bfad->pport.im_port);
952 kfree(bfad->pport.im_port);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700953 bfad->pport.roles &= ~BFA_LPORT_ROLE_FCP_IM;
Jing Huang7725ccf2009-09-23 17:46:15 -0700954 }
955
956 bfad->bfad_flags &= ~BFAD_CFG_PPORT_DONE;
957}
958
Krishna Gudipatie6714322010-03-03 17:44:02 -0800959bfa_status_t
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700960bfad_start_ops(struct bfad_s *bfad) {
961
962 int retval;
963 unsigned long flags;
964 struct bfad_vport_s *vport, *vport_new;
965 struct bfa_fcs_driver_info_s driver_info;
966
Krishna Gudipati61e62e22011-06-24 20:29:07 -0700967 /* Limit min/max. xfer size to [64k-32MB] */
968 if (max_xfer_size < BFAD_MIN_SECTORS >> 1)
969 max_xfer_size = BFAD_MIN_SECTORS >> 1;
970 if (max_xfer_size > BFAD_MAX_SECTORS >> 1)
971 max_xfer_size = BFAD_MAX_SECTORS >> 1;
972
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700973 /* Fill the driver_info info to fcs*/
974 memset(&driver_info, 0, sizeof(driver_info));
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100975 strlcpy(driver_info.version, BFAD_DRIVER_VERSION,
976 sizeof(driver_info.version));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700977 if (host_name)
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100978 strlcpy(driver_info.host_machine_name, host_name,
979 sizeof(driver_info.host_machine_name));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700980 if (os_name)
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100981 strlcpy(driver_info.host_os_name, os_name,
982 sizeof(driver_info.host_os_name));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700983 if (os_patch)
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100984 strlcpy(driver_info.host_os_patch, os_patch,
985 sizeof(driver_info.host_os_patch));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700986
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100987 strlcpy(driver_info.os_device_name, bfad->pci_name,
988 sizeof(driver_info.os_device_name));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700989
Krishna Gudipati75332a72011-06-13 15:54:31 -0700990 /* FCS driver info init */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700991 spin_lock_irqsave(&bfad->bfad_lock, flags);
992 bfa_fcs_driver_info_init(&bfad->bfa_fcs, &driver_info);
Vijaya Mohan Guvvada3e0be2013-11-21 01:37:33 -0800993
994 if (bfad->bfad_flags & BFAD_CFG_PPORT_DONE)
995 bfa_fcs_update_cfg(&bfad->bfa_fcs);
996 else
997 bfa_fcs_init(&bfad->bfa_fcs);
998
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700999 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
Krishna Gudipatie6714322010-03-03 17:44:02 -08001000
Vijaya Mohan Guvvada3e0be2013-11-21 01:37:33 -08001001 if (!(bfad->bfad_flags & BFAD_CFG_PPORT_DONE)) {
1002 retval = bfad_cfg_pport(bfad, BFA_LPORT_ROLE_FCP_IM);
1003 if (retval != BFA_STATUS_OK)
1004 return BFA_STATUS_FAILED;
1005 }
Krishna Gudipati75332a72011-06-13 15:54:31 -07001006
1007 /* Setup fc host fixed attribute if the lk supports */
1008 bfad_fc_host_init(bfad->pport.im_port);
Krishna Gudipatie6714322010-03-03 17:44:02 -08001009
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001010 /* BFAD level FC4 IM specific resource allocation */
1011 retval = bfad_im_probe(bfad);
1012 if (retval != BFA_STATUS_OK) {
1013 printk(KERN_WARNING "bfad_im_probe failed\n");
1014 if (bfa_sm_cmp_state(bfad, bfad_sm_initializing))
1015 bfa_sm_set_state(bfad, bfad_sm_failed);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001016 return BFA_STATUS_FAILED;
1017 } else
1018 bfad->bfad_flags |= BFAD_FC4_PROBE_DONE;
1019
Krishna Gudipatie6714322010-03-03 17:44:02 -08001020 bfad_drv_start(bfad);
1021
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001022 /* Complete pbc vport create */
1023 list_for_each_entry_safe(vport, vport_new, &bfad->pbc_vport_list,
1024 list_entry) {
Jing Huangd9883542010-07-08 19:46:26 -07001025 struct fc_vport_identifiers vid;
1026 struct fc_vport *fc_vport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001027 char pwwn_buf[BFA_STRING_32];
Jing Huangd9883542010-07-08 19:46:26 -07001028
1029 memset(&vid, 0, sizeof(vid));
1030 vid.roles = FC_PORT_ROLE_FCP_INITIATOR;
1031 vid.vport_type = FC_PORTTYPE_NPIV;
1032 vid.disable = false;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001033 vid.node_name = wwn_to_u64((u8 *)
1034 (&((vport->fcs_vport).lport.port_cfg.nwwn)));
1035 vid.port_name = wwn_to_u64((u8 *)
1036 (&((vport->fcs_vport).lport.port_cfg.pwwn)));
Jing Huangd9883542010-07-08 19:46:26 -07001037 fc_vport = fc_vport_create(bfad->pport.im_port->shost, 0, &vid);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001038 if (!fc_vport) {
1039 wwn2str(pwwn_buf, vid.port_name);
Jing Huangd9883542010-07-08 19:46:26 -07001040 printk(KERN_WARNING "bfad%d: failed to create pbc vport"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001041 " %s\n", bfad->inst_no, pwwn_buf);
1042 }
1043 list_del(&vport->list_entry);
1044 kfree(vport);
Jing Huangd9883542010-07-08 19:46:26 -07001045 }
1046
Krishna Gudipatie6714322010-03-03 17:44:02 -08001047 /*
1048 * If bfa_linkup_delay is set to -1 default; try to retrive the
Maggie Zhangf16a1752010-12-09 19:12:32 -08001049 * value using the bfad_get_linkup_delay(); else use the
Krishna Gudipatie6714322010-03-03 17:44:02 -08001050 * passed in module param value as the bfa_linkup_delay.
1051 */
1052 if (bfa_linkup_delay < 0) {
Maggie Zhangf16a1752010-12-09 19:12:32 -08001053 bfa_linkup_delay = bfad_get_linkup_delay(bfad);
1054 bfad_rport_online_wait(bfad);
Krishna Gudipatie6714322010-03-03 17:44:02 -08001055 bfa_linkup_delay = -1;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001056 } else
Maggie Zhangf16a1752010-12-09 19:12:32 -08001057 bfad_rport_online_wait(bfad);
Krishna Gudipatie6714322010-03-03 17:44:02 -08001058
Jing Huang88166242010-12-09 17:11:53 -08001059 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "bfa device claimed\n");
Krishna Gudipatie6714322010-03-03 17:44:02 -08001060
1061 return BFA_STATUS_OK;
Krishna Gudipatie6714322010-03-03 17:44:02 -08001062}
1063
1064int
Jing Huangd9883542010-07-08 19:46:26 -07001065bfad_worker(void *ptr)
Krishna Gudipatie6714322010-03-03 17:44:02 -08001066{
Jiri Slaby8f7d3f02015-04-16 12:48:29 -07001067 struct bfad_s *bfad = ptr;
1068 unsigned long flags;
Krishna Gudipatie6714322010-03-03 17:44:02 -08001069
Jiri Slaby8f7d3f02015-04-16 12:48:29 -07001070 if (kthread_should_stop())
1071 return 0;
Krishna Gudipatie6714322010-03-03 17:44:02 -08001072
Jiri Slaby8f7d3f02015-04-16 12:48:29 -07001073 /* Send event BFAD_E_INIT_SUCCESS */
1074 bfa_sm_send_event(bfad, BFAD_E_INIT_SUCCESS);
Krishna Gudipatie6714322010-03-03 17:44:02 -08001075
Jiri Slaby8f7d3f02015-04-16 12:48:29 -07001076 spin_lock_irqsave(&bfad->bfad_lock, flags);
1077 bfad->bfad_tsk = NULL;
1078 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
Krishna Gudipatie6714322010-03-03 17:44:02 -08001079
1080 return 0;
1081}
1082
Jing Huang5fbe25c2010-10-18 17:17:23 -07001083/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001084 * BFA driver interrupt functions
1085 */
1086irqreturn_t
1087bfad_intx(int irq, void *dev_id)
1088{
1089 struct bfad_s *bfad = dev_id;
1090 struct list_head doneq;
1091 unsigned long flags;
1092 bfa_boolean_t rc;
1093
1094 spin_lock_irqsave(&bfad->bfad_lock, flags);
1095 rc = bfa_intx(&bfad->bfa);
1096 if (!rc) {
1097 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1098 return IRQ_NONE;
1099 }
1100
1101 bfa_comp_deq(&bfad->bfa, &doneq);
1102 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1103
1104 if (!list_empty(&doneq)) {
1105 bfa_comp_process(&bfad->bfa, &doneq);
1106
1107 spin_lock_irqsave(&bfad->bfad_lock, flags);
1108 bfa_comp_free(&bfad->bfa, &doneq);
1109 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001110 }
1111
1112 return IRQ_HANDLED;
1113
1114}
1115
1116static irqreturn_t
1117bfad_msix(int irq, void *dev_id)
1118{
1119 struct bfad_msix_s *vec = dev_id;
1120 struct bfad_s *bfad = vec->bfad;
1121 struct list_head doneq;
1122 unsigned long flags;
1123
1124 spin_lock_irqsave(&bfad->bfad_lock, flags);
1125
1126 bfa_msix(&bfad->bfa, vec->msix.entry);
1127 bfa_comp_deq(&bfad->bfa, &doneq);
1128 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1129
1130 if (!list_empty(&doneq)) {
1131 bfa_comp_process(&bfad->bfa, &doneq);
1132
1133 spin_lock_irqsave(&bfad->bfad_lock, flags);
1134 bfa_comp_free(&bfad->bfa, &doneq);
1135 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1136 }
1137
1138 return IRQ_HANDLED;
1139}
1140
Jing Huang5fbe25c2010-10-18 17:17:23 -07001141/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001142 * Initialize the MSIX entry table.
1143 */
1144static void
1145bfad_init_msix_entry(struct bfad_s *bfad, struct msix_entry *msix_entries,
1146 int mask, int max_bit)
1147{
1148 int i;
1149 int match = 0x00000001;
1150
1151 for (i = 0, bfad->nvec = 0; i < MAX_MSIX_ENTRY; i++) {
1152 if (mask & match) {
1153 bfad->msix_tab[bfad->nvec].msix.entry = i;
1154 bfad->msix_tab[bfad->nvec].bfad = bfad;
1155 msix_entries[bfad->nvec].entry = i;
1156 bfad->nvec++;
1157 }
1158
1159 match <<= 1;
1160 }
1161
1162}
1163
1164int
1165bfad_install_msix_handler(struct bfad_s *bfad)
1166{
1167 int i, error = 0;
1168
1169 for (i = 0; i < bfad->nvec; i++) {
1170 sprintf(bfad->msix_tab[i].name, "bfa-%s-%s",
1171 bfad->pci_name,
Krishna Gudipati11189202011-06-13 15:50:35 -07001172 ((bfa_asic_id_cb(bfad->hal_pcidev.device_id)) ?
1173 msix_name_cb[i] : msix_name_ct[i]));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001174
1175 error = request_irq(bfad->msix_tab[i].msix.vector,
1176 (irq_handler_t) bfad_msix, 0,
1177 bfad->msix_tab[i].name, &bfad->msix_tab[i]);
1178 bfa_trc(bfad, i);
1179 bfa_trc(bfad, bfad->msix_tab[i].msix.vector);
1180 if (error) {
1181 int j;
1182
1183 for (j = 0; j < i; j++)
1184 free_irq(bfad->msix_tab[j].msix.vector,
1185 &bfad->msix_tab[j]);
1186
Krishna Gudipati61e62e22011-06-24 20:29:07 -07001187 bfad->bfad_flags &= ~BFAD_MSIX_ON;
1188 pci_disable_msix(bfad->pcidev);
1189
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001190 return 1;
1191 }
1192 }
1193
1194 return 0;
1195}
1196
Jing Huang5fbe25c2010-10-18 17:17:23 -07001197/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001198 * Setup MSIX based interrupt.
1199 */
1200int
1201bfad_setup_intr(struct bfad_s *bfad)
1202{
Alexander Gordeev8cb7f632014-07-16 20:05:07 +02001203 int error;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001204 u32 mask = 0, i, num_bit = 0, max_bit = 0;
1205 struct msix_entry msix_entries[MAX_MSIX_ENTRY];
1206 struct pci_dev *pdev = bfad->pcidev;
Krishna Gudipati10a07372011-06-24 20:23:38 -07001207 u16 reg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001208
1209 /* Call BFA to get the msix map for this PCI function. */
1210 bfa_msix_getvecs(&bfad->bfa, &mask, &num_bit, &max_bit);
1211
1212 /* Set up the msix entry table */
1213 bfad_init_msix_entry(bfad, msix_entries, mask, max_bit);
1214
Krishna Gudipati11189202011-06-13 15:50:35 -07001215 if ((bfa_asic_id_ctc(pdev->device) && !msix_disable_ct) ||
1216 (bfa_asic_id_cb(pdev->device) && !msix_disable_cb)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001217
Alexander Gordeevb427d002014-07-16 20:05:08 +02001218 error = pci_enable_msix_exact(bfad->pcidev,
1219 msix_entries, bfad->nvec);
Alexander Gordeevcd69a092014-07-16 20:05:06 +02001220 /* In CT1 & CT2, try to allocate just one vector */
Alexander Gordeevb427d002014-07-16 20:05:08 +02001221 if (error == -ENOSPC && bfa_asic_id_ctc(pdev->device)) {
Alexander Gordeevcd69a092014-07-16 20:05:06 +02001222 printk(KERN_WARNING "bfa %s: trying one msix "
1223 "vector failed to allocate %d[%d]\n",
1224 bfad->pci_name, bfad->nvec, error);
1225 bfad->nvec = 1;
Alexander Gordeevb427d002014-07-16 20:05:08 +02001226 error = pci_enable_msix_exact(bfad->pcidev,
1227 msix_entries, 1);
Alexander Gordeevcd69a092014-07-16 20:05:06 +02001228 }
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001229
Alexander Gordeevcd69a092014-07-16 20:05:06 +02001230 if (error) {
1231 printk(KERN_WARNING "bfad%d: "
Alexander Gordeevb427d002014-07-16 20:05:08 +02001232 "pci_enable_msix_exact failed (%d), "
Alexander Gordeevcd69a092014-07-16 20:05:06 +02001233 "use line based.\n",
1234 bfad->inst_no, error);
1235 goto line_based;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001236 }
1237
Krishna Gudipati10a07372011-06-24 20:23:38 -07001238 /* Disable INTX in MSI-X mode */
1239 pci_read_config_word(pdev, PCI_COMMAND, &reg);
1240
1241 if (!(reg & PCI_COMMAND_INTX_DISABLE))
1242 pci_write_config_word(pdev, PCI_COMMAND,
1243 reg | PCI_COMMAND_INTX_DISABLE);
1244
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001245 /* Save the vectors */
1246 for (i = 0; i < bfad->nvec; i++) {
1247 bfa_trc(bfad, msix_entries[i].vector);
1248 bfad->msix_tab[i].msix.vector = msix_entries[i].vector;
1249 }
1250
1251 bfa_msix_init(&bfad->bfa, bfad->nvec);
1252
1253 bfad->bfad_flags |= BFAD_MSIX_ON;
1254
Alexander Gordeev8cb7f632014-07-16 20:05:07 +02001255 return 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001256 }
1257
1258line_based:
Alexander Gordeev8cb7f632014-07-16 20:05:07 +02001259 error = request_irq(bfad->pcidev->irq, (irq_handler_t)bfad_intx,
1260 BFAD_IRQ_FLAGS, BFAD_DRIVER_NAME, bfad);
1261 if (error)
1262 return error;
1263
Krishna Gudipati61e62e22011-06-24 20:29:07 -07001264 bfad->bfad_flags |= BFAD_INTX_ON;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001265
Alexander Gordeev8cb7f632014-07-16 20:05:07 +02001266 return 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001267}
1268
1269void
1270bfad_remove_intr(struct bfad_s *bfad)
1271{
1272 int i;
1273
1274 if (bfad->bfad_flags & BFAD_MSIX_ON) {
1275 for (i = 0; i < bfad->nvec; i++)
1276 free_irq(bfad->msix_tab[i].msix.vector,
1277 &bfad->msix_tab[i]);
1278
1279 pci_disable_msix(bfad->pcidev);
1280 bfad->bfad_flags &= ~BFAD_MSIX_ON;
Krishna Gudipati61e62e22011-06-24 20:29:07 -07001281 } else if (bfad->bfad_flags & BFAD_INTX_ON) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001282 free_irq(bfad->pcidev->irq, bfad);
1283 }
1284}
Jing Huang7725ccf2009-09-23 17:46:15 -07001285
Jing Huang5fbe25c2010-10-18 17:17:23 -07001286/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001287 * PCI probe entry.
1288 */
1289int
1290bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
1291{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001292 struct bfad_s *bfad;
Krishna Gudipati7826f302011-07-20 16:59:13 -07001293 int error = -ENODEV, retval, i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001294
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001295 /* For single port cards - only claim function 0 */
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001296 if ((pdev->device == BFA_PCI_DEVICE_ID_FC_8G1P) &&
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001297 (PCI_FUNC(pdev->devfn) != 0))
Jing Huang7725ccf2009-09-23 17:46:15 -07001298 return -ENODEV;
1299
Jing Huang7725ccf2009-09-23 17:46:15 -07001300 bfad = kzalloc(sizeof(struct bfad_s), GFP_KERNEL);
1301 if (!bfad) {
1302 error = -ENOMEM;
1303 goto out;
1304 }
1305
1306 bfad->trcmod = kzalloc(sizeof(struct bfa_trc_mod_s), GFP_KERNEL);
1307 if (!bfad->trcmod) {
1308 printk(KERN_WARNING "Error alloc trace buffer!\n");
1309 error = -ENOMEM;
1310 goto out_alloc_trace_failure;
1311 }
1312
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001313 /* TRACE INIT */
Jing Huang7725ccf2009-09-23 17:46:15 -07001314 bfa_trc_init(bfad->trcmod);
1315 bfa_trc(bfad, bfad_inst);
1316
Krishna Gudipati7826f302011-07-20 16:59:13 -07001317 /* AEN INIT */
1318 INIT_LIST_HEAD(&bfad->free_aen_q);
1319 INIT_LIST_HEAD(&bfad->active_aen_q);
1320 for (i = 0; i < BFA_AEN_MAX_ENTRY; i++)
1321 list_add_tail(&bfad->aen_list[i].qe, &bfad->free_aen_q);
1322
Jing Huang7725ccf2009-09-23 17:46:15 -07001323 if (!(bfad_load_fwimg(pdev))) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001324 kfree(bfad->trcmod);
1325 goto out_alloc_trace_failure;
1326 }
1327
1328 retval = bfad_pci_init(pdev, bfad);
1329 if (retval) {
1330 printk(KERN_WARNING "bfad_pci_init failure!\n");
1331 error = retval;
1332 goto out_pci_init_failure;
1333 }
1334
1335 mutex_lock(&bfad_mutex);
1336 bfad->inst_no = bfad_inst++;
1337 list_add_tail(&bfad->list_entry, &bfad_list);
1338 mutex_unlock(&bfad_mutex);
1339
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001340 /* Initializing the state machine: State set to uninit */
1341 bfa_sm_set_state(bfad, bfad_sm_uninit);
1342
Jing Huang7725ccf2009-09-23 17:46:15 -07001343 spin_lock_init(&bfad->bfad_lock);
Kyle McMartin0b1017a2012-07-11 12:42:55 -04001344 spin_lock_init(&bfad->bfad_aen_spinlock);
1345
Jing Huang7725ccf2009-09-23 17:46:15 -07001346 pci_set_drvdata(pdev, bfad);
1347
1348 bfad->ref_count = 0;
1349 bfad->pport.bfad = bfad;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001350 INIT_LIST_HEAD(&bfad->pbc_vport_list);
Krishna Gudipati5b7db7a2011-12-20 18:58:32 -08001351 INIT_LIST_HEAD(&bfad->vport_list);
Krishna Gudipatie6714322010-03-03 17:44:02 -08001352
Krishna Gudipati7c38c052011-04-14 16:50:35 -07001353 /* Setup the debugfs node for this bfad */
1354 if (bfa_debugfs_enable)
1355 bfad_debugfs_init(&bfad->pport);
1356
Jing Huang7725ccf2009-09-23 17:46:15 -07001357 retval = bfad_drv_init(bfad);
1358 if (retval != BFA_STATUS_OK)
1359 goto out_drv_init_failure;
Jing Huang7725ccf2009-09-23 17:46:15 -07001360
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001361 bfa_sm_send_event(bfad, BFAD_E_CREATE);
Jing Huang7725ccf2009-09-23 17:46:15 -07001362
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001363 if (bfa_sm_cmp_state(bfad, bfad_sm_uninit))
1364 goto out_bfad_sm_failure;
Jing Huang7725ccf2009-09-23 17:46:15 -07001365
Jing Huang7725ccf2009-09-23 17:46:15 -07001366 return 0;
1367
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001368out_bfad_sm_failure:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001369 bfad_hal_mem_release(bfad);
Jing Huang7725ccf2009-09-23 17:46:15 -07001370out_drv_init_failure:
Krishna Gudipati7c38c052011-04-14 16:50:35 -07001371 /* Remove the debugfs node for this bfad */
1372 kfree(bfad->regdata);
1373 bfad_debugfs_exit(&bfad->pport);
Jing Huang7725ccf2009-09-23 17:46:15 -07001374 mutex_lock(&bfad_mutex);
1375 bfad_inst--;
1376 list_del(&bfad->list_entry);
1377 mutex_unlock(&bfad_mutex);
1378 bfad_pci_uninit(pdev, bfad);
1379out_pci_init_failure:
1380 kfree(bfad->trcmod);
1381out_alloc_trace_failure:
1382 kfree(bfad);
1383out:
1384 return error;
1385}
1386
Jing Huang5fbe25c2010-10-18 17:17:23 -07001387/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001388 * PCI remove entry.
1389 */
1390void
1391bfad_pci_remove(struct pci_dev *pdev)
1392{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001393 struct bfad_s *bfad = pci_get_drvdata(pdev);
1394 unsigned long flags;
Jing Huang7725ccf2009-09-23 17:46:15 -07001395
1396 bfa_trc(bfad, bfad->inst_no);
1397
Krishna Gudipatie6714322010-03-03 17:44:02 -08001398 spin_lock_irqsave(&bfad->bfad_lock, flags);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001399 if (bfad->bfad_tsk != NULL) {
1400 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
Krishna Gudipatie6714322010-03-03 17:44:02 -08001401 kthread_stop(bfad->bfad_tsk);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001402 } else {
Jing Huang7725ccf2009-09-23 17:46:15 -07001403 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
Jing Huang7725ccf2009-09-23 17:46:15 -07001404 }
1405
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001406 /* Send Event BFAD_E_STOP */
1407 bfa_sm_send_event(bfad, BFAD_E_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -07001408
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001409 /* Driver detach and dealloc mem */
Jing Huang7725ccf2009-09-23 17:46:15 -07001410 spin_lock_irqsave(&bfad->bfad_lock, flags);
1411 bfa_detach(&bfad->bfa);
1412 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1413 bfad_hal_mem_release(bfad);
Jing Huang7725ccf2009-09-23 17:46:15 -07001414
Krishna Gudipati7c38c052011-04-14 16:50:35 -07001415 /* Remove the debugfs node for this bfad */
1416 kfree(bfad->regdata);
1417 bfad_debugfs_exit(&bfad->pport);
1418
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001419 /* Cleaning the BFAD instance */
Jing Huang7725ccf2009-09-23 17:46:15 -07001420 mutex_lock(&bfad_mutex);
1421 bfad_inst--;
1422 list_del(&bfad->list_entry);
1423 mutex_unlock(&bfad_mutex);
1424 bfad_pci_uninit(pdev, bfad);
1425
1426 kfree(bfad->trcmod);
1427 kfree(bfad);
1428}
1429
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001430/*
1431 * PCI Error Recovery entry, error detected.
1432 */
1433static pci_ers_result_t
1434bfad_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
1435{
1436 struct bfad_s *bfad = pci_get_drvdata(pdev);
1437 unsigned long flags;
1438 pci_ers_result_t ret = PCI_ERS_RESULT_NONE;
1439
1440 dev_printk(KERN_ERR, &pdev->dev,
1441 "error detected state: %d - flags: 0x%x\n",
1442 state, bfad->bfad_flags);
1443
1444 switch (state) {
1445 case pci_channel_io_normal: /* non-fatal error */
1446 spin_lock_irqsave(&bfad->bfad_lock, flags);
1447 bfad->bfad_flags &= ~BFAD_EEH_BUSY;
1448 /* Suspend/fail all bfa operations */
1449 bfa_ioc_suspend(&bfad->bfa.ioc);
1450 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1451 del_timer_sync(&bfad->hal_tmo);
1452 ret = PCI_ERS_RESULT_CAN_RECOVER;
1453 break;
1454 case pci_channel_io_frozen: /* fatal error */
1455 init_completion(&bfad->comp);
1456 spin_lock_irqsave(&bfad->bfad_lock, flags);
1457 bfad->bfad_flags |= BFAD_EEH_BUSY;
1458 /* Suspend/fail all bfa operations */
1459 bfa_ioc_suspend(&bfad->bfa.ioc);
1460 bfa_fcs_stop(&bfad->bfa_fcs);
1461 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1462 wait_for_completion(&bfad->comp);
1463
1464 bfad_remove_intr(bfad);
1465 del_timer_sync(&bfad->hal_tmo);
1466 pci_disable_device(pdev);
1467 ret = PCI_ERS_RESULT_NEED_RESET;
1468 break;
1469 case pci_channel_io_perm_failure: /* PCI Card is DEAD */
1470 spin_lock_irqsave(&bfad->bfad_lock, flags);
1471 bfad->bfad_flags |= BFAD_EEH_BUSY |
1472 BFAD_EEH_PCI_CHANNEL_IO_PERM_FAILURE;
1473 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1474
1475 /* If the error_detected handler is called with the reason
1476 * pci_channel_io_perm_failure - it will subsequently call
1477 * pci_remove() entry point to remove the pci device from the
1478 * system - So defer the cleanup to pci_remove(); cleaning up
1479 * here causes inconsistent state during pci_remove().
1480 */
1481 ret = PCI_ERS_RESULT_DISCONNECT;
1482 break;
1483 default:
1484 WARN_ON(1);
1485 }
1486
1487 return ret;
1488}
1489
1490int
1491restart_bfa(struct bfad_s *bfad)
1492{
1493 unsigned long flags;
1494 struct pci_dev *pdev = bfad->pcidev;
1495
1496 bfa_attach(&bfad->bfa, bfad, &bfad->ioc_cfg,
1497 &bfad->meminfo, &bfad->hal_pcidev);
1498
1499 /* Enable Interrupt and wait bfa_init completion */
1500 if (bfad_setup_intr(bfad)) {
1501 dev_printk(KERN_WARNING, &pdev->dev,
1502 "%s: bfad_setup_intr failed\n", bfad->pci_name);
Vijaya Mohan Guvvada3e0be2013-11-21 01:37:33 -08001503 bfa_sm_send_event(bfad, BFAD_E_INIT_FAILED);
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001504 return -1;
1505 }
1506
1507 init_completion(&bfad->comp);
1508 spin_lock_irqsave(&bfad->bfad_lock, flags);
1509 bfa_iocfc_init(&bfad->bfa);
1510 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1511
1512 /* Set up interrupt handler for each vectors */
1513 if ((bfad->bfad_flags & BFAD_MSIX_ON) &&
1514 bfad_install_msix_handler(bfad))
1515 dev_printk(KERN_WARNING, &pdev->dev,
1516 "%s: install_msix failed.\n", bfad->pci_name);
1517
1518 bfad_init_timer(bfad);
1519 wait_for_completion(&bfad->comp);
1520 bfad_drv_start(bfad);
1521
1522 return 0;
1523}
1524
1525/*
1526 * PCI Error Recovery entry, re-initialize the chip.
1527 */
1528static pci_ers_result_t
1529bfad_pci_slot_reset(struct pci_dev *pdev)
1530{
1531 struct bfad_s *bfad = pci_get_drvdata(pdev);
1532 u8 byte;
Hannes Reinecke11ea3822019-02-18 08:34:23 +01001533 int rc;
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001534
1535 dev_printk(KERN_ERR, &pdev->dev,
1536 "bfad_pci_slot_reset flags: 0x%x\n", bfad->bfad_flags);
1537
1538 if (pci_enable_device(pdev)) {
1539 dev_printk(KERN_ERR, &pdev->dev, "Cannot re-enable "
1540 "PCI device after reset.\n");
1541 return PCI_ERS_RESULT_DISCONNECT;
1542 }
1543
1544 pci_restore_state(pdev);
1545
1546 /*
1547 * Read some byte (e.g. DMA max. payload size which can't
1548 * be 0xff any time) to make sure - we did not hit another PCI error
1549 * in the middle of recovery. If we did, then declare permanent failure.
1550 */
1551 pci_read_config_byte(pdev, 0x68, &byte);
1552 if (byte == 0xff) {
1553 dev_printk(KERN_ERR, &pdev->dev,
1554 "slot_reset failed ... got another PCI error !\n");
1555 goto out_disable_device;
1556 }
1557
1558 pci_save_state(pdev);
1559 pci_set_master(pdev);
1560
Hannes Reinecke11ea3822019-02-18 08:34:23 +01001561 rc = dma_set_mask_and_coherent(&bfad->pcidev->dev, DMA_BIT_MASK(64));
1562 if (rc)
1563 rc = dma_set_mask_and_coherent(&bfad->pcidev->dev,
1564 DMA_BIT_MASK(32));
1565 if (rc)
Christoph Hellwiga69b0802018-10-18 15:10:14 +02001566 goto out_disable_device;
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001567
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001568 if (restart_bfa(bfad) == -1)
1569 goto out_disable_device;
1570
1571 pci_enable_pcie_error_reporting(pdev);
1572 dev_printk(KERN_WARNING, &pdev->dev,
1573 "slot_reset completed flags: 0x%x!\n", bfad->bfad_flags);
1574
1575 return PCI_ERS_RESULT_RECOVERED;
1576
1577out_disable_device:
1578 pci_disable_device(pdev);
1579 return PCI_ERS_RESULT_DISCONNECT;
1580}
1581
1582static pci_ers_result_t
1583bfad_pci_mmio_enabled(struct pci_dev *pdev)
1584{
1585 unsigned long flags;
1586 struct bfad_s *bfad = pci_get_drvdata(pdev);
1587
1588 dev_printk(KERN_INFO, &pdev->dev, "mmio_enabled\n");
1589
1590 /* Fetch FW diagnostic information */
1591 bfa_ioc_debug_save_ftrc(&bfad->bfa.ioc);
1592
1593 /* Cancel all pending IOs */
1594 spin_lock_irqsave(&bfad->bfad_lock, flags);
1595 init_completion(&bfad->comp);
1596 bfa_fcs_stop(&bfad->bfa_fcs);
1597 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1598 wait_for_completion(&bfad->comp);
1599
1600 bfad_remove_intr(bfad);
1601 del_timer_sync(&bfad->hal_tmo);
1602 pci_disable_device(pdev);
1603
1604 return PCI_ERS_RESULT_NEED_RESET;
1605}
1606
1607static void
1608bfad_pci_resume(struct pci_dev *pdev)
1609{
1610 unsigned long flags;
1611 struct bfad_s *bfad = pci_get_drvdata(pdev);
1612
1613 dev_printk(KERN_WARNING, &pdev->dev, "resume\n");
1614
1615 /* wait until the link is online */
1616 bfad_rport_online_wait(bfad);
1617
1618 spin_lock_irqsave(&bfad->bfad_lock, flags);
1619 bfad->bfad_flags &= ~BFAD_EEH_BUSY;
1620 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1621}
1622
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001623struct pci_device_id bfad_id_table[] = {
Jing Huang7725ccf2009-09-23 17:46:15 -07001624 {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001625 .vendor = BFA_PCI_VENDOR_ID_BROCADE,
1626 .device = BFA_PCI_DEVICE_ID_FC_8G2P,
1627 .subvendor = PCI_ANY_ID,
1628 .subdevice = PCI_ANY_ID,
1629 },
Jing Huang7725ccf2009-09-23 17:46:15 -07001630 {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001631 .vendor = BFA_PCI_VENDOR_ID_BROCADE,
1632 .device = BFA_PCI_DEVICE_ID_FC_8G1P,
1633 .subvendor = PCI_ANY_ID,
1634 .subdevice = PCI_ANY_ID,
1635 },
Jing Huang7725ccf2009-09-23 17:46:15 -07001636 {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001637 .vendor = BFA_PCI_VENDOR_ID_BROCADE,
1638 .device = BFA_PCI_DEVICE_ID_CT,
1639 .subvendor = PCI_ANY_ID,
1640 .subdevice = PCI_ANY_ID,
1641 .class = (PCI_CLASS_SERIAL_FIBER << 8),
1642 .class_mask = ~0,
1643 },
Jing Huang293f82d2010-07-08 19:45:20 -07001644 {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001645 .vendor = BFA_PCI_VENDOR_ID_BROCADE,
1646 .device = BFA_PCI_DEVICE_ID_CT_FC,
1647 .subvendor = PCI_ANY_ID,
1648 .subdevice = PCI_ANY_ID,
1649 .class = (PCI_CLASS_SERIAL_FIBER << 8),
1650 .class_mask = ~0,
Jing Huang293f82d2010-07-08 19:45:20 -07001651 },
Krishna Gudipati11189202011-06-13 15:50:35 -07001652 {
1653 .vendor = BFA_PCI_VENDOR_ID_BROCADE,
1654 .device = BFA_PCI_DEVICE_ID_CT2,
1655 .subvendor = PCI_ANY_ID,
1656 .subdevice = PCI_ANY_ID,
1657 .class = (PCI_CLASS_SERIAL_FIBER << 8),
1658 .class_mask = ~0,
1659 },
Jing Huang7725ccf2009-09-23 17:46:15 -07001660
Vijaya Mohan Guvvaf9c867b2013-05-13 02:33:33 -07001661 {
1662 .vendor = BFA_PCI_VENDOR_ID_BROCADE,
1663 .device = BFA_PCI_DEVICE_ID_CT2_QUAD,
1664 .subvendor = PCI_ANY_ID,
1665 .subdevice = PCI_ANY_ID,
1666 .class = (PCI_CLASS_SERIAL_FIBER << 8),
1667 .class_mask = ~0,
1668 },
Jing Huang7725ccf2009-09-23 17:46:15 -07001669 {0, 0},
1670};
1671
1672MODULE_DEVICE_TABLE(pci, bfad_id_table);
1673
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001674/*
1675 * PCI error recovery handlers.
1676 */
1677static struct pci_error_handlers bfad_err_handler = {
1678 .error_detected = bfad_pci_error_detected,
1679 .slot_reset = bfad_pci_slot_reset,
1680 .mmio_enabled = bfad_pci_mmio_enabled,
1681 .resume = bfad_pci_resume,
1682};
1683
Jing Huang7725ccf2009-09-23 17:46:15 -07001684static struct pci_driver bfad_pci_driver = {
1685 .name = BFAD_DRIVER_NAME,
1686 .id_table = bfad_id_table,
1687 .probe = bfad_pci_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08001688 .remove = bfad_pci_remove,
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001689 .err_handler = &bfad_err_handler,
Jing Huang7725ccf2009-09-23 17:46:15 -07001690};
1691
Jing Huang5fbe25c2010-10-18 17:17:23 -07001692/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001693 * Driver module init.
1694 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001695static int __init
Jing Huang7725ccf2009-09-23 17:46:15 -07001696bfad_init(void)
1697{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001698 int error = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07001699
Anil Gurumurthy31e1d562015-11-26 03:54:46 -05001700 pr_info("QLogic BR-series BFA FC/FCOE SCSI driver - version: %s\n",
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001701 BFAD_DRIVER_VERSION);
Jing Huang7725ccf2009-09-23 17:46:15 -07001702
1703 if (num_sgpgs > 0)
1704 num_sgpgs_parm = num_sgpgs;
1705
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001706 error = bfad_im_module_init();
Jing Huang7725ccf2009-09-23 17:46:15 -07001707 if (error) {
1708 error = -ENOMEM;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001709 printk(KERN_WARNING "bfad_im_module_init failure\n");
Jing Huang7725ccf2009-09-23 17:46:15 -07001710 goto ext;
1711 }
1712
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001713 if (strcmp(FCPI_NAME, " fcpim") == 0)
1714 supported_fc4s |= BFA_LPORT_ROLE_FCP_IM;
Jing Huang7725ccf2009-09-23 17:46:15 -07001715
Maggie Zhangf7f738122010-12-09 19:08:43 -08001716 bfa_auto_recover = ioc_auto_recover;
Jing Huang7725ccf2009-09-23 17:46:15 -07001717 bfa_fcs_rport_set_del_timeout(rport_del_timeout);
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001718 bfa_fcs_rport_set_max_logins(max_rport_logins);
Jing Huang7725ccf2009-09-23 17:46:15 -07001719
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001720 error = pci_register_driver(&bfad_pci_driver);
Jing Huang7725ccf2009-09-23 17:46:15 -07001721 if (error) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001722 printk(KERN_WARNING "pci_register_driver failure\n");
Jing Huang7725ccf2009-09-23 17:46:15 -07001723 goto ext;
1724 }
1725
1726 return 0;
1727
1728ext:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001729 bfad_im_module_exit();
Jing Huang7725ccf2009-09-23 17:46:15 -07001730 return error;
1731}
1732
Jing Huang5fbe25c2010-10-18 17:17:23 -07001733/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001734 * Driver module exit.
1735 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001736static void __exit
Jing Huang7725ccf2009-09-23 17:46:15 -07001737bfad_exit(void)
1738{
1739 pci_unregister_driver(&bfad_pci_driver);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001740 bfad_im_module_exit();
Jing Huang7725ccf2009-09-23 17:46:15 -07001741 bfad_free_fwimg();
1742}
1743
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001744/* Firmware handling */
Jing Huang61338a02011-04-13 11:44:03 -07001745static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001746bfad_read_firmware(struct pci_dev *pdev, u32 **bfi_image,
1747 u32 *bfi_image_size, char *fw_name)
1748{
1749 const struct firmware *fw;
1750
1751 if (request_firmware(&fw, fw_name, &pdev->dev)) {
1752 printk(KERN_ALERT "Can't locate firmware %s\n", fw_name);
Jing Huang61338a02011-04-13 11:44:03 -07001753 *bfi_image = NULL;
1754 goto out;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001755 }
1756
1757 *bfi_image = vmalloc(fw->size);
1758 if (NULL == *bfi_image) {
1759 printk(KERN_ALERT "Fail to allocate buffer for fw image "
1760 "size=%x!\n", (u32) fw->size);
Jing Huang61338a02011-04-13 11:44:03 -07001761 goto out;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001762 }
1763
1764 memcpy(*bfi_image, fw->data, fw->size);
1765 *bfi_image_size = fw->size/sizeof(u32);
Jing Huang61338a02011-04-13 11:44:03 -07001766out:
1767 release_firmware(fw);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001768}
1769
Jing Huang61338a02011-04-13 11:44:03 -07001770static u32 *
1771bfad_load_fwimg(struct pci_dev *pdev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001772{
Vijaya Mohan Guvvadcaf9ae2013-12-04 05:43:58 -08001773 if (bfa_asic_id_ct2(pdev->device)) {
Krishna Gudipati11189202011-06-13 15:50:35 -07001774 if (bfi_image_ct2_size == 0)
1775 bfad_read_firmware(pdev, &bfi_image_ct2,
1776 &bfi_image_ct2_size, BFAD_FW_FILE_CT2);
1777 return bfi_image_ct2;
1778 } else if (bfa_asic_id_ct(pdev->device)) {
1779 if (bfi_image_ct_size == 0)
1780 bfad_read_firmware(pdev, &bfi_image_ct,
1781 &bfi_image_ct_size, BFAD_FW_FILE_CT);
1782 return bfi_image_ct;
Vijaya Mohan Guvvadcaf9ae2013-12-04 05:43:58 -08001783 } else if (bfa_asic_id_cb(pdev->device)) {
Krishna Gudipati11189202011-06-13 15:50:35 -07001784 if (bfi_image_cb_size == 0)
1785 bfad_read_firmware(pdev, &bfi_image_cb,
1786 &bfi_image_cb_size, BFAD_FW_FILE_CB);
1787 return bfi_image_cb;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001788 }
Vijaya Mohan Guvvadcaf9ae2013-12-04 05:43:58 -08001789
1790 return NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001791}
Jing Huang7725ccf2009-09-23 17:46:15 -07001792
Jing Huang61338a02011-04-13 11:44:03 -07001793static void
1794bfad_free_fwimg(void)
1795{
Krishna Gudipati11189202011-06-13 15:50:35 -07001796 if (bfi_image_ct2_size && bfi_image_ct2)
1797 vfree(bfi_image_ct2);
1798 if (bfi_image_ct_size && bfi_image_ct)
1799 vfree(bfi_image_ct);
1800 if (bfi_image_cb_size && bfi_image_cb)
1801 vfree(bfi_image_cb);
Jing Huang61338a02011-04-13 11:44:03 -07001802}
1803
Jing Huang7725ccf2009-09-23 17:46:15 -07001804module_init(bfad_init);
1805module_exit(bfad_exit);
1806MODULE_LICENSE("GPL");
Anil Gurumurthy31e1d562015-11-26 03:54:46 -05001807MODULE_DESCRIPTION("QLogic BR-series Fibre Channel HBA Driver" BFAD_PROTO_NAME);
1808MODULE_AUTHOR("QLogic Corporation");
Jing Huang7725ccf2009-09-23 17:46:15 -07001809MODULE_VERSION(BFAD_DRIVER_VERSION);