blob: f344b6816fd327f83c9b0a41153a100d29111fbc [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
68static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
69
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -070070int ql2xfdmienable=1;
Andrew Vasquezcca53352005-08-26 19:08:30 -070071module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
72MODULE_PARM_DESC(ql2xfdmienable,
73 "Enables FDMI registratons "
74 "Default is 0 - no FDMI. 1 - perfom FDMI.");
75
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070076#define MAX_Q_DEPTH 32
77static int ql2xmaxqdepth = MAX_Q_DEPTH;
78module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
79MODULE_PARM_DESC(ql2xmaxqdepth,
80 "Maximum queue depth to report for target devices.");
81
82int ql2xqfullrampup = 120;
83module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR);
84MODULE_PARM_DESC(ql2xqfullrampup,
85 "Number of seconds to wait to begin to ramp-up the queue "
86 "depth for a device after a queue-full condition has been "
87 "detected. Default is 120 seconds.");
88
Andrew Vasqueze5896bd2008-07-10 16:55:52 -070089int ql2xiidmaenable=1;
90module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
91MODULE_PARM_DESC(ql2xiidmaenable,
92 "Enables iIDMA settings "
93 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
94
Anirban Chakraborty73208df2008-12-09 16:45:39 -080095int ql2xmaxqueues = 1;
96module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
97MODULE_PARM_DESC(ql2xmaxqueues,
98 "Enables MQ settings "
99 "Default is 1 for single queue. Set it to number \
100 of queues in MQ mode.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700102 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 */
104static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500105static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800106static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
107static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500108static void qla2xxx_slave_destroy(struct scsi_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
110 void (*fn)(struct scsi_cmnd *));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700111static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
112 void (*fn)(struct scsi_cmnd *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113static int qla2xxx_eh_abort(struct scsi_cmnd *);
114static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700115static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
117static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700119static int qla2x00_change_queue_depth(struct scsi_device *, int);
120static int qla2x00_change_queue_type(struct scsi_device *, int);
121
Adrian Bunka824ebb2008-01-17 09:02:15 -0800122static struct scsi_host_template qla2x00_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700124 .name = QLA2XXX_DRIVER_NAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 .queuecommand = qla2x00_queuecommand,
126
127 .eh_abort_handler = qla2xxx_eh_abort,
128 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700129 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
131 .eh_host_reset_handler = qla2xxx_eh_host_reset,
132
133 .slave_configure = qla2xxx_slave_configure,
134
f4f051e2005-04-17 15:02:26 -0500135 .slave_alloc = qla2xxx_slave_alloc,
136 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800137 .scan_finished = qla2xxx_scan_finished,
138 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700139 .change_queue_depth = qla2x00_change_queue_depth,
140 .change_queue_type = qla2x00_change_queue_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 .this_id = -1,
142 .cmd_per_lun = 3,
143 .use_clustering = ENABLE_CLUSTERING,
144 .sg_tablesize = SG_ALL,
145
146 /*
147 * The RISC allows for each command to transfer (2^32-1) bytes of data,
148 * which equates to 0x800000 sectors.
149 */
150 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700151 .shost_attrs = qla2x00_host_attrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152};
153
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700154struct scsi_host_template qla24xx_driver_template = {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700155 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700156 .name = QLA2XXX_DRIVER_NAME,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700157 .queuecommand = qla24xx_queuecommand,
158
159 .eh_abort_handler = qla2xxx_eh_abort,
160 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700161 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700162 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
163 .eh_host_reset_handler = qla2xxx_eh_host_reset,
164
165 .slave_configure = qla2xxx_slave_configure,
166
167 .slave_alloc = qla2xxx_slave_alloc,
168 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700169 .scan_finished = qla2xxx_scan_finished,
170 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700171 .change_queue_depth = qla2x00_change_queue_depth,
172 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700173 .this_id = -1,
174 .cmd_per_lun = 3,
175 .use_clustering = ENABLE_CLUSTERING,
176 .sg_tablesize = SG_ALL,
177
178 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700179 .shost_attrs = qla2x00_host_attrs,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700180};
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700183struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185/* TODO Convert to inlines
186 *
187 * Timer routines
188 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700190__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800191qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800193 init_timer(&vha->timer);
194 vha->timer.expires = jiffies + interval * HZ;
195 vha->timer.data = (unsigned long)vha;
196 vha->timer.function = (void (*)(unsigned long))func;
197 add_timer(&vha->timer);
198 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199}
200
201static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800202qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800204 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
Adrian Bunka824ebb2008-01-17 09:02:15 -0800207static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800208qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800210 del_timer_sync(&vha->timer);
211 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214static int qla2x00_do_dpc(void *data);
215
216static void qla2x00_rst_aen(scsi_qla_host_t *);
217
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800218static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
219 struct req_que **, struct rsp_que **);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800220static void qla2x00_mem_free(struct qla_hw_data *);
221static void qla2x00_sp_free_dma(srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223/* -------------------------------------------------------------------------- */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800224static int qla2x00_alloc_queues(struct qla_hw_data *ha)
225{
226 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_queues,
227 GFP_KERNEL);
228 if (!ha->req_q_map) {
229 qla_printk(KERN_WARNING, ha,
230 "Unable to allocate memory for request queue ptrs\n");
231 goto fail_req_map;
232 }
233
234 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_queues,
235 GFP_KERNEL);
236 if (!ha->rsp_q_map) {
237 qla_printk(KERN_WARNING, ha,
238 "Unable to allocate memory for response queue ptrs\n");
239 goto fail_rsp_map;
240 }
241 set_bit(0, ha->rsp_qid_map);
242 set_bit(0, ha->req_qid_map);
243 return 1;
244
245fail_rsp_map:
246 kfree(ha->req_q_map);
247 ha->req_q_map = NULL;
248fail_req_map:
249 return -ENOMEM;
250}
251
252static void qla2x00_free_que(struct qla_hw_data *ha, struct req_que *req,
253 struct rsp_que *rsp)
254{
255 if (rsp && rsp->ring)
256 dma_free_coherent(&ha->pdev->dev,
257 (rsp->length + 1) * sizeof(response_t),
258 rsp->ring, rsp->dma);
259
260 kfree(rsp);
261 rsp = NULL;
262 if (req && req->ring)
263 dma_free_coherent(&ha->pdev->dev,
264 (req->length + 1) * sizeof(request_t),
265 req->ring, req->dma);
266
267 kfree(req);
268 req = NULL;
269}
270
271static void qla2x00_free_queues(struct qla_hw_data *ha)
272{
273 struct req_que *req;
274 struct rsp_que *rsp;
275 int cnt;
276
277 for (cnt = 0; cnt < ha->max_queues; cnt++) {
278 rsp = ha->rsp_q_map[cnt];
279 req = ha->req_q_map[cnt];
280 qla2x00_free_que(ha, req, rsp);
281 }
282 kfree(ha->rsp_q_map);
283 ha->rsp_q_map = NULL;
284
285 kfree(ha->req_q_map);
286 ha->req_q_map = NULL;
287}
288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800290qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800292 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 static char *pci_bus_modes[] = {
294 "33", "66", "100", "133",
295 };
296 uint16_t pci_bus;
297
298 strcpy(str, "PCI");
299 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
300 if (pci_bus) {
301 strcat(str, "-X (");
302 strcat(str, pci_bus_modes[pci_bus]);
303 } else {
304 pci_bus = (ha->pci_attr & BIT_8) >> 8;
305 strcat(str, " (");
306 strcat(str, pci_bus_modes[pci_bus]);
307 }
308 strcat(str, " MHz)");
309
310 return (str);
311}
312
Andrew Vasquezfca29702005-07-06 10:31:47 -0700313static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800314qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700315{
316 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800317 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700318 uint32_t pci_bus;
319 int pcie_reg;
320
321 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
322 if (pcie_reg) {
323 char lwstr[6];
324 uint16_t pcie_lstat, lspeed, lwidth;
325
326 pcie_reg += 0x12;
327 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
328 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
329 lwidth = (pcie_lstat &
330 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
331
332 strcpy(str, "PCIe (");
333 if (lspeed == 1)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700334 strcat(str, "2.5GT/s ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700335 else if (lspeed == 2)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700336 strcat(str, "5.0GT/s ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700337 else
338 strcat(str, "<unknown> ");
339 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
340 strcat(str, lwstr);
341
342 return str;
343 }
344
345 strcpy(str, "PCI");
346 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
347 if (pci_bus == 0 || pci_bus == 8) {
348 strcat(str, " (");
349 strcat(str, pci_bus_modes[pci_bus >> 3]);
350 } else {
351 strcat(str, "-X ");
352 if (pci_bus & BIT_2)
353 strcat(str, "Mode 2");
354 else
355 strcat(str, "Mode 1");
356 strcat(str, " (");
357 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
358 }
359 strcat(str, " MHz)");
360
361 return str;
362}
363
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800364static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800365qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
367 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800368 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
371 ha->fw_minor_version,
372 ha->fw_subminor_version);
373
374 if (ha->fw_attributes & BIT_9) {
375 strcat(str, "FLX");
376 return (str);
377 }
378
379 switch (ha->fw_attributes & 0xFF) {
380 case 0x7:
381 strcat(str, "EF");
382 break;
383 case 0x17:
384 strcat(str, "TP");
385 break;
386 case 0x37:
387 strcat(str, "IP");
388 break;
389 case 0x77:
390 strcat(str, "VI");
391 break;
392 default:
393 sprintf(un_str, "(%x)", ha->fw_attributes);
394 strcat(str, un_str);
395 break;
396 }
397 if (ha->fw_attributes & 0x100)
398 strcat(str, "X");
399
400 return (str);
401}
402
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800403static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800404qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700405{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800406 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700407
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800408 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
409 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700410 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700411}
412
413static inline srb_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800414qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700415 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
416{
417 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800418 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700419
420 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
421 if (!sp)
422 return sp;
423
Andrew Vasquezfca29702005-07-06 10:31:47 -0700424 sp->fcport = fcport;
425 sp->cmd = cmd;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800426 sp->que = ha->req_q_map[0];
Andrew Vasquezfca29702005-07-06 10:31:47 -0700427 sp->flags = 0;
428 CMD_SP(cmd) = (void *)sp;
429 cmd->scsi_done = done;
430
431 return sp;
432}
433
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434static int
f4f051e2005-04-17 15:02:26 -0500435qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800437 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500438 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400439 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800440 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500441 srb_t *sp;
442 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Seokmann Ju14e660e2007-09-20 14:07:36 -0700444 if (unlikely(pci_channel_offline(ha->pdev))) {
445 cmd->result = DID_REQUEUE << 16;
446 goto qc_fail_command;
447 }
448
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400449 rval = fc_remote_port_chkready(rport);
450 if (rval) {
451 cmd->result = rval;
f4f051e2005-04-17 15:02:26 -0500452 goto qc_fail_command;
453 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800455 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500456 if (fcport->drport)
457 goto qc_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800458
f4f051e2005-04-17 15:02:26 -0500459 if (atomic_read(&fcport->state) != FCS_ONLINE) {
460 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800461 atomic_read(&vha->loop_state) == LOOP_DEAD) {
f4f051e2005-04-17 15:02:26 -0500462 cmd->result = DID_NO_CONNECT << 16;
463 goto qc_fail_command;
464 }
Mike Christie7b594132008-08-17 15:24:40 -0500465 goto qc_target_busy;
f4f051e2005-04-17 15:02:26 -0500466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800468 spin_unlock_irq(vha->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800470 sp = qla2x00_get_new_sp(vha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700471 if (!sp)
f4f051e2005-04-17 15:02:26 -0500472 goto qc_host_busy_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800474 rval = ha->isp_ops->start_scsi(sp);
f4f051e2005-04-17 15:02:26 -0500475 if (rval != QLA_SUCCESS)
476 goto qc_host_busy_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800478 spin_lock_irq(vha->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
f4f051e2005-04-17 15:02:26 -0500480 return 0;
481
482qc_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800483 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -0500484 mempool_free(sp, ha->srb_mempool);
485
486qc_host_busy_lock:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800487 spin_lock_irq(vha->host->host_lock);
f4f051e2005-04-17 15:02:26 -0500488 return SCSI_MLQUEUE_HOST_BUSY;
489
Mike Christie7b594132008-08-17 15:24:40 -0500490qc_target_busy:
491 return SCSI_MLQUEUE_TARGET_BUSY;
492
f4f051e2005-04-17 15:02:26 -0500493qc_fail_command:
494 done(cmd);
495
496 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497}
498
Andrew Vasquezfca29702005-07-06 10:31:47 -0700499
500static int
501qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
502{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800503 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700504 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400505 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800506 struct qla_hw_data *ha = vha->hw;
507 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700508 srb_t *sp;
509 int rval;
510
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800511 if (unlikely(pci_channel_offline(ha->pdev))) {
Seokmann Ju14e660e2007-09-20 14:07:36 -0700512 cmd->result = DID_REQUEUE << 16;
513 goto qc24_fail_command;
514 }
515
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400516 rval = fc_remote_port_chkready(rport);
517 if (rval) {
518 cmd->result = rval;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700519 goto qc24_fail_command;
520 }
521
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800522 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500523 if (fcport->drport)
524 goto qc24_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800525
Andrew Vasquezfca29702005-07-06 10:31:47 -0700526 if (atomic_read(&fcport->state) != FCS_ONLINE) {
527 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800528 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700529 cmd->result = DID_NO_CONNECT << 16;
530 goto qc24_fail_command;
531 }
Mike Christie7b594132008-08-17 15:24:40 -0500532 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700533 }
534
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800535 spin_unlock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700536
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800537 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700538 if (!sp)
539 goto qc24_host_busy_lock;
540
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800541 rval = ha->isp_ops->start_scsi(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700542 if (rval != QLA_SUCCESS)
543 goto qc24_host_busy_free_sp;
544
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800545 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700546
547 return 0;
548
549qc24_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800550 qla2x00_sp_free_dma(sp);
551 mempool_free(sp, ha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700552
553qc24_host_busy_lock:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800554 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700555 return SCSI_MLQUEUE_HOST_BUSY;
556
Mike Christie7b594132008-08-17 15:24:40 -0500557qc24_target_busy:
558 return SCSI_MLQUEUE_TARGET_BUSY;
559
Andrew Vasquezfca29702005-07-06 10:31:47 -0700560qc24_fail_command:
561 done(cmd);
562
563 return 0;
564}
565
566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567/*
568 * qla2x00_eh_wait_on_command
569 * Waits for the command to be returned by the Firmware for some
570 * max time.
571 *
572 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 *
575 * Return:
576 * Not Found : 0
577 * Found : 1
578 */
579static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800580qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700582#define ABORT_POLLING_PERIOD 1000
583#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500584 unsigned long wait_iter = ABORT_WAIT_ITER;
585 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
f4f051e2005-04-17 15:02:26 -0500587 while (CMD_SP(cmd)) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700588 msleep(ABORT_POLLING_PERIOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
f4f051e2005-04-17 15:02:26 -0500590 if (--wait_iter)
591 break;
592 }
593 if (CMD_SP(cmd))
594 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
f4f051e2005-04-17 15:02:26 -0500596 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597}
598
599/*
600 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700601 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 * <= MAX_RETRIES_OF_ISP_ABORT or
603 * finally HBA is disabled ie marked offline
604 *
605 * Input:
606 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700607 *
608 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 * Does context switching-Release SPIN_LOCK
610 * (if any) before calling this routine.
611 *
612 * Return:
613 * Success (Adapter is online) : 0
614 * Failed (Adapter is offline/disabled) : 1
615 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800616int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800617qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700619 int return_status;
620 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800621 struct qla_hw_data *ha = vha->hw;
622 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700624 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800625 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
626 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
627 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
628 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
630 msleep(1000);
631 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800632 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700633 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 else
635 return_status = QLA_FUNCTION_FAILED;
636
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 return (return_status);
638}
639
640/*
641 * qla2x00_wait_for_loop_ready
642 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700643 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 * Input:
645 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700646 *
647 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 * Does context switching-Release SPIN_LOCK
649 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700650 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 *
652 * Return:
653 * Success (LOOP_READY) : 0
654 * Failed (LOOP_NOT_READY) : 1
655 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700656static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800657qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658{
659 int return_status = QLA_SUCCESS;
660 unsigned long loop_timeout ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800661 struct qla_hw_data *ha = vha->hw;
662 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700665 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800667 while ((!atomic_read(&base_vha->loop_down_timer) &&
668 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
669 atomic_read(&base_vha->loop_state) != LOOP_READY) {
670 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Ravi Anand57680082006-05-17 15:08:44 -0700671 return_status = QLA_FUNCTION_FAILED;
672 break;
673 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 msleep(1000);
675 if (time_after_eq(jiffies, loop_timeout)) {
676 return_status = QLA_FUNCTION_FAILED;
677 break;
678 }
679 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700680 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700683void
684qla2x00_abort_fcport_cmds(fc_port_t *fcport)
685{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800686 int cnt, que, id;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700687 unsigned long flags;
688 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800689 scsi_qla_host_t *vha = fcport->vha;
690 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800691 struct req_que *req;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700692
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800693 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800694 for (que = 0; que < QLA_MAX_HOST_QUES; que++) {
695 id = vha->req_ques[que];
696 req = ha->req_q_map[id];
697 if (!req)
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700698 continue;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800699 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
700 sp = req->outstanding_cmds[cnt];
701 if (!sp)
702 continue;
703 if (sp->fcport != fcport)
704 continue;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700705
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800706 spin_unlock_irqrestore(&ha->hardware_lock, flags);
707 if (ha->isp_ops->abort_command(vha, sp, req)) {
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700708 DEBUG2(qla_printk(KERN_WARNING, ha,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800709 "Abort failed -- %lx\n",
710 sp->cmd->serial_number));
711 } else {
712 if (qla2x00_eh_wait_on_command(sp->cmd) !=
713 QLA_SUCCESS)
714 DEBUG2(qla_printk(KERN_WARNING, ha,
715 "Abort failed while waiting -- %lx\n",
716 sp->cmd->serial_number));
717 }
718 spin_lock_irqsave(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700719 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700720 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800721 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700722}
723
Andrew Vasquez07db5182006-10-02 12:00:49 -0700724static void
725qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
726{
727 struct Scsi_Host *shost = cmnd->device->host;
728 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
729 unsigned long flags;
730
731 spin_lock_irqsave(shost->host_lock, flags);
732 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
733 spin_unlock_irqrestore(shost->host_lock, flags);
734 msleep(1000);
735 spin_lock_irqsave(shost->host_lock, flags);
736 }
737 spin_unlock_irqrestore(shost->host_lock, flags);
738 return;
739}
740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741/**************************************************************************
742* qla2xxx_eh_abort
743*
744* Description:
745* The abort function will abort the specified command.
746*
747* Input:
748* cmd = Linux SCSI command packet to be aborted.
749*
750* Returns:
751* Either SUCCESS or FAILED.
752*
753* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700754* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800756static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757qla2xxx_eh_abort(struct scsi_cmnd *cmd)
758{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800759 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500760 srb_t *sp;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800761 int ret, i;
f4f051e2005-04-17 15:02:26 -0500762 unsigned int id, lun;
763 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700764 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700765 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800766 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800767 struct req_que *req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800768 srb_t *spt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Andrew Vasquez07db5182006-10-02 12:00:49 -0700770 qla2x00_block_error_handler(cmd);
771
f4f051e2005-04-17 15:02:26 -0500772 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700773 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Michael Reed2ea00202006-04-27 16:25:30 -0700775 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
f4f051e2005-04-17 15:02:26 -0500777 id = cmd->device->id;
778 lun = cmd->device->lun;
779 serial = cmd->serial_number;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800780 spt = (srb_t *) CMD_SP(cmd);
781 if (!spt)
782 return SUCCESS;
783 req = spt->que;
f4f051e2005-04-17 15:02:26 -0500784
785 /* Check active list for command command. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800786 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800787 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
788 sp = req->outstanding_cmds[i];
789
790 if (sp == NULL)
f4f051e2005-04-17 15:02:26 -0500791 continue;
792
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800793 if (sp->cmd != cmd)
794 continue;
f4f051e2005-04-17 15:02:26 -0500795
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800796 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
797 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
f4f051e2005-04-17 15:02:26 -0500798
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800799 spin_unlock_irqrestore(&ha->hardware_lock, flags);
800 if (ha->isp_ops->abort_command(vha, sp, req)) {
801 DEBUG2(printk("%s(%ld): abort_command "
802 "mbx failed.\n", __func__, vha->host_no));
Andrew Vasquez2ac4b642009-01-22 09:45:35 -0800803 ret = FAILED;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800804 } else {
805 DEBUG3(printk("%s(%ld): abort_command "
806 "mbx success.\n", __func__, vha->host_no));
807 wait = 1;
f4f051e2005-04-17 15:02:26 -0500808 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800809 spin_lock_irqsave(&ha->hardware_lock, flags);
810 break;
f4f051e2005-04-17 15:02:26 -0500811 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800812 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500813
814 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700815 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800816 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700817 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500818 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800819 "%x.\n", vha->host_no, id, lun, serial, ret);
Michael Reed2ea00202006-04-27 16:25:30 -0700820 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500821 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700824 qla_printk(KERN_INFO, ha,
Michael Reed2ea00202006-04-27 16:25:30 -0700825 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800826 vha->host_no, id, lun, wait, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
f4f051e2005-04-17 15:02:26 -0500828 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829}
830
Andrew Vasquez523ec772008-04-03 13:13:24 -0700831enum nexus_wait_type {
832 WAIT_HOST = 0,
833 WAIT_TARGET,
834 WAIT_LUN,
835};
836
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800838qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800839 unsigned int l, srb_t *sp, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840{
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800841 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700842 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800843 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800844 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Andrew Vasquez523ec772008-04-03 13:13:24 -0700846 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800847 if (!sp)
848 return status;
849
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800850 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800851 req = sp->que;
852 for (cnt = 1; status == QLA_SUCCESS &&
853 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
854 sp = req->outstanding_cmds[cnt];
855 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700856 continue;
Andrew Vasquez19851f12008-08-13 21:37:00 -0700857
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800858 if (vha->vp_idx != sp->fcport->vha->vp_idx)
859 continue;
860 match = 0;
861 switch (type) {
862 case WAIT_HOST:
863 match = 1;
864 break;
865 case WAIT_TARGET:
866 match = sp->cmd->device->id == t;
867 break;
868 case WAIT_LUN:
869 match = (sp->cmd->device->id == t &&
870 sp->cmd->device->lun == l);
871 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800873 if (!match)
874 continue;
875
876 spin_unlock_irqrestore(&ha->hardware_lock, flags);
877 status = qla2x00_eh_wait_on_command(sp->cmd);
878 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800880 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700881
882 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883}
884
Andrew Vasquez523ec772008-04-03 13:13:24 -0700885static char *reset_errors[] = {
886 "HBA not online",
887 "HBA not ready",
888 "Task management failed",
889 "Waiting for command completions",
890};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Andrew Vasquez523ec772008-04-03 13:13:24 -0700892static int
893__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
894 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int))
895{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800896 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700897 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
898 int err;
899
900 qla2x00_block_error_handler(cmd);
901
902 if (!fcport)
903 return FAILED;
904
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800905 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
906 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700907
908 err = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800909 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700910 goto eh_reset_failed;
911 err = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800912 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700913 goto eh_reset_failed;
914 err = 2;
915 if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS)
916 goto eh_reset_failed;
917 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800918 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800919 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700920 goto eh_reset_failed;
921
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800922 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
923 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700924
925 return SUCCESS;
926
927 eh_reset_failed:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800928 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
929 , vha->host_no, cmd->device->id, cmd->device->lun, name,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700930 reset_errors[err]);
931 return FAILED;
932}
933
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800934static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
936{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800937 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
938 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Andrew Vasquez523ec772008-04-03 13:13:24 -0700940 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
941 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942}
943
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700945qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800947 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
948 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Andrew Vasquez523ec772008-04-03 13:13:24 -0700950 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
951 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952}
953
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954/**************************************************************************
955* qla2xxx_eh_bus_reset
956*
957* Description:
958* The bus reset function will reset the bus and abort any executing
959* commands.
960*
961* Input:
962* cmd = Linux SCSI command packet of the command that cause the
963* bus reset.
964*
965* Returns:
966* SUCCESS/FAILURE (defined as macro in scsi.h).
967*
968**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800969static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
971{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800972 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500973 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700974 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500975 unsigned int id, lun;
976 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800977 srb_t *sp = (srb_t *) CMD_SP(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
Andrew Vasquez07db5182006-10-02 12:00:49 -0700979 qla2x00_block_error_handler(cmd);
980
f4f051e2005-04-17 15:02:26 -0500981 id = cmd->device->id;
982 lun = cmd->device->lun;
983 serial = cmd->serial_number;
984
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700985 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500986 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800988 qla_printk(KERN_INFO, vha->hw,
Anirban Chakraborty749af3d2008-11-14 13:48:12 -0800989 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800991 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500993 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 }
995
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800996 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
997 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500998 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 }
f4f051e2005-04-17 15:02:26 -05001000 if (ret == FAILED)
1001 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001003 /* Flush outstanding commands. */
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001004 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
Andrew Vasquez523ec772008-04-03 13:13:24 -07001005 QLA_SUCCESS)
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001006 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
f4f051e2005-04-17 15:02:26 -05001008eh_bus_reset_done:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001009 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -05001010 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
f4f051e2005-04-17 15:02:26 -05001012 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013}
1014
1015/**************************************************************************
1016* qla2xxx_eh_host_reset
1017*
1018* Description:
1019* The reset function will reset the Adapter.
1020*
1021* Input:
1022* cmd = Linux SCSI command packet of the command that cause the
1023* adapter reset.
1024*
1025* Returns:
1026* Either SUCCESS or FAILED.
1027*
1028* Note:
1029**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001030static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1032{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001033 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001034 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001035 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001036 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001037 unsigned int id, lun;
1038 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001039 srb_t *sp = (srb_t *) CMD_SP(cmd);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001040 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
Andrew Vasquez07db5182006-10-02 12:00:49 -07001042 qla2x00_block_error_handler(cmd);
1043
f4f051e2005-04-17 15:02:26 -05001044 id = cmd->device->id;
1045 lun = cmd->device->lun;
1046 serial = cmd->serial_number;
1047
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -07001048 if (!fcport)
f4f051e2005-04-17 15:02:26 -05001049 return ret;
1050
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 qla_printk(KERN_INFO, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001052 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001054 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001055 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
1057 /*
1058 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001059 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 * be completed and then issue big hammer.Otherwise
1061 * it may cause I/O failure as big hammer marks the
1062 * devices as lost kicking of the port_down_timer
1063 * while dpc is stuck for the mailbox to complete.
1064 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001065 qla2x00_wait_for_loop_ready(vha);
1066 if (vha != base_vha) {
1067 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001068 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001069 } else {
1070 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1071 if (qla2x00_abort_isp(base_vha)) {
1072 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1073 /* failed. schedule dpc to try */
1074 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1075
1076 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1077 goto eh_host_reset_lock;
1078 }
1079 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001082 /* Waiting for command to be returned to OS.*/
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001083 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001084 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001085 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
f4f051e2005-04-17 15:02:26 -05001087eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001088 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1089 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
f4f051e2005-04-17 15:02:26 -05001091 return ret;
1092}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
1094/*
1095* qla2x00_loop_reset
1096* Issue loop reset.
1097*
1098* Input:
1099* ha = adapter block pointer.
1100*
1101* Returns:
1102* 0 = success
1103*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001104int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001105qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001107 int ret;
bdf79622005-04-17 15:06:53 -05001108 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001109 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001111 if (ha->flags.enable_lip_full_login && !vha->vp_idx) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001112 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001113 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001114 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001115 "full_login_lip=%d.\n", __func__, vha->host_no,
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001116 ret));
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001117 }
1118 atomic_set(&vha->loop_state, LOOP_DOWN);
1119 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1120 qla2x00_mark_all_devices_lost(vha, 0);
1121 qla2x00_wait_for_loop_ready(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 }
1123
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001124 if (ha->flags.enable_lip_reset && !vha->vp_idx) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001125 ret = qla2x00_lip_reset(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001126 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001127 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001128 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1129 } else
1130 qla2x00_wait_for_loop_ready(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001131 }
1132
1133 if (ha->flags.enable_target_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001134 list_for_each_entry(fcport, &vha->vp_fcports, list) {
bdf79622005-04-17 15:06:53 -05001135 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 continue;
1137
Andrew Vasquez523ec772008-04-03 13:13:24 -07001138 ret = ha->isp_ops->target_reset(fcport, 0);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001139 if (ret != QLA_SUCCESS) {
1140 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1141 "target_reset=%d d_id=%x.\n", __func__,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001142 vha->host_no, ret, fcport->d_id.b24));
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001143 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 }
1145 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001147 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001149 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150}
1151
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001152void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001153qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001154{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001155 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001156 unsigned long flags;
1157 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001158 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001159 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001160
1161 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001162 for (que = 0; que < ha->max_queues; que++) {
1163 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001164 if (!req)
1165 continue;
1166 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1167 sp = req->outstanding_cmds[cnt];
Andrew Vasquez444786d2009-01-05 11:18:10 -08001168 if (sp && sp->fcport->vha == vha) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001169 req->outstanding_cmds[cnt] = NULL;
1170 sp->cmd->result = res;
1171 qla2x00_sp_compl(ha, sp);
1172 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001173 }
1174 }
1175 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1176}
1177
f4f051e2005-04-17 15:02:26 -05001178static int
1179qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180{
bdf79622005-04-17 15:06:53 -05001181 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001183 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001184 return -ENXIO;
1185
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001186 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001187
1188 return 0;
1189}
1190
1191static int
1192qla2xxx_slave_configure(struct scsi_device *sdev)
1193{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001194 scsi_qla_host_t *vha = shost_priv(sdev->host);
1195 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -05001196 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001197 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
8482e112005-04-17 15:04:54 -05001198
f4f051e2005-04-17 15:02:26 -05001199 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001200 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001202 scsi_deactivate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Andrew Vasquez85821c92008-07-10 16:55:48 -07001204 rport->dev_loss_tmo = ha->port_down_retry_count;
8482e112005-04-17 15:04:54 -05001205
f4f051e2005-04-17 15:02:26 -05001206 return 0;
1207}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
f4f051e2005-04-17 15:02:26 -05001209static void
1210qla2xxx_slave_destroy(struct scsi_device *sdev)
1211{
1212 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213}
1214
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001215static int
1216qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1217{
1218 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1219 return sdev->queue_depth;
1220}
1221
1222static int
1223qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1224{
1225 if (sdev->tagged_supported) {
1226 scsi_set_tag_type(sdev, tag_type);
1227 if (tag_type)
1228 scsi_activate_tcq(sdev, sdev->queue_depth);
1229 else
1230 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1231 } else
1232 tag_type = 0;
1233
1234 return tag_type;
1235}
1236
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237/**
1238 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1239 * @ha: HA context
1240 *
1241 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1242 * supported addressing method.
1243 */
1244static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001245qla2x00_config_dma_addressing(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001247 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001248 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001251 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1252 /* Any upper-dword bits set? */
1253 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1254 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1255 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001257 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1258 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001259 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001262
1263 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1264 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265}
1266
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001267static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001268qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001269{
1270 unsigned long flags = 0;
1271 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1272
1273 spin_lock_irqsave(&ha->hardware_lock, flags);
1274 ha->interrupts_on = 1;
1275 /* enable risc and host interrupts */
1276 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1277 RD_REG_WORD(&reg->ictrl);
1278 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1279
1280}
1281
1282static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001283qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001284{
1285 unsigned long flags = 0;
1286 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1287
1288 spin_lock_irqsave(&ha->hardware_lock, flags);
1289 ha->interrupts_on = 0;
1290 /* disable risc and host interrupts */
1291 WRT_REG_WORD(&reg->ictrl, 0);
1292 RD_REG_WORD(&reg->ictrl);
1293 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1294}
1295
1296static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001297qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001298{
1299 unsigned long flags = 0;
1300 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1301
1302 spin_lock_irqsave(&ha->hardware_lock, flags);
1303 ha->interrupts_on = 1;
1304 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1305 RD_REG_DWORD(&reg->ictrl);
1306 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1307}
1308
1309static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001310qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001311{
1312 unsigned long flags = 0;
1313 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1314
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001315 if (IS_NOPOLLING_TYPE(ha))
1316 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001317 spin_lock_irqsave(&ha->hardware_lock, flags);
1318 ha->interrupts_on = 0;
1319 WRT_REG_DWORD(&reg->ictrl, 0);
1320 RD_REG_DWORD(&reg->ictrl);
1321 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1322}
1323
1324static struct isp_operations qla2100_isp_ops = {
1325 .pci_config = qla2100_pci_config,
1326 .reset_chip = qla2x00_reset_chip,
1327 .chip_diag = qla2x00_chip_diag,
1328 .config_rings = qla2x00_config_rings,
1329 .reset_adapter = qla2x00_reset_adapter,
1330 .nvram_config = qla2x00_nvram_config,
1331 .update_fw_options = qla2x00_update_fw_options,
1332 .load_risc = qla2x00_load_risc,
1333 .pci_info_str = qla2x00_pci_info_str,
1334 .fw_version_str = qla2x00_fw_version_str,
1335 .intr_handler = qla2100_intr_handler,
1336 .enable_intrs = qla2x00_enable_intrs,
1337 .disable_intrs = qla2x00_disable_intrs,
1338 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001339 .target_reset = qla2x00_abort_target,
1340 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001341 .fabric_login = qla2x00_login_fabric,
1342 .fabric_logout = qla2x00_fabric_logout,
1343 .calc_req_entries = qla2x00_calc_iocbs_32,
1344 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1345 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1346 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1347 .read_nvram = qla2x00_read_nvram_data,
1348 .write_nvram = qla2x00_write_nvram_data,
1349 .fw_dump = qla2100_fw_dump,
1350 .beacon_on = NULL,
1351 .beacon_off = NULL,
1352 .beacon_blink = NULL,
1353 .read_optrom = qla2x00_read_optrom_data,
1354 .write_optrom = qla2x00_write_optrom_data,
1355 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001356 .start_scsi = qla2x00_start_scsi,
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001357 .wrt_req_reg = NULL,
1358 .wrt_rsp_reg = NULL,
1359 .rd_req_reg = NULL,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001360};
1361
1362static struct isp_operations qla2300_isp_ops = {
1363 .pci_config = qla2300_pci_config,
1364 .reset_chip = qla2x00_reset_chip,
1365 .chip_diag = qla2x00_chip_diag,
1366 .config_rings = qla2x00_config_rings,
1367 .reset_adapter = qla2x00_reset_adapter,
1368 .nvram_config = qla2x00_nvram_config,
1369 .update_fw_options = qla2x00_update_fw_options,
1370 .load_risc = qla2x00_load_risc,
1371 .pci_info_str = qla2x00_pci_info_str,
1372 .fw_version_str = qla2x00_fw_version_str,
1373 .intr_handler = qla2300_intr_handler,
1374 .enable_intrs = qla2x00_enable_intrs,
1375 .disable_intrs = qla2x00_disable_intrs,
1376 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001377 .target_reset = qla2x00_abort_target,
1378 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001379 .fabric_login = qla2x00_login_fabric,
1380 .fabric_logout = qla2x00_fabric_logout,
1381 .calc_req_entries = qla2x00_calc_iocbs_32,
1382 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1383 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1384 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1385 .read_nvram = qla2x00_read_nvram_data,
1386 .write_nvram = qla2x00_write_nvram_data,
1387 .fw_dump = qla2300_fw_dump,
1388 .beacon_on = qla2x00_beacon_on,
1389 .beacon_off = qla2x00_beacon_off,
1390 .beacon_blink = qla2x00_beacon_blink,
1391 .read_optrom = qla2x00_read_optrom_data,
1392 .write_optrom = qla2x00_write_optrom_data,
1393 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001394 .start_scsi = qla2x00_start_scsi,
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001395 .wrt_req_reg = NULL,
1396 .wrt_rsp_reg = NULL,
1397 .rd_req_reg = NULL,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001398};
1399
1400static struct isp_operations qla24xx_isp_ops = {
1401 .pci_config = qla24xx_pci_config,
1402 .reset_chip = qla24xx_reset_chip,
1403 .chip_diag = qla24xx_chip_diag,
1404 .config_rings = qla24xx_config_rings,
1405 .reset_adapter = qla24xx_reset_adapter,
1406 .nvram_config = qla24xx_nvram_config,
1407 .update_fw_options = qla24xx_update_fw_options,
1408 .load_risc = qla24xx_load_risc,
1409 .pci_info_str = qla24xx_pci_info_str,
1410 .fw_version_str = qla24xx_fw_version_str,
1411 .intr_handler = qla24xx_intr_handler,
1412 .enable_intrs = qla24xx_enable_intrs,
1413 .disable_intrs = qla24xx_disable_intrs,
1414 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001415 .target_reset = qla24xx_abort_target,
1416 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001417 .fabric_login = qla24xx_login_fabric,
1418 .fabric_logout = qla24xx_fabric_logout,
1419 .calc_req_entries = NULL,
1420 .build_iocbs = NULL,
1421 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1422 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1423 .read_nvram = qla24xx_read_nvram_data,
1424 .write_nvram = qla24xx_write_nvram_data,
1425 .fw_dump = qla24xx_fw_dump,
1426 .beacon_on = qla24xx_beacon_on,
1427 .beacon_off = qla24xx_beacon_off,
1428 .beacon_blink = qla24xx_beacon_blink,
1429 .read_optrom = qla24xx_read_optrom_data,
1430 .write_optrom = qla24xx_write_optrom_data,
1431 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001432 .start_scsi = qla24xx_start_scsi,
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001433 .wrt_req_reg = qla24xx_wrt_req_reg,
1434 .wrt_rsp_reg = qla24xx_wrt_rsp_reg,
1435 .rd_req_reg = qla24xx_rd_req_reg,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001436};
1437
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001438static struct isp_operations qla25xx_isp_ops = {
1439 .pci_config = qla25xx_pci_config,
1440 .reset_chip = qla24xx_reset_chip,
1441 .chip_diag = qla24xx_chip_diag,
1442 .config_rings = qla24xx_config_rings,
1443 .reset_adapter = qla24xx_reset_adapter,
1444 .nvram_config = qla24xx_nvram_config,
1445 .update_fw_options = qla24xx_update_fw_options,
1446 .load_risc = qla24xx_load_risc,
1447 .pci_info_str = qla24xx_pci_info_str,
1448 .fw_version_str = qla24xx_fw_version_str,
1449 .intr_handler = qla24xx_intr_handler,
1450 .enable_intrs = qla24xx_enable_intrs,
1451 .disable_intrs = qla24xx_disable_intrs,
1452 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001453 .target_reset = qla24xx_abort_target,
1454 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001455 .fabric_login = qla24xx_login_fabric,
1456 .fabric_logout = qla24xx_fabric_logout,
1457 .calc_req_entries = NULL,
1458 .build_iocbs = NULL,
1459 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1460 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1461 .read_nvram = qla25xx_read_nvram_data,
1462 .write_nvram = qla25xx_write_nvram_data,
1463 .fw_dump = qla25xx_fw_dump,
1464 .beacon_on = qla24xx_beacon_on,
1465 .beacon_off = qla24xx_beacon_off,
1466 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001467 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001468 .write_optrom = qla24xx_write_optrom_data,
1469 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001470 .start_scsi = qla24xx_start_scsi,
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001471 .wrt_req_reg = qla24xx_wrt_req_reg,
1472 .wrt_rsp_reg = qla24xx_wrt_rsp_reg,
1473 .rd_req_reg = qla24xx_rd_req_reg,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001474};
1475
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001476static struct isp_operations qla81xx_isp_ops = {
1477 .pci_config = qla25xx_pci_config,
1478 .reset_chip = qla24xx_reset_chip,
1479 .chip_diag = qla24xx_chip_diag,
1480 .config_rings = qla24xx_config_rings,
1481 .reset_adapter = qla24xx_reset_adapter,
1482 .nvram_config = qla81xx_nvram_config,
1483 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001484 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001485 .pci_info_str = qla24xx_pci_info_str,
1486 .fw_version_str = qla24xx_fw_version_str,
1487 .intr_handler = qla24xx_intr_handler,
1488 .enable_intrs = qla24xx_enable_intrs,
1489 .disable_intrs = qla24xx_disable_intrs,
1490 .abort_command = qla24xx_abort_command,
1491 .target_reset = qla24xx_abort_target,
1492 .lun_reset = qla24xx_lun_reset,
1493 .fabric_login = qla24xx_login_fabric,
1494 .fabric_logout = qla24xx_fabric_logout,
1495 .calc_req_entries = NULL,
1496 .build_iocbs = NULL,
1497 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1498 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1499 .read_nvram = qla25xx_read_nvram_data,
1500 .write_nvram = qla25xx_write_nvram_data,
1501 .fw_dump = qla81xx_fw_dump,
1502 .beacon_on = qla24xx_beacon_on,
1503 .beacon_off = qla24xx_beacon_off,
1504 .beacon_blink = qla24xx_beacon_blink,
1505 .read_optrom = qla25xx_read_optrom_data,
1506 .write_optrom = qla24xx_write_optrom_data,
1507 .get_flash_version = qla24xx_get_flash_version,
1508 .start_scsi = qla24xx_start_scsi,
1509 .wrt_req_reg = qla24xx_wrt_req_reg,
1510 .wrt_rsp_reg = qla24xx_wrt_rsp_reg,
1511 .rd_req_reg = qla24xx_rd_req_reg,
1512};
1513
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001514static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001515qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001516{
1517 ha->device_type = DT_EXTENDED_IDS;
1518 switch (ha->pdev->device) {
1519 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1520 ha->device_type |= DT_ISP2100;
1521 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001522 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001523 break;
1524 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1525 ha->device_type |= DT_ISP2200;
1526 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001527 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001528 break;
1529 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1530 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001531 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001532 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001533 break;
1534 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1535 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001536 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001537 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001538 break;
1539 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1540 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001541 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001542 if (ha->pdev->subsystem_vendor == 0x1028 &&
1543 ha->pdev->subsystem_device == 0x0170)
1544 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001545 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001546 break;
1547 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1548 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001549 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001550 break;
1551 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1552 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001553 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001554 break;
1555 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1556 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001557 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001558 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001559 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001560 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001561 break;
1562 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1563 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001564 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001565 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001566 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001567 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001568 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001569 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1570 ha->device_type |= DT_ISP8432;
1571 ha->device_type |= DT_ZIO_SUPPORTED;
1572 ha->device_type |= DT_FWI2;
1573 ha->device_type |= DT_IIDMA;
1574 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1575 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001576 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1577 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001578 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001579 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001580 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001581 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1582 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001583 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001584 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001585 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001586 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1587 ha->device_type |= DT_ISP2532;
1588 ha->device_type |= DT_ZIO_SUPPORTED;
1589 ha->device_type |= DT_FWI2;
1590 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001591 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1592 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001593 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1594 ha->device_type |= DT_ISP8001;
1595 ha->device_type |= DT_ZIO_SUPPORTED;
1596 ha->device_type |= DT_FWI2;
1597 ha->device_type |= DT_IIDMA;
1598 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1599 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001600 }
1601}
1602
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001604qla2x00_iospace_config(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605{
Andrew Vasquez37765412008-01-17 09:02:09 -08001606 resource_size_t pio;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001607 uint16_t msix;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
Andrew Vasquez285d0322007-10-19 15:59:17 -07001609 if (pci_request_selected_regions(ha->pdev, ha->bars,
1610 QLA2XXX_DRIVER_NAME)) {
1611 qla_printk(KERN_WARNING, ha,
1612 "Failed to reserve PIO/MMIO regions (%s)\n",
1613 pci_name(ha->pdev));
1614
1615 goto iospace_error_exit;
1616 }
1617 if (!(ha->bars & 1))
1618 goto skip_pio;
1619
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1621 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001622 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1623 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 qla_printk(KERN_WARNING, ha,
1625 "Invalid PCI I/O region size (%s)...\n",
1626 pci_name(ha->pdev));
1627 pio = 0;
1628 }
1629 } else {
1630 qla_printk(KERN_WARNING, ha,
1631 "region #0 not a PIO resource (%s)...\n",
1632 pci_name(ha->pdev));
1633 pio = 0;
1634 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001635 ha->pio_address = pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
Andrew Vasquez285d0322007-10-19 15:59:17 -07001637skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001639 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 qla_printk(KERN_ERR, ha,
Andrew Vasquez37765412008-01-17 09:02:09 -08001641 "region #1 not an MMIO resource (%s), aborting\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 pci_name(ha->pdev));
1643 goto iospace_error_exit;
1644 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001645 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 qla_printk(KERN_ERR, ha,
1647 "Invalid PCI mem region size (%s), aborting\n",
1648 pci_name(ha->pdev));
1649 goto iospace_error_exit;
1650 }
1651
Andrew Vasquez37765412008-01-17 09:02:09 -08001652 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 if (!ha->iobase) {
1654 qla_printk(KERN_ERR, ha,
1655 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1656
1657 goto iospace_error_exit;
1658 }
1659
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001660 /* Determine queue resources */
1661 ha->max_queues = 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001662 if (ql2xmaxqueues <= 1 || (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001663 goto mqiobase_exit;
1664 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1665 pci_resource_len(ha->pdev, 3));
1666 if (ha->mqiobase) {
1667 /* Read MSIX vector size of the board */
1668 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1669 ha->msix_count = msix;
1670 /* Max queues are bounded by available msix vectors */
1671 /* queue 0 uses two msix vectors */
1672 if (ha->msix_count - 1 < ql2xmaxqueues)
1673 ha->max_queues = ha->msix_count - 1;
1674 else if (ql2xmaxqueues > QLA_MQ_SIZE)
1675 ha->max_queues = QLA_MQ_SIZE;
1676 else
1677 ha->max_queues = ql2xmaxqueues;
1678 qla_printk(KERN_INFO, ha,
1679 "MSI-X vector count: %d\n", msix);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001680 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001681
1682mqiobase_exit:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001683 ha->msix_count = ha->max_queues + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 return (0);
1685
1686iospace_error_exit:
1687 return (-ENOMEM);
1688}
1689
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001690static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001691qla2xxx_scan_start(struct Scsi_Host *shost)
1692{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001693 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001694
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001695 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1696 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1697 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1698 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001699}
1700
1701static int
1702qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1703{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001704 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001705
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001706 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001707 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001708 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001709 return 1;
1710
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001711 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001712}
1713
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714/*
1715 * PCI driver interface
1716 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001717static int __devinit
1718qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001720 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001722 scsi_qla_host_t *base_vha = NULL;
1723 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001724 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001726 struct scsi_host_template *sht;
Anirban Chakrabortyc51da4e2008-11-10 15:53:20 -08001727 int bars, max_id, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001728 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001729 struct req_que *req = NULL;
1730 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Andrew Vasquez285d0322007-10-19 15:59:17 -07001732 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1733 sht = &qla2x00_driver_template;
1734 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1735 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001736 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001737 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1738 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001739 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
1740 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07001741 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1742 sht = &qla24xx_driver_template;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001743 mem_only = 1;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001744 }
1745
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001746 if (mem_only) {
1747 if (pci_enable_device_mem(pdev))
1748 goto probe_out;
1749 } else {
1750 if (pci_enable_device(pdev))
1751 goto probe_out;
1752 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753
Jesse Barnes09276782008-10-18 17:33:19 -07001754 /* This may fail but that's ok */
1755 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07001756
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001757 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1758 if (!ha) {
1759 DEBUG(printk("Unable to allocate memory for ha\n"));
1760 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001762 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
1764 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07001765 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001766 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001767 spin_lock_init(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001769 /* Set ISP-type information. */
1770 qla2x00_set_isp_flags(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 /* Configure PCI I/O space */
1772 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001773 if (ret)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001774 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08001777 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1778 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001781 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001782 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001783 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001785 /* Assign ISP specific operations. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001786 max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 if (IS_QLA2100(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001788 max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001790 req_length = REQUEST_ENTRY_CNT_2100;
1791 rsp_length = RESPONSE_ENTRY_CNT_2100;
1792 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001793 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001794 ha->flash_conf_off = ~0;
1795 ha->flash_data_off = ~0;
1796 ha->nvram_conf_off = ~0;
1797 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001798 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 } else if (IS_QLA2200(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001801 req_length = REQUEST_ENTRY_CNT_2200;
1802 rsp_length = RESPONSE_ENTRY_CNT_2100;
1803 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001804 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001805 ha->flash_conf_off = ~0;
1806 ha->flash_data_off = ~0;
1807 ha->nvram_conf_off = ~0;
1808 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001809 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001810 } else if (IS_QLA23XX(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001812 req_length = REQUEST_ENTRY_CNT_2200;
1813 rsp_length = RESPONSE_ENTRY_CNT_2300;
1814 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001815 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001816 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1817 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001818 ha->flash_conf_off = ~0;
1819 ha->flash_data_off = ~0;
1820 ha->nvram_conf_off = ~0;
1821 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001822 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001823 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07001824 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001825 req_length = REQUEST_ENTRY_CNT_24XX;
1826 rsp_length = RESPONSE_ENTRY_CNT_2300;
1827 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001828 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001829 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001830 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001831 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001832 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001833 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1834 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1835 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1836 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001837 } else if (IS_QLA25XX(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001838 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001839 req_length = REQUEST_ENTRY_CNT_24XX;
1840 rsp_length = RESPONSE_ENTRY_CNT_2300;
1841 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001842 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001843 ha->gid_list_info_size = 8;
1844 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001845 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001846 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001847 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1848 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1849 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1850 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1851 } else if (IS_QLA81XX(ha)) {
1852 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1853 req_length = REQUEST_ENTRY_CNT_24XX;
1854 rsp_length = RESPONSE_ENTRY_CNT_2300;
1855 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1856 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
1857 ha->gid_list_info_size = 8;
1858 ha->optrom_size = OPTROM_SIZE_81XX;
1859 ha->isp_ops = &qla81xx_isp_ops;
1860 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
1861 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
1862 ha->nvram_conf_off = ~0;
1863 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07001866 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001867 init_completion(&ha->mbx_cmd_comp);
1868 complete(&ha->mbx_cmd_comp);
1869 init_completion(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001871 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001873 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001874 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 qla_printk(KERN_WARNING, ha,
1876 "[ERROR] Failed to allocate memory for adapter\n");
1877
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001878 goto probe_hw_failed;
1879 }
1880
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001881 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001882 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001883 req->max_q_depth = ql2xmaxqdepth;
1884
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001885
1886 base_vha = qla2x00_create_host(sht, ha);
1887 if (!base_vha) {
1888 qla_printk(KERN_WARNING, ha,
1889 "[ERROR] Failed to allocate memory for scsi_host\n");
1890
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001891 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001892 qla2x00_mem_free(ha);
1893 qla2x00_free_que(ha, req, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001894 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 }
1896
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001897 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001899 qla2x00_config_dma_addressing(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001901 host = base_vha->host;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001902 base_vha->req_ques[0] = req->id;
1903 host->can_queue = req->length + 128;
1904 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001905 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001906 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001907 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1908 base_vha->vp_idx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001909 if (IS_QLA2100(ha))
1910 host->sg_tablesize = 32;
1911 host->max_id = max_id;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001912 host->this_id = 255;
1913 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07001914 host->unique_id = host->host_no;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001915 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001916 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001917 host->max_lun = MAX_LUNS;
1918 host->transportt = qla2xxx_transport_template;
1919
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001920 /* Set up the irqs */
1921 ret = qla2x00_request_irqs(ha, rsp);
1922 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001923 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001924 /* Alloc arrays of request and response ring ptrs */
1925 if (!qla2x00_alloc_queues(ha)) {
1926 qla_printk(KERN_WARNING, ha,
1927 "[ERROR] Failed to allocate memory for queue"
1928 " pointers\n");
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001929 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001930 }
1931 ha->rsp_q_map[0] = rsp;
1932 ha->req_q_map[0] = req;
1933
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001934 if (ha->mqenable) {
1935 ha->isp_ops->wrt_req_reg = qla25xx_wrt_req_reg;
1936 ha->isp_ops->wrt_rsp_reg = qla25xx_wrt_rsp_reg;
1937 ha->isp_ops->rd_req_reg = qla25xx_rd_req_reg;
1938 }
1939
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001940 if (qla2x00_initialize_adapter(base_vha)) {
1941 qla_printk(KERN_WARNING, ha,
1942 "Failed to initialize adapter\n");
1943
1944 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1945 "Adapter flags %x.\n",
1946 base_vha->host_no, base_vha->device_flags));
1947
1948 ret = -ENODEV;
1949 goto probe_failed;
1950 }
1951
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001952 /*
1953 * Startup the kernel thread for this host adapter
1954 */
1955 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1956 "%s_dpc", base_vha->host_str);
1957 if (IS_ERR(ha->dpc_thread)) {
1958 qla_printk(KERN_WARNING, ha,
1959 "Unable to start DPC thread!\n");
1960 ret = PTR_ERR(ha->dpc_thread);
1961 goto probe_failed;
1962 }
1963
1964 list_add_tail(&base_vha->list, &ha->vp_list);
1965 base_vha->host->irq = ha->pdev->irq;
1966
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001968 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969
1970 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001971 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001973 base_vha->flags.init_done = 1;
1974 base_vha->flags.online = 1;
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001975
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001976 ret = scsi_add_host(host, &pdev->dev);
1977 if (ret)
1978 goto probe_failed;
1979
Andrew Vasquez048feec2008-09-11 22:19:45 -07001980 ha->isp_ops->enable_intrs(ha);
1981
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001982 scsi_scan_host(host);
1983
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001984 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001985
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001986 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001987
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001988 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001989
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 qla_printk(KERN_INFO, ha, "\n"
1991 " QLogic Fibre Channel HBA Driver: %s\n"
1992 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08001993 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1994 qla2x00_version_str, ha->model_number,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001995 ha->model_desc ? ha->model_desc : "", pdev->device,
1996 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
1997 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
1998 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 return 0;
2001
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002002probe_init_failed:
2003 qla2x00_free_que(ha, req, rsp);
2004 ha->max_queues = 0;
2005
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006probe_failed:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002007 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002009 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002011probe_hw_failed:
2012 if (ha->iobase)
2013 iounmap(ha->iobase);
2014
2015 pci_release_selected_regions(ha->pdev, ha->bars);
2016 kfree(ha);
2017 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002019probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002020 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002021 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
Adrian Bunk4c993f72008-01-14 00:55:16 -08002024static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002025qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002027 scsi_qla_host_t *base_vha, *vha, *temp;
2028 struct qla_hw_data *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002030 base_vha = pci_get_drvdata(pdev);
2031 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002033 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
2034 if (vha && vha->fc_vport)
2035 fc_vport_terminate(vha->fc_vport);
2036 }
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002037
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002038 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002039
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002040 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002041
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002042 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002044 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002046 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05002047
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002048 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002050 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 scsi_host_put(base_vha->host);
2053
2054 if (ha->iobase)
2055 iounmap(ha->iobase);
2056
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002057 if (ha->mqiobase)
2058 iounmap(ha->mqiobase);
2059
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002060 pci_release_selected_regions(ha->pdev, ha->bars);
2061 kfree(ha);
2062 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
Bernhard Walle665db932007-03-28 00:49:49 +02002064 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 pci_set_drvdata(pdev, NULL);
2066}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067
2068static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002069qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002071 struct qla_hw_data *ha = vha->hw;
2072 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002073
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 /* Disable timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002075 if (vha->timer_active)
2076 qla2x00_stop_timer(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002078 vha->flags.online = 0;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002079
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 /* Kill the kernel thread for this host */
Christoph Hellwig39a11242006-02-14 18:46:22 +01002081 if (ha->dpc_thread) {
2082 struct task_struct *t = ha->dpc_thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
Christoph Hellwig39a11242006-02-14 18:46:22 +01002084 /*
2085 * qla2xxx_wake_dpc checks for ->dpc_thread
2086 * so we need to zero it out.
2087 */
2088 ha->dpc_thread = NULL;
2089 kthread_stop(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 }
2091
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002092 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002093 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002094
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002095 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002096 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002097
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002098 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002099 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002101 /* turn-off interrupts on the card */
2102 if (ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002103 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002104
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002105 qla2x00_free_irqs(vha);
2106
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002107 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002108
2109 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110}
2111
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002112static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002113qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002114 int defer)
2115{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002116 struct fc_rport *rport;
2117
2118 if (!fcport->rport)
2119 return;
2120
2121 rport = fcport->rport;
2122 if (defer) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002123 spin_lock_irq(vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002124 fcport->drport = rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002125 spin_unlock_irq(vha->host->host_lock);
2126 set_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
2127 qla2xxx_wake_dpc(vha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002128 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002129 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002130}
2131
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2134 *
2135 * Input: ha = adapter block pointer. fcport = port structure pointer.
2136 *
2137 * Return: None.
2138 *
2139 * Context:
2140 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002141void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002142 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002144 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002145 vha->vp_idx == fcport->vp_idx) {
2146 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2147 qla2x00_schedule_rport_del(vha, fcport, defer);
2148 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002149 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 * We may need to retry the login, so don't change the state of the
2151 * port but do the retries.
2152 */
2153 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2154 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2155
2156 if (!do_login)
2157 return;
2158
2159 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002160 fcport->login_retry = vha->hw->login_retry_count;
2161 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
2163 DEBUG(printk("scsi(%ld): Port login retry: "
2164 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2165 "id = 0x%04x retry cnt=%d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002166 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 fcport->port_name[0],
2168 fcport->port_name[1],
2169 fcport->port_name[2],
2170 fcport->port_name[3],
2171 fcport->port_name[4],
2172 fcport->port_name[5],
2173 fcport->port_name[6],
2174 fcport->port_name[7],
2175 fcport->loop_id,
2176 fcport->login_retry));
2177 }
2178}
2179
2180/*
2181 * qla2x00_mark_all_devices_lost
2182 * Updates fcport state when device goes offline.
2183 *
2184 * Input:
2185 * ha = adapter block pointer.
2186 * fcport = port structure pointer.
2187 *
2188 * Return:
2189 * None.
2190 *
2191 * Context:
2192 */
2193void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002194qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195{
2196 fc_port_t *fcport;
2197
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002198 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2199 if (vha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 /*
2202 * No point in marking the device as lost, if the device is
2203 * already DEAD.
2204 */
2205 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2206 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002207 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2208 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2209 qla2x00_schedule_rport_del(vha, fcport, defer);
2210 } else
2211 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 }
2213}
2214
2215/*
2216* qla2x00_mem_alloc
2217* Allocates adapter memory.
2218*
2219* Returns:
2220* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08002221* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002223static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002224qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2225 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226{
2227 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002229 ha->init_cb_size = sizeof(init_cb_t);
2230 if (IS_QLA2XXX_MIDTYPE(ha))
2231 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
Andrew Vasqueze8711082008-01-31 12:33:48 -08002233 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002234 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002235 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002236 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002238 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2239 &ha->gid_list_dma, GFP_KERNEL);
2240 if (!ha->gid_list)
Andrew Vasqueze8711082008-01-31 12:33:48 -08002241 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
Andrew Vasqueze8711082008-01-31 12:33:48 -08002243 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2244 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002245 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246
Andrew Vasqueze8711082008-01-31 12:33:48 -08002247 /* Get memory for cached NVRAM */
2248 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2249 if (!ha->nvram)
2250 goto fail_free_srb_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002252 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2253 ha->pdev->device);
2254 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2255 DMA_POOL_SIZE, 8, 0);
2256 if (!ha->s_dma_pool)
2257 goto fail_free_nvram;
2258
Andrew Vasqueze8711082008-01-31 12:33:48 -08002259 /* Allocate memory for SNS commands */
2260 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002261 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002262 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002263 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002264 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002265 goto fail_dma_pool;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002266 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002267 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002268 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002269 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002270 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002271 goto fail_dma_pool;
2272 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002273 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002274 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002275 if (!ha->ct_sns)
2276 goto fail_free_ms_iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 }
2278
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002279 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002280 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2281 if (!*req) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002282 DEBUG(printk("Unable to allocate memory for req\n"));
2283 goto fail_req;
2284 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002285 (*req)->length = req_len;
2286 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2287 ((*req)->length + 1) * sizeof(request_t),
2288 &(*req)->dma, GFP_KERNEL);
2289 if (!(*req)->ring) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002290 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2291 goto fail_req_ring;
2292 }
2293 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002294 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2295 if (!*rsp) {
2296 qla_printk(KERN_WARNING, ha,
2297 "Unable to allocate memory for rsp\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002298 goto fail_rsp;
2299 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002300 (*rsp)->hw = ha;
2301 (*rsp)->length = rsp_len;
2302 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2303 ((*rsp)->length + 1) * sizeof(response_t),
2304 &(*rsp)->dma, GFP_KERNEL);
2305 if (!(*rsp)->ring) {
2306 qla_printk(KERN_WARNING, ha,
2307 "Unable to allocate memory for rsp_ring\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002308 goto fail_rsp_ring;
2309 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002310 (*req)->rsp = *rsp;
2311 (*rsp)->req = *req;
2312 /* Allocate memory for NVRAM data for vports */
2313 if (ha->nvram_npiv_size) {
2314 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2315 ha->nvram_npiv_size, GFP_KERNEL);
2316 if (!ha->npiv_info) {
2317 qla_printk(KERN_WARNING, ha,
2318 "Unable to allocate memory for npiv info\n");
2319 goto fail_npiv_info;
2320 }
2321 } else
2322 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002323
2324 INIT_LIST_HEAD(&ha->vp_list);
2325 return 1;
2326
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002327fail_npiv_info:
2328 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2329 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2330 (*rsp)->ring = NULL;
2331 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002332fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002333 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002334fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002335 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2336 sizeof(request_t), (*req)->ring, (*req)->dma);
2337 (*req)->ring = NULL;
2338 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002339fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002340 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002341fail_req:
2342 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2343 ha->ct_sns, ha->ct_sns_dma);
2344 ha->ct_sns = NULL;
2345 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002346fail_free_ms_iocb:
2347 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2348 ha->ms_iocb = NULL;
2349 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002350fail_dma_pool:
2351 dma_pool_destroy(ha->s_dma_pool);
2352 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002353fail_free_nvram:
2354 kfree(ha->nvram);
2355 ha->nvram = NULL;
2356fail_free_srb_mempool:
2357 mempool_destroy(ha->srb_mempool);
2358 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002359fail_free_gid_list:
2360 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002361 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002362 ha->gid_list = NULL;
2363 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002364fail_free_init_cb:
2365 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2366 ha->init_cb_dma);
2367 ha->init_cb = NULL;
2368 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002369fail:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002370 DEBUG(printk("%s: Memory allocation failure\n", __func__));
Andrew Vasqueze8711082008-01-31 12:33:48 -08002371 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372}
2373
2374/*
2375* qla2x00_mem_free
2376* Frees all adapter allocated memory.
2377*
2378* Input:
2379* ha = adapter block pointer.
2380*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08002381static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002382qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383{
Andrew Vasqueze8711082008-01-31 12:33:48 -08002384 if (ha->srb_mempool)
2385 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002387 if (ha->fce)
2388 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002389 ha->fce_dma);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002390
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002391 if (ha->fw_dump) {
2392 if (ha->eft)
2393 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002394 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002395 vfree(ha->fw_dump);
2396 }
2397
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 if (ha->sns_cmd)
2399 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002400 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
2402 if (ha->ct_sns)
2403 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002404 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405
Andrew Vasquez88729e52006-06-23 16:10:50 -07002406 if (ha->sfp_data)
2407 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2408
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 if (ha->ms_iocb)
2410 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2411
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 if (ha->s_dma_pool)
2413 dma_pool_destroy(ha->s_dma_pool);
2414
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002415
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 if (ha->gid_list)
2417 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002418 ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002421 if (ha->init_cb)
2422 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2423 ha->init_cb, ha->init_cb_dma);
2424 vfree(ha->optrom_buffer);
2425 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002426 kfree(ha->npiv_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
Andrew Vasqueze8711082008-01-31 12:33:48 -08002428 ha->srb_mempool = NULL;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002429 ha->eft = NULL;
2430 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 ha->sns_cmd = NULL;
2432 ha->sns_cmd_dma = 0;
2433 ha->ct_sns = NULL;
2434 ha->ct_sns_dma = 0;
2435 ha->ms_iocb = NULL;
2436 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 ha->init_cb = NULL;
2438 ha->init_cb_dma = 0;
2439
2440 ha->s_dma_pool = NULL;
2441
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 ha->gid_list = NULL;
2443 ha->gid_list_dma = 0;
2444
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002446 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 ha->fw_dump_reading = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002448}
2449
2450struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2451 struct qla_hw_data *ha)
2452{
2453 struct Scsi_Host *host;
2454 struct scsi_qla_host *vha = NULL;
2455
2456 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2457 if (host == NULL) {
2458 printk(KERN_WARNING
2459 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2460 goto fail;
2461 }
2462
2463 /* Clear our data area */
2464 vha = shost_priv(host);
2465 memset(vha, 0, sizeof(scsi_qla_host_t));
2466
2467 vha->host = host;
2468 vha->host_no = host->host_no;
2469 vha->hw = ha;
2470
2471 INIT_LIST_HEAD(&vha->vp_fcports);
2472 INIT_LIST_HEAD(&vha->work_list);
2473 INIT_LIST_HEAD(&vha->list);
2474
2475 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2476 return vha;
2477
2478fail:
2479 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480}
2481
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002482static struct qla_work_evt *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002483qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002484 int locked)
2485{
2486 struct qla_work_evt *e;
2487
2488 e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
2489 GFP_KERNEL);
2490 if (!e)
2491 return NULL;
2492
2493 INIT_LIST_HEAD(&e->list);
2494 e->type = type;
2495 e->flags = QLA_EVT_FLAG_FREE;
2496 return e;
2497}
2498
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002499static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002500qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e, int locked)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002501{
Andrew Mortonbf6583b2008-07-24 08:31:48 -07002502 unsigned long uninitialized_var(flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002503 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002504
2505 if (!locked)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002506 spin_lock_irqsave(&ha->hardware_lock, flags);
2507 list_add_tail(&e->list, &vha->work_list);
2508 qla2xxx_wake_dpc(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002509 if (!locked)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002510 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002511 return QLA_SUCCESS;
2512}
2513
2514int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002515qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002516 u32 data)
2517{
2518 struct qla_work_evt *e;
2519
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002520 e = qla2x00_alloc_work(vha, QLA_EVT_AEN, 1);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002521 if (!e)
2522 return QLA_FUNCTION_FAILED;
2523
2524 e->u.aen.code = code;
2525 e->u.aen.data = data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002526 return qla2x00_post_work(vha, e, 1);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002527}
2528
2529static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002530qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002531{
2532 struct qla_work_evt *e;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002533 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002534
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002535 spin_lock_irq(&ha->hardware_lock);
2536 while (!list_empty(&vha->work_list)) {
2537 e = list_entry(vha->work_list.next, struct qla_work_evt, list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002538 list_del_init(&e->list);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002539 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002540
2541 switch (e->type) {
2542 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002543 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07002544 e->u.aen.code, e->u.aen.data);
2545 break;
2546 }
2547 if (e->flags & QLA_EVT_FLAG_FREE)
2548 kfree(e);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002549 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002550 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002551 spin_unlock_irq(&ha->hardware_lock);
2552}
2553/* Relogins all the fcports of a vport
2554 * Context: dpc thread
2555 */
2556void qla2x00_relogin(struct scsi_qla_host *vha)
2557{
2558 fc_port_t *fcport;
2559 uint8_t status;
2560 uint16_t next_loopid = 0;
2561 struct qla_hw_data *ha = vha->hw;
2562
2563 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2564 /*
2565 * If the port is not ONLINE then try to login
2566 * to it if we haven't run out of retries.
2567 */
2568 if (atomic_read(&fcport->state) !=
2569 FCS_ONLINE && fcport->login_retry) {
2570
2571 if (fcport->flags & FCF_FABRIC_DEVICE) {
2572 if (fcport->flags & FCF_TAPE_PRESENT)
2573 ha->isp_ops->fabric_logout(vha,
2574 fcport->loop_id,
2575 fcport->d_id.b.domain,
2576 fcport->d_id.b.area,
2577 fcport->d_id.b.al_pa);
2578
2579 status = qla2x00_fabric_login(vha, fcport,
2580 &next_loopid);
2581 } else
2582 status = qla2x00_local_device_login(vha,
2583 fcport);
2584
2585 fcport->login_retry--;
2586 if (status == QLA_SUCCESS) {
2587 fcport->old_loop_id = fcport->loop_id;
2588
2589 DEBUG(printk("scsi(%ld): port login OK: logged "
2590 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2591
2592 qla2x00_update_fcport(vha, fcport);
2593
2594 } else if (status == 1) {
2595 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2596 /* retry the login again */
2597 DEBUG(printk("scsi(%ld): Retrying"
2598 " %d login again loop_id 0x%x\n",
2599 vha->host_no, fcport->login_retry,
2600 fcport->loop_id));
2601 } else {
2602 fcport->login_retry = 0;
2603 }
2604
2605 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2606 fcport->loop_id = FC_NO_LOOP_ID;
2607 }
2608 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2609 break;
2610 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07002611}
2612
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613/**************************************************************************
2614* qla2x00_do_dpc
2615* This kernel thread is a task that is schedule by the interrupt handler
2616* to perform the background processing for interrupts.
2617*
2618* Notes:
2619* This task always run in the context of a kernel thread. It
2620* is kick-off by the driver's detect code and starts up
2621* up one per adapter. It immediately goes to sleep and waits for
2622* some fibre event. When either the interrupt handler or
2623* the timer routine detects a event it will one of the task
2624* bits then wake us up.
2625**************************************************************************/
2626static int
2627qla2x00_do_dpc(void *data)
2628{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002629 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002630 scsi_qla_host_t *base_vha;
2631 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08002632
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002633 ha = (struct qla_hw_data *)data;
2634 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 set_user_nice(current, -20);
2637
Christoph Hellwig39a11242006-02-14 18:46:22 +01002638 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2640
Christoph Hellwig39a11242006-02-14 18:46:22 +01002641 set_current_state(TASK_INTERRUPTIBLE);
2642 schedule();
2643 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
2645 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2646
2647 /* Initialization not yet finished. Don't do anything yet. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002648 if (!base_vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 continue;
2650
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002651 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652
2653 ha->dpc_active = 1;
2654
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 ha->dpc_active = 0;
2657 continue;
2658 }
2659
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002660 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002661
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002662 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2663 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
2665 DEBUG(printk("scsi(%ld): dpc: sched "
2666 "qla2x00_abort_isp ha = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002667 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002669 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002671 if (qla2x00_abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 /* failed. retry later */
2673 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002674 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002676 clear_bit(ABORT_ISP_ACTIVE,
2677 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08002678 }
2679
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002681 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 }
2683
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002684 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2685 qla2x00_update_fcports(base_vha);
2686 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07002687 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002688
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002689 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2690 &base_vha->dpc_flags) &&
2691 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692
2693 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002694 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002696 qla2x00_rst_aen(base_vha);
2697 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 }
2699
2700 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002701 if ((test_and_clear_bit(RELOGIN_NEEDED,
2702 &base_vha->dpc_flags)) &&
2703 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2704 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705
2706 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002707 base_vha->host_no));
2708 qla2x00_relogin(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002711 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 }
2713
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002714 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2715 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716
2717 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002718 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719
2720 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002721 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002723 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002725 clear_bit(LOOP_RESYNC_ACTIVE,
2726 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 }
2728
2729 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002730 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 }
2732
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002733 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2734 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2735 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2736 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07002737 }
2738
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002740 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002742 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2743 &base_vha->dpc_flags))
2744 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002745
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002746 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002747
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 ha->dpc_active = 0;
2749 } /* End of while(1) */
2750
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002751 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752
2753 /*
2754 * Make sure that nobody tries to wake us up again.
2755 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 ha->dpc_active = 0;
2757
Christoph Hellwig39a11242006-02-14 18:46:22 +01002758 return 0;
2759}
2760
2761void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002762qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01002763{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002764 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002765 struct task_struct *t = ha->dpc_thread;
2766
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002767 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002768 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769}
2770
2771/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772* qla2x00_rst_aen
2773* Processes asynchronous reset.
2774*
2775* Input:
2776* ha = adapter block pointer.
2777*/
2778static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002779qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002781 if (vha->flags.online && !vha->flags.reset_active &&
2782 !atomic_read(&vha->loop_down_timer) &&
2783 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002785 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786
2787 /*
2788 * Issue marker command only when we are going to start
2789 * the I/O.
2790 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002791 vha->marker_needed = 1;
2792 } while (!atomic_read(&vha->loop_down_timer) &&
2793 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 }
2795}
2796
f4f051e2005-04-17 15:02:26 -05002797static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002798qla2x00_sp_free_dma(srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002799{
2800 struct scsi_cmnd *cmd = sp->cmd;
2801
2802 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002803 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05002804 sp->flags &= ~SRB_DMA_VALID;
2805 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002806 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002807}
2808
2809void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002810qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002811{
2812 struct scsi_cmnd *cmd = sp->cmd;
2813
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002814 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -05002815
f4f051e2005-04-17 15:02:26 -05002816 mempool_free(sp, ha->srb_mempool);
2817
2818 cmd->scsi_done(cmd);
2819}
bdf79622005-04-17 15:06:53 -05002820
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821/**************************************************************************
2822* qla2x00_timer
2823*
2824* Description:
2825* One second timer
2826*
2827* Context: Interrupt
2828***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002829void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002830qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 unsigned long cpu_flags = 0;
2833 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 int start_dpc = 0;
2835 int index;
2836 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002837 int t;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002838 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002839 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 /*
2841 * Ports - Port down timer.
2842 *
2843 * Whenever, a port is in the LOST state we start decrementing its port
2844 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002845 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 */
2847 t = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002848 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 if (fcport->port_type != FCT_TARGET)
2850 continue;
2851
2852 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2853
2854 if (atomic_read(&fcport->port_down_timer) == 0)
2855 continue;
2856
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002857 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002859
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002861 "%d remaining\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002862 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 t, atomic_read(&fcport->port_down_timer)));
2864 }
2865 t++;
2866 } /* End of for fcport */
2867
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868
2869 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002870 if (atomic_read(&vha->loop_down_timer) > 0 &&
2871 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
2872 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002874 if (atomic_read(&vha->loop_down_timer) ==
2875 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876
2877 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2878 "queues before time expire\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002879 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002881 if (!IS_QLA2100(ha) && vha->link_down_timeout)
2882 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883
2884 /* Schedule an ISP abort to return any tape commands. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002885 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002886 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002887 spin_lock_irqsave(&ha->hardware_lock,
2888 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002889 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002890 for (index = 1;
2891 index < MAX_OUTSTANDING_COMMANDS;
2892 index++) {
2893 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05002894
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002895 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002896 if (!sp)
2897 continue;
2898 sfcp = sp->fcport;
2899 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2900 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002902 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002903 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002904 break;
2905 }
2906 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002907 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002909 set_bit(ABORT_QUEUES_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 start_dpc++;
2911 }
2912
2913 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002914 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2916 "restarting queues.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002917 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002919 set_bit(RESTART_QUEUES_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 start_dpc++;
2921
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002922 if (!(vha->device_flags & DFLG_NO_CABLE) &&
2923 !vha->vp_idx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 DEBUG(printk("scsi(%ld): Loop down - "
2925 "aborting ISP.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002926 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 qla_printk(KERN_WARNING, ha,
2928 "Loop down - aborting ISP.\n");
2929
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002930 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 }
2932 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002933 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002934 vha->host_no,
2935 atomic_read(&vha->loop_down_timer)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 }
2937
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002938 /* Check if beacon LED needs to be blinked */
2939 if (ha->beacon_blink_led == 1) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002940 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002941 start_dpc++;
2942 }
2943
Andrew Vasquez550bf572008-04-24 15:21:23 -07002944 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002945 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07002946 start_dpc++;
2947
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002949 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
2950 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
2951 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002953 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
2954 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
2955 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
2956 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
2957 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002959 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960}
2961
Andrew Vasquez54333832005-11-09 15:49:04 -08002962/* Firmware interface routines. */
2963
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002964#define FW_BLOBS 7
Andrew Vasquez54333832005-11-09 15:49:04 -08002965#define FW_ISP21XX 0
2966#define FW_ISP22XX 1
2967#define FW_ISP2300 2
2968#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002969#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002970#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002971#define FW_ISP81XX 6
Andrew Vasquez54333832005-11-09 15:49:04 -08002972
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002973#define FW_FILE_ISP21XX "ql2100_fw.bin"
2974#define FW_FILE_ISP22XX "ql2200_fw.bin"
2975#define FW_FILE_ISP2300 "ql2300_fw.bin"
2976#define FW_FILE_ISP2322 "ql2322_fw.bin"
2977#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002978#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002979#define FW_FILE_ISP81XX "ql8100_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002980
Daniel Walkere1e82b62008-05-12 22:21:10 -07002981static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002982
2983static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002984 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
2985 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
2986 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
2987 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
2988 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002989 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002990 { .name = FW_FILE_ISP81XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08002991};
2992
2993struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002994qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08002995{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002996 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08002997 struct fw_blob *blob;
2998
2999 blob = NULL;
3000 if (IS_QLA2100(ha)) {
3001 blob = &qla_fw_blobs[FW_ISP21XX];
3002 } else if (IS_QLA2200(ha)) {
3003 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003004 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003005 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003006 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003007 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003008 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003009 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003010 } else if (IS_QLA25XX(ha)) {
3011 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003012 } else if (IS_QLA81XX(ha)) {
3013 blob = &qla_fw_blobs[FW_ISP81XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08003014 }
3015
Daniel Walkere1e82b62008-05-12 22:21:10 -07003016 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003017 if (blob->fw)
3018 goto out;
3019
3020 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
3021 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003022 "(%s).\n", vha->host_no, blob->name));
Andrew Vasquez54333832005-11-09 15:49:04 -08003023 blob->fw = NULL;
3024 blob = NULL;
3025 goto out;
3026 }
3027
3028out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07003029 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003030 return blob;
3031}
3032
3033static void
3034qla2x00_release_firmware(void)
3035{
3036 int idx;
3037
Daniel Walkere1e82b62008-05-12 22:21:10 -07003038 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003039 for (idx = 0; idx < FW_BLOBS; idx++)
3040 if (qla_fw_blobs[idx].fw)
3041 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07003042 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003043}
3044
Seokmann Ju14e660e2007-09-20 14:07:36 -07003045static pci_ers_result_t
3046qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3047{
3048 switch (state) {
3049 case pci_channel_io_normal:
3050 return PCI_ERS_RESULT_CAN_RECOVER;
3051 case pci_channel_io_frozen:
3052 pci_disable_device(pdev);
3053 return PCI_ERS_RESULT_NEED_RESET;
3054 case pci_channel_io_perm_failure:
3055 qla2x00_remove_one(pdev);
3056 return PCI_ERS_RESULT_DISCONNECT;
3057 }
3058 return PCI_ERS_RESULT_NEED_RESET;
3059}
3060
3061static pci_ers_result_t
3062qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
3063{
3064 int risc_paused = 0;
3065 uint32_t stat;
3066 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003067 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3068 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003069 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3070 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
3071
3072 spin_lock_irqsave(&ha->hardware_lock, flags);
3073 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3074 stat = RD_REG_DWORD(&reg->hccr);
3075 if (stat & HCCR_RISC_PAUSE)
3076 risc_paused = 1;
3077 } else if (IS_QLA23XX(ha)) {
3078 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
3079 if (stat & HSR_RISC_PAUSED)
3080 risc_paused = 1;
3081 } else if (IS_FWI2_CAPABLE(ha)) {
3082 stat = RD_REG_DWORD(&reg24->host_status);
3083 if (stat & HSRX_RISC_PAUSED)
3084 risc_paused = 1;
3085 }
3086 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3087
3088 if (risc_paused) {
3089 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3090 "Dumping firmware!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003091 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003092
3093 return PCI_ERS_RESULT_NEED_RESET;
3094 } else
3095 return PCI_ERS_RESULT_RECOVERED;
3096}
3097
3098static pci_ers_result_t
3099qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3100{
3101 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003102 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3103 struct qla_hw_data *ha = base_vha->hw;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003104 int rc;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003105
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003106 if (ha->mem_only)
3107 rc = pci_enable_device_mem(pdev);
3108 else
3109 rc = pci_enable_device(pdev);
3110
3111 if (rc) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07003112 qla_printk(KERN_WARNING, ha,
3113 "Can't re-enable PCI device after reset.\n");
3114
3115 return ret;
3116 }
3117 pci_set_master(pdev);
3118
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003119 if (ha->isp_ops->pci_config(base_vha))
Seokmann Ju14e660e2007-09-20 14:07:36 -07003120 return ret;
3121
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003122 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3123 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07003124 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003125 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003126
3127 return ret;
3128}
3129
3130static void
3131qla2xxx_pci_resume(struct pci_dev *pdev)
3132{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003133 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3134 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003135 int ret;
3136
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003137 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003138 if (ret != QLA_SUCCESS) {
3139 qla_printk(KERN_ERR, ha,
3140 "the device failed to resume I/O "
3141 "from slot/link_reset");
3142 }
3143 pci_cleanup_aer_uncorrect_error_status(pdev);
3144}
3145
3146static struct pci_error_handlers qla2xxx_err_handler = {
3147 .error_detected = qla2xxx_pci_error_detected,
3148 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3149 .slot_reset = qla2xxx_pci_slot_reset,
3150 .resume = qla2xxx_pci_resume,
3151};
3152
Andrew Vasquez54333832005-11-09 15:49:04 -08003153static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003154 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3155 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3156 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3157 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3158 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3159 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3160 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3161 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3162 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003163 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003164 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3165 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003166 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003167 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Andrew Vasquez54333832005-11-09 15:49:04 -08003168 { 0 },
3169};
3170MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3171
Andrew Vasquezfca29702005-07-06 10:31:47 -07003172static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07003173 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06003174 .driver = {
3175 .owner = THIS_MODULE,
3176 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07003177 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003178 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08003179 .remove = qla2x00_remove_one,
Seokmann Ju14e660e2007-09-20 14:07:36 -07003180 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07003181};
3182
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183/**
3184 * qla2x00_module_init - Module initialization.
3185 **/
3186static int __init
3187qla2x00_module_init(void)
3188{
Andrew Vasquezfca29702005-07-06 10:31:47 -07003189 int ret = 0;
3190
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003192 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09003193 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 if (srb_cachep == NULL) {
3195 printk(KERN_ERR
3196 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3197 return -ENOMEM;
3198 }
3199
3200 /* Derive version string. */
3201 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07003202 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07003203 strcat(qla2x00_version_str, "-debug");
3204
Andrew Vasquez1c97a122005-04-21 16:13:36 -04003205 qla2xxx_transport_template =
3206 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003207 if (!qla2xxx_transport_template) {
3208 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003210 }
3211 qla2xxx_transport_vport_template =
3212 fc_attach_transport(&qla2xxx_transport_vport_functions);
3213 if (!qla2xxx_transport_vport_template) {
3214 kmem_cache_destroy(srb_cachep);
3215 fc_release_transport(qla2xxx_transport_template);
3216 return -ENODEV;
3217 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218
Andrew Vasquezfd9a29f2008-05-12 22:21:08 -07003219 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3220 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003221 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003222 if (ret) {
3223 kmem_cache_destroy(srb_cachep);
3224 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003225 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003226 }
3227 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228}
3229
3230/**
3231 * qla2x00_module_exit - Module cleanup.
3232 **/
3233static void __exit
3234qla2x00_module_exit(void)
3235{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003236 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08003237 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003238 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003240 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241}
3242
3243module_init(qla2x00_module_init);
3244module_exit(qla2x00_module_exit);
3245
3246MODULE_AUTHOR("QLogic Corporation");
3247MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3248MODULE_LICENSE("GPL");
3249MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003250MODULE_FIRMWARE(FW_FILE_ISP21XX);
3251MODULE_FIRMWARE(FW_FILE_ISP22XX);
3252MODULE_FIRMWARE(FW_FILE_ISP2300);
3253MODULE_FIRMWARE(FW_FILE_ISP2322);
3254MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08003255MODULE_FIRMWARE(FW_FILE_ISP25XX);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003256MODULE_FIRMWARE(FW_FILE_ISP81XX);