blob: c7954612ef11931466883e7f1e7ecdcbea4a4994 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
8
9#include <linux/moduleparam.h>
10#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/delay.h>
Christoph Hellwig39a11242006-02-14 18:46:22 +010012#include <linux/kthread.h>
Daniel Walkere1e82b62008-05-12 22:21:10 -070013#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#include <scsi/scsi_tcq.h>
16#include <scsi/scsicam.h>
17#include <scsi/scsi_transport.h>
18#include <scsi/scsi_transport_fc.h>
19
20/*
21 * Driver version
22 */
23char qla2x00_version_str[40];
24
25/*
26 * SRB allocation cache
27 */
Christoph Lametere18b8902006-12-06 20:33:20 -080028static struct kmem_cache *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030int ql2xlogintimeout = 20;
31module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
32MODULE_PARM_DESC(ql2xlogintimeout,
33 "Login timeout value in seconds.");
34
Andrew Vasqueza7b61842007-05-07 07:42:59 -070035int qlport_down_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
37MODULE_PARM_DESC(qlport_down_retry,
Jesper Juhl900d9f92006-06-30 02:33:07 -070038 "Maximum number of command retries to a port that returns "
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 "a PORT-DOWN status.");
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041int ql2xplogiabsentdevice;
42module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
43MODULE_PARM_DESC(ql2xplogiabsentdevice,
44 "Option to enable PLOGI to devices that are not present after "
Jesper Juhl900d9f92006-06-30 02:33:07 -070045 "a Fabric scan. This is needed for several broken switches. "
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048int ql2xloginretrycount = 0;
49module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
50MODULE_PARM_DESC(ql2xloginretrycount,
51 "Specify an alternate value for the NVRAM login retry count.");
52
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070053int ql2xallocfwdump = 1;
54module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
55MODULE_PARM_DESC(ql2xallocfwdump,
56 "Option to enable allocation of memory for a firmware dump "
57 "during HBA initialization. Memory allocation requirements "
58 "vary by ISP type. Default is 1 - allocate memory.");
59
Andrew Vasquez11010fe2006-10-06 09:54:59 -070060int ql2xextended_error_logging;
Andrew Vasquez27d94032007-03-12 10:41:30 -070061module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070062MODULE_PARM_DESC(ql2xextended_error_logging,
Andrew Vasquez01819442006-06-23 16:11:10 -070063 "Option to enable extended error logging, "
64 "Default is 0 - no logging. 1 - log errors.");
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066static void qla2x00_free_device(scsi_qla_host_t *);
67
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -070068int ql2xfdmienable=1;
Andrew Vasquezcca53352005-08-26 19:08:30 -070069module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
70MODULE_PARM_DESC(ql2xfdmienable,
71 "Enables FDMI registratons "
72 "Default is 0 - no FDMI. 1 - perfom FDMI.");
73
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070074#define MAX_Q_DEPTH 32
75static int ql2xmaxqdepth = MAX_Q_DEPTH;
76module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
77MODULE_PARM_DESC(ql2xmaxqdepth,
78 "Maximum queue depth to report for target devices.");
79
80int ql2xqfullrampup = 120;
81module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR);
82MODULE_PARM_DESC(ql2xqfullrampup,
83 "Number of seconds to wait to begin to ramp-up the queue "
84 "depth for a device after a queue-full condition has been "
85 "detected. Default is 120 seconds.");
86
Andrew Vasqueze5896bd2008-07-10 16:55:52 -070087int ql2xiidmaenable=1;
88module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
89MODULE_PARM_DESC(ql2xiidmaenable,
90 "Enables iIDMA settings "
91 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
92
Anirban Chakraborty73208df2008-12-09 16:45:39 -080093int ql2xmaxqueues = 1;
94module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
95MODULE_PARM_DESC(ql2xmaxqueues,
96 "Enables MQ settings "
97 "Default is 1 for single queue. Set it to number \
98 of queues in MQ mode.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700100 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 */
102static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500103static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800104static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
105static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500106static void qla2xxx_slave_destroy(struct scsi_device *);
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700107static int qla2xxx_queuecommand(struct scsi_cmnd *cmd,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700108 void (*fn)(struct scsi_cmnd *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109static int qla2xxx_eh_abort(struct scsi_cmnd *);
110static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700111static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
113static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700115static int qla2x00_change_queue_depth(struct scsi_device *, int);
116static int qla2x00_change_queue_type(struct scsi_device *, int);
117
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700118struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700120 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700121 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700122
123 .eh_abort_handler = qla2xxx_eh_abort,
124 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700125 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700126 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
127 .eh_host_reset_handler = qla2xxx_eh_host_reset,
128
129 .slave_configure = qla2xxx_slave_configure,
130
131 .slave_alloc = qla2xxx_slave_alloc,
132 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700133 .scan_finished = qla2xxx_scan_finished,
134 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700135 .change_queue_depth = qla2x00_change_queue_depth,
136 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700137 .this_id = -1,
138 .cmd_per_lun = 3,
139 .use_clustering = ENABLE_CLUSTERING,
140 .sg_tablesize = SG_ALL,
141
142 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700143 .shost_attrs = qla2x00_host_attrs,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700144};
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700147struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149/* TODO Convert to inlines
150 *
151 * Timer routines
152 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700154__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800155qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800157 init_timer(&vha->timer);
158 vha->timer.expires = jiffies + interval * HZ;
159 vha->timer.data = (unsigned long)vha;
160 vha->timer.function = (void (*)(unsigned long))func;
161 add_timer(&vha->timer);
162 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800166qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800168 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
170
Adrian Bunka824ebb2008-01-17 09:02:15 -0800171static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800172qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800174 del_timer_sync(&vha->timer);
175 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178static int qla2x00_do_dpc(void *data);
179
180static void qla2x00_rst_aen(scsi_qla_host_t *);
181
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800182static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
183 struct req_que **, struct rsp_que **);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800184static void qla2x00_mem_free(struct qla_hw_data *);
185static void qla2x00_sp_free_dma(srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187/* -------------------------------------------------------------------------- */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800188static int qla2x00_alloc_queues(struct qla_hw_data *ha)
189{
190 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_queues,
191 GFP_KERNEL);
192 if (!ha->req_q_map) {
193 qla_printk(KERN_WARNING, ha,
194 "Unable to allocate memory for request queue ptrs\n");
195 goto fail_req_map;
196 }
197
198 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_queues,
199 GFP_KERNEL);
200 if (!ha->rsp_q_map) {
201 qla_printk(KERN_WARNING, ha,
202 "Unable to allocate memory for response queue ptrs\n");
203 goto fail_rsp_map;
204 }
205 set_bit(0, ha->rsp_qid_map);
206 set_bit(0, ha->req_qid_map);
207 return 1;
208
209fail_rsp_map:
210 kfree(ha->req_q_map);
211 ha->req_q_map = NULL;
212fail_req_map:
213 return -ENOMEM;
214}
215
216static void qla2x00_free_que(struct qla_hw_data *ha, struct req_que *req,
217 struct rsp_que *rsp)
218{
219 if (rsp && rsp->ring)
220 dma_free_coherent(&ha->pdev->dev,
221 (rsp->length + 1) * sizeof(response_t),
222 rsp->ring, rsp->dma);
223
224 kfree(rsp);
225 rsp = NULL;
226 if (req && req->ring)
227 dma_free_coherent(&ha->pdev->dev,
228 (req->length + 1) * sizeof(request_t),
229 req->ring, req->dma);
230
231 kfree(req);
232 req = NULL;
233}
234
235static void qla2x00_free_queues(struct qla_hw_data *ha)
236{
237 struct req_que *req;
238 struct rsp_que *rsp;
239 int cnt;
240
241 for (cnt = 0; cnt < ha->max_queues; cnt++) {
242 rsp = ha->rsp_q_map[cnt];
243 req = ha->req_q_map[cnt];
244 qla2x00_free_que(ha, req, rsp);
245 }
246 kfree(ha->rsp_q_map);
247 ha->rsp_q_map = NULL;
248
249 kfree(ha->req_q_map);
250 ha->req_q_map = NULL;
251}
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800254qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800256 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 static char *pci_bus_modes[] = {
258 "33", "66", "100", "133",
259 };
260 uint16_t pci_bus;
261
262 strcpy(str, "PCI");
263 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
264 if (pci_bus) {
265 strcat(str, "-X (");
266 strcat(str, pci_bus_modes[pci_bus]);
267 } else {
268 pci_bus = (ha->pci_attr & BIT_8) >> 8;
269 strcat(str, " (");
270 strcat(str, pci_bus_modes[pci_bus]);
271 }
272 strcat(str, " MHz)");
273
274 return (str);
275}
276
Andrew Vasquezfca29702005-07-06 10:31:47 -0700277static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800278qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700279{
280 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800281 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700282 uint32_t pci_bus;
283 int pcie_reg;
284
285 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
286 if (pcie_reg) {
287 char lwstr[6];
288 uint16_t pcie_lstat, lspeed, lwidth;
289
290 pcie_reg += 0x12;
291 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
292 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
293 lwidth = (pcie_lstat &
294 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
295
296 strcpy(str, "PCIe (");
297 if (lspeed == 1)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700298 strcat(str, "2.5GT/s ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700299 else if (lspeed == 2)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700300 strcat(str, "5.0GT/s ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700301 else
302 strcat(str, "<unknown> ");
303 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
304 strcat(str, lwstr);
305
306 return str;
307 }
308
309 strcpy(str, "PCI");
310 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
311 if (pci_bus == 0 || pci_bus == 8) {
312 strcat(str, " (");
313 strcat(str, pci_bus_modes[pci_bus >> 3]);
314 } else {
315 strcat(str, "-X ");
316 if (pci_bus & BIT_2)
317 strcat(str, "Mode 2");
318 else
319 strcat(str, "Mode 1");
320 strcat(str, " (");
321 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
322 }
323 strcat(str, " MHz)");
324
325 return str;
326}
327
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800328static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800329qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330{
331 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800332 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
335 ha->fw_minor_version,
336 ha->fw_subminor_version);
337
338 if (ha->fw_attributes & BIT_9) {
339 strcat(str, "FLX");
340 return (str);
341 }
342
343 switch (ha->fw_attributes & 0xFF) {
344 case 0x7:
345 strcat(str, "EF");
346 break;
347 case 0x17:
348 strcat(str, "TP");
349 break;
350 case 0x37:
351 strcat(str, "IP");
352 break;
353 case 0x77:
354 strcat(str, "VI");
355 break;
356 default:
357 sprintf(un_str, "(%x)", ha->fw_attributes);
358 strcat(str, un_str);
359 break;
360 }
361 if (ha->fw_attributes & 0x100)
362 strcat(str, "X");
363
364 return (str);
365}
366
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800367static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800368qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700369{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800370 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700371
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800372 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
373 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700374 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700375}
376
377static inline srb_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800378qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700379 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
380{
381 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800382 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700383
384 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
385 if (!sp)
386 return sp;
387
Andrew Vasquezfca29702005-07-06 10:31:47 -0700388 sp->fcport = fcport;
389 sp->cmd = cmd;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800390 sp->que = ha->req_q_map[0];
Andrew Vasquezfca29702005-07-06 10:31:47 -0700391 sp->flags = 0;
392 CMD_SP(cmd) = (void *)sp;
393 cmd->scsi_done = done;
394
395 return sp;
396}
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398static int
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700399qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Andrew Vasquezfca29702005-07-06 10:31:47 -0700400{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800401 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700402 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400403 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800404 struct qla_hw_data *ha = vha->hw;
405 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700406 srb_t *sp;
407 int rval;
408
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800409 if (unlikely(pci_channel_offline(ha->pdev))) {
Seokmann Ju14e660e2007-09-20 14:07:36 -0700410 cmd->result = DID_REQUEUE << 16;
411 goto qc24_fail_command;
412 }
413
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400414 rval = fc_remote_port_chkready(rport);
415 if (rval) {
416 cmd->result = rval;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700417 goto qc24_fail_command;
418 }
419
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800420 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500421 if (fcport->drport)
422 goto qc24_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800423
Andrew Vasquezfca29702005-07-06 10:31:47 -0700424 if (atomic_read(&fcport->state) != FCS_ONLINE) {
425 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800426 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700427 cmd->result = DID_NO_CONNECT << 16;
428 goto qc24_fail_command;
429 }
Mike Christie7b594132008-08-17 15:24:40 -0500430 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700431 }
432
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800433 spin_unlock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700434
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800435 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700436 if (!sp)
437 goto qc24_host_busy_lock;
438
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800439 rval = ha->isp_ops->start_scsi(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700440 if (rval != QLA_SUCCESS)
441 goto qc24_host_busy_free_sp;
442
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800443 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700444
445 return 0;
446
447qc24_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800448 qla2x00_sp_free_dma(sp);
449 mempool_free(sp, ha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700450
451qc24_host_busy_lock:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800452 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700453 return SCSI_MLQUEUE_HOST_BUSY;
454
Mike Christie7b594132008-08-17 15:24:40 -0500455qc24_target_busy:
456 return SCSI_MLQUEUE_TARGET_BUSY;
457
Andrew Vasquezfca29702005-07-06 10:31:47 -0700458qc24_fail_command:
459 done(cmd);
460
461 return 0;
462}
463
464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465/*
466 * qla2x00_eh_wait_on_command
467 * Waits for the command to be returned by the Firmware for some
468 * max time.
469 *
470 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 *
473 * Return:
474 * Not Found : 0
475 * Found : 1
476 */
477static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800478qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700480#define ABORT_POLLING_PERIOD 1000
481#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500482 unsigned long wait_iter = ABORT_WAIT_ITER;
483 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
f4f051e2005-04-17 15:02:26 -0500485 while (CMD_SP(cmd)) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700486 msleep(ABORT_POLLING_PERIOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
f4f051e2005-04-17 15:02:26 -0500488 if (--wait_iter)
489 break;
490 }
491 if (CMD_SP(cmd))
492 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
f4f051e2005-04-17 15:02:26 -0500494 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495}
496
497/*
498 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700499 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 * <= MAX_RETRIES_OF_ISP_ABORT or
501 * finally HBA is disabled ie marked offline
502 *
503 * Input:
504 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700505 *
506 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 * Does context switching-Release SPIN_LOCK
508 * (if any) before calling this routine.
509 *
510 * Return:
511 * Success (Adapter is online) : 0
512 * Failed (Adapter is offline/disabled) : 1
513 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800514int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800515qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700517 int return_status;
518 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800519 struct qla_hw_data *ha = vha->hw;
520 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700522 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800523 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
524 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
525 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
526 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
528 msleep(1000);
529 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800530 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700531 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 else
533 return_status = QLA_FUNCTION_FAILED;
534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 return (return_status);
536}
537
538/*
539 * qla2x00_wait_for_loop_ready
540 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700541 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 * Input:
543 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700544 *
545 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 * Does context switching-Release SPIN_LOCK
547 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700548 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 *
550 * Return:
551 * Success (LOOP_READY) : 0
552 * Failed (LOOP_NOT_READY) : 1
553 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700554static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800555qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556{
557 int return_status = QLA_SUCCESS;
558 unsigned long loop_timeout ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800559 struct qla_hw_data *ha = vha->hw;
560 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
562 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700563 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800565 while ((!atomic_read(&base_vha->loop_down_timer) &&
566 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
567 atomic_read(&base_vha->loop_state) != LOOP_READY) {
568 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Ravi Anand57680082006-05-17 15:08:44 -0700569 return_status = QLA_FUNCTION_FAILED;
570 break;
571 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 msleep(1000);
573 if (time_after_eq(jiffies, loop_timeout)) {
574 return_status = QLA_FUNCTION_FAILED;
575 break;
576 }
577 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700578 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579}
580
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700581void
582qla2x00_abort_fcport_cmds(fc_port_t *fcport)
583{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800584 int cnt, que, id;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700585 unsigned long flags;
586 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800587 scsi_qla_host_t *vha = fcport->vha;
588 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800589 struct req_que *req;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700590
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800591 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800592 for (que = 0; que < QLA_MAX_HOST_QUES; que++) {
593 id = vha->req_ques[que];
594 req = ha->req_q_map[id];
595 if (!req)
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700596 continue;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800597 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
598 sp = req->outstanding_cmds[cnt];
599 if (!sp)
600 continue;
601 if (sp->fcport != fcport)
602 continue;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700603
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800604 spin_unlock_irqrestore(&ha->hardware_lock, flags);
605 if (ha->isp_ops->abort_command(vha, sp, req)) {
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700606 DEBUG2(qla_printk(KERN_WARNING, ha,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800607 "Abort failed -- %lx\n",
608 sp->cmd->serial_number));
609 } else {
610 if (qla2x00_eh_wait_on_command(sp->cmd) !=
611 QLA_SUCCESS)
612 DEBUG2(qla_printk(KERN_WARNING, ha,
613 "Abort failed while waiting -- %lx\n",
614 sp->cmd->serial_number));
615 }
616 spin_lock_irqsave(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700617 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700618 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800619 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700620}
621
Andrew Vasquez07db5182006-10-02 12:00:49 -0700622static void
623qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
624{
625 struct Scsi_Host *shost = cmnd->device->host;
626 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
627 unsigned long flags;
628
629 spin_lock_irqsave(shost->host_lock, flags);
630 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
631 spin_unlock_irqrestore(shost->host_lock, flags);
632 msleep(1000);
633 spin_lock_irqsave(shost->host_lock, flags);
634 }
635 spin_unlock_irqrestore(shost->host_lock, flags);
636 return;
637}
638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639/**************************************************************************
640* qla2xxx_eh_abort
641*
642* Description:
643* The abort function will abort the specified command.
644*
645* Input:
646* cmd = Linux SCSI command packet to be aborted.
647*
648* Returns:
649* Either SUCCESS or FAILED.
650*
651* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700652* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800654static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655qla2xxx_eh_abort(struct scsi_cmnd *cmd)
656{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800657 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500658 srb_t *sp;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800659 int ret, i;
f4f051e2005-04-17 15:02:26 -0500660 unsigned int id, lun;
661 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700662 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700663 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800664 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800665 struct req_que *req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800666 srb_t *spt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Andrew Vasquez07db5182006-10-02 12:00:49 -0700668 qla2x00_block_error_handler(cmd);
669
f4f051e2005-04-17 15:02:26 -0500670 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700671 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Michael Reed2ea00202006-04-27 16:25:30 -0700673 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
f4f051e2005-04-17 15:02:26 -0500675 id = cmd->device->id;
676 lun = cmd->device->lun;
677 serial = cmd->serial_number;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800678 spt = (srb_t *) CMD_SP(cmd);
679 if (!spt)
680 return SUCCESS;
681 req = spt->que;
f4f051e2005-04-17 15:02:26 -0500682
683 /* Check active list for command command. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800684 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800685 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
686 sp = req->outstanding_cmds[i];
687
688 if (sp == NULL)
f4f051e2005-04-17 15:02:26 -0500689 continue;
690
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800691 if (sp->cmd != cmd)
692 continue;
f4f051e2005-04-17 15:02:26 -0500693
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800694 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
695 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
f4f051e2005-04-17 15:02:26 -0500696
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800697 spin_unlock_irqrestore(&ha->hardware_lock, flags);
698 if (ha->isp_ops->abort_command(vha, sp, req)) {
699 DEBUG2(printk("%s(%ld): abort_command "
700 "mbx failed.\n", __func__, vha->host_no));
Andrew Vasquez2ac4b642009-01-22 09:45:35 -0800701 ret = FAILED;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800702 } else {
703 DEBUG3(printk("%s(%ld): abort_command "
704 "mbx success.\n", __func__, vha->host_no));
705 wait = 1;
f4f051e2005-04-17 15:02:26 -0500706 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800707 spin_lock_irqsave(&ha->hardware_lock, flags);
708 break;
f4f051e2005-04-17 15:02:26 -0500709 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800710 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500711
712 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700713 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800714 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700715 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500716 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800717 "%x.\n", vha->host_no, id, lun, serial, ret);
Michael Reed2ea00202006-04-27 16:25:30 -0700718 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700722 qla_printk(KERN_INFO, ha,
Michael Reed2ea00202006-04-27 16:25:30 -0700723 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800724 vha->host_no, id, lun, wait, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
f4f051e2005-04-17 15:02:26 -0500726 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727}
728
Andrew Vasquez523ec772008-04-03 13:13:24 -0700729enum nexus_wait_type {
730 WAIT_HOST = 0,
731 WAIT_TARGET,
732 WAIT_LUN,
733};
734
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800736qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800737 unsigned int l, srb_t *sp, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738{
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800739 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700740 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800741 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800742 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
Andrew Vasquez523ec772008-04-03 13:13:24 -0700744 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800745 if (!sp)
746 return status;
747
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800748 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800749 req = sp->que;
750 for (cnt = 1; status == QLA_SUCCESS &&
751 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
752 sp = req->outstanding_cmds[cnt];
753 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700754 continue;
Andrew Vasquez19851f12008-08-13 21:37:00 -0700755
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800756 if (vha->vp_idx != sp->fcport->vha->vp_idx)
757 continue;
758 match = 0;
759 switch (type) {
760 case WAIT_HOST:
761 match = 1;
762 break;
763 case WAIT_TARGET:
764 match = sp->cmd->device->id == t;
765 break;
766 case WAIT_LUN:
767 match = (sp->cmd->device->id == t &&
768 sp->cmd->device->lun == l);
769 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800771 if (!match)
772 continue;
773
774 spin_unlock_irqrestore(&ha->hardware_lock, flags);
775 status = qla2x00_eh_wait_on_command(sp->cmd);
776 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800778 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700779
780 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781}
782
Andrew Vasquez523ec772008-04-03 13:13:24 -0700783static char *reset_errors[] = {
784 "HBA not online",
785 "HBA not ready",
786 "Task management failed",
787 "Waiting for command completions",
788};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
Andrew Vasquez523ec772008-04-03 13:13:24 -0700790static int
791__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
792 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int))
793{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800794 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700795 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
796 int err;
797
798 qla2x00_block_error_handler(cmd);
799
800 if (!fcport)
801 return FAILED;
802
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800803 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
804 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700805
806 err = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800807 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700808 goto eh_reset_failed;
809 err = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800810 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700811 goto eh_reset_failed;
812 err = 2;
813 if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS)
814 goto eh_reset_failed;
815 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800816 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800817 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700818 goto eh_reset_failed;
819
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800820 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
821 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700822
823 return SUCCESS;
824
825 eh_reset_failed:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800826 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
827 , vha->host_no, cmd->device->id, cmd->device->lun, name,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700828 reset_errors[err]);
829 return FAILED;
830}
831
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800832static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
834{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800835 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
836 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
Andrew Vasquez523ec772008-04-03 13:13:24 -0700838 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
839 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840}
841
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700843qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800845 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
846 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
Andrew Vasquez523ec772008-04-03 13:13:24 -0700848 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
849 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850}
851
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852/**************************************************************************
853* qla2xxx_eh_bus_reset
854*
855* Description:
856* The bus reset function will reset the bus and abort any executing
857* commands.
858*
859* Input:
860* cmd = Linux SCSI command packet of the command that cause the
861* bus reset.
862*
863* Returns:
864* SUCCESS/FAILURE (defined as macro in scsi.h).
865*
866**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800867static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
869{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800870 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500871 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700872 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500873 unsigned int id, lun;
874 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800875 srb_t *sp = (srb_t *) CMD_SP(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
Andrew Vasquez07db5182006-10-02 12:00:49 -0700877 qla2x00_block_error_handler(cmd);
878
f4f051e2005-04-17 15:02:26 -0500879 id = cmd->device->id;
880 lun = cmd->device->lun;
881 serial = cmd->serial_number;
882
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700883 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500884 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800886 qla_printk(KERN_INFO, vha->hw,
Anirban Chakraborty749af3d2008-11-14 13:48:12 -0800887 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800889 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500891 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 }
893
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800894 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
895 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500896 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 }
f4f051e2005-04-17 15:02:26 -0500898 if (ret == FAILED)
899 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700901 /* Flush outstanding commands. */
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800902 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
Andrew Vasquez523ec772008-04-03 13:13:24 -0700903 QLA_SUCCESS)
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700904 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
f4f051e2005-04-17 15:02:26 -0500906eh_bus_reset_done:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800907 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500908 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
f4f051e2005-04-17 15:02:26 -0500910 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911}
912
913/**************************************************************************
914* qla2xxx_eh_host_reset
915*
916* Description:
917* The reset function will reset the Adapter.
918*
919* Input:
920* cmd = Linux SCSI command packet of the command that cause the
921* adapter reset.
922*
923* Returns:
924* Either SUCCESS or FAILED.
925*
926* Note:
927**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800928static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
930{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800931 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500932 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800933 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700934 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500935 unsigned int id, lun;
936 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800937 srb_t *sp = (srb_t *) CMD_SP(cmd);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800938 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Andrew Vasquez07db5182006-10-02 12:00:49 -0700940 qla2x00_block_error_handler(cmd);
941
f4f051e2005-04-17 15:02:26 -0500942 id = cmd->device->id;
943 lun = cmd->device->lun;
944 serial = cmd->serial_number;
945
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700946 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500947 return ret;
948
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 qla_printk(KERN_INFO, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800950 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800952 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500953 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
955 /*
956 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700957 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 * be completed and then issue big hammer.Otherwise
959 * it may cause I/O failure as big hammer marks the
960 * devices as lost kicking of the port_down_timer
961 * while dpc is stuck for the mailbox to complete.
962 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800963 qla2x00_wait_for_loop_ready(vha);
964 if (vha != base_vha) {
965 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -0500966 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800967 } else {
968 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
969 if (qla2x00_abort_isp(base_vha)) {
970 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
971 /* failed. schedule dpc to try */
972 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
973
974 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
975 goto eh_host_reset_lock;
976 }
977 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700978 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800980 /* Waiting for command to be returned to OS.*/
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800981 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800982 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500983 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
f4f051e2005-04-17 15:02:26 -0500985eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -0500986 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
987 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
f4f051e2005-04-17 15:02:26 -0500989 return ret;
990}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
992/*
993* qla2x00_loop_reset
994* Issue loop reset.
995*
996* Input:
997* ha = adapter block pointer.
998*
999* Returns:
1000* 0 = success
1001*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001002int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001003qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001005 int ret;
bdf79622005-04-17 15:06:53 -05001006 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001007 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001009 if (ha->flags.enable_lip_full_login && !vha->vp_idx) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001010 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001011 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001012 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001013 "full_login_lip=%d.\n", __func__, vha->host_no,
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001014 ret));
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001015 }
1016 atomic_set(&vha->loop_state, LOOP_DOWN);
1017 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1018 qla2x00_mark_all_devices_lost(vha, 0);
1019 qla2x00_wait_for_loop_ready(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 }
1021
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001022 if (ha->flags.enable_lip_reset && !vha->vp_idx) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001023 ret = qla2x00_lip_reset(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001024 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001025 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001026 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1027 } else
1028 qla2x00_wait_for_loop_ready(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001029 }
1030
1031 if (ha->flags.enable_target_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001032 list_for_each_entry(fcport, &vha->vp_fcports, list) {
bdf79622005-04-17 15:06:53 -05001033 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 continue;
1035
Andrew Vasquez523ec772008-04-03 13:13:24 -07001036 ret = ha->isp_ops->target_reset(fcport, 0);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001037 if (ret != QLA_SUCCESS) {
1038 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1039 "target_reset=%d d_id=%x.\n", __func__,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001040 vha->host_no, ret, fcport->d_id.b24));
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001041 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 }
1043 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001045 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001047 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048}
1049
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001050void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001051qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001052{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001053 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001054 unsigned long flags;
1055 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001056 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001057 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001058
1059 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001060 for (que = 0; que < ha->max_queues; que++) {
1061 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001062 if (!req)
1063 continue;
1064 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1065 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001066 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001067 req->outstanding_cmds[cnt] = NULL;
1068 sp->cmd->result = res;
1069 qla2x00_sp_compl(ha, sp);
1070 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001071 }
1072 }
1073 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1074}
1075
f4f051e2005-04-17 15:02:26 -05001076static int
1077qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078{
bdf79622005-04-17 15:06:53 -05001079 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001081 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001082 return -ENXIO;
1083
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001084 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001085
1086 return 0;
1087}
1088
1089static int
1090qla2xxx_slave_configure(struct scsi_device *sdev)
1091{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001092 scsi_qla_host_t *vha = shost_priv(sdev->host);
1093 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05001094 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001095 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
8482e1182005-04-17 15:04:54 -05001096
f4f051e2005-04-17 15:02:26 -05001097 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001098 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001100 scsi_deactivate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
Andrew Vasquez85821c92008-07-10 16:55:48 -07001102 rport->dev_loss_tmo = ha->port_down_retry_count;
8482e1182005-04-17 15:04:54 -05001103
f4f051e2005-04-17 15:02:26 -05001104 return 0;
1105}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
f4f051e2005-04-17 15:02:26 -05001107static void
1108qla2xxx_slave_destroy(struct scsi_device *sdev)
1109{
1110 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111}
1112
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001113static int
1114qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1115{
1116 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1117 return sdev->queue_depth;
1118}
1119
1120static int
1121qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1122{
1123 if (sdev->tagged_supported) {
1124 scsi_set_tag_type(sdev, tag_type);
1125 if (tag_type)
1126 scsi_activate_tcq(sdev, sdev->queue_depth);
1127 else
1128 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1129 } else
1130 tag_type = 0;
1131
1132 return tag_type;
1133}
1134
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135/**
1136 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1137 * @ha: HA context
1138 *
1139 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1140 * supported addressing method.
1141 */
1142static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001143qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001145 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001148 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1149 /* Any upper-dword bits set? */
1150 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1151 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1152 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001154 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1155 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001156 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001159
1160 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1161 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162}
1163
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001164static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001165qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001166{
1167 unsigned long flags = 0;
1168 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1169
1170 spin_lock_irqsave(&ha->hardware_lock, flags);
1171 ha->interrupts_on = 1;
1172 /* enable risc and host interrupts */
1173 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1174 RD_REG_WORD(&reg->ictrl);
1175 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1176
1177}
1178
1179static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001180qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001181{
1182 unsigned long flags = 0;
1183 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1184
1185 spin_lock_irqsave(&ha->hardware_lock, flags);
1186 ha->interrupts_on = 0;
1187 /* disable risc and host interrupts */
1188 WRT_REG_WORD(&reg->ictrl, 0);
1189 RD_REG_WORD(&reg->ictrl);
1190 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1191}
1192
1193static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001194qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001195{
1196 unsigned long flags = 0;
1197 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1198
1199 spin_lock_irqsave(&ha->hardware_lock, flags);
1200 ha->interrupts_on = 1;
1201 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1202 RD_REG_DWORD(&reg->ictrl);
1203 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1204}
1205
1206static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001207qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001208{
1209 unsigned long flags = 0;
1210 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1211
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001212 if (IS_NOPOLLING_TYPE(ha))
1213 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001214 spin_lock_irqsave(&ha->hardware_lock, flags);
1215 ha->interrupts_on = 0;
1216 WRT_REG_DWORD(&reg->ictrl, 0);
1217 RD_REG_DWORD(&reg->ictrl);
1218 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1219}
1220
1221static struct isp_operations qla2100_isp_ops = {
1222 .pci_config = qla2100_pci_config,
1223 .reset_chip = qla2x00_reset_chip,
1224 .chip_diag = qla2x00_chip_diag,
1225 .config_rings = qla2x00_config_rings,
1226 .reset_adapter = qla2x00_reset_adapter,
1227 .nvram_config = qla2x00_nvram_config,
1228 .update_fw_options = qla2x00_update_fw_options,
1229 .load_risc = qla2x00_load_risc,
1230 .pci_info_str = qla2x00_pci_info_str,
1231 .fw_version_str = qla2x00_fw_version_str,
1232 .intr_handler = qla2100_intr_handler,
1233 .enable_intrs = qla2x00_enable_intrs,
1234 .disable_intrs = qla2x00_disable_intrs,
1235 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001236 .target_reset = qla2x00_abort_target,
1237 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001238 .fabric_login = qla2x00_login_fabric,
1239 .fabric_logout = qla2x00_fabric_logout,
1240 .calc_req_entries = qla2x00_calc_iocbs_32,
1241 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1242 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1243 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1244 .read_nvram = qla2x00_read_nvram_data,
1245 .write_nvram = qla2x00_write_nvram_data,
1246 .fw_dump = qla2100_fw_dump,
1247 .beacon_on = NULL,
1248 .beacon_off = NULL,
1249 .beacon_blink = NULL,
1250 .read_optrom = qla2x00_read_optrom_data,
1251 .write_optrom = qla2x00_write_optrom_data,
1252 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001253 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001254};
1255
1256static struct isp_operations qla2300_isp_ops = {
1257 .pci_config = qla2300_pci_config,
1258 .reset_chip = qla2x00_reset_chip,
1259 .chip_diag = qla2x00_chip_diag,
1260 .config_rings = qla2x00_config_rings,
1261 .reset_adapter = qla2x00_reset_adapter,
1262 .nvram_config = qla2x00_nvram_config,
1263 .update_fw_options = qla2x00_update_fw_options,
1264 .load_risc = qla2x00_load_risc,
1265 .pci_info_str = qla2x00_pci_info_str,
1266 .fw_version_str = qla2x00_fw_version_str,
1267 .intr_handler = qla2300_intr_handler,
1268 .enable_intrs = qla2x00_enable_intrs,
1269 .disable_intrs = qla2x00_disable_intrs,
1270 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001271 .target_reset = qla2x00_abort_target,
1272 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001273 .fabric_login = qla2x00_login_fabric,
1274 .fabric_logout = qla2x00_fabric_logout,
1275 .calc_req_entries = qla2x00_calc_iocbs_32,
1276 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1277 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1278 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1279 .read_nvram = qla2x00_read_nvram_data,
1280 .write_nvram = qla2x00_write_nvram_data,
1281 .fw_dump = qla2300_fw_dump,
1282 .beacon_on = qla2x00_beacon_on,
1283 .beacon_off = qla2x00_beacon_off,
1284 .beacon_blink = qla2x00_beacon_blink,
1285 .read_optrom = qla2x00_read_optrom_data,
1286 .write_optrom = qla2x00_write_optrom_data,
1287 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001288 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001289};
1290
1291static struct isp_operations qla24xx_isp_ops = {
1292 .pci_config = qla24xx_pci_config,
1293 .reset_chip = qla24xx_reset_chip,
1294 .chip_diag = qla24xx_chip_diag,
1295 .config_rings = qla24xx_config_rings,
1296 .reset_adapter = qla24xx_reset_adapter,
1297 .nvram_config = qla24xx_nvram_config,
1298 .update_fw_options = qla24xx_update_fw_options,
1299 .load_risc = qla24xx_load_risc,
1300 .pci_info_str = qla24xx_pci_info_str,
1301 .fw_version_str = qla24xx_fw_version_str,
1302 .intr_handler = qla24xx_intr_handler,
1303 .enable_intrs = qla24xx_enable_intrs,
1304 .disable_intrs = qla24xx_disable_intrs,
1305 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001306 .target_reset = qla24xx_abort_target,
1307 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001308 .fabric_login = qla24xx_login_fabric,
1309 .fabric_logout = qla24xx_fabric_logout,
1310 .calc_req_entries = NULL,
1311 .build_iocbs = NULL,
1312 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1313 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1314 .read_nvram = qla24xx_read_nvram_data,
1315 .write_nvram = qla24xx_write_nvram_data,
1316 .fw_dump = qla24xx_fw_dump,
1317 .beacon_on = qla24xx_beacon_on,
1318 .beacon_off = qla24xx_beacon_off,
1319 .beacon_blink = qla24xx_beacon_blink,
1320 .read_optrom = qla24xx_read_optrom_data,
1321 .write_optrom = qla24xx_write_optrom_data,
1322 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001323 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001324};
1325
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001326static struct isp_operations qla25xx_isp_ops = {
1327 .pci_config = qla25xx_pci_config,
1328 .reset_chip = qla24xx_reset_chip,
1329 .chip_diag = qla24xx_chip_diag,
1330 .config_rings = qla24xx_config_rings,
1331 .reset_adapter = qla24xx_reset_adapter,
1332 .nvram_config = qla24xx_nvram_config,
1333 .update_fw_options = qla24xx_update_fw_options,
1334 .load_risc = qla24xx_load_risc,
1335 .pci_info_str = qla24xx_pci_info_str,
1336 .fw_version_str = qla24xx_fw_version_str,
1337 .intr_handler = qla24xx_intr_handler,
1338 .enable_intrs = qla24xx_enable_intrs,
1339 .disable_intrs = qla24xx_disable_intrs,
1340 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001341 .target_reset = qla24xx_abort_target,
1342 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001343 .fabric_login = qla24xx_login_fabric,
1344 .fabric_logout = qla24xx_fabric_logout,
1345 .calc_req_entries = NULL,
1346 .build_iocbs = NULL,
1347 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1348 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1349 .read_nvram = qla25xx_read_nvram_data,
1350 .write_nvram = qla25xx_write_nvram_data,
1351 .fw_dump = qla25xx_fw_dump,
1352 .beacon_on = qla24xx_beacon_on,
1353 .beacon_off = qla24xx_beacon_off,
1354 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001355 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001356 .write_optrom = qla24xx_write_optrom_data,
1357 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001358 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001359};
1360
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001361static struct isp_operations qla81xx_isp_ops = {
1362 .pci_config = qla25xx_pci_config,
1363 .reset_chip = qla24xx_reset_chip,
1364 .chip_diag = qla24xx_chip_diag,
1365 .config_rings = qla24xx_config_rings,
1366 .reset_adapter = qla24xx_reset_adapter,
1367 .nvram_config = qla81xx_nvram_config,
1368 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001369 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001370 .pci_info_str = qla24xx_pci_info_str,
1371 .fw_version_str = qla24xx_fw_version_str,
1372 .intr_handler = qla24xx_intr_handler,
1373 .enable_intrs = qla24xx_enable_intrs,
1374 .disable_intrs = qla24xx_disable_intrs,
1375 .abort_command = qla24xx_abort_command,
1376 .target_reset = qla24xx_abort_target,
1377 .lun_reset = qla24xx_lun_reset,
1378 .fabric_login = qla24xx_login_fabric,
1379 .fabric_logout = qla24xx_fabric_logout,
1380 .calc_req_entries = NULL,
1381 .build_iocbs = NULL,
1382 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1383 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1384 .read_nvram = qla25xx_read_nvram_data,
1385 .write_nvram = qla25xx_write_nvram_data,
1386 .fw_dump = qla81xx_fw_dump,
1387 .beacon_on = qla24xx_beacon_on,
1388 .beacon_off = qla24xx_beacon_off,
1389 .beacon_blink = qla24xx_beacon_blink,
1390 .read_optrom = qla25xx_read_optrom_data,
1391 .write_optrom = qla24xx_write_optrom_data,
1392 .get_flash_version = qla24xx_get_flash_version,
1393 .start_scsi = qla24xx_start_scsi,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001394};
1395
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001396static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001397qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001398{
1399 ha->device_type = DT_EXTENDED_IDS;
1400 switch (ha->pdev->device) {
1401 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1402 ha->device_type |= DT_ISP2100;
1403 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001404 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001405 break;
1406 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1407 ha->device_type |= DT_ISP2200;
1408 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001409 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001410 break;
1411 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1412 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001413 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001414 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001415 break;
1416 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1417 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001418 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001419 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001420 break;
1421 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1422 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001423 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001424 if (ha->pdev->subsystem_vendor == 0x1028 &&
1425 ha->pdev->subsystem_device == 0x0170)
1426 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001427 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001428 break;
1429 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1430 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001431 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001432 break;
1433 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1434 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001435 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001436 break;
1437 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1438 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001439 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001440 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001441 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001442 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001443 break;
1444 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1445 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001446 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001447 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001448 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001449 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001450 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001451 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1452 ha->device_type |= DT_ISP8432;
1453 ha->device_type |= DT_ZIO_SUPPORTED;
1454 ha->device_type |= DT_FWI2;
1455 ha->device_type |= DT_IIDMA;
1456 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1457 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001458 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1459 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001460 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001461 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001462 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001463 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1464 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001465 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001466 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001467 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001468 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1469 ha->device_type |= DT_ISP2532;
1470 ha->device_type |= DT_ZIO_SUPPORTED;
1471 ha->device_type |= DT_FWI2;
1472 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001473 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1474 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001475 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1476 ha->device_type |= DT_ISP8001;
1477 ha->device_type |= DT_ZIO_SUPPORTED;
1478 ha->device_type |= DT_FWI2;
1479 ha->device_type |= DT_IIDMA;
1480 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1481 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001482 }
1483}
1484
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001486qla2x00_iospace_config(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487{
Andrew Vasquez37765412008-01-17 09:02:09 -08001488 resource_size_t pio;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001489 uint16_t msix;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
Andrew Vasquez285d0322007-10-19 15:59:17 -07001491 if (pci_request_selected_regions(ha->pdev, ha->bars,
1492 QLA2XXX_DRIVER_NAME)) {
1493 qla_printk(KERN_WARNING, ha,
1494 "Failed to reserve PIO/MMIO regions (%s)\n",
1495 pci_name(ha->pdev));
1496
1497 goto iospace_error_exit;
1498 }
1499 if (!(ha->bars & 1))
1500 goto skip_pio;
1501
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1503 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001504 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1505 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 qla_printk(KERN_WARNING, ha,
1507 "Invalid PCI I/O region size (%s)...\n",
1508 pci_name(ha->pdev));
1509 pio = 0;
1510 }
1511 } else {
1512 qla_printk(KERN_WARNING, ha,
1513 "region #0 not a PIO resource (%s)...\n",
1514 pci_name(ha->pdev));
1515 pio = 0;
1516 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001517 ha->pio_address = pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
Andrew Vasquez285d0322007-10-19 15:59:17 -07001519skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001521 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 qla_printk(KERN_ERR, ha,
Andrew Vasquez37765412008-01-17 09:02:09 -08001523 "region #1 not an MMIO resource (%s), aborting\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 pci_name(ha->pdev));
1525 goto iospace_error_exit;
1526 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001527 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 qla_printk(KERN_ERR, ha,
1529 "Invalid PCI mem region size (%s), aborting\n",
1530 pci_name(ha->pdev));
1531 goto iospace_error_exit;
1532 }
1533
Andrew Vasquez37765412008-01-17 09:02:09 -08001534 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 if (!ha->iobase) {
1536 qla_printk(KERN_ERR, ha,
1537 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1538
1539 goto iospace_error_exit;
1540 }
1541
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001542 /* Determine queue resources */
1543 ha->max_queues = 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001544 if (ql2xmaxqueues <= 1 || (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001545 goto mqiobase_exit;
1546 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1547 pci_resource_len(ha->pdev, 3));
1548 if (ha->mqiobase) {
1549 /* Read MSIX vector size of the board */
1550 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1551 ha->msix_count = msix;
1552 /* Max queues are bounded by available msix vectors */
1553 /* queue 0 uses two msix vectors */
1554 if (ha->msix_count - 1 < ql2xmaxqueues)
1555 ha->max_queues = ha->msix_count - 1;
1556 else if (ql2xmaxqueues > QLA_MQ_SIZE)
1557 ha->max_queues = QLA_MQ_SIZE;
1558 else
1559 ha->max_queues = ql2xmaxqueues;
1560 qla_printk(KERN_INFO, ha,
1561 "MSI-X vector count: %d\n", msix);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001562 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001563
1564mqiobase_exit:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001565 ha->msix_count = ha->max_queues + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 return (0);
1567
1568iospace_error_exit:
1569 return (-ENOMEM);
1570}
1571
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001572static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001573qla2xxx_scan_start(struct Scsi_Host *shost)
1574{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001575 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001576
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001577 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1578 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1579 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1580 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001581}
1582
1583static int
1584qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1585{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001586 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001587
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001588 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001589 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001590 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001591 return 1;
1592
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001593 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001594}
1595
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596/*
1597 * PCI driver interface
1598 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001599static int __devinit
1600qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001602 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001604 scsi_qla_host_t *base_vha = NULL;
1605 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001606 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001608 struct scsi_host_template *sht;
Anirban Chakrabortyc51da4e2008-11-10 15:53:20 -08001609 int bars, max_id, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001610 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001611 struct req_que *req = NULL;
1612 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
Andrew Vasquez285d0322007-10-19 15:59:17 -07001614 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07001615 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001616 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1617 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001618 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001619 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1620 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001621 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
1622 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07001623 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001624 mem_only = 1;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001625 }
1626
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001627 if (mem_only) {
1628 if (pci_enable_device_mem(pdev))
1629 goto probe_out;
1630 } else {
1631 if (pci_enable_device(pdev))
1632 goto probe_out;
1633 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
Jesse Barnes09276782008-10-18 17:33:19 -07001635 /* This may fail but that's ok */
1636 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07001637
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001638 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1639 if (!ha) {
1640 DEBUG(printk("Unable to allocate memory for ha\n"));
1641 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001643 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
1645 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07001646 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001647 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001648 spin_lock_init(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001650 /* Set ISP-type information. */
1651 qla2x00_set_isp_flags(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 /* Configure PCI I/O space */
1653 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001654 if (ret)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001655 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08001658 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1659 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001662 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001663 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001664 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001666 /* Assign ISP specific operations. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001667 max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 if (IS_QLA2100(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001669 max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001671 req_length = REQUEST_ENTRY_CNT_2100;
1672 rsp_length = RESPONSE_ENTRY_CNT_2100;
1673 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001674 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001675 ha->flash_conf_off = ~0;
1676 ha->flash_data_off = ~0;
1677 ha->nvram_conf_off = ~0;
1678 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001679 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 } else if (IS_QLA2200(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001682 req_length = REQUEST_ENTRY_CNT_2200;
1683 rsp_length = RESPONSE_ENTRY_CNT_2100;
1684 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001685 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001686 ha->flash_conf_off = ~0;
1687 ha->flash_data_off = ~0;
1688 ha->nvram_conf_off = ~0;
1689 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001690 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001691 } else if (IS_QLA23XX(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001693 req_length = REQUEST_ENTRY_CNT_2200;
1694 rsp_length = RESPONSE_ENTRY_CNT_2300;
1695 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001696 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001697 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1698 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001699 ha->flash_conf_off = ~0;
1700 ha->flash_data_off = ~0;
1701 ha->nvram_conf_off = ~0;
1702 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001703 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001704 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07001705 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001706 req_length = REQUEST_ENTRY_CNT_24XX;
1707 rsp_length = RESPONSE_ENTRY_CNT_2300;
1708 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001709 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001710 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001711 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001712 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001713 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001714 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1715 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1716 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1717 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001718 } else if (IS_QLA25XX(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001719 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001720 req_length = REQUEST_ENTRY_CNT_24XX;
1721 rsp_length = RESPONSE_ENTRY_CNT_2300;
1722 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001723 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001724 ha->gid_list_info_size = 8;
1725 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001726 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001727 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001728 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1729 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1730 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1731 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1732 } else if (IS_QLA81XX(ha)) {
1733 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1734 req_length = REQUEST_ENTRY_CNT_24XX;
1735 rsp_length = RESPONSE_ENTRY_CNT_2300;
1736 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1737 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
1738 ha->gid_list_info_size = 8;
1739 ha->optrom_size = OPTROM_SIZE_81XX;
1740 ha->isp_ops = &qla81xx_isp_ops;
1741 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
1742 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
1743 ha->nvram_conf_off = ~0;
1744 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07001747 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001748 init_completion(&ha->mbx_cmd_comp);
1749 complete(&ha->mbx_cmd_comp);
1750 init_completion(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001752 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753
Andrew Vasquez53303c42009-01-22 09:45:37 -08001754 qla2x00_config_dma_addressing(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001755 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001756 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 qla_printk(KERN_WARNING, ha,
1758 "[ERROR] Failed to allocate memory for adapter\n");
1759
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001760 goto probe_hw_failed;
1761 }
1762
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001763 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001764 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001765 req->max_q_depth = ql2xmaxqdepth;
1766
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001767
1768 base_vha = qla2x00_create_host(sht, ha);
1769 if (!base_vha) {
1770 qla_printk(KERN_WARNING, ha,
1771 "[ERROR] Failed to allocate memory for scsi_host\n");
1772
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001773 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001774 qla2x00_mem_free(ha);
1775 qla2x00_free_que(ha, req, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001776 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 }
1778
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001779 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001781 host = base_vha->host;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001782 base_vha->req_ques[0] = req->id;
1783 host->can_queue = req->length + 128;
1784 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001785 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001786 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001787 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1788 base_vha->vp_idx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001789 if (IS_QLA2100(ha))
1790 host->sg_tablesize = 32;
1791 host->max_id = max_id;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001792 host->this_id = 255;
1793 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07001794 host->unique_id = host->host_no;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001795 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001796 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001797 host->max_lun = MAX_LUNS;
1798 host->transportt = qla2xxx_transport_template;
1799
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001800 /* Set up the irqs */
1801 ret = qla2x00_request_irqs(ha, rsp);
1802 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001803 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001804 /* Alloc arrays of request and response ring ptrs */
1805 if (!qla2x00_alloc_queues(ha)) {
1806 qla_printk(KERN_WARNING, ha,
1807 "[ERROR] Failed to allocate memory for queue"
1808 " pointers\n");
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001809 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001810 }
1811 ha->rsp_q_map[0] = rsp;
1812 ha->req_q_map[0] = req;
1813
Andrew Vasquez08029992009-03-24 09:07:55 -07001814 /* FWI2-capable only. */
1815 req->req_q_in = &ha->iobase->isp24.req_q_in;
1816 req->req_q_out = &ha->iobase->isp24.req_q_out;
1817 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
1818 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001819 if (ha->mqenable) {
Andrew Vasquez08029992009-03-24 09:07:55 -07001820 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
1821 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
1822 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
1823 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001824 }
1825
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001826 if (qla2x00_initialize_adapter(base_vha)) {
1827 qla_printk(KERN_WARNING, ha,
1828 "Failed to initialize adapter\n");
1829
1830 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1831 "Adapter flags %x.\n",
1832 base_vha->host_no, base_vha->device_flags));
1833
1834 ret = -ENODEV;
1835 goto probe_failed;
1836 }
1837
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001838 /*
1839 * Startup the kernel thread for this host adapter
1840 */
1841 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1842 "%s_dpc", base_vha->host_str);
1843 if (IS_ERR(ha->dpc_thread)) {
1844 qla_printk(KERN_WARNING, ha,
1845 "Unable to start DPC thread!\n");
1846 ret = PTR_ERR(ha->dpc_thread);
1847 goto probe_failed;
1848 }
1849
1850 list_add_tail(&base_vha->list, &ha->vp_list);
1851 base_vha->host->irq = ha->pdev->irq;
1852
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001854 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
1856 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001857 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001859 base_vha->flags.init_done = 1;
1860 base_vha->flags.online = 1;
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001861
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001862 ret = scsi_add_host(host, &pdev->dev);
1863 if (ret)
1864 goto probe_failed;
1865
Andrew Vasquez048feec2008-09-11 22:19:45 -07001866 ha->isp_ops->enable_intrs(ha);
1867
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001868 scsi_scan_host(host);
1869
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001870 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001871
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001872 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001873
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001874 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001875
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 qla_printk(KERN_INFO, ha, "\n"
1877 " QLogic Fibre Channel HBA Driver: %s\n"
1878 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08001879 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1880 qla2x00_version_str, ha->model_number,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001881 ha->model_desc ? ha->model_desc : "", pdev->device,
1882 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
1883 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
1884 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 return 0;
1887
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001888probe_init_failed:
1889 qla2x00_free_que(ha, req, rsp);
1890 ha->max_queues = 0;
1891
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07001893 if (base_vha->timer_active)
1894 qla2x00_stop_timer(base_vha);
1895 base_vha->flags.online = 0;
1896 if (ha->dpc_thread) {
1897 struct task_struct *t = ha->dpc_thread;
1898
1899 ha->dpc_thread = NULL;
1900 kthread_stop(t);
1901 }
1902
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001903 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001905 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001907probe_hw_failed:
1908 if (ha->iobase)
1909 iounmap(ha->iobase);
1910
1911 pci_release_selected_regions(ha->pdev, ha->bars);
1912 kfree(ha);
1913 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001915probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001916 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001917 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919
Adrian Bunk4c993f72008-01-14 00:55:16 -08001920static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001921qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001923 scsi_qla_host_t *base_vha, *vha, *temp;
1924 struct qla_hw_data *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001926 base_vha = pci_get_drvdata(pdev);
1927 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001929 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
1930 if (vha && vha->fc_vport)
1931 fc_vport_terminate(vha->fc_vport);
1932 }
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07001933
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001934 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07001935
Andrew Vasquezb9978762009-03-24 09:08:05 -07001936 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
1937
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001938 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001939
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001940 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001941
Andrew Vasquezb9978762009-03-24 09:08:05 -07001942 /* Disable timer */
1943 if (base_vha->timer_active)
1944 qla2x00_stop_timer(base_vha);
1945
1946 base_vha->flags.online = 0;
1947
1948 /* Kill the kernel thread for this host */
1949 if (ha->dpc_thread) {
1950 struct task_struct *t = ha->dpc_thread;
1951
1952 /*
1953 * qla2xxx_wake_dpc checks for ->dpc_thread
1954 * so we need to zero it out.
1955 */
1956 ha->dpc_thread = NULL;
1957 kthread_stop(t);
1958 }
1959
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001960 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001962 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05001963
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001964 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001966 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001968 scsi_host_put(base_vha->host);
1969
1970 if (ha->iobase)
1971 iounmap(ha->iobase);
1972
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001973 if (ha->mqiobase)
1974 iounmap(ha->mqiobase);
1975
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001976 pci_release_selected_regions(ha->pdev, ha->bars);
1977 kfree(ha);
1978 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
Bernhard Walle665db932007-03-28 00:49:49 +02001980 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 pci_set_drvdata(pdev, NULL);
1982}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983
1984static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001985qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001987 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001989 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001990 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001991
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001992 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001993 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001994
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001995 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001996 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001998 /* turn-off interrupts on the card */
1999 if (ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002000 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002001
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002002 qla2x00_free_irqs(vha);
2003
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002004 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002005
2006 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007}
2008
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002009static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002010qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002011 int defer)
2012{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002013 struct fc_rport *rport;
2014
2015 if (!fcport->rport)
2016 return;
2017
2018 rport = fcport->rport;
2019 if (defer) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002020 spin_lock_irq(vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002021 fcport->drport = rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002022 spin_unlock_irq(vha->host->host_lock);
2023 set_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
2024 qla2xxx_wake_dpc(vha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002025 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002026 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002027}
2028
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2031 *
2032 * Input: ha = adapter block pointer. fcport = port structure pointer.
2033 *
2034 * Return: None.
2035 *
2036 * Context:
2037 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002038void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002039 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002041 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002042 vha->vp_idx == fcport->vp_idx) {
2043 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2044 qla2x00_schedule_rport_del(vha, fcport, defer);
2045 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002046 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 * We may need to retry the login, so don't change the state of the
2048 * port but do the retries.
2049 */
2050 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2051 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2052
2053 if (!do_login)
2054 return;
2055
2056 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002057 fcport->login_retry = vha->hw->login_retry_count;
2058 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
2060 DEBUG(printk("scsi(%ld): Port login retry: "
2061 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2062 "id = 0x%04x retry cnt=%d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002063 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 fcport->port_name[0],
2065 fcport->port_name[1],
2066 fcport->port_name[2],
2067 fcport->port_name[3],
2068 fcport->port_name[4],
2069 fcport->port_name[5],
2070 fcport->port_name[6],
2071 fcport->port_name[7],
2072 fcport->loop_id,
2073 fcport->login_retry));
2074 }
2075}
2076
2077/*
2078 * qla2x00_mark_all_devices_lost
2079 * Updates fcport state when device goes offline.
2080 *
2081 * Input:
2082 * ha = adapter block pointer.
2083 * fcport = port structure pointer.
2084 *
2085 * Return:
2086 * None.
2087 *
2088 * Context:
2089 */
2090void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002091qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092{
2093 fc_port_t *fcport;
2094
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002095 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2096 if (vha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 /*
2099 * No point in marking the device as lost, if the device is
2100 * already DEAD.
2101 */
2102 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2103 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002104 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2105 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2106 qla2x00_schedule_rport_del(vha, fcport, defer);
2107 } else
2108 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 }
2110}
2111
2112/*
2113* qla2x00_mem_alloc
2114* Allocates adapter memory.
2115*
2116* Returns:
2117* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08002118* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002120static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002121qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2122 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123{
2124 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125
Andrew Vasqueze8711082008-01-31 12:33:48 -08002126 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002127 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002128 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002129 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002131 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2132 &ha->gid_list_dma, GFP_KERNEL);
2133 if (!ha->gid_list)
Andrew Vasqueze8711082008-01-31 12:33:48 -08002134 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135
Andrew Vasqueze8711082008-01-31 12:33:48 -08002136 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2137 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002138 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
Andrew Vasqueze8711082008-01-31 12:33:48 -08002140 /* Get memory for cached NVRAM */
2141 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2142 if (!ha->nvram)
2143 goto fail_free_srb_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002145 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2146 ha->pdev->device);
2147 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2148 DMA_POOL_SIZE, 8, 0);
2149 if (!ha->s_dma_pool)
2150 goto fail_free_nvram;
2151
Andrew Vasqueze8711082008-01-31 12:33:48 -08002152 /* Allocate memory for SNS commands */
2153 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002154 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002155 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002156 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002157 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002158 goto fail_dma_pool;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002159 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002160 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002161 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002162 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002163 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002164 goto fail_dma_pool;
2165 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002166 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002167 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002168 if (!ha->ct_sns)
2169 goto fail_free_ms_iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 }
2171
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002172 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002173 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2174 if (!*req) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002175 DEBUG(printk("Unable to allocate memory for req\n"));
2176 goto fail_req;
2177 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002178 (*req)->length = req_len;
2179 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2180 ((*req)->length + 1) * sizeof(request_t),
2181 &(*req)->dma, GFP_KERNEL);
2182 if (!(*req)->ring) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002183 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2184 goto fail_req_ring;
2185 }
2186 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002187 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2188 if (!*rsp) {
2189 qla_printk(KERN_WARNING, ha,
2190 "Unable to allocate memory for rsp\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002191 goto fail_rsp;
2192 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002193 (*rsp)->hw = ha;
2194 (*rsp)->length = rsp_len;
2195 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2196 ((*rsp)->length + 1) * sizeof(response_t),
2197 &(*rsp)->dma, GFP_KERNEL);
2198 if (!(*rsp)->ring) {
2199 qla_printk(KERN_WARNING, ha,
2200 "Unable to allocate memory for rsp_ring\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002201 goto fail_rsp_ring;
2202 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002203 (*req)->rsp = *rsp;
2204 (*rsp)->req = *req;
2205 /* Allocate memory for NVRAM data for vports */
2206 if (ha->nvram_npiv_size) {
2207 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2208 ha->nvram_npiv_size, GFP_KERNEL);
2209 if (!ha->npiv_info) {
2210 qla_printk(KERN_WARNING, ha,
2211 "Unable to allocate memory for npiv info\n");
2212 goto fail_npiv_info;
2213 }
2214 } else
2215 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002216
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002217 /* Get consistent memory allocated for EX-INIT-CB. */
2218 if (IS_QLA81XX(ha)) {
2219 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2220 &ha->ex_init_cb_dma);
2221 if (!ha->ex_init_cb)
2222 goto fail_ex_init_cb;
2223 }
2224
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002225 INIT_LIST_HEAD(&ha->vp_list);
2226 return 1;
2227
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002228fail_ex_init_cb:
2229 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002230fail_npiv_info:
2231 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2232 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2233 (*rsp)->ring = NULL;
2234 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002235fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002236 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002237fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002238 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2239 sizeof(request_t), (*req)->ring, (*req)->dma);
2240 (*req)->ring = NULL;
2241 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002242fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002243 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002244fail_req:
2245 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2246 ha->ct_sns, ha->ct_sns_dma);
2247 ha->ct_sns = NULL;
2248 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002249fail_free_ms_iocb:
2250 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2251 ha->ms_iocb = NULL;
2252 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002253fail_dma_pool:
2254 dma_pool_destroy(ha->s_dma_pool);
2255 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002256fail_free_nvram:
2257 kfree(ha->nvram);
2258 ha->nvram = NULL;
2259fail_free_srb_mempool:
2260 mempool_destroy(ha->srb_mempool);
2261 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002262fail_free_gid_list:
2263 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002264 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002265 ha->gid_list = NULL;
2266 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002267fail_free_init_cb:
2268 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2269 ha->init_cb_dma);
2270 ha->init_cb = NULL;
2271 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002272fail:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002273 DEBUG(printk("%s: Memory allocation failure\n", __func__));
Andrew Vasqueze8711082008-01-31 12:33:48 -08002274 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275}
2276
2277/*
2278* qla2x00_mem_free
2279* Frees all adapter allocated memory.
2280*
2281* Input:
2282* ha = adapter block pointer.
2283*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08002284static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002285qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286{
Andrew Vasqueze8711082008-01-31 12:33:48 -08002287 if (ha->srb_mempool)
2288 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002290 if (ha->fce)
2291 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002292 ha->fce_dma);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002293
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002294 if (ha->fw_dump) {
2295 if (ha->eft)
2296 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002297 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002298 vfree(ha->fw_dump);
2299 }
2300
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 if (ha->sns_cmd)
2302 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002303 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
2305 if (ha->ct_sns)
2306 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002307 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308
Andrew Vasquez88729e52006-06-23 16:10:50 -07002309 if (ha->sfp_data)
2310 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2311
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 if (ha->ms_iocb)
2313 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2314
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002315 if (ha->ex_init_cb)
2316 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
2317
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 if (ha->s_dma_pool)
2319 dma_pool_destroy(ha->s_dma_pool);
2320
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 if (ha->gid_list)
2322 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002323 ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002325 if (ha->init_cb)
2326 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2327 ha->init_cb, ha->init_cb_dma);
2328 vfree(ha->optrom_buffer);
2329 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002330 kfree(ha->npiv_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331
Andrew Vasqueze8711082008-01-31 12:33:48 -08002332 ha->srb_mempool = NULL;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002333 ha->eft = NULL;
2334 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 ha->sns_cmd = NULL;
2336 ha->sns_cmd_dma = 0;
2337 ha->ct_sns = NULL;
2338 ha->ct_sns_dma = 0;
2339 ha->ms_iocb = NULL;
2340 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 ha->init_cb = NULL;
2342 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002343 ha->ex_init_cb = NULL;
2344 ha->ex_init_cb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
2346 ha->s_dma_pool = NULL;
2347
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 ha->gid_list = NULL;
2349 ha->gid_list_dma = 0;
2350
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002352 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 ha->fw_dump_reading = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002354}
2355
2356struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2357 struct qla_hw_data *ha)
2358{
2359 struct Scsi_Host *host;
2360 struct scsi_qla_host *vha = NULL;
2361
2362 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2363 if (host == NULL) {
2364 printk(KERN_WARNING
2365 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2366 goto fail;
2367 }
2368
2369 /* Clear our data area */
2370 vha = shost_priv(host);
2371 memset(vha, 0, sizeof(scsi_qla_host_t));
2372
2373 vha->host = host;
2374 vha->host_no = host->host_no;
2375 vha->hw = ha;
2376
2377 INIT_LIST_HEAD(&vha->vp_fcports);
2378 INIT_LIST_HEAD(&vha->work_list);
2379 INIT_LIST_HEAD(&vha->list);
2380
2381 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2382 return vha;
2383
2384fail:
2385 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386}
2387
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002388static struct qla_work_evt *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002389qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002390 int locked)
2391{
2392 struct qla_work_evt *e;
2393
2394 e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
2395 GFP_KERNEL);
2396 if (!e)
2397 return NULL;
2398
2399 INIT_LIST_HEAD(&e->list);
2400 e->type = type;
2401 e->flags = QLA_EVT_FLAG_FREE;
2402 return e;
2403}
2404
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002405static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002406qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e, int locked)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002407{
Andrew Mortonbf6583b2008-07-24 08:31:48 -07002408 unsigned long uninitialized_var(flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002409 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002410
2411 if (!locked)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002412 spin_lock_irqsave(&ha->hardware_lock, flags);
2413 list_add_tail(&e->list, &vha->work_list);
2414 qla2xxx_wake_dpc(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002415 if (!locked)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002416 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002417 return QLA_SUCCESS;
2418}
2419
2420int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002421qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002422 u32 data)
2423{
2424 struct qla_work_evt *e;
2425
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002426 e = qla2x00_alloc_work(vha, QLA_EVT_AEN, 1);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002427 if (!e)
2428 return QLA_FUNCTION_FAILED;
2429
2430 e->u.aen.code = code;
2431 e->u.aen.data = data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002432 return qla2x00_post_work(vha, e, 1);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002433}
2434
Andrew Vasquez8a659572009-02-08 20:50:12 -08002435int
2436qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
2437{
2438 struct qla_work_evt *e;
2439
2440 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK, 1);
2441 if (!e)
2442 return QLA_FUNCTION_FAILED;
2443
2444 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
2445 return qla2x00_post_work(vha, e, 1);
2446}
2447
Andrew Vasquez0971de72008-04-03 13:13:18 -07002448static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002449qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002450{
2451 struct qla_work_evt *e;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002452 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002453
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002454 spin_lock_irq(&ha->hardware_lock);
2455 while (!list_empty(&vha->work_list)) {
2456 e = list_entry(vha->work_list.next, struct qla_work_evt, list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002457 list_del_init(&e->list);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002458 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002459
2460 switch (e->type) {
2461 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002462 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07002463 e->u.aen.code, e->u.aen.data);
2464 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08002465 case QLA_EVT_IDC_ACK:
2466 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
2467 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002468 }
2469 if (e->flags & QLA_EVT_FLAG_FREE)
2470 kfree(e);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002471 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002472 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473 spin_unlock_irq(&ha->hardware_lock);
2474}
2475/* Relogins all the fcports of a vport
2476 * Context: dpc thread
2477 */
2478void qla2x00_relogin(struct scsi_qla_host *vha)
2479{
2480 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08002481 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002482 uint16_t next_loopid = 0;
2483 struct qla_hw_data *ha = vha->hw;
2484
2485 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2486 /*
2487 * If the port is not ONLINE then try to login
2488 * to it if we haven't run out of retries.
2489 */
2490 if (atomic_read(&fcport->state) !=
2491 FCS_ONLINE && fcport->login_retry) {
2492
2493 if (fcport->flags & FCF_FABRIC_DEVICE) {
2494 if (fcport->flags & FCF_TAPE_PRESENT)
2495 ha->isp_ops->fabric_logout(vha,
2496 fcport->loop_id,
2497 fcport->d_id.b.domain,
2498 fcport->d_id.b.area,
2499 fcport->d_id.b.al_pa);
2500
2501 status = qla2x00_fabric_login(vha, fcport,
2502 &next_loopid);
2503 } else
2504 status = qla2x00_local_device_login(vha,
2505 fcport);
2506
2507 fcport->login_retry--;
2508 if (status == QLA_SUCCESS) {
2509 fcport->old_loop_id = fcport->loop_id;
2510
2511 DEBUG(printk("scsi(%ld): port login OK: logged "
2512 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2513
2514 qla2x00_update_fcport(vha, fcport);
2515
2516 } else if (status == 1) {
2517 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2518 /* retry the login again */
2519 DEBUG(printk("scsi(%ld): Retrying"
2520 " %d login again loop_id 0x%x\n",
2521 vha->host_no, fcport->login_retry,
2522 fcport->loop_id));
2523 } else {
2524 fcport->login_retry = 0;
2525 }
2526
2527 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2528 fcport->loop_id = FC_NO_LOOP_ID;
2529 }
2530 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2531 break;
2532 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07002533}
2534
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535/**************************************************************************
2536* qla2x00_do_dpc
2537* This kernel thread is a task that is schedule by the interrupt handler
2538* to perform the background processing for interrupts.
2539*
2540* Notes:
2541* This task always run in the context of a kernel thread. It
2542* is kick-off by the driver's detect code and starts up
2543* up one per adapter. It immediately goes to sleep and waits for
2544* some fibre event. When either the interrupt handler or
2545* the timer routine detects a event it will one of the task
2546* bits then wake us up.
2547**************************************************************************/
2548static int
2549qla2x00_do_dpc(void *data)
2550{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002551 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002552 scsi_qla_host_t *base_vha;
2553 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08002554
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002555 ha = (struct qla_hw_data *)data;
2556 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 set_user_nice(current, -20);
2559
Christoph Hellwig39a11242006-02-14 18:46:22 +01002560 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2562
Christoph Hellwig39a11242006-02-14 18:46:22 +01002563 set_current_state(TASK_INTERRUPTIBLE);
2564 schedule();
2565 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566
2567 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2568
2569 /* Initialization not yet finished. Don't do anything yet. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002570 if (!base_vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 continue;
2572
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002573 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574
2575 ha->dpc_active = 1;
2576
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 ha->dpc_active = 0;
2579 continue;
2580 }
2581
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002582 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002583
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002584 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2585 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586
2587 DEBUG(printk("scsi(%ld): dpc: sched "
2588 "qla2x00_abort_isp ha = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002589 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002591 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002593 if (qla2x00_abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 /* failed. retry later */
2595 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002596 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002598 clear_bit(ABORT_ISP_ACTIVE,
2599 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08002600 }
2601
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002603 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 }
2605
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002606 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2607 qla2x00_update_fcports(base_vha);
2608 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07002609 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002610
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002611 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2612 &base_vha->dpc_flags) &&
2613 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614
2615 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002616 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002618 qla2x00_rst_aen(base_vha);
2619 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 }
2621
2622 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002623 if ((test_and_clear_bit(RELOGIN_NEEDED,
2624 &base_vha->dpc_flags)) &&
2625 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2626 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627
2628 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002629 base_vha->host_no));
2630 qla2x00_relogin(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002633 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 }
2635
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002636 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2637 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638
2639 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002640 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641
2642 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002643 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002645 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002647 clear_bit(LOOP_RESYNC_ACTIVE,
2648 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 }
2650
2651 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002652 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 }
2654
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002655 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2656 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2657 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2658 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07002659 }
2660
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002662 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002664 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2665 &base_vha->dpc_flags))
2666 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002667
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002668 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002669
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 ha->dpc_active = 0;
2671 } /* End of while(1) */
2672
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002673 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674
2675 /*
2676 * Make sure that nobody tries to wake us up again.
2677 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 ha->dpc_active = 0;
2679
Christoph Hellwig39a11242006-02-14 18:46:22 +01002680 return 0;
2681}
2682
2683void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002684qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01002685{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002686 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002687 struct task_struct *t = ha->dpc_thread;
2688
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002689 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002690 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691}
2692
2693/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694* qla2x00_rst_aen
2695* Processes asynchronous reset.
2696*
2697* Input:
2698* ha = adapter block pointer.
2699*/
2700static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002701qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002703 if (vha->flags.online && !vha->flags.reset_active &&
2704 !atomic_read(&vha->loop_down_timer) &&
2705 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002707 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708
2709 /*
2710 * Issue marker command only when we are going to start
2711 * the I/O.
2712 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002713 vha->marker_needed = 1;
2714 } while (!atomic_read(&vha->loop_down_timer) &&
2715 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 }
2717}
2718
f4f051e2005-04-17 15:02:26 -05002719static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002720qla2x00_sp_free_dma(srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002721{
2722 struct scsi_cmnd *cmd = sp->cmd;
2723
2724 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002725 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05002726 sp->flags &= ~SRB_DMA_VALID;
2727 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002728 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002729}
2730
2731void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002732qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002733{
2734 struct scsi_cmnd *cmd = sp->cmd;
2735
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002736 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -05002737
f4f051e2005-04-17 15:02:26 -05002738 mempool_free(sp, ha->srb_mempool);
2739
2740 cmd->scsi_done(cmd);
2741}
bdf79622005-04-17 15:06:53 -05002742
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743/**************************************************************************
2744* qla2x00_timer
2745*
2746* Description:
2747* One second timer
2748*
2749* Context: Interrupt
2750***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002751void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002752qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 unsigned long cpu_flags = 0;
2755 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 int start_dpc = 0;
2757 int index;
2758 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002759 int t;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002760 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002761 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 /*
2763 * Ports - Port down timer.
2764 *
2765 * Whenever, a port is in the LOST state we start decrementing its port
2766 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002767 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 */
2769 t = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002770 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 if (fcport->port_type != FCT_TARGET)
2772 continue;
2773
2774 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2775
2776 if (atomic_read(&fcport->port_down_timer) == 0)
2777 continue;
2778
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002779 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002781
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002783 "%d remaining\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002784 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 t, atomic_read(&fcport->port_down_timer)));
2786 }
2787 t++;
2788 } /* End of for fcport */
2789
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790
2791 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002792 if (atomic_read(&vha->loop_down_timer) > 0 &&
2793 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
2794 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002796 if (atomic_read(&vha->loop_down_timer) ==
2797 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798
2799 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2800 "queues before time expire\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002801 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002803 if (!IS_QLA2100(ha) && vha->link_down_timeout)
2804 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
2806 /* Schedule an ISP abort to return any tape commands. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002807 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002808 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002809 spin_lock_irqsave(&ha->hardware_lock,
2810 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002811 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002812 for (index = 1;
2813 index < MAX_OUTSTANDING_COMMANDS;
2814 index++) {
2815 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05002816
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002817 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002818 if (!sp)
2819 continue;
2820 sfcp = sp->fcport;
2821 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2822 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002824 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002825 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002826 break;
2827 }
2828 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002829 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002831 set_bit(ABORT_QUEUES_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 start_dpc++;
2833 }
2834
2835 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002836 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2838 "restarting queues.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002839 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002841 set_bit(RESTART_QUEUES_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 start_dpc++;
2843
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002844 if (!(vha->device_flags & DFLG_NO_CABLE) &&
2845 !vha->vp_idx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 DEBUG(printk("scsi(%ld): Loop down - "
2847 "aborting ISP.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002848 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 qla_printk(KERN_WARNING, ha,
2850 "Loop down - aborting ISP.\n");
2851
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002852 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 }
2854 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002855 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002856 vha->host_no,
2857 atomic_read(&vha->loop_down_timer)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 }
2859
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002860 /* Check if beacon LED needs to be blinked */
2861 if (ha->beacon_blink_led == 1) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002862 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002863 start_dpc++;
2864 }
2865
Andrew Vasquez550bf572008-04-24 15:21:23 -07002866 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002867 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07002868 start_dpc++;
2869
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002871 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
2872 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
2873 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002875 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
2876 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
2877 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
2878 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
2879 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002881 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882}
2883
Andrew Vasquez54333832005-11-09 15:49:04 -08002884/* Firmware interface routines. */
2885
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002886#define FW_BLOBS 7
Andrew Vasquez54333832005-11-09 15:49:04 -08002887#define FW_ISP21XX 0
2888#define FW_ISP22XX 1
2889#define FW_ISP2300 2
2890#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002891#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002892#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002893#define FW_ISP81XX 6
Andrew Vasquez54333832005-11-09 15:49:04 -08002894
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002895#define FW_FILE_ISP21XX "ql2100_fw.bin"
2896#define FW_FILE_ISP22XX "ql2200_fw.bin"
2897#define FW_FILE_ISP2300 "ql2300_fw.bin"
2898#define FW_FILE_ISP2322 "ql2322_fw.bin"
2899#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002900#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002901#define FW_FILE_ISP81XX "ql8100_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002902
Daniel Walkere1e82b62008-05-12 22:21:10 -07002903static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002904
2905static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002906 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
2907 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
2908 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
2909 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
2910 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002911 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002912 { .name = FW_FILE_ISP81XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08002913};
2914
2915struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002916qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08002917{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002918 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08002919 struct fw_blob *blob;
2920
2921 blob = NULL;
2922 if (IS_QLA2100(ha)) {
2923 blob = &qla_fw_blobs[FW_ISP21XX];
2924 } else if (IS_QLA2200(ha)) {
2925 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002926 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002927 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002928 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002929 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002930 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002931 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002932 } else if (IS_QLA25XX(ha)) {
2933 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002934 } else if (IS_QLA81XX(ha)) {
2935 blob = &qla_fw_blobs[FW_ISP81XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08002936 }
2937
Daniel Walkere1e82b62008-05-12 22:21:10 -07002938 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002939 if (blob->fw)
2940 goto out;
2941
2942 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
2943 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002944 "(%s).\n", vha->host_no, blob->name));
Andrew Vasquez54333832005-11-09 15:49:04 -08002945 blob->fw = NULL;
2946 blob = NULL;
2947 goto out;
2948 }
2949
2950out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07002951 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002952 return blob;
2953}
2954
2955static void
2956qla2x00_release_firmware(void)
2957{
2958 int idx;
2959
Daniel Walkere1e82b62008-05-12 22:21:10 -07002960 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002961 for (idx = 0; idx < FW_BLOBS; idx++)
2962 if (qla_fw_blobs[idx].fw)
2963 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07002964 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002965}
2966
Seokmann Ju14e660e2007-09-20 14:07:36 -07002967static pci_ers_result_t
2968qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
2969{
2970 switch (state) {
2971 case pci_channel_io_normal:
2972 return PCI_ERS_RESULT_CAN_RECOVER;
2973 case pci_channel_io_frozen:
2974 pci_disable_device(pdev);
2975 return PCI_ERS_RESULT_NEED_RESET;
2976 case pci_channel_io_perm_failure:
2977 qla2x00_remove_one(pdev);
2978 return PCI_ERS_RESULT_DISCONNECT;
2979 }
2980 return PCI_ERS_RESULT_NEED_RESET;
2981}
2982
2983static pci_ers_result_t
2984qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
2985{
2986 int risc_paused = 0;
2987 uint32_t stat;
2988 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002989 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
2990 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07002991 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2992 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
2993
2994 spin_lock_irqsave(&ha->hardware_lock, flags);
2995 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
2996 stat = RD_REG_DWORD(&reg->hccr);
2997 if (stat & HCCR_RISC_PAUSE)
2998 risc_paused = 1;
2999 } else if (IS_QLA23XX(ha)) {
3000 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
3001 if (stat & HSR_RISC_PAUSED)
3002 risc_paused = 1;
3003 } else if (IS_FWI2_CAPABLE(ha)) {
3004 stat = RD_REG_DWORD(&reg24->host_status);
3005 if (stat & HSRX_RISC_PAUSED)
3006 risc_paused = 1;
3007 }
3008 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3009
3010 if (risc_paused) {
3011 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3012 "Dumping firmware!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003013 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003014
3015 return PCI_ERS_RESULT_NEED_RESET;
3016 } else
3017 return PCI_ERS_RESULT_RECOVERED;
3018}
3019
3020static pci_ers_result_t
3021qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3022{
3023 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003024 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3025 struct qla_hw_data *ha = base_vha->hw;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003026 int rc;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003027
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003028 if (ha->mem_only)
3029 rc = pci_enable_device_mem(pdev);
3030 else
3031 rc = pci_enable_device(pdev);
3032
3033 if (rc) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07003034 qla_printk(KERN_WARNING, ha,
3035 "Can't re-enable PCI device after reset.\n");
3036
3037 return ret;
3038 }
3039 pci_set_master(pdev);
3040
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003041 if (ha->isp_ops->pci_config(base_vha))
Seokmann Ju14e660e2007-09-20 14:07:36 -07003042 return ret;
3043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003044 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3045 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07003046 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003047 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003048
3049 return ret;
3050}
3051
3052static void
3053qla2xxx_pci_resume(struct pci_dev *pdev)
3054{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003055 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3056 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003057 int ret;
3058
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003059 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003060 if (ret != QLA_SUCCESS) {
3061 qla_printk(KERN_ERR, ha,
3062 "the device failed to resume I/O "
3063 "from slot/link_reset");
3064 }
3065 pci_cleanup_aer_uncorrect_error_status(pdev);
3066}
3067
3068static struct pci_error_handlers qla2xxx_err_handler = {
3069 .error_detected = qla2xxx_pci_error_detected,
3070 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3071 .slot_reset = qla2xxx_pci_slot_reset,
3072 .resume = qla2xxx_pci_resume,
3073};
3074
Andrew Vasquez54333832005-11-09 15:49:04 -08003075static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003076 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3077 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3078 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3079 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3080 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3081 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3082 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3083 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3084 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003085 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003086 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3087 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003088 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003089 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Andrew Vasquez54333832005-11-09 15:49:04 -08003090 { 0 },
3091};
3092MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3093
Andrew Vasquezfca29702005-07-06 10:31:47 -07003094static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07003095 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06003096 .driver = {
3097 .owner = THIS_MODULE,
3098 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07003099 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003100 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08003101 .remove = qla2x00_remove_one,
Seokmann Ju14e660e2007-09-20 14:07:36 -07003102 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07003103};
3104
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105/**
3106 * qla2x00_module_init - Module initialization.
3107 **/
3108static int __init
3109qla2x00_module_init(void)
3110{
Andrew Vasquezfca29702005-07-06 10:31:47 -07003111 int ret = 0;
3112
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003114 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09003115 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 if (srb_cachep == NULL) {
3117 printk(KERN_ERR
3118 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3119 return -ENOMEM;
3120 }
3121
3122 /* Derive version string. */
3123 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07003124 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07003125 strcat(qla2x00_version_str, "-debug");
3126
Andrew Vasquez1c97a122005-04-21 16:13:36 -04003127 qla2xxx_transport_template =
3128 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003129 if (!qla2xxx_transport_template) {
3130 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003132 }
3133 qla2xxx_transport_vport_template =
3134 fc_attach_transport(&qla2xxx_transport_vport_functions);
3135 if (!qla2xxx_transport_vport_template) {
3136 kmem_cache_destroy(srb_cachep);
3137 fc_release_transport(qla2xxx_transport_template);
3138 return -ENODEV;
3139 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07003141 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3142 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003143 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003144 if (ret) {
3145 kmem_cache_destroy(srb_cachep);
3146 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003147 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003148 }
3149 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150}
3151
3152/**
3153 * qla2x00_module_exit - Module cleanup.
3154 **/
3155static void __exit
3156qla2x00_module_exit(void)
3157{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003158 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08003159 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003160 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003162 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163}
3164
3165module_init(qla2x00_module_init);
3166module_exit(qla2x00_module_exit);
3167
3168MODULE_AUTHOR("QLogic Corporation");
3169MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3170MODULE_LICENSE("GPL");
3171MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003172MODULE_FIRMWARE(FW_FILE_ISP21XX);
3173MODULE_FIRMWARE(FW_FILE_ISP22XX);
3174MODULE_FIRMWARE(FW_FILE_ISP2300);
3175MODULE_FIRMWARE(FW_FILE_ISP2322);
3176MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08003177MODULE_FIRMWARE(FW_FILE_ISP25XX);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003178MODULE_FIRMWARE(FW_FILE_ISP81XX);