blob: 3580c034ab0aadf97470f7989110a9d91f46a663 [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 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
408 ha->fw_minor_version,
409 ha->fw_subminor_version);
410
Andrew Vasquezfca29702005-07-06 10:31:47 -0700411 if (ha->fw_attributes & BIT_0)
412 strcat(str, "[Class 2] ");
413 if (ha->fw_attributes & BIT_1)
414 strcat(str, "[IP] ");
415 if (ha->fw_attributes & BIT_2)
416 strcat(str, "[Multi-ID] ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700417 if (ha->fw_attributes & BIT_3)
418 strcat(str, "[SB-2] ");
419 if (ha->fw_attributes & BIT_4)
420 strcat(str, "[T10 CRC] ");
421 if (ha->fw_attributes & BIT_5)
422 strcat(str, "[VI] ");
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700423 if (ha->fw_attributes & BIT_10)
424 strcat(str, "[84XX] ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700425 if (ha->fw_attributes & BIT_13)
426 strcat(str, "[Experimental]");
427 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700428}
429
430static inline srb_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800431qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700432 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
433{
434 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800435 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700436
437 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
438 if (!sp)
439 return sp;
440
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800441 sp->vha = vha;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700442 sp->fcport = fcport;
443 sp->cmd = cmd;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800444 sp->que = ha->req_q_map[0];
Andrew Vasquezfca29702005-07-06 10:31:47 -0700445 sp->flags = 0;
446 CMD_SP(cmd) = (void *)sp;
447 cmd->scsi_done = done;
448
449 return sp;
450}
451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452static int
f4f051e2005-04-17 15:02:26 -0500453qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800455 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500456 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400457 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800458 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500459 srb_t *sp;
460 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Seokmann Ju14e660e2007-09-20 14:07:36 -0700462 if (unlikely(pci_channel_offline(ha->pdev))) {
463 cmd->result = DID_REQUEUE << 16;
464 goto qc_fail_command;
465 }
466
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400467 rval = fc_remote_port_chkready(rport);
468 if (rval) {
469 cmd->result = rval;
f4f051e2005-04-17 15:02:26 -0500470 goto qc_fail_command;
471 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800473 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500474 if (fcport->drport)
475 goto qc_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800476
f4f051e2005-04-17 15:02:26 -0500477 if (atomic_read(&fcport->state) != FCS_ONLINE) {
478 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800479 atomic_read(&vha->loop_state) == LOOP_DEAD) {
f4f051e2005-04-17 15:02:26 -0500480 cmd->result = DID_NO_CONNECT << 16;
481 goto qc_fail_command;
482 }
Mike Christie7b594132008-08-17 15:24:40 -0500483 goto qc_target_busy;
f4f051e2005-04-17 15:02:26 -0500484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800486 spin_unlock_irq(vha->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800488 sp = qla2x00_get_new_sp(vha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700489 if (!sp)
f4f051e2005-04-17 15:02:26 -0500490 goto qc_host_busy_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800492 rval = ha->isp_ops->start_scsi(sp);
f4f051e2005-04-17 15:02:26 -0500493 if (rval != QLA_SUCCESS)
494 goto qc_host_busy_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800496 spin_lock_irq(vha->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
f4f051e2005-04-17 15:02:26 -0500498 return 0;
499
500qc_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800501 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -0500502 mempool_free(sp, ha->srb_mempool);
503
504qc_host_busy_lock:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800505 spin_lock_irq(vha->host->host_lock);
f4f051e2005-04-17 15:02:26 -0500506 return SCSI_MLQUEUE_HOST_BUSY;
507
Mike Christie7b594132008-08-17 15:24:40 -0500508qc_target_busy:
509 return SCSI_MLQUEUE_TARGET_BUSY;
510
f4f051e2005-04-17 15:02:26 -0500511qc_fail_command:
512 done(cmd);
513
514 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515}
516
Andrew Vasquezfca29702005-07-06 10:31:47 -0700517
518static int
519qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
520{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800521 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700522 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400523 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800524 struct qla_hw_data *ha = vha->hw;
525 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700526 srb_t *sp;
527 int rval;
528
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800529 if (unlikely(pci_channel_offline(ha->pdev))) {
Seokmann Ju14e660e2007-09-20 14:07:36 -0700530 cmd->result = DID_REQUEUE << 16;
531 goto qc24_fail_command;
532 }
533
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400534 rval = fc_remote_port_chkready(rport);
535 if (rval) {
536 cmd->result = rval;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700537 goto qc24_fail_command;
538 }
539
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800540 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500541 if (fcport->drport)
542 goto qc24_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800543
Andrew Vasquezfca29702005-07-06 10:31:47 -0700544 if (atomic_read(&fcport->state) != FCS_ONLINE) {
545 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800546 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700547 cmd->result = DID_NO_CONNECT << 16;
548 goto qc24_fail_command;
549 }
Mike Christie7b594132008-08-17 15:24:40 -0500550 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700551 }
552
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800553 spin_unlock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700554
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800555 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700556 if (!sp)
557 goto qc24_host_busy_lock;
558
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800559 rval = ha->isp_ops->start_scsi(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700560 if (rval != QLA_SUCCESS)
561 goto qc24_host_busy_free_sp;
562
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800563 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700564
565 return 0;
566
567qc24_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800568 qla2x00_sp_free_dma(sp);
569 mempool_free(sp, ha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700570
571qc24_host_busy_lock:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800572 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700573 return SCSI_MLQUEUE_HOST_BUSY;
574
Mike Christie7b594132008-08-17 15:24:40 -0500575qc24_target_busy:
576 return SCSI_MLQUEUE_TARGET_BUSY;
577
Andrew Vasquezfca29702005-07-06 10:31:47 -0700578qc24_fail_command:
579 done(cmd);
580
581 return 0;
582}
583
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585/*
586 * qla2x00_eh_wait_on_command
587 * Waits for the command to be returned by the Firmware for some
588 * max time.
589 *
590 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 *
593 * Return:
594 * Not Found : 0
595 * Found : 1
596 */
597static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800598qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700600#define ABORT_POLLING_PERIOD 1000
601#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500602 unsigned long wait_iter = ABORT_WAIT_ITER;
603 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
f4f051e2005-04-17 15:02:26 -0500605 while (CMD_SP(cmd)) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700606 msleep(ABORT_POLLING_PERIOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
f4f051e2005-04-17 15:02:26 -0500608 if (--wait_iter)
609 break;
610 }
611 if (CMD_SP(cmd))
612 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
f4f051e2005-04-17 15:02:26 -0500614 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615}
616
617/*
618 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700619 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 * <= MAX_RETRIES_OF_ISP_ABORT or
621 * finally HBA is disabled ie marked offline
622 *
623 * Input:
624 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700625 *
626 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 * Does context switching-Release SPIN_LOCK
628 * (if any) before calling this routine.
629 *
630 * Return:
631 * Success (Adapter is online) : 0
632 * Failed (Adapter is offline/disabled) : 1
633 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800634int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800635qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700637 int return_status;
638 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800639 struct qla_hw_data *ha = vha->hw;
640 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700642 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800643 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
644 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
645 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
646 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
648 msleep(1000);
649 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800650 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700651 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 else
653 return_status = QLA_FUNCTION_FAILED;
654
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 return (return_status);
656}
657
658/*
659 * qla2x00_wait_for_loop_ready
660 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700661 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 * Input:
663 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700664 *
665 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 * Does context switching-Release SPIN_LOCK
667 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700668 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 *
670 * Return:
671 * Success (LOOP_READY) : 0
672 * Failed (LOOP_NOT_READY) : 1
673 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700674static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800675qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
677 int return_status = QLA_SUCCESS;
678 unsigned long loop_timeout ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800679 struct qla_hw_data *ha = vha->hw;
680 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
682 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700683 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800685 while ((!atomic_read(&base_vha->loop_down_timer) &&
686 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
687 atomic_read(&base_vha->loop_state) != LOOP_READY) {
688 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Ravi Anand57680082006-05-17 15:08:44 -0700689 return_status = QLA_FUNCTION_FAILED;
690 break;
691 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 msleep(1000);
693 if (time_after_eq(jiffies, loop_timeout)) {
694 return_status = QLA_FUNCTION_FAILED;
695 break;
696 }
697 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700698 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699}
700
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700701void
702qla2x00_abort_fcport_cmds(fc_port_t *fcport)
703{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800704 int cnt, que, id;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700705 unsigned long flags;
706 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800707 scsi_qla_host_t *vha = fcport->vha;
708 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800709 struct req_que *req;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700710
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800711 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800712 for (que = 0; que < QLA_MAX_HOST_QUES; que++) {
713 id = vha->req_ques[que];
714 req = ha->req_q_map[id];
715 if (!req)
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700716 continue;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800717 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
718 sp = req->outstanding_cmds[cnt];
719 if (!sp)
720 continue;
721 if (sp->fcport != fcport)
722 continue;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700723
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800724 spin_unlock_irqrestore(&ha->hardware_lock, flags);
725 if (ha->isp_ops->abort_command(vha, sp, req)) {
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700726 DEBUG2(qla_printk(KERN_WARNING, ha,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800727 "Abort failed -- %lx\n",
728 sp->cmd->serial_number));
729 } else {
730 if (qla2x00_eh_wait_on_command(sp->cmd) !=
731 QLA_SUCCESS)
732 DEBUG2(qla_printk(KERN_WARNING, ha,
733 "Abort failed while waiting -- %lx\n",
734 sp->cmd->serial_number));
735 }
736 spin_lock_irqsave(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700737 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700738 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800739 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700740}
741
Andrew Vasquez07db5182006-10-02 12:00:49 -0700742static void
743qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
744{
745 struct Scsi_Host *shost = cmnd->device->host;
746 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
747 unsigned long flags;
748
749 spin_lock_irqsave(shost->host_lock, flags);
750 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
751 spin_unlock_irqrestore(shost->host_lock, flags);
752 msleep(1000);
753 spin_lock_irqsave(shost->host_lock, flags);
754 }
755 spin_unlock_irqrestore(shost->host_lock, flags);
756 return;
757}
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759/**************************************************************************
760* qla2xxx_eh_abort
761*
762* Description:
763* The abort function will abort the specified command.
764*
765* Input:
766* cmd = Linux SCSI command packet to be aborted.
767*
768* Returns:
769* Either SUCCESS or FAILED.
770*
771* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700772* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800774static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775qla2xxx_eh_abort(struct scsi_cmnd *cmd)
776{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800777 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500778 srb_t *sp;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800779 int ret, i;
f4f051e2005-04-17 15:02:26 -0500780 unsigned int id, lun;
781 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700782 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700783 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800784 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800785 struct req_que *req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800786 srb_t *spt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Andrew Vasquez07db5182006-10-02 12:00:49 -0700788 qla2x00_block_error_handler(cmd);
789
f4f051e2005-04-17 15:02:26 -0500790 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700791 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
Michael Reed2ea00202006-04-27 16:25:30 -0700793 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
f4f051e2005-04-17 15:02:26 -0500795 id = cmd->device->id;
796 lun = cmd->device->lun;
797 serial = cmd->serial_number;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800798 spt = (srb_t *) CMD_SP(cmd);
799 if (!spt)
800 return SUCCESS;
801 req = spt->que;
f4f051e2005-04-17 15:02:26 -0500802
803 /* Check active list for command command. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800804 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800805 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
806 sp = req->outstanding_cmds[i];
807
808 if (sp == NULL)
f4f051e2005-04-17 15:02:26 -0500809 continue;
810
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800811 if (sp->cmd != cmd)
812 continue;
f4f051e2005-04-17 15:02:26 -0500813
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800814 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
815 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
f4f051e2005-04-17 15:02:26 -0500816
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800817 spin_unlock_irqrestore(&ha->hardware_lock, flags);
818 if (ha->isp_ops->abort_command(vha, sp, req)) {
819 DEBUG2(printk("%s(%ld): abort_command "
820 "mbx failed.\n", __func__, vha->host_no));
821 } else {
822 DEBUG3(printk("%s(%ld): abort_command "
823 "mbx success.\n", __func__, vha->host_no));
824 wait = 1;
f4f051e2005-04-17 15:02:26 -0500825 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800826 spin_lock_irqsave(&ha->hardware_lock, flags);
827 break;
f4f051e2005-04-17 15:02:26 -0500828 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800829 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500830
831 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700832 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800833 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700834 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500835 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800836 "%x.\n", vha->host_no, id, lun, serial, ret);
Michael Reed2ea00202006-04-27 16:25:30 -0700837 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500838 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700841 qla_printk(KERN_INFO, ha,
Michael Reed2ea00202006-04-27 16:25:30 -0700842 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800843 vha->host_no, id, lun, wait, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
f4f051e2005-04-17 15:02:26 -0500845 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846}
847
Andrew Vasquez523ec772008-04-03 13:13:24 -0700848enum nexus_wait_type {
849 WAIT_HOST = 0,
850 WAIT_TARGET,
851 WAIT_LUN,
852};
853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800855qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800856 unsigned int l, srb_t *sp, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800858 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700859 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800860 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800861 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Andrew Vasquez523ec772008-04-03 13:13:24 -0700863 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800864 if (!sp)
865 return status;
866
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800867 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800868 req = sp->que;
869 for (cnt = 1; status == QLA_SUCCESS &&
870 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
871 sp = req->outstanding_cmds[cnt];
872 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700873 continue;
Andrew Vasquez19851f12008-08-13 21:37:00 -0700874
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800875 if (vha->vp_idx != sp->fcport->vha->vp_idx)
876 continue;
877 match = 0;
878 switch (type) {
879 case WAIT_HOST:
880 match = 1;
881 break;
882 case WAIT_TARGET:
883 match = sp->cmd->device->id == t;
884 break;
885 case WAIT_LUN:
886 match = (sp->cmd->device->id == t &&
887 sp->cmd->device->lun == l);
888 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800890 if (!match)
891 continue;
892
893 spin_unlock_irqrestore(&ha->hardware_lock, flags);
894 status = qla2x00_eh_wait_on_command(sp->cmd);
895 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800897 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700898
899 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900}
901
Andrew Vasquez523ec772008-04-03 13:13:24 -0700902static char *reset_errors[] = {
903 "HBA not online",
904 "HBA not ready",
905 "Task management failed",
906 "Waiting for command completions",
907};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Andrew Vasquez523ec772008-04-03 13:13:24 -0700909static int
910__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
911 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int))
912{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800913 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700914 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
915 int err;
916
917 qla2x00_block_error_handler(cmd);
918
919 if (!fcport)
920 return FAILED;
921
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800922 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
923 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700924
925 err = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800926 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700927 goto eh_reset_failed;
928 err = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800929 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700930 goto eh_reset_failed;
931 err = 2;
932 if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS)
933 goto eh_reset_failed;
934 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800935 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800936 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700937 goto eh_reset_failed;
938
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800939 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
940 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700941
942 return SUCCESS;
943
944 eh_reset_failed:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800945 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
946 , vha->host_no, cmd->device->id, cmd->device->lun, name,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700947 reset_errors[err]);
948 return FAILED;
949}
950
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800951static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
953{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800954 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
955 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Andrew Vasquez523ec772008-04-03 13:13:24 -0700957 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
958 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959}
960
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700962qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800964 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
965 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Andrew Vasquez523ec772008-04-03 13:13:24 -0700967 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
968 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969}
970
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971/**************************************************************************
972* qla2xxx_eh_bus_reset
973*
974* Description:
975* The bus reset function will reset the bus and abort any executing
976* commands.
977*
978* Input:
979* cmd = Linux SCSI command packet of the command that cause the
980* bus reset.
981*
982* Returns:
983* SUCCESS/FAILURE (defined as macro in scsi.h).
984*
985**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800986static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
988{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800989 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500990 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700991 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500992 unsigned int id, lun;
993 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800994 srb_t *sp = (srb_t *) CMD_SP(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
Andrew Vasquez07db5182006-10-02 12:00:49 -0700996 qla2x00_block_error_handler(cmd);
997
f4f051e2005-04-17 15:02:26 -0500998 id = cmd->device->id;
999 lun = cmd->device->lun;
1000 serial = cmd->serial_number;
1001
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -07001002 if (!fcport)
f4f051e2005-04-17 15:02:26 -05001003 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001005 qla_printk(KERN_INFO, vha->hw,
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001006 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001008 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -05001010 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
1012
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001013 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
1014 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001015 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 }
f4f051e2005-04-17 15:02:26 -05001017 if (ret == FAILED)
1018 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001020 /* Flush outstanding commands. */
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001021 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
Andrew Vasquez523ec772008-04-03 13:13:24 -07001022 QLA_SUCCESS)
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001023 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
f4f051e2005-04-17 15:02:26 -05001025eh_bus_reset_done:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001026 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -05001027 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
f4f051e2005-04-17 15:02:26 -05001029 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030}
1031
1032/**************************************************************************
1033* qla2xxx_eh_host_reset
1034*
1035* Description:
1036* The reset function will reset the Adapter.
1037*
1038* Input:
1039* cmd = Linux SCSI command packet of the command that cause the
1040* adapter reset.
1041*
1042* Returns:
1043* Either SUCCESS or FAILED.
1044*
1045* Note:
1046**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001047static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1049{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001050 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001051 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001052 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001053 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001054 unsigned int id, lun;
1055 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001056 srb_t *sp = (srb_t *) CMD_SP(cmd);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001057 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
Andrew Vasquez07db5182006-10-02 12:00:49 -07001059 qla2x00_block_error_handler(cmd);
1060
f4f051e2005-04-17 15:02:26 -05001061 id = cmd->device->id;
1062 lun = cmd->device->lun;
1063 serial = cmd->serial_number;
1064
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -07001065 if (!fcport)
f4f051e2005-04-17 15:02:26 -05001066 return ret;
1067
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 qla_printk(KERN_INFO, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001069 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001071 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001072 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
1074 /*
1075 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001076 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 * be completed and then issue big hammer.Otherwise
1078 * it may cause I/O failure as big hammer marks the
1079 * devices as lost kicking of the port_down_timer
1080 * while dpc is stuck for the mailbox to complete.
1081 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001082 qla2x00_wait_for_loop_ready(vha);
1083 if (vha != base_vha) {
1084 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001085 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001086 } else {
1087 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1088 if (qla2x00_abort_isp(base_vha)) {
1089 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1090 /* failed. schedule dpc to try */
1091 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1092
1093 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1094 goto eh_host_reset_lock;
1095 }
1096 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001099 /* Waiting for command to be returned to OS.*/
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001100 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001101 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001102 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
f4f051e2005-04-17 15:02:26 -05001104eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001105 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1106 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
f4f051e2005-04-17 15:02:26 -05001108 return ret;
1109}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
1111/*
1112* qla2x00_loop_reset
1113* Issue loop reset.
1114*
1115* Input:
1116* ha = adapter block pointer.
1117*
1118* Returns:
1119* 0 = success
1120*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001121int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001122qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001124 int ret;
bdf79622005-04-17 15:06:53 -05001125 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001126 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001128 if (ha->flags.enable_lip_full_login && !vha->vp_idx) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001129 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001130 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001131 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001132 "full_login_lip=%d.\n", __func__, vha->host_no,
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001133 ret));
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001134 }
1135 atomic_set(&vha->loop_state, LOOP_DOWN);
1136 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1137 qla2x00_mark_all_devices_lost(vha, 0);
1138 qla2x00_wait_for_loop_ready(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 }
1140
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001141 if (ha->flags.enable_lip_reset && !vha->vp_idx) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001142 ret = qla2x00_lip_reset(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001143 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001144 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001145 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1146 } else
1147 qla2x00_wait_for_loop_ready(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001148 }
1149
1150 if (ha->flags.enable_target_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001151 list_for_each_entry(fcport, &vha->vp_fcports, list) {
bdf79622005-04-17 15:06:53 -05001152 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 continue;
1154
Andrew Vasquez523ec772008-04-03 13:13:24 -07001155 ret = ha->isp_ops->target_reset(fcport, 0);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001156 if (ret != QLA_SUCCESS) {
1157 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1158 "target_reset=%d d_id=%x.\n", __func__,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001159 vha->host_no, ret, fcport->d_id.b24));
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 }
1162 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001164 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001166 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167}
1168
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001169void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001170qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001171{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001172 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001173 unsigned long flags;
1174 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001175 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001176 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001177
1178 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001179 for (que = 0; que < QLA_MAX_HOST_QUES; que++) {
1180 req = ha->req_q_map[vha->req_ques[que]];
1181 if (!req)
1182 continue;
1183 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1184 sp = req->outstanding_cmds[cnt];
1185 if (sp && sp->vha == vha) {
1186 req->outstanding_cmds[cnt] = NULL;
1187 sp->cmd->result = res;
1188 qla2x00_sp_compl(ha, sp);
1189 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001190 }
1191 }
1192 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1193}
1194
f4f051e2005-04-17 15:02:26 -05001195static int
1196qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197{
bdf79622005-04-17 15:06:53 -05001198 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001200 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001201 return -ENXIO;
1202
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001203 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001204
1205 return 0;
1206}
1207
1208static int
1209qla2xxx_slave_configure(struct scsi_device *sdev)
1210{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001211 scsi_qla_host_t *vha = shost_priv(sdev->host);
1212 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05001213 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001214 struct req_que *req = ha->req_q_map[0];
8482e1182005-04-17 15:04:54 -05001215
f4f051e2005-04-17 15:02:26 -05001216 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001217 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001219 scsi_deactivate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
Andrew Vasquez85821c92008-07-10 16:55:48 -07001221 rport->dev_loss_tmo = ha->port_down_retry_count;
8482e1182005-04-17 15:04:54 -05001222
f4f051e2005-04-17 15:02:26 -05001223 return 0;
1224}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225
f4f051e2005-04-17 15:02:26 -05001226static void
1227qla2xxx_slave_destroy(struct scsi_device *sdev)
1228{
1229 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230}
1231
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001232static int
1233qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1234{
1235 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1236 return sdev->queue_depth;
1237}
1238
1239static int
1240qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1241{
1242 if (sdev->tagged_supported) {
1243 scsi_set_tag_type(sdev, tag_type);
1244 if (tag_type)
1245 scsi_activate_tcq(sdev, sdev->queue_depth);
1246 else
1247 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1248 } else
1249 tag_type = 0;
1250
1251 return tag_type;
1252}
1253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254/**
1255 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1256 * @ha: HA context
1257 *
1258 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1259 * supported addressing method.
1260 */
1261static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001262qla2x00_config_dma_addressing(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001264 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001265 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001268 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1269 /* Any upper-dword bits set? */
1270 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1271 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1272 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001274 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1275 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001276 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001279
1280 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1281 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282}
1283
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001284static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001285qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001286{
1287 unsigned long flags = 0;
1288 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1289
1290 spin_lock_irqsave(&ha->hardware_lock, flags);
1291 ha->interrupts_on = 1;
1292 /* enable risc and host interrupts */
1293 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1294 RD_REG_WORD(&reg->ictrl);
1295 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1296
1297}
1298
1299static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001300qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001301{
1302 unsigned long flags = 0;
1303 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1304
1305 spin_lock_irqsave(&ha->hardware_lock, flags);
1306 ha->interrupts_on = 0;
1307 /* disable risc and host interrupts */
1308 WRT_REG_WORD(&reg->ictrl, 0);
1309 RD_REG_WORD(&reg->ictrl);
1310 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1311}
1312
1313static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001314qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001315{
1316 unsigned long flags = 0;
1317 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1318
1319 spin_lock_irqsave(&ha->hardware_lock, flags);
1320 ha->interrupts_on = 1;
1321 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1322 RD_REG_DWORD(&reg->ictrl);
1323 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1324}
1325
1326static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001327qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001328{
1329 unsigned long flags = 0;
1330 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1331
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001332 if (IS_NOPOLLING_TYPE(ha))
1333 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001334 spin_lock_irqsave(&ha->hardware_lock, flags);
1335 ha->interrupts_on = 0;
1336 WRT_REG_DWORD(&reg->ictrl, 0);
1337 RD_REG_DWORD(&reg->ictrl);
1338 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1339}
1340
1341static struct isp_operations qla2100_isp_ops = {
1342 .pci_config = qla2100_pci_config,
1343 .reset_chip = qla2x00_reset_chip,
1344 .chip_diag = qla2x00_chip_diag,
1345 .config_rings = qla2x00_config_rings,
1346 .reset_adapter = qla2x00_reset_adapter,
1347 .nvram_config = qla2x00_nvram_config,
1348 .update_fw_options = qla2x00_update_fw_options,
1349 .load_risc = qla2x00_load_risc,
1350 .pci_info_str = qla2x00_pci_info_str,
1351 .fw_version_str = qla2x00_fw_version_str,
1352 .intr_handler = qla2100_intr_handler,
1353 .enable_intrs = qla2x00_enable_intrs,
1354 .disable_intrs = qla2x00_disable_intrs,
1355 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001356 .target_reset = qla2x00_abort_target,
1357 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001358 .fabric_login = qla2x00_login_fabric,
1359 .fabric_logout = qla2x00_fabric_logout,
1360 .calc_req_entries = qla2x00_calc_iocbs_32,
1361 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1362 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1363 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1364 .read_nvram = qla2x00_read_nvram_data,
1365 .write_nvram = qla2x00_write_nvram_data,
1366 .fw_dump = qla2100_fw_dump,
1367 .beacon_on = NULL,
1368 .beacon_off = NULL,
1369 .beacon_blink = NULL,
1370 .read_optrom = qla2x00_read_optrom_data,
1371 .write_optrom = qla2x00_write_optrom_data,
1372 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001373 .start_scsi = qla2x00_start_scsi,
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001374 .wrt_req_reg = NULL,
1375 .wrt_rsp_reg = NULL,
1376 .rd_req_reg = NULL,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001377};
1378
1379static struct isp_operations qla2300_isp_ops = {
1380 .pci_config = qla2300_pci_config,
1381 .reset_chip = qla2x00_reset_chip,
1382 .chip_diag = qla2x00_chip_diag,
1383 .config_rings = qla2x00_config_rings,
1384 .reset_adapter = qla2x00_reset_adapter,
1385 .nvram_config = qla2x00_nvram_config,
1386 .update_fw_options = qla2x00_update_fw_options,
1387 .load_risc = qla2x00_load_risc,
1388 .pci_info_str = qla2x00_pci_info_str,
1389 .fw_version_str = qla2x00_fw_version_str,
1390 .intr_handler = qla2300_intr_handler,
1391 .enable_intrs = qla2x00_enable_intrs,
1392 .disable_intrs = qla2x00_disable_intrs,
1393 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001394 .target_reset = qla2x00_abort_target,
1395 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001396 .fabric_login = qla2x00_login_fabric,
1397 .fabric_logout = qla2x00_fabric_logout,
1398 .calc_req_entries = qla2x00_calc_iocbs_32,
1399 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1400 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1401 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1402 .read_nvram = qla2x00_read_nvram_data,
1403 .write_nvram = qla2x00_write_nvram_data,
1404 .fw_dump = qla2300_fw_dump,
1405 .beacon_on = qla2x00_beacon_on,
1406 .beacon_off = qla2x00_beacon_off,
1407 .beacon_blink = qla2x00_beacon_blink,
1408 .read_optrom = qla2x00_read_optrom_data,
1409 .write_optrom = qla2x00_write_optrom_data,
1410 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001411 .start_scsi = qla2x00_start_scsi,
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001412 .wrt_req_reg = NULL,
1413 .wrt_rsp_reg = NULL,
1414 .rd_req_reg = NULL,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001415};
1416
1417static struct isp_operations qla24xx_isp_ops = {
1418 .pci_config = qla24xx_pci_config,
1419 .reset_chip = qla24xx_reset_chip,
1420 .chip_diag = qla24xx_chip_diag,
1421 .config_rings = qla24xx_config_rings,
1422 .reset_adapter = qla24xx_reset_adapter,
1423 .nvram_config = qla24xx_nvram_config,
1424 .update_fw_options = qla24xx_update_fw_options,
1425 .load_risc = qla24xx_load_risc,
1426 .pci_info_str = qla24xx_pci_info_str,
1427 .fw_version_str = qla24xx_fw_version_str,
1428 .intr_handler = qla24xx_intr_handler,
1429 .enable_intrs = qla24xx_enable_intrs,
1430 .disable_intrs = qla24xx_disable_intrs,
1431 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001432 .target_reset = qla24xx_abort_target,
1433 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001434 .fabric_login = qla24xx_login_fabric,
1435 .fabric_logout = qla24xx_fabric_logout,
1436 .calc_req_entries = NULL,
1437 .build_iocbs = NULL,
1438 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1439 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1440 .read_nvram = qla24xx_read_nvram_data,
1441 .write_nvram = qla24xx_write_nvram_data,
1442 .fw_dump = qla24xx_fw_dump,
1443 .beacon_on = qla24xx_beacon_on,
1444 .beacon_off = qla24xx_beacon_off,
1445 .beacon_blink = qla24xx_beacon_blink,
1446 .read_optrom = qla24xx_read_optrom_data,
1447 .write_optrom = qla24xx_write_optrom_data,
1448 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001449 .start_scsi = qla24xx_start_scsi,
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001450 .wrt_req_reg = qla24xx_wrt_req_reg,
1451 .wrt_rsp_reg = qla24xx_wrt_rsp_reg,
1452 .rd_req_reg = qla24xx_rd_req_reg,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001453};
1454
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001455static struct isp_operations qla25xx_isp_ops = {
1456 .pci_config = qla25xx_pci_config,
1457 .reset_chip = qla24xx_reset_chip,
1458 .chip_diag = qla24xx_chip_diag,
1459 .config_rings = qla24xx_config_rings,
1460 .reset_adapter = qla24xx_reset_adapter,
1461 .nvram_config = qla24xx_nvram_config,
1462 .update_fw_options = qla24xx_update_fw_options,
1463 .load_risc = qla24xx_load_risc,
1464 .pci_info_str = qla24xx_pci_info_str,
1465 .fw_version_str = qla24xx_fw_version_str,
1466 .intr_handler = qla24xx_intr_handler,
1467 .enable_intrs = qla24xx_enable_intrs,
1468 .disable_intrs = qla24xx_disable_intrs,
1469 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001470 .target_reset = qla24xx_abort_target,
1471 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001472 .fabric_login = qla24xx_login_fabric,
1473 .fabric_logout = qla24xx_fabric_logout,
1474 .calc_req_entries = NULL,
1475 .build_iocbs = NULL,
1476 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1477 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1478 .read_nvram = qla25xx_read_nvram_data,
1479 .write_nvram = qla25xx_write_nvram_data,
1480 .fw_dump = qla25xx_fw_dump,
1481 .beacon_on = qla24xx_beacon_on,
1482 .beacon_off = qla24xx_beacon_off,
1483 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001484 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001485 .write_optrom = qla24xx_write_optrom_data,
1486 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001487 .start_scsi = qla24xx_start_scsi,
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001488 .wrt_req_reg = qla24xx_wrt_req_reg,
1489 .wrt_rsp_reg = qla24xx_wrt_rsp_reg,
1490 .rd_req_reg = qla24xx_rd_req_reg,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001491};
1492
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001493static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001494qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001495{
1496 ha->device_type = DT_EXTENDED_IDS;
1497 switch (ha->pdev->device) {
1498 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1499 ha->device_type |= DT_ISP2100;
1500 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001501 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001502 break;
1503 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1504 ha->device_type |= DT_ISP2200;
1505 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001506 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001507 break;
1508 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1509 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001510 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001511 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001512 break;
1513 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1514 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001515 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001516 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001517 break;
1518 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1519 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001520 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001521 if (ha->pdev->subsystem_vendor == 0x1028 &&
1522 ha->pdev->subsystem_device == 0x0170)
1523 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001524 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001525 break;
1526 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1527 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001528 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001529 break;
1530 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1531 ha->device_type |= DT_ISP6322;
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_ISP2422:
1535 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001536 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001537 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001538 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001539 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001540 break;
1541 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1542 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001543 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001544 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001545 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001546 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001547 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001548 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1549 ha->device_type |= DT_ISP8432;
1550 ha->device_type |= DT_ZIO_SUPPORTED;
1551 ha->device_type |= DT_FWI2;
1552 ha->device_type |= DT_IIDMA;
1553 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1554 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001555 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1556 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001557 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001558 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001559 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001560 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1561 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001562 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001563 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001564 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001565 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1566 ha->device_type |= DT_ISP2532;
1567 ha->device_type |= DT_ZIO_SUPPORTED;
1568 ha->device_type |= DT_FWI2;
1569 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001570 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1571 break;
1572 }
1573}
1574
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001576qla2x00_iospace_config(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577{
Andrew Vasquez37765412008-01-17 09:02:09 -08001578 resource_size_t pio;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001579 uint16_t msix;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
Andrew Vasquez285d0322007-10-19 15:59:17 -07001581 if (pci_request_selected_regions(ha->pdev, ha->bars,
1582 QLA2XXX_DRIVER_NAME)) {
1583 qla_printk(KERN_WARNING, ha,
1584 "Failed to reserve PIO/MMIO regions (%s)\n",
1585 pci_name(ha->pdev));
1586
1587 goto iospace_error_exit;
1588 }
1589 if (!(ha->bars & 1))
1590 goto skip_pio;
1591
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1593 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001594 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1595 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 qla_printk(KERN_WARNING, ha,
1597 "Invalid PCI I/O region size (%s)...\n",
1598 pci_name(ha->pdev));
1599 pio = 0;
1600 }
1601 } else {
1602 qla_printk(KERN_WARNING, ha,
1603 "region #0 not a PIO resource (%s)...\n",
1604 pci_name(ha->pdev));
1605 pio = 0;
1606 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001607 ha->pio_address = pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
Andrew Vasquez285d0322007-10-19 15:59:17 -07001609skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001611 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 qla_printk(KERN_ERR, ha,
Andrew Vasquez37765412008-01-17 09:02:09 -08001613 "region #1 not an MMIO resource (%s), aborting\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 pci_name(ha->pdev));
1615 goto iospace_error_exit;
1616 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001617 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 qla_printk(KERN_ERR, ha,
1619 "Invalid PCI mem region size (%s), aborting\n",
1620 pci_name(ha->pdev));
1621 goto iospace_error_exit;
1622 }
1623
Andrew Vasquez37765412008-01-17 09:02:09 -08001624 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 if (!ha->iobase) {
1626 qla_printk(KERN_ERR, ha,
1627 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1628
1629 goto iospace_error_exit;
1630 }
1631
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001632 /* Determine queue resources */
1633 ha->max_queues = 1;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001634 if (ql2xmaxqueues <= 1 || !IS_QLA25XX(ha))
1635 goto mqiobase_exit;
1636 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1637 pci_resource_len(ha->pdev, 3));
1638 if (ha->mqiobase) {
1639 /* Read MSIX vector size of the board */
1640 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1641 ha->msix_count = msix;
1642 /* Max queues are bounded by available msix vectors */
1643 /* queue 0 uses two msix vectors */
1644 if (ha->msix_count - 1 < ql2xmaxqueues)
1645 ha->max_queues = ha->msix_count - 1;
1646 else if (ql2xmaxqueues > QLA_MQ_SIZE)
1647 ha->max_queues = QLA_MQ_SIZE;
1648 else
1649 ha->max_queues = ql2xmaxqueues;
1650 qla_printk(KERN_INFO, ha,
1651 "MSI-X vector count: %d\n", msix);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001652 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001653
1654mqiobase_exit:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001655 ha->msix_count = ha->max_queues + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 return (0);
1657
1658iospace_error_exit:
1659 return (-ENOMEM);
1660}
1661
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001662static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001663qla2xxx_scan_start(struct Scsi_Host *shost)
1664{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001665 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001666
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001667 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1668 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1669 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1670 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001671}
1672
1673static int
1674qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1675{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001676 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001677
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001678 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001679 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001680 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001681 return 1;
1682
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001683 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001684}
1685
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686/*
1687 * PCI driver interface
1688 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001689static int __devinit
1690qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001692 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001694 scsi_qla_host_t *base_vha = NULL;
1695 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001696 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001698 struct scsi_host_template *sht;
Anirban Chakrabortyc51da4e2008-11-10 15:53:20 -08001699 int bars, max_id, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001700 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001701 struct req_que *req = NULL;
1702 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
Andrew Vasquez285d0322007-10-19 15:59:17 -07001704 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1705 sht = &qla2x00_driver_template;
1706 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1707 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001708 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001709 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1710 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1711 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532) {
1712 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1713 sht = &qla24xx_driver_template;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001714 mem_only = 1;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001715 }
1716
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001717 if (mem_only) {
1718 if (pci_enable_device_mem(pdev))
1719 goto probe_out;
1720 } else {
1721 if (pci_enable_device(pdev))
1722 goto probe_out;
1723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
Jesse Barnes09276782008-10-18 17:33:19 -07001725 /* This may fail but that's ok */
1726 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07001727
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001728 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1729 if (!ha) {
1730 DEBUG(printk("Unable to allocate memory for ha\n"));
1731 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001733 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
1735 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07001736 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001737 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001738 spin_lock_init(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001740 /* Set ISP-type information. */
1741 qla2x00_set_isp_flags(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 /* Configure PCI I/O space */
1743 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001744 if (ret)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001745 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08001748 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1749 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001752 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001753 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001754 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001756 /* Assign ISP specific operations. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001757 max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 if (IS_QLA2100(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001759 max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001761 req_length = REQUEST_ENTRY_CNT_2100;
1762 rsp_length = RESPONSE_ENTRY_CNT_2100;
1763 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001764 ha->gid_list_info_size = 4;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001765 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 } else if (IS_QLA2200(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001768 req_length = REQUEST_ENTRY_CNT_2200;
1769 rsp_length = RESPONSE_ENTRY_CNT_2100;
1770 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001771 ha->gid_list_info_size = 4;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001772 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001773 } else if (IS_QLA23XX(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001775 req_length = REQUEST_ENTRY_CNT_2200;
1776 rsp_length = RESPONSE_ENTRY_CNT_2300;
1777 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001778 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001779 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1780 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001781 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001782 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07001783 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001784 req_length = REQUEST_ENTRY_CNT_24XX;
1785 rsp_length = RESPONSE_ENTRY_CNT_2300;
1786 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001787 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001788 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001789 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001790 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001791 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001792 } else if (IS_QLA25XX(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001793 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001794 req_length = REQUEST_ENTRY_CNT_24XX;
1795 rsp_length = RESPONSE_ENTRY_CNT_2300;
1796 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001797 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001798 ha->gid_list_info_size = 8;
1799 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001800 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001801 ha->isp_ops = &qla25xx_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07001804 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001805 init_completion(&ha->mbx_cmd_comp);
1806 complete(&ha->mbx_cmd_comp);
1807 init_completion(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001809 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001811 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001812 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 qla_printk(KERN_WARNING, ha,
1814 "[ERROR] Failed to allocate memory for adapter\n");
1815
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001816 goto probe_hw_failed;
1817 }
1818
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001819 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001820 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001821 req->max_q_depth = ql2xmaxqdepth;
1822
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001823
1824 base_vha = qla2x00_create_host(sht, ha);
1825 if (!base_vha) {
1826 qla_printk(KERN_WARNING, ha,
1827 "[ERROR] Failed to allocate memory for scsi_host\n");
1828
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001829 ret = -ENOMEM;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001830 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 }
1832
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001833 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001835 qla2x00_config_dma_addressing(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001837 host = base_vha->host;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001838 base_vha->req_ques[0] = req->id;
1839 host->can_queue = req->length + 128;
1840 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001841 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001842 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001843 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1844 base_vha->vp_idx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001845 if (IS_QLA2100(ha))
1846 host->sg_tablesize = 32;
1847 host->max_id = max_id;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001848 host->this_id = 255;
1849 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07001850 host->unique_id = host->host_no;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001851 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001852 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001853 host->max_lun = MAX_LUNS;
1854 host->transportt = qla2xxx_transport_template;
1855
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001856 /* Set up the irqs */
1857 ret = qla2x00_request_irqs(ha, rsp);
1858 if (ret)
1859 goto probe_failed;
1860
1861 /* Alloc arrays of request and response ring ptrs */
1862 if (!qla2x00_alloc_queues(ha)) {
1863 qla_printk(KERN_WARNING, ha,
1864 "[ERROR] Failed to allocate memory for queue"
1865 " pointers\n");
1866 goto probe_failed;
1867 }
1868 ha->rsp_q_map[0] = rsp;
1869 ha->req_q_map[0] = req;
1870
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001871 if (ha->mqenable) {
1872 ha->isp_ops->wrt_req_reg = qla25xx_wrt_req_reg;
1873 ha->isp_ops->wrt_rsp_reg = qla25xx_wrt_rsp_reg;
1874 ha->isp_ops->rd_req_reg = qla25xx_rd_req_reg;
1875 }
1876
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001877 if (qla2x00_initialize_adapter(base_vha)) {
1878 qla_printk(KERN_WARNING, ha,
1879 "Failed to initialize adapter\n");
1880
1881 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1882 "Adapter flags %x.\n",
1883 base_vha->host_no, base_vha->device_flags));
1884
1885 ret = -ENODEV;
1886 goto probe_failed;
1887 }
1888
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001889 /*
1890 * Startup the kernel thread for this host adapter
1891 */
1892 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1893 "%s_dpc", base_vha->host_str);
1894 if (IS_ERR(ha->dpc_thread)) {
1895 qla_printk(KERN_WARNING, ha,
1896 "Unable to start DPC thread!\n");
1897 ret = PTR_ERR(ha->dpc_thread);
1898 goto probe_failed;
1899 }
1900
1901 list_add_tail(&base_vha->list, &ha->vp_list);
1902 base_vha->host->irq = ha->pdev->irq;
1903
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001905 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906
1907 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001908 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001910 base_vha->flags.init_done = 1;
1911 base_vha->flags.online = 1;
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001912
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001913 ret = scsi_add_host(host, &pdev->dev);
1914 if (ret)
1915 goto probe_failed;
1916
Andrew Vasquez048feec2008-09-11 22:19:45 -07001917 ha->isp_ops->enable_intrs(ha);
1918
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001919 scsi_scan_host(host);
1920
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001921 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001922
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001923 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001924
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001925 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001926
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 qla_printk(KERN_INFO, ha, "\n"
1928 " QLogic Fibre Channel HBA Driver: %s\n"
1929 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08001930 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1931 qla2x00_version_str, ha->model_number,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001932 ha->model_desc ? ha->model_desc : "", pdev->device,
1933 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
1934 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
1935 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 return 0;
1938
1939probe_failed:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001940 qla2x00_free_que(ha, req, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001941 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001943 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001945probe_hw_failed:
1946 if (ha->iobase)
1947 iounmap(ha->iobase);
1948
1949 pci_release_selected_regions(ha->pdev, ha->bars);
1950 kfree(ha);
1951 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001953probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001954 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001955 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957
Adrian Bunk4c993f72008-01-14 00:55:16 -08001958static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001959qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001961 scsi_qla_host_t *base_vha, *vha, *temp;
1962 struct qla_hw_data *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001964 base_vha = pci_get_drvdata(pdev);
1965 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001967 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
1968 if (vha && vha->fc_vport)
1969 fc_vport_terminate(vha->fc_vport);
1970 }
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07001971
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001972 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07001973
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001974 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001975
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001976 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001977
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001978 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001980 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05001981
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001982 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001984 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001986 scsi_host_put(base_vha->host);
1987
1988 if (ha->iobase)
1989 iounmap(ha->iobase);
1990
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001991 if (ha->mqiobase)
1992 iounmap(ha->mqiobase);
1993
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001994 pci_release_selected_regions(ha->pdev, ha->bars);
1995 kfree(ha);
1996 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997
Bernhard Walle665db932007-03-28 00:49:49 +02001998 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 pci_set_drvdata(pdev, NULL);
2000}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
2002static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002003qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002005 struct qla_hw_data *ha = vha->hw;
2006 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002007
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 /* Disable timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002009 if (vha->timer_active)
2010 qla2x00_stop_timer(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002012 vha->flags.online = 0;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002013
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 /* Kill the kernel thread for this host */
Christoph Hellwig39a11242006-02-14 18:46:22 +01002015 if (ha->dpc_thread) {
2016 struct task_struct *t = ha->dpc_thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017
Christoph Hellwig39a11242006-02-14 18:46:22 +01002018 /*
2019 * qla2xxx_wake_dpc checks for ->dpc_thread
2020 * so we need to zero it out.
2021 */
2022 ha->dpc_thread = NULL;
2023 kthread_stop(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 }
2025
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002026 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002027 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002028
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002029 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002030 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002031
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002032 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002033 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002035 /* turn-off interrupts on the card */
2036 if (ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002037 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002038
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002039 qla2x00_free_irqs(vha);
2040
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002041 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002042
2043 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044}
2045
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002046static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002047qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002048 int defer)
2049{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002050 struct fc_rport *rport;
2051
2052 if (!fcport->rport)
2053 return;
2054
2055 rport = fcport->rport;
2056 if (defer) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002057 spin_lock_irq(vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002058 fcport->drport = rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002059 spin_unlock_irq(vha->host->host_lock);
2060 set_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
2061 qla2xxx_wake_dpc(vha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002062 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002063 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002064}
2065
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2068 *
2069 * Input: ha = adapter block pointer. fcport = port structure pointer.
2070 *
2071 * Return: None.
2072 *
2073 * Context:
2074 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002075void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002076 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002078 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002079 vha->vp_idx == fcport->vp_idx) {
2080 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2081 qla2x00_schedule_rport_del(vha, fcport, defer);
2082 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002083 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 * We may need to retry the login, so don't change the state of the
2085 * port but do the retries.
2086 */
2087 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2088 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2089
2090 if (!do_login)
2091 return;
2092
2093 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002094 fcport->login_retry = vha->hw->login_retry_count;
2095 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096
2097 DEBUG(printk("scsi(%ld): Port login retry: "
2098 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2099 "id = 0x%04x retry cnt=%d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002100 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 fcport->port_name[0],
2102 fcport->port_name[1],
2103 fcport->port_name[2],
2104 fcport->port_name[3],
2105 fcport->port_name[4],
2106 fcport->port_name[5],
2107 fcport->port_name[6],
2108 fcport->port_name[7],
2109 fcport->loop_id,
2110 fcport->login_retry));
2111 }
2112}
2113
2114/*
2115 * qla2x00_mark_all_devices_lost
2116 * Updates fcport state when device goes offline.
2117 *
2118 * Input:
2119 * ha = adapter block pointer.
2120 * fcport = port structure pointer.
2121 *
2122 * Return:
2123 * None.
2124 *
2125 * Context:
2126 */
2127void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002128qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129{
2130 fc_port_t *fcport;
2131
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002132 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2133 if (vha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 /*
2136 * No point in marking the device as lost, if the device is
2137 * already DEAD.
2138 */
2139 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2140 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002141 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2142 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2143 qla2x00_schedule_rport_del(vha, fcport, defer);
2144 } else
2145 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 }
2147}
2148
2149/*
2150* qla2x00_mem_alloc
2151* Allocates adapter memory.
2152*
2153* Returns:
2154* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08002155* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002157static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002158qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2159 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160{
2161 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002163 ha->init_cb_size = sizeof(init_cb_t);
2164 if (IS_QLA2XXX_MIDTYPE(ha))
2165 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
Andrew Vasqueze8711082008-01-31 12:33:48 -08002167 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002168 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002169 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002170 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002172 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2173 &ha->gid_list_dma, GFP_KERNEL);
2174 if (!ha->gid_list)
Andrew Vasqueze8711082008-01-31 12:33:48 -08002175 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
Andrew Vasqueze8711082008-01-31 12:33:48 -08002177 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2178 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002179 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180
Andrew Vasqueze8711082008-01-31 12:33:48 -08002181 /* Get memory for cached NVRAM */
2182 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2183 if (!ha->nvram)
2184 goto fail_free_srb_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002186 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2187 ha->pdev->device);
2188 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2189 DMA_POOL_SIZE, 8, 0);
2190 if (!ha->s_dma_pool)
2191 goto fail_free_nvram;
2192
Andrew Vasqueze8711082008-01-31 12:33:48 -08002193 /* Allocate memory for SNS commands */
2194 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002195 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002196 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002197 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002198 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002199 goto fail_dma_pool;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002200 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002201 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002202 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002203 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002204 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002205 goto fail_dma_pool;
2206 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002207 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002208 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002209 if (!ha->ct_sns)
2210 goto fail_free_ms_iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 }
2212
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002213 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002214 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2215 if (!*req) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002216 DEBUG(printk("Unable to allocate memory for req\n"));
2217 goto fail_req;
2218 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002219 (*req)->length = req_len;
2220 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2221 ((*req)->length + 1) * sizeof(request_t),
2222 &(*req)->dma, GFP_KERNEL);
2223 if (!(*req)->ring) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002224 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2225 goto fail_req_ring;
2226 }
2227 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002228 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2229 if (!*rsp) {
2230 qla_printk(KERN_WARNING, ha,
2231 "Unable to allocate memory for rsp\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002232 goto fail_rsp;
2233 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002234 (*rsp)->hw = ha;
2235 (*rsp)->length = rsp_len;
2236 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2237 ((*rsp)->length + 1) * sizeof(response_t),
2238 &(*rsp)->dma, GFP_KERNEL);
2239 if (!(*rsp)->ring) {
2240 qla_printk(KERN_WARNING, ha,
2241 "Unable to allocate memory for rsp_ring\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002242 goto fail_rsp_ring;
2243 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002244 (*req)->rsp = *rsp;
2245 (*rsp)->req = *req;
2246 /* Allocate memory for NVRAM data for vports */
2247 if (ha->nvram_npiv_size) {
2248 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2249 ha->nvram_npiv_size, GFP_KERNEL);
2250 if (!ha->npiv_info) {
2251 qla_printk(KERN_WARNING, ha,
2252 "Unable to allocate memory for npiv info\n");
2253 goto fail_npiv_info;
2254 }
2255 } else
2256 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002257
2258 INIT_LIST_HEAD(&ha->vp_list);
2259 return 1;
2260
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002261fail_npiv_info:
2262 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2263 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2264 (*rsp)->ring = NULL;
2265 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002266fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002267 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002268fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002269 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2270 sizeof(request_t), (*req)->ring, (*req)->dma);
2271 (*req)->ring = NULL;
2272 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002273fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002274 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002275fail_req:
2276 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2277 ha->ct_sns, ha->ct_sns_dma);
2278 ha->ct_sns = NULL;
2279 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002280fail_free_ms_iocb:
2281 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2282 ha->ms_iocb = NULL;
2283 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002284fail_dma_pool:
2285 dma_pool_destroy(ha->s_dma_pool);
2286 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002287fail_free_nvram:
2288 kfree(ha->nvram);
2289 ha->nvram = NULL;
2290fail_free_srb_mempool:
2291 mempool_destroy(ha->srb_mempool);
2292 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002293fail_free_gid_list:
2294 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002295 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002296 ha->gid_list = NULL;
2297 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002298fail_free_init_cb:
2299 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2300 ha->init_cb_dma);
2301 ha->init_cb = NULL;
2302 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002303fail:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002304 DEBUG(printk("%s: Memory allocation failure\n", __func__));
Andrew Vasqueze8711082008-01-31 12:33:48 -08002305 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306}
2307
2308/*
2309* qla2x00_mem_free
2310* Frees all adapter allocated memory.
2311*
2312* Input:
2313* ha = adapter block pointer.
2314*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08002315static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002316qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317{
Andrew Vasqueze8711082008-01-31 12:33:48 -08002318 if (ha->srb_mempool)
2319 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002321 if (ha->fce)
2322 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002323 ha->fce_dma);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002324
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002325 if (ha->fw_dump) {
2326 if (ha->eft)
2327 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002328 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002329 vfree(ha->fw_dump);
2330 }
2331
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 if (ha->sns_cmd)
2333 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002334 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
2336 if (ha->ct_sns)
2337 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002338 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339
Andrew Vasquez88729e52006-06-23 16:10:50 -07002340 if (ha->sfp_data)
2341 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2342
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 if (ha->ms_iocb)
2344 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2345
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 if (ha->s_dma_pool)
2347 dma_pool_destroy(ha->s_dma_pool);
2348
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002349
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 if (ha->gid_list)
2351 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002352 ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002355 if (ha->init_cb)
2356 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2357 ha->init_cb, ha->init_cb_dma);
2358 vfree(ha->optrom_buffer);
2359 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002360 kfree(ha->npiv_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
Andrew Vasqueze8711082008-01-31 12:33:48 -08002362 ha->srb_mempool = NULL;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002363 ha->eft = NULL;
2364 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 ha->sns_cmd = NULL;
2366 ha->sns_cmd_dma = 0;
2367 ha->ct_sns = NULL;
2368 ha->ct_sns_dma = 0;
2369 ha->ms_iocb = NULL;
2370 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 ha->init_cb = NULL;
2372 ha->init_cb_dma = 0;
2373
2374 ha->s_dma_pool = NULL;
2375
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 ha->gid_list = NULL;
2377 ha->gid_list_dma = 0;
2378
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002380 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 ha->fw_dump_reading = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002382}
2383
2384struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2385 struct qla_hw_data *ha)
2386{
2387 struct Scsi_Host *host;
2388 struct scsi_qla_host *vha = NULL;
2389
2390 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2391 if (host == NULL) {
2392 printk(KERN_WARNING
2393 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2394 goto fail;
2395 }
2396
2397 /* Clear our data area */
2398 vha = shost_priv(host);
2399 memset(vha, 0, sizeof(scsi_qla_host_t));
2400
2401 vha->host = host;
2402 vha->host_no = host->host_no;
2403 vha->hw = ha;
2404
2405 INIT_LIST_HEAD(&vha->vp_fcports);
2406 INIT_LIST_HEAD(&vha->work_list);
2407 INIT_LIST_HEAD(&vha->list);
2408
2409 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2410 return vha;
2411
2412fail:
2413 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414}
2415
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002416static struct qla_work_evt *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002417qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002418 int locked)
2419{
2420 struct qla_work_evt *e;
2421
2422 e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
2423 GFP_KERNEL);
2424 if (!e)
2425 return NULL;
2426
2427 INIT_LIST_HEAD(&e->list);
2428 e->type = type;
2429 e->flags = QLA_EVT_FLAG_FREE;
2430 return e;
2431}
2432
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002433static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002434qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e, int locked)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002435{
Andrew Mortonbf6583b2008-07-24 08:31:48 -07002436 unsigned long uninitialized_var(flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002437 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002438
2439 if (!locked)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002440 spin_lock_irqsave(&ha->hardware_lock, flags);
2441 list_add_tail(&e->list, &vha->work_list);
2442 qla2xxx_wake_dpc(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002443 if (!locked)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002444 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002445 return QLA_SUCCESS;
2446}
2447
2448int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002449qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002450 u32 data)
2451{
2452 struct qla_work_evt *e;
2453
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002454 e = qla2x00_alloc_work(vha, QLA_EVT_AEN, 1);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002455 if (!e)
2456 return QLA_FUNCTION_FAILED;
2457
2458 e->u.aen.code = code;
2459 e->u.aen.data = data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002460 return qla2x00_post_work(vha, e, 1);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002461}
2462
2463static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002464qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002465{
2466 struct qla_work_evt *e;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002467 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002468
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002469 spin_lock_irq(&ha->hardware_lock);
2470 while (!list_empty(&vha->work_list)) {
2471 e = list_entry(vha->work_list.next, struct qla_work_evt, list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002472 list_del_init(&e->list);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002474
2475 switch (e->type) {
2476 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002477 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07002478 e->u.aen.code, e->u.aen.data);
2479 break;
2480 }
2481 if (e->flags & QLA_EVT_FLAG_FREE)
2482 kfree(e);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002483 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002484 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002485 spin_unlock_irq(&ha->hardware_lock);
2486}
2487/* Relogins all the fcports of a vport
2488 * Context: dpc thread
2489 */
2490void qla2x00_relogin(struct scsi_qla_host *vha)
2491{
2492 fc_port_t *fcport;
2493 uint8_t status;
2494 uint16_t next_loopid = 0;
2495 struct qla_hw_data *ha = vha->hw;
2496
2497 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2498 /*
2499 * If the port is not ONLINE then try to login
2500 * to it if we haven't run out of retries.
2501 */
2502 if (atomic_read(&fcport->state) !=
2503 FCS_ONLINE && fcport->login_retry) {
2504
2505 if (fcport->flags & FCF_FABRIC_DEVICE) {
2506 if (fcport->flags & FCF_TAPE_PRESENT)
2507 ha->isp_ops->fabric_logout(vha,
2508 fcport->loop_id,
2509 fcport->d_id.b.domain,
2510 fcport->d_id.b.area,
2511 fcport->d_id.b.al_pa);
2512
2513 status = qla2x00_fabric_login(vha, fcport,
2514 &next_loopid);
2515 } else
2516 status = qla2x00_local_device_login(vha,
2517 fcport);
2518
2519 fcport->login_retry--;
2520 if (status == QLA_SUCCESS) {
2521 fcport->old_loop_id = fcport->loop_id;
2522
2523 DEBUG(printk("scsi(%ld): port login OK: logged "
2524 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2525
2526 qla2x00_update_fcport(vha, fcport);
2527
2528 } else if (status == 1) {
2529 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2530 /* retry the login again */
2531 DEBUG(printk("scsi(%ld): Retrying"
2532 " %d login again loop_id 0x%x\n",
2533 vha->host_no, fcport->login_retry,
2534 fcport->loop_id));
2535 } else {
2536 fcport->login_retry = 0;
2537 }
2538
2539 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2540 fcport->loop_id = FC_NO_LOOP_ID;
2541 }
2542 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2543 break;
2544 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07002545}
2546
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547/**************************************************************************
2548* qla2x00_do_dpc
2549* This kernel thread is a task that is schedule by the interrupt handler
2550* to perform the background processing for interrupts.
2551*
2552* Notes:
2553* This task always run in the context of a kernel thread. It
2554* is kick-off by the driver's detect code and starts up
2555* up one per adapter. It immediately goes to sleep and waits for
2556* some fibre event. When either the interrupt handler or
2557* the timer routine detects a event it will one of the task
2558* bits then wake us up.
2559**************************************************************************/
2560static int
2561qla2x00_do_dpc(void *data)
2562{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002563 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002564 scsi_qla_host_t *base_vha;
2565 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08002566
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002567 ha = (struct qla_hw_data *)data;
2568 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 set_user_nice(current, -20);
2571
Christoph Hellwig39a11242006-02-14 18:46:22 +01002572 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2574
Christoph Hellwig39a11242006-02-14 18:46:22 +01002575 set_current_state(TASK_INTERRUPTIBLE);
2576 schedule();
2577 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578
2579 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2580
2581 /* Initialization not yet finished. Don't do anything yet. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002582 if (!base_vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 continue;
2584
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002585 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586
2587 ha->dpc_active = 1;
2588
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 ha->dpc_active = 0;
2591 continue;
2592 }
2593
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002594 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002595
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002596 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2597 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598
2599 DEBUG(printk("scsi(%ld): dpc: sched "
2600 "qla2x00_abort_isp ha = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002601 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002603 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002605 if (qla2x00_abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 /* failed. retry later */
2607 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002608 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002610 clear_bit(ABORT_ISP_ACTIVE,
2611 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08002612 }
2613
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002615 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 }
2617
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002618 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2619 qla2x00_update_fcports(base_vha);
2620 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07002621 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002622
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002623 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2624 &base_vha->dpc_flags) &&
2625 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
2627 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002628 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002630 qla2x00_rst_aen(base_vha);
2631 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 }
2633
2634 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002635 if ((test_and_clear_bit(RELOGIN_NEEDED,
2636 &base_vha->dpc_flags)) &&
2637 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2638 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639
2640 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002641 base_vha->host_no));
2642 qla2x00_relogin(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002645 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 }
2647
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002648 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2649 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650
2651 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002652 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653
2654 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002655 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002657 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002659 clear_bit(LOOP_RESYNC_ACTIVE,
2660 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 }
2662
2663 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002664 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 }
2666
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002667 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2668 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2669 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2670 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07002671 }
2672
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002674 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002676 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2677 &base_vha->dpc_flags))
2678 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002679
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002680 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002681
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 ha->dpc_active = 0;
2683 } /* End of while(1) */
2684
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002685 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686
2687 /*
2688 * Make sure that nobody tries to wake us up again.
2689 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 ha->dpc_active = 0;
2691
Christoph Hellwig39a11242006-02-14 18:46:22 +01002692 return 0;
2693}
2694
2695void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002696qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01002697{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002698 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002699 struct task_struct *t = ha->dpc_thread;
2700
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002701 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002702 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703}
2704
2705/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706* qla2x00_rst_aen
2707* Processes asynchronous reset.
2708*
2709* Input:
2710* ha = adapter block pointer.
2711*/
2712static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002713qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002715 if (vha->flags.online && !vha->flags.reset_active &&
2716 !atomic_read(&vha->loop_down_timer) &&
2717 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002719 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720
2721 /*
2722 * Issue marker command only when we are going to start
2723 * the I/O.
2724 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002725 vha->marker_needed = 1;
2726 } while (!atomic_read(&vha->loop_down_timer) &&
2727 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 }
2729}
2730
f4f051e2005-04-17 15:02:26 -05002731static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002732qla2x00_sp_free_dma(srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002733{
2734 struct scsi_cmnd *cmd = sp->cmd;
2735
2736 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002737 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05002738 sp->flags &= ~SRB_DMA_VALID;
2739 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002740 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002741}
2742
2743void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002744qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002745{
2746 struct scsi_cmnd *cmd = sp->cmd;
2747
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002748 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -05002749
f4f051e2005-04-17 15:02:26 -05002750 mempool_free(sp, ha->srb_mempool);
2751
2752 cmd->scsi_done(cmd);
2753}
bdf79622005-04-17 15:06:53 -05002754
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755/**************************************************************************
2756* qla2x00_timer
2757*
2758* Description:
2759* One second timer
2760*
2761* Context: Interrupt
2762***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002763void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002764qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 unsigned long cpu_flags = 0;
2767 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 int start_dpc = 0;
2769 int index;
2770 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002771 int t;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002772 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002773 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 /*
2775 * Ports - Port down timer.
2776 *
2777 * Whenever, a port is in the LOST state we start decrementing its port
2778 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002779 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 */
2781 t = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002782 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 if (fcport->port_type != FCT_TARGET)
2784 continue;
2785
2786 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2787
2788 if (atomic_read(&fcport->port_down_timer) == 0)
2789 continue;
2790
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002791 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002793
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002795 "%d remaining\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002796 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 t, atomic_read(&fcport->port_down_timer)));
2798 }
2799 t++;
2800 } /* End of for fcport */
2801
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802
2803 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002804 if (atomic_read(&vha->loop_down_timer) > 0 &&
2805 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
2806 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002808 if (atomic_read(&vha->loop_down_timer) ==
2809 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810
2811 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2812 "queues before time expire\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002813 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002815 if (!IS_QLA2100(ha) && vha->link_down_timeout)
2816 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817
2818 /* Schedule an ISP abort to return any tape commands. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002819 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002820 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002821 spin_lock_irqsave(&ha->hardware_lock,
2822 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002823 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002824 for (index = 1;
2825 index < MAX_OUTSTANDING_COMMANDS;
2826 index++) {
2827 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05002828
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002829 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002830 if (!sp)
2831 continue;
2832 sfcp = sp->fcport;
2833 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2834 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002836 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002837 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002838 break;
2839 }
2840 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002841 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002843 set_bit(ABORT_QUEUES_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 start_dpc++;
2845 }
2846
2847 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002848 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2850 "restarting queues.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002851 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002853 set_bit(RESTART_QUEUES_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 start_dpc++;
2855
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002856 if (!(vha->device_flags & DFLG_NO_CABLE) &&
2857 !vha->vp_idx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 DEBUG(printk("scsi(%ld): Loop down - "
2859 "aborting ISP.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002860 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 qla_printk(KERN_WARNING, ha,
2862 "Loop down - aborting ISP.\n");
2863
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002864 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 }
2866 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002867 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002868 vha->host_no,
2869 atomic_read(&vha->loop_down_timer)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 }
2871
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002872 /* Check if beacon LED needs to be blinked */
2873 if (ha->beacon_blink_led == 1) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002874 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002875 start_dpc++;
2876 }
2877
Andrew Vasquez550bf572008-04-24 15:21:23 -07002878 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002879 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07002880 start_dpc++;
2881
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002883 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
2884 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
2885 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002887 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
2888 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
2889 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
2890 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
2891 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002893 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894}
2895
Andrew Vasquez54333832005-11-09 15:49:04 -08002896/* Firmware interface routines. */
2897
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002898#define FW_BLOBS 6
Andrew Vasquez54333832005-11-09 15:49:04 -08002899#define FW_ISP21XX 0
2900#define FW_ISP22XX 1
2901#define FW_ISP2300 2
2902#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002903#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002904#define FW_ISP25XX 5
Andrew Vasquez54333832005-11-09 15:49:04 -08002905
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002906#define FW_FILE_ISP21XX "ql2100_fw.bin"
2907#define FW_FILE_ISP22XX "ql2200_fw.bin"
2908#define FW_FILE_ISP2300 "ql2300_fw.bin"
2909#define FW_FILE_ISP2322 "ql2322_fw.bin"
2910#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002911#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002912
Daniel Walkere1e82b62008-05-12 22:21:10 -07002913static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002914
2915static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002916 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
2917 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
2918 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
2919 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
2920 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002921 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08002922};
2923
2924struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002925qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08002926{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08002928 struct fw_blob *blob;
2929
2930 blob = NULL;
2931 if (IS_QLA2100(ha)) {
2932 blob = &qla_fw_blobs[FW_ISP21XX];
2933 } else if (IS_QLA2200(ha)) {
2934 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002935 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002936 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002937 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002938 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002939 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002940 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002941 } else if (IS_QLA25XX(ha)) {
2942 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08002943 }
2944
Daniel Walkere1e82b62008-05-12 22:21:10 -07002945 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002946 if (blob->fw)
2947 goto out;
2948
2949 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
2950 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002951 "(%s).\n", vha->host_no, blob->name));
Andrew Vasquez54333832005-11-09 15:49:04 -08002952 blob->fw = NULL;
2953 blob = NULL;
2954 goto out;
2955 }
2956
2957out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07002958 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002959 return blob;
2960}
2961
2962static void
2963qla2x00_release_firmware(void)
2964{
2965 int idx;
2966
Daniel Walkere1e82b62008-05-12 22:21:10 -07002967 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002968 for (idx = 0; idx < FW_BLOBS; idx++)
2969 if (qla_fw_blobs[idx].fw)
2970 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07002971 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002972}
2973
Seokmann Ju14e660e2007-09-20 14:07:36 -07002974static pci_ers_result_t
2975qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
2976{
2977 switch (state) {
2978 case pci_channel_io_normal:
2979 return PCI_ERS_RESULT_CAN_RECOVER;
2980 case pci_channel_io_frozen:
2981 pci_disable_device(pdev);
2982 return PCI_ERS_RESULT_NEED_RESET;
2983 case pci_channel_io_perm_failure:
2984 qla2x00_remove_one(pdev);
2985 return PCI_ERS_RESULT_DISCONNECT;
2986 }
2987 return PCI_ERS_RESULT_NEED_RESET;
2988}
2989
2990static pci_ers_result_t
2991qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
2992{
2993 int risc_paused = 0;
2994 uint32_t stat;
2995 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002996 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
2997 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07002998 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2999 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
3000
3001 spin_lock_irqsave(&ha->hardware_lock, flags);
3002 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3003 stat = RD_REG_DWORD(&reg->hccr);
3004 if (stat & HCCR_RISC_PAUSE)
3005 risc_paused = 1;
3006 } else if (IS_QLA23XX(ha)) {
3007 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
3008 if (stat & HSR_RISC_PAUSED)
3009 risc_paused = 1;
3010 } else if (IS_FWI2_CAPABLE(ha)) {
3011 stat = RD_REG_DWORD(&reg24->host_status);
3012 if (stat & HSRX_RISC_PAUSED)
3013 risc_paused = 1;
3014 }
3015 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3016
3017 if (risc_paused) {
3018 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3019 "Dumping firmware!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003020 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003021
3022 return PCI_ERS_RESULT_NEED_RESET;
3023 } else
3024 return PCI_ERS_RESULT_RECOVERED;
3025}
3026
3027static pci_ers_result_t
3028qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3029{
3030 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003031 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3032 struct qla_hw_data *ha = base_vha->hw;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003033 int rc;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003034
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003035 if (ha->mem_only)
3036 rc = pci_enable_device_mem(pdev);
3037 else
3038 rc = pci_enable_device(pdev);
3039
3040 if (rc) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07003041 qla_printk(KERN_WARNING, ha,
3042 "Can't re-enable PCI device after reset.\n");
3043
3044 return ret;
3045 }
3046 pci_set_master(pdev);
3047
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003048 if (ha->isp_ops->pci_config(base_vha))
Seokmann Ju14e660e2007-09-20 14:07:36 -07003049 return ret;
3050
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003051 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3052 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07003053 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003054 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003055
3056 return ret;
3057}
3058
3059static void
3060qla2xxx_pci_resume(struct pci_dev *pdev)
3061{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003062 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3063 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003064 int ret;
3065
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003066 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003067 if (ret != QLA_SUCCESS) {
3068 qla_printk(KERN_ERR, ha,
3069 "the device failed to resume I/O "
3070 "from slot/link_reset");
3071 }
3072 pci_cleanup_aer_uncorrect_error_status(pdev);
3073}
3074
3075static struct pci_error_handlers qla2xxx_err_handler = {
3076 .error_detected = qla2xxx_pci_error_detected,
3077 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3078 .slot_reset = qla2xxx_pci_slot_reset,
3079 .resume = qla2xxx_pci_resume,
3080};
3081
Andrew Vasquez54333832005-11-09 15:49:04 -08003082static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003083 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3084 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3085 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3086 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3087 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3088 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3089 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3090 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3091 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003092 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003093 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3094 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003095 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez54333832005-11-09 15:49:04 -08003096 { 0 },
3097};
3098MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3099
Andrew Vasquezfca29702005-07-06 10:31:47 -07003100static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07003101 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06003102 .driver = {
3103 .owner = THIS_MODULE,
3104 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07003105 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003106 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08003107 .remove = qla2x00_remove_one,
Seokmann Ju14e660e2007-09-20 14:07:36 -07003108 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07003109};
3110
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111/**
3112 * qla2x00_module_init - Module initialization.
3113 **/
3114static int __init
3115qla2x00_module_init(void)
3116{
Andrew Vasquezfca29702005-07-06 10:31:47 -07003117 int ret = 0;
3118
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003120 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09003121 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 if (srb_cachep == NULL) {
3123 printk(KERN_ERR
3124 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3125 return -ENOMEM;
3126 }
3127
3128 /* Derive version string. */
3129 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07003130 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07003131 strcat(qla2x00_version_str, "-debug");
3132
Andrew Vasquez1c97a122005-04-21 16:13:36 -04003133 qla2xxx_transport_template =
3134 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003135 if (!qla2xxx_transport_template) {
3136 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003138 }
3139 qla2xxx_transport_vport_template =
3140 fc_attach_transport(&qla2xxx_transport_vport_functions);
3141 if (!qla2xxx_transport_vport_template) {
3142 kmem_cache_destroy(srb_cachep);
3143 fc_release_transport(qla2xxx_transport_template);
3144 return -ENODEV;
3145 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07003147 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3148 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003149 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003150 if (ret) {
3151 kmem_cache_destroy(srb_cachep);
3152 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003153 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003154 }
3155 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156}
3157
3158/**
3159 * qla2x00_module_exit - Module cleanup.
3160 **/
3161static void __exit
3162qla2x00_module_exit(void)
3163{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003164 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08003165 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003166 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003168 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169}
3170
3171module_init(qla2x00_module_init);
3172module_exit(qla2x00_module_exit);
3173
3174MODULE_AUTHOR("QLogic Corporation");
3175MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3176MODULE_LICENSE("GPL");
3177MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003178MODULE_FIRMWARE(FW_FILE_ISP21XX);
3179MODULE_FIRMWARE(FW_FILE_ISP22XX);
3180MODULE_FIRMWARE(FW_FILE_ISP2300);
3181MODULE_FIRMWARE(FW_FILE_ISP2322);
3182MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08003183MODULE_FIRMWARE(FW_FILE_ISP25XX);