blob: 9142025db3d8ce8bb7dc274f7987bfea97ee2df3 [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;
444 sp->flags = 0;
445 CMD_SP(cmd) = (void *)sp;
446 cmd->scsi_done = done;
447
448 return sp;
449}
450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451static int
f4f051e2005-04-17 15:02:26 -0500452qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800454 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500455 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400456 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800457 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500458 srb_t *sp;
459 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Seokmann Ju14e660e2007-09-20 14:07:36 -0700461 if (unlikely(pci_channel_offline(ha->pdev))) {
462 cmd->result = DID_REQUEUE << 16;
463 goto qc_fail_command;
464 }
465
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400466 rval = fc_remote_port_chkready(rport);
467 if (rval) {
468 cmd->result = rval;
f4f051e2005-04-17 15:02:26 -0500469 goto qc_fail_command;
470 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800472 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500473 if (fcport->drport)
474 goto qc_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800475
f4f051e2005-04-17 15:02:26 -0500476 if (atomic_read(&fcport->state) != FCS_ONLINE) {
477 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800478 atomic_read(&vha->loop_state) == LOOP_DEAD) {
f4f051e2005-04-17 15:02:26 -0500479 cmd->result = DID_NO_CONNECT << 16;
480 goto qc_fail_command;
481 }
Mike Christie7b594132008-08-17 15:24:40 -0500482 goto qc_target_busy;
f4f051e2005-04-17 15:02:26 -0500483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800485 spin_unlock_irq(vha->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800487 sp = qla2x00_get_new_sp(vha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700488 if (!sp)
f4f051e2005-04-17 15:02:26 -0500489 goto qc_host_busy_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800491 rval = ha->isp_ops->start_scsi(sp);
f4f051e2005-04-17 15:02:26 -0500492 if (rval != QLA_SUCCESS)
493 goto qc_host_busy_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800495 spin_lock_irq(vha->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
f4f051e2005-04-17 15:02:26 -0500497 return 0;
498
499qc_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800500 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -0500501 mempool_free(sp, ha->srb_mempool);
502
503qc_host_busy_lock:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800504 spin_lock_irq(vha->host->host_lock);
f4f051e2005-04-17 15:02:26 -0500505 return SCSI_MLQUEUE_HOST_BUSY;
506
Mike Christie7b594132008-08-17 15:24:40 -0500507qc_target_busy:
508 return SCSI_MLQUEUE_TARGET_BUSY;
509
f4f051e2005-04-17 15:02:26 -0500510qc_fail_command:
511 done(cmd);
512
513 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514}
515
Andrew Vasquezfca29702005-07-06 10:31:47 -0700516
517static int
518qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
519{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800520 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700521 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400522 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800523 struct qla_hw_data *ha = vha->hw;
524 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700525 srb_t *sp;
526 int rval;
527
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800528 if (unlikely(pci_channel_offline(ha->pdev))) {
Seokmann Ju14e660e2007-09-20 14:07:36 -0700529 cmd->result = DID_REQUEUE << 16;
530 goto qc24_fail_command;
531 }
532
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400533 rval = fc_remote_port_chkready(rport);
534 if (rval) {
535 cmd->result = rval;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700536 goto qc24_fail_command;
537 }
538
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800539 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500540 if (fcport->drport)
541 goto qc24_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800542
Andrew Vasquezfca29702005-07-06 10:31:47 -0700543 if (atomic_read(&fcport->state) != FCS_ONLINE) {
544 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800545 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700546 cmd->result = DID_NO_CONNECT << 16;
547 goto qc24_fail_command;
548 }
Mike Christie7b594132008-08-17 15:24:40 -0500549 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700550 }
551
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800552 spin_unlock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700553
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800554 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700555 if (!sp)
556 goto qc24_host_busy_lock;
557
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800558 rval = ha->isp_ops->start_scsi(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700559 if (rval != QLA_SUCCESS)
560 goto qc24_host_busy_free_sp;
561
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800562 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700563
564 return 0;
565
566qc24_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800567 qla2x00_sp_free_dma(sp);
568 mempool_free(sp, ha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700569
570qc24_host_busy_lock:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800571 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700572 return SCSI_MLQUEUE_HOST_BUSY;
573
Mike Christie7b594132008-08-17 15:24:40 -0500574qc24_target_busy:
575 return SCSI_MLQUEUE_TARGET_BUSY;
576
Andrew Vasquezfca29702005-07-06 10:31:47 -0700577qc24_fail_command:
578 done(cmd);
579
580 return 0;
581}
582
583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584/*
585 * qla2x00_eh_wait_on_command
586 * Waits for the command to be returned by the Firmware for some
587 * max time.
588 *
589 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 *
592 * Return:
593 * Not Found : 0
594 * Found : 1
595 */
596static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800597qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700599#define ABORT_POLLING_PERIOD 1000
600#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500601 unsigned long wait_iter = ABORT_WAIT_ITER;
602 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
f4f051e2005-04-17 15:02:26 -0500604 while (CMD_SP(cmd)) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700605 msleep(ABORT_POLLING_PERIOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
f4f051e2005-04-17 15:02:26 -0500607 if (--wait_iter)
608 break;
609 }
610 if (CMD_SP(cmd))
611 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
f4f051e2005-04-17 15:02:26 -0500613 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614}
615
616/*
617 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700618 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 * <= MAX_RETRIES_OF_ISP_ABORT or
620 * finally HBA is disabled ie marked offline
621 *
622 * Input:
623 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700624 *
625 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 * Does context switching-Release SPIN_LOCK
627 * (if any) before calling this routine.
628 *
629 * Return:
630 * Success (Adapter is online) : 0
631 * Failed (Adapter is offline/disabled) : 1
632 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800633int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800634qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700636 int return_status;
637 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800638 struct qla_hw_data *ha = vha->hw;
639 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700641 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800642 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
643 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
644 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
645 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
647 msleep(1000);
648 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800649 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700650 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 else
652 return_status = QLA_FUNCTION_FAILED;
653
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 return (return_status);
655}
656
657/*
658 * qla2x00_wait_for_loop_ready
659 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700660 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 * Input:
662 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700663 *
664 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 * Does context switching-Release SPIN_LOCK
666 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700667 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 *
669 * Return:
670 * Success (LOOP_READY) : 0
671 * Failed (LOOP_NOT_READY) : 1
672 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700673static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800674qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675{
676 int return_status = QLA_SUCCESS;
677 unsigned long loop_timeout ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800678 struct qla_hw_data *ha = vha->hw;
679 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
681 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700682 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800684 while ((!atomic_read(&base_vha->loop_down_timer) &&
685 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
686 atomic_read(&base_vha->loop_state) != LOOP_READY) {
687 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Ravi Anand57680082006-05-17 15:08:44 -0700688 return_status = QLA_FUNCTION_FAILED;
689 break;
690 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 msleep(1000);
692 if (time_after_eq(jiffies, loop_timeout)) {
693 return_status = QLA_FUNCTION_FAILED;
694 break;
695 }
696 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700697 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698}
699
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700700void
701qla2x00_abort_fcport_cmds(fc_port_t *fcport)
702{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800703 int cnt, que, id;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700704 unsigned long flags;
705 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800706 scsi_qla_host_t *vha = fcport->vha;
707 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800708 struct req_que *req;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700709
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800710 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800711 for (que = 0; que < QLA_MAX_HOST_QUES; que++) {
712 id = vha->req_ques[que];
713 req = ha->req_q_map[id];
714 if (!req)
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700715 continue;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800716 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
717 sp = req->outstanding_cmds[cnt];
718 if (!sp)
719 continue;
720 if (sp->fcport != fcport)
721 continue;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700722
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800723 spin_unlock_irqrestore(&ha->hardware_lock, flags);
724 if (ha->isp_ops->abort_command(vha, sp, req)) {
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700725 DEBUG2(qla_printk(KERN_WARNING, ha,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800726 "Abort failed -- %lx\n",
727 sp->cmd->serial_number));
728 } else {
729 if (qla2x00_eh_wait_on_command(sp->cmd) !=
730 QLA_SUCCESS)
731 DEBUG2(qla_printk(KERN_WARNING, ha,
732 "Abort failed while waiting -- %lx\n",
733 sp->cmd->serial_number));
734 }
735 spin_lock_irqsave(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700736 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700737 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800738 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700739}
740
Andrew Vasquez07db5182006-10-02 12:00:49 -0700741static void
742qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
743{
744 struct Scsi_Host *shost = cmnd->device->host;
745 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
746 unsigned long flags;
747
748 spin_lock_irqsave(shost->host_lock, flags);
749 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
750 spin_unlock_irqrestore(shost->host_lock, flags);
751 msleep(1000);
752 spin_lock_irqsave(shost->host_lock, flags);
753 }
754 spin_unlock_irqrestore(shost->host_lock, flags);
755 return;
756}
757
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758/**************************************************************************
759* qla2xxx_eh_abort
760*
761* Description:
762* The abort function will abort the specified command.
763*
764* Input:
765* cmd = Linux SCSI command packet to be aborted.
766*
767* Returns:
768* Either SUCCESS or FAILED.
769*
770* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700771* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800773static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774qla2xxx_eh_abort(struct scsi_cmnd *cmd)
775{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800776 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500777 srb_t *sp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800778 int ret, i, que;
f4f051e2005-04-17 15:02:26 -0500779 unsigned int id, lun;
780 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700781 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700782 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800783 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800784 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Andrew Vasquez07db5182006-10-02 12:00:49 -0700786 qla2x00_block_error_handler(cmd);
787
f4f051e2005-04-17 15:02:26 -0500788 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700789 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
Michael Reed2ea00202006-04-27 16:25:30 -0700791 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
f4f051e2005-04-17 15:02:26 -0500793 id = cmd->device->id;
794 lun = cmd->device->lun;
795 serial = cmd->serial_number;
796
797 /* Check active list for command command. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800798 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800799 for (que = 0; que < QLA_MAX_HOST_QUES; que++) {
800 req = ha->req_q_map[vha->req_ques[que]];
801 if (!req)
f4f051e2005-04-17 15:02:26 -0500802 continue;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800803 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
804 sp = req->outstanding_cmds[i];
f4f051e2005-04-17 15:02:26 -0500805
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800806 if (sp == NULL)
807 continue;
f4f051e2005-04-17 15:02:26 -0500808
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800809 if (sp->cmd != cmd)
810 continue;
f4f051e2005-04-17 15:02:26 -0500811
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800812 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
813 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
814
815 spin_unlock_irqrestore(&ha->hardware_lock, flags);
816 if (ha->isp_ops->abort_command(vha, sp, req)) {
817 DEBUG2(printk("%s(%ld): abort_command "
818 "mbx failed.\n", __func__, vha->host_no));
819 } else {
820 DEBUG3(printk("%s(%ld): abort_command "
821 "mbx success.\n", __func__, vha->host_no));
822 wait = 1;
823 }
824 spin_lock_irqsave(&ha->hardware_lock, flags);
825 break;
f4f051e2005-04-17 15:02:26 -0500826 }
f4f051e2005-04-17 15:02:26 -0500827 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800828 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500829
830 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700831 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800832 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700833 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500834 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800835 "%x.\n", vha->host_no, id, lun, serial, ret);
Michael Reed2ea00202006-04-27 16:25:30 -0700836 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500837 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700840 qla_printk(KERN_INFO, ha,
Michael Reed2ea00202006-04-27 16:25:30 -0700841 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800842 vha->host_no, id, lun, wait, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
f4f051e2005-04-17 15:02:26 -0500844 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845}
846
Andrew Vasquez523ec772008-04-03 13:13:24 -0700847enum nexus_wait_type {
848 WAIT_HOST = 0,
849 WAIT_TARGET,
850 WAIT_LUN,
851};
852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800854qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700855 unsigned int l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800857 int cnt, match, status, que;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700858 srb_t *sp;
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 Chakrabortye315cd22008-11-06 10:40:51 -0800864 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800865 for (que = 0; que < QLA_MAX_HOST_QUES; que++) {
866 req = ha->req_q_map[vha->req_ques[que]];
867 if (!req)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700868 continue;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800869 for (cnt = 1; status == QLA_SUCCESS &&
870 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
871 sp = req->outstanding_cmds[cnt];
872 if (!sp)
873 continue;
Andrew Vasquez19851f12008-08-13 21:37:00 -0700874
Anirban Chakraborty73208df2008-12-09 16:45:39 -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;
889 }
890 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 }
897 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800898 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700899
900 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901}
902
Andrew Vasquez523ec772008-04-03 13:13:24 -0700903static char *reset_errors[] = {
904 "HBA not online",
905 "HBA not ready",
906 "Task management failed",
907 "Waiting for command completions",
908};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
Andrew Vasquez523ec772008-04-03 13:13:24 -0700910static int
911__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
912 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int))
913{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800914 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700915 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
916 int err;
917
918 qla2x00_block_error_handler(cmd);
919
920 if (!fcport)
921 return FAILED;
922
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800923 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
924 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700925
926 err = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800927 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700928 goto eh_reset_failed;
929 err = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800930 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700931 goto eh_reset_failed;
932 err = 2;
933 if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS)
934 goto eh_reset_failed;
935 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800936 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700937 cmd->device->lun, type) != QLA_SUCCESS)
938 goto eh_reset_failed;
939
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800940 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
941 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700942
943 return SUCCESS;
944
945 eh_reset_failed:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800946 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
947 , vha->host_no, cmd->device->id, cmd->device->lun, name,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700948 reset_errors[err]);
949 return FAILED;
950}
951
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800952static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
954{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800955 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
956 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Andrew Vasquez523ec772008-04-03 13:13:24 -0700958 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
959 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960}
961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700963qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800965 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
966 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
Andrew Vasquez523ec772008-04-03 13:13:24 -0700968 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
969 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970}
971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972/**************************************************************************
973* qla2xxx_eh_bus_reset
974*
975* Description:
976* The bus reset function will reset the bus and abort any executing
977* commands.
978*
979* Input:
980* cmd = Linux SCSI command packet of the command that cause the
981* bus reset.
982*
983* Returns:
984* SUCCESS/FAILURE (defined as macro in scsi.h).
985*
986**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800987static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
989{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800990 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500991 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700992 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500993 unsigned int id, lun;
994 unsigned long serial;
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 Chakrabortye315cd22008-11-06 10:40:51 -08001021 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, 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 Chakrabortye315cd22008-11-06 10:40:51 -08001056 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Andrew Vasquez07db5182006-10-02 12:00:49 -07001058 qla2x00_block_error_handler(cmd);
1059
f4f051e2005-04-17 15:02:26 -05001060 id = cmd->device->id;
1061 lun = cmd->device->lun;
1062 serial = cmd->serial_number;
1063
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -07001064 if (!fcport)
f4f051e2005-04-17 15:02:26 -05001065 return ret;
1066
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 qla_printk(KERN_INFO, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001068 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001070 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001071 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073 /*
1074 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001075 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 * be completed and then issue big hammer.Otherwise
1077 * it may cause I/O failure as big hammer marks the
1078 * devices as lost kicking of the port_down_timer
1079 * while dpc is stuck for the mailbox to complete.
1080 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001081 qla2x00_wait_for_loop_ready(vha);
1082 if (vha != base_vha) {
1083 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001084 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001085 } else {
1086 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1087 if (qla2x00_abort_isp(base_vha)) {
1088 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1089 /* failed. schedule dpc to try */
1090 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1091
1092 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1093 goto eh_host_reset_lock;
1094 }
1095 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001096 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001098 /* Waiting for command to be returned to OS.*/
1099 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
1100 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001101 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
f4f051e2005-04-17 15:02:26 -05001103eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001104 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1105 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
f4f051e2005-04-17 15:02:26 -05001107 return ret;
1108}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
1110/*
1111* qla2x00_loop_reset
1112* Issue loop reset.
1113*
1114* Input:
1115* ha = adapter block pointer.
1116*
1117* Returns:
1118* 0 = success
1119*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001120int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001121qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001123 int ret;
bdf79622005-04-17 15:06:53 -05001124 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001125 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001127 if (ha->flags.enable_lip_full_login && !vha->vp_idx) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001128 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001129 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001130 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001131 "full_login_lip=%d.\n", __func__, vha->host_no,
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001132 ret));
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001133 }
1134 atomic_set(&vha->loop_state, LOOP_DOWN);
1135 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1136 qla2x00_mark_all_devices_lost(vha, 0);
1137 qla2x00_wait_for_loop_ready(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 }
1139
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001140 if (ha->flags.enable_lip_reset && !vha->vp_idx) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001141 ret = qla2x00_lip_reset(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001142 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001143 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001144 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1145 } else
1146 qla2x00_wait_for_loop_ready(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001147 }
1148
1149 if (ha->flags.enable_target_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001150 list_for_each_entry(fcport, &vha->vp_fcports, list) {
bdf79622005-04-17 15:06:53 -05001151 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 continue;
1153
Andrew Vasquez523ec772008-04-03 13:13:24 -07001154 ret = ha->isp_ops->target_reset(fcport, 0);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001155 if (ret != QLA_SUCCESS) {
1156 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1157 "target_reset=%d d_id=%x.\n", __func__,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001158 vha->host_no, ret, fcport->d_id.b24));
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001159 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 }
1161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001163 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001165 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166}
1167
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001168void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001169qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001170{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001171 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001172 unsigned long flags;
1173 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001174 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001175 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001176
1177 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001178 for (que = 0; que < QLA_MAX_HOST_QUES; que++) {
1179 req = ha->req_q_map[vha->req_ques[que]];
1180 if (!req)
1181 continue;
1182 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1183 sp = req->outstanding_cmds[cnt];
1184 if (sp && sp->vha == vha) {
1185 req->outstanding_cmds[cnt] = NULL;
1186 sp->cmd->result = res;
1187 qla2x00_sp_compl(ha, sp);
1188 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001189 }
1190 }
1191 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1192}
1193
f4f051e2005-04-17 15:02:26 -05001194static int
1195qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196{
bdf79622005-04-17 15:06:53 -05001197 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001199 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001200 return -ENXIO;
1201
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001202 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001203
1204 return 0;
1205}
1206
1207static int
1208qla2xxx_slave_configure(struct scsi_device *sdev)
1209{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001210 scsi_qla_host_t *vha = shost_priv(sdev->host);
1211 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05001212 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001213 struct req_que *req = ha->req_q_map[0];
8482e1182005-04-17 15:04:54 -05001214
f4f051e2005-04-17 15:02:26 -05001215 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001216 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001218 scsi_deactivate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
Andrew Vasquez85821c92008-07-10 16:55:48 -07001220 rport->dev_loss_tmo = ha->port_down_retry_count;
8482e1182005-04-17 15:04:54 -05001221
f4f051e2005-04-17 15:02:26 -05001222 return 0;
1223}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
f4f051e2005-04-17 15:02:26 -05001225static void
1226qla2xxx_slave_destroy(struct scsi_device *sdev)
1227{
1228 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229}
1230
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001231static int
1232qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1233{
1234 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1235 return sdev->queue_depth;
1236}
1237
1238static int
1239qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1240{
1241 if (sdev->tagged_supported) {
1242 scsi_set_tag_type(sdev, tag_type);
1243 if (tag_type)
1244 scsi_activate_tcq(sdev, sdev->queue_depth);
1245 else
1246 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1247 } else
1248 tag_type = 0;
1249
1250 return tag_type;
1251}
1252
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253/**
1254 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1255 * @ha: HA context
1256 *
1257 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1258 * supported addressing method.
1259 */
1260static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001261qla2x00_config_dma_addressing(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001263 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001264 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001267 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1268 /* Any upper-dword bits set? */
1269 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1270 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1271 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001273 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1274 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001275 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001278
1279 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1280 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281}
1282
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001283static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001284qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001285{
1286 unsigned long flags = 0;
1287 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1288
1289 spin_lock_irqsave(&ha->hardware_lock, flags);
1290 ha->interrupts_on = 1;
1291 /* enable risc and host interrupts */
1292 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1293 RD_REG_WORD(&reg->ictrl);
1294 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1295
1296}
1297
1298static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001299qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001300{
1301 unsigned long flags = 0;
1302 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1303
1304 spin_lock_irqsave(&ha->hardware_lock, flags);
1305 ha->interrupts_on = 0;
1306 /* disable risc and host interrupts */
1307 WRT_REG_WORD(&reg->ictrl, 0);
1308 RD_REG_WORD(&reg->ictrl);
1309 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1310}
1311
1312static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001313qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001314{
1315 unsigned long flags = 0;
1316 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1317
1318 spin_lock_irqsave(&ha->hardware_lock, flags);
1319 ha->interrupts_on = 1;
1320 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1321 RD_REG_DWORD(&reg->ictrl);
1322 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1323}
1324
1325static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001326qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001327{
1328 unsigned long flags = 0;
1329 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1330
1331 spin_lock_irqsave(&ha->hardware_lock, flags);
1332 ha->interrupts_on = 0;
1333 WRT_REG_DWORD(&reg->ictrl, 0);
1334 RD_REG_DWORD(&reg->ictrl);
1335 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1336}
1337
1338static struct isp_operations qla2100_isp_ops = {
1339 .pci_config = qla2100_pci_config,
1340 .reset_chip = qla2x00_reset_chip,
1341 .chip_diag = qla2x00_chip_diag,
1342 .config_rings = qla2x00_config_rings,
1343 .reset_adapter = qla2x00_reset_adapter,
1344 .nvram_config = qla2x00_nvram_config,
1345 .update_fw_options = qla2x00_update_fw_options,
1346 .load_risc = qla2x00_load_risc,
1347 .pci_info_str = qla2x00_pci_info_str,
1348 .fw_version_str = qla2x00_fw_version_str,
1349 .intr_handler = qla2100_intr_handler,
1350 .enable_intrs = qla2x00_enable_intrs,
1351 .disable_intrs = qla2x00_disable_intrs,
1352 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001353 .target_reset = qla2x00_abort_target,
1354 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001355 .fabric_login = qla2x00_login_fabric,
1356 .fabric_logout = qla2x00_fabric_logout,
1357 .calc_req_entries = qla2x00_calc_iocbs_32,
1358 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1359 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1360 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1361 .read_nvram = qla2x00_read_nvram_data,
1362 .write_nvram = qla2x00_write_nvram_data,
1363 .fw_dump = qla2100_fw_dump,
1364 .beacon_on = NULL,
1365 .beacon_off = NULL,
1366 .beacon_blink = NULL,
1367 .read_optrom = qla2x00_read_optrom_data,
1368 .write_optrom = qla2x00_write_optrom_data,
1369 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001370 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001371};
1372
1373static struct isp_operations qla2300_isp_ops = {
1374 .pci_config = qla2300_pci_config,
1375 .reset_chip = qla2x00_reset_chip,
1376 .chip_diag = qla2x00_chip_diag,
1377 .config_rings = qla2x00_config_rings,
1378 .reset_adapter = qla2x00_reset_adapter,
1379 .nvram_config = qla2x00_nvram_config,
1380 .update_fw_options = qla2x00_update_fw_options,
1381 .load_risc = qla2x00_load_risc,
1382 .pci_info_str = qla2x00_pci_info_str,
1383 .fw_version_str = qla2x00_fw_version_str,
1384 .intr_handler = qla2300_intr_handler,
1385 .enable_intrs = qla2x00_enable_intrs,
1386 .disable_intrs = qla2x00_disable_intrs,
1387 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001388 .target_reset = qla2x00_abort_target,
1389 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001390 .fabric_login = qla2x00_login_fabric,
1391 .fabric_logout = qla2x00_fabric_logout,
1392 .calc_req_entries = qla2x00_calc_iocbs_32,
1393 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1394 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1395 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1396 .read_nvram = qla2x00_read_nvram_data,
1397 .write_nvram = qla2x00_write_nvram_data,
1398 .fw_dump = qla2300_fw_dump,
1399 .beacon_on = qla2x00_beacon_on,
1400 .beacon_off = qla2x00_beacon_off,
1401 .beacon_blink = qla2x00_beacon_blink,
1402 .read_optrom = qla2x00_read_optrom_data,
1403 .write_optrom = qla2x00_write_optrom_data,
1404 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001405 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001406};
1407
1408static struct isp_operations qla24xx_isp_ops = {
1409 .pci_config = qla24xx_pci_config,
1410 .reset_chip = qla24xx_reset_chip,
1411 .chip_diag = qla24xx_chip_diag,
1412 .config_rings = qla24xx_config_rings,
1413 .reset_adapter = qla24xx_reset_adapter,
1414 .nvram_config = qla24xx_nvram_config,
1415 .update_fw_options = qla24xx_update_fw_options,
1416 .load_risc = qla24xx_load_risc,
1417 .pci_info_str = qla24xx_pci_info_str,
1418 .fw_version_str = qla24xx_fw_version_str,
1419 .intr_handler = qla24xx_intr_handler,
1420 .enable_intrs = qla24xx_enable_intrs,
1421 .disable_intrs = qla24xx_disable_intrs,
1422 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001423 .target_reset = qla24xx_abort_target,
1424 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001425 .fabric_login = qla24xx_login_fabric,
1426 .fabric_logout = qla24xx_fabric_logout,
1427 .calc_req_entries = NULL,
1428 .build_iocbs = NULL,
1429 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1430 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1431 .read_nvram = qla24xx_read_nvram_data,
1432 .write_nvram = qla24xx_write_nvram_data,
1433 .fw_dump = qla24xx_fw_dump,
1434 .beacon_on = qla24xx_beacon_on,
1435 .beacon_off = qla24xx_beacon_off,
1436 .beacon_blink = qla24xx_beacon_blink,
1437 .read_optrom = qla24xx_read_optrom_data,
1438 .write_optrom = qla24xx_write_optrom_data,
1439 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001440 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001441};
1442
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001443static struct isp_operations qla25xx_isp_ops = {
1444 .pci_config = qla25xx_pci_config,
1445 .reset_chip = qla24xx_reset_chip,
1446 .chip_diag = qla24xx_chip_diag,
1447 .config_rings = qla24xx_config_rings,
1448 .reset_adapter = qla24xx_reset_adapter,
1449 .nvram_config = qla24xx_nvram_config,
1450 .update_fw_options = qla24xx_update_fw_options,
1451 .load_risc = qla24xx_load_risc,
1452 .pci_info_str = qla24xx_pci_info_str,
1453 .fw_version_str = qla24xx_fw_version_str,
1454 .intr_handler = qla24xx_intr_handler,
1455 .enable_intrs = qla24xx_enable_intrs,
1456 .disable_intrs = qla24xx_disable_intrs,
1457 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001458 .target_reset = qla24xx_abort_target,
1459 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001460 .fabric_login = qla24xx_login_fabric,
1461 .fabric_logout = qla24xx_fabric_logout,
1462 .calc_req_entries = NULL,
1463 .build_iocbs = NULL,
1464 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1465 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1466 .read_nvram = qla25xx_read_nvram_data,
1467 .write_nvram = qla25xx_write_nvram_data,
1468 .fw_dump = qla25xx_fw_dump,
1469 .beacon_on = qla24xx_beacon_on,
1470 .beacon_off = qla24xx_beacon_off,
1471 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001472 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001473 .write_optrom = qla24xx_write_optrom_data,
1474 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001475 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001476};
1477
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001478static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001479qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001480{
1481 ha->device_type = DT_EXTENDED_IDS;
1482 switch (ha->pdev->device) {
1483 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1484 ha->device_type |= DT_ISP2100;
1485 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001486 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001487 break;
1488 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1489 ha->device_type |= DT_ISP2200;
1490 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001491 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001492 break;
1493 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1494 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001495 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001496 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001497 break;
1498 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1499 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001500 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001501 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001502 break;
1503 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1504 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001505 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001506 if (ha->pdev->subsystem_vendor == 0x1028 &&
1507 ha->pdev->subsystem_device == 0x0170)
1508 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001509 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001510 break;
1511 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1512 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001513 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001514 break;
1515 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1516 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001517 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001518 break;
1519 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1520 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001521 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001522 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001523 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001524 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001525 break;
1526 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1527 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001528 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001529 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001530 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001531 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001532 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001533 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1534 ha->device_type |= DT_ISP8432;
1535 ha->device_type |= DT_ZIO_SUPPORTED;
1536 ha->device_type |= DT_FWI2;
1537 ha->device_type |= DT_IIDMA;
1538 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1539 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001540 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1541 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001542 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001543 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001544 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001545 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1546 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001547 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001548 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001549 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001550 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1551 ha->device_type |= DT_ISP2532;
1552 ha->device_type |= DT_ZIO_SUPPORTED;
1553 ha->device_type |= DT_FWI2;
1554 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001555 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1556 break;
1557 }
1558}
1559
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001561qla2x00_iospace_config(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562{
Andrew Vasquez37765412008-01-17 09:02:09 -08001563 resource_size_t pio;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001564 uint16_t msix;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
Andrew Vasquez285d0322007-10-19 15:59:17 -07001566 if (pci_request_selected_regions(ha->pdev, ha->bars,
1567 QLA2XXX_DRIVER_NAME)) {
1568 qla_printk(KERN_WARNING, ha,
1569 "Failed to reserve PIO/MMIO regions (%s)\n",
1570 pci_name(ha->pdev));
1571
1572 goto iospace_error_exit;
1573 }
1574 if (!(ha->bars & 1))
1575 goto skip_pio;
1576
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1578 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001579 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1580 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 qla_printk(KERN_WARNING, ha,
1582 "Invalid PCI I/O region size (%s)...\n",
1583 pci_name(ha->pdev));
1584 pio = 0;
1585 }
1586 } else {
1587 qla_printk(KERN_WARNING, ha,
1588 "region #0 not a PIO resource (%s)...\n",
1589 pci_name(ha->pdev));
1590 pio = 0;
1591 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001592 ha->pio_address = pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
Andrew Vasquez285d0322007-10-19 15:59:17 -07001594skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001596 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 qla_printk(KERN_ERR, ha,
Andrew Vasquez37765412008-01-17 09:02:09 -08001598 "region #1 not an MMIO resource (%s), aborting\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 pci_name(ha->pdev));
1600 goto iospace_error_exit;
1601 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001602 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 qla_printk(KERN_ERR, ha,
1604 "Invalid PCI mem region size (%s), aborting\n",
1605 pci_name(ha->pdev));
1606 goto iospace_error_exit;
1607 }
1608
Andrew Vasquez37765412008-01-17 09:02:09 -08001609 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 if (!ha->iobase) {
1611 qla_printk(KERN_ERR, ha,
1612 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1613
1614 goto iospace_error_exit;
1615 }
1616
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001617 /* Determine queue resources */
1618 ha->max_queues = 1;
1619 if (ql2xmaxqueues > 1) {
1620 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1621 pci_resource_len(ha->pdev, 3));
1622 if (ha->mqiobase) {
1623 /* Read MSIX vector size of the board */
1624 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL,
1625 &msix);
1626 ha->msix_count = msix;
1627 /* Max queues are bounded by available msix vectors */
1628 /* queue 0 uses two msix vectors */
1629 if (ha->msix_count - 1 < ql2xmaxqueues)
1630 ha->max_queues = ha->msix_count - 1;
1631 else if (ql2xmaxqueues > QLA_MQ_SIZE)
1632 ha->max_queues = QLA_MQ_SIZE;
1633 else
1634 ha->max_queues = ql2xmaxqueues;
1635 qla_printk(KERN_INFO, ha,
1636 "MSI-X vector count: %d\n", msix);
1637 }
1638 }
1639 ha->msix_count = ha->max_queues + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 return (0);
1641
1642iospace_error_exit:
1643 return (-ENOMEM);
1644}
1645
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001646static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001647qla2xxx_scan_start(struct Scsi_Host *shost)
1648{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001649 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001650
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001651 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1652 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1653 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1654 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001655}
1656
1657static int
1658qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1659{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001660 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001661
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001662 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001663 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001664 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001665 return 1;
1666
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001667 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001668}
1669
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670/*
1671 * PCI driver interface
1672 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001673static int __devinit
1674qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001676 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001678 scsi_qla_host_t *base_vha = NULL;
1679 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001680 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001682 struct scsi_host_template *sht;
Anirban Chakrabortyc51da4e2008-11-10 15:53:20 -08001683 int bars, max_id, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001684 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001685 struct req_que *req = NULL;
1686 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
Andrew Vasquez285d0322007-10-19 15:59:17 -07001688 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1689 sht = &qla2x00_driver_template;
1690 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1691 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001692 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001693 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1694 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1695 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532) {
1696 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1697 sht = &qla24xx_driver_template;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001698 mem_only = 1;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001699 }
1700
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001701 if (mem_only) {
1702 if (pci_enable_device_mem(pdev))
1703 goto probe_out;
1704 } else {
1705 if (pci_enable_device(pdev))
1706 goto probe_out;
1707 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
Jesse Barnes09276782008-10-18 17:33:19 -07001709 /* This may fail but that's ok */
1710 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07001711
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001712 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1713 if (!ha) {
1714 DEBUG(printk("Unable to allocate memory for ha\n"));
1715 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001717 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718
1719 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07001720 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001721 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001722 spin_lock_init(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001724 /* Set ISP-type information. */
1725 qla2x00_set_isp_flags(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 /* Configure PCI I/O space */
1727 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001728 if (ret)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001729 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08001732 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1733 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001736 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001737 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001738 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001740 /* Assign ISP specific operations. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001741 max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 if (IS_QLA2100(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001743 max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001745 req_length = REQUEST_ENTRY_CNT_2100;
1746 rsp_length = RESPONSE_ENTRY_CNT_2100;
1747 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001748 ha->gid_list_info_size = 4;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001749 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 } else if (IS_QLA2200(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001752 req_length = REQUEST_ENTRY_CNT_2200;
1753 rsp_length = RESPONSE_ENTRY_CNT_2100;
1754 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001755 ha->gid_list_info_size = 4;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001756 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001757 } else if (IS_QLA23XX(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001759 req_length = REQUEST_ENTRY_CNT_2200;
1760 rsp_length = RESPONSE_ENTRY_CNT_2300;
1761 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001762 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001763 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1764 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001765 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001766 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07001767 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001768 req_length = REQUEST_ENTRY_CNT_24XX;
1769 rsp_length = RESPONSE_ENTRY_CNT_2300;
1770 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001771 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001772 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001773 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001774 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001775 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001776 } else if (IS_QLA25XX(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001777 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001778 req_length = REQUEST_ENTRY_CNT_24XX;
1779 rsp_length = RESPONSE_ENTRY_CNT_2300;
1780 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001781 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001782 ha->gid_list_info_size = 8;
1783 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001784 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001785 ha->isp_ops = &qla25xx_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07001788 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001789 init_completion(&ha->mbx_cmd_comp);
1790 complete(&ha->mbx_cmd_comp);
1791 init_completion(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001793 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001795 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001796 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 qla_printk(KERN_WARNING, ha,
1798 "[ERROR] Failed to allocate memory for adapter\n");
1799
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001800 goto probe_hw_failed;
1801 }
1802
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001803 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001804 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001805 req->max_q_depth = ql2xmaxqdepth;
1806
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001807
1808 base_vha = qla2x00_create_host(sht, ha);
1809 if (!base_vha) {
1810 qla_printk(KERN_WARNING, ha,
1811 "[ERROR] Failed to allocate memory for scsi_host\n");
1812
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001813 ret = -ENOMEM;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001814 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 }
1816
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001817 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001819 qla2x00_config_dma_addressing(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001821 host = base_vha->host;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001822 base_vha->req_ques[0] = req->id;
1823 host->can_queue = req->length + 128;
1824 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001825 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001826 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001827 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1828 base_vha->vp_idx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001829 if (IS_QLA2100(ha))
1830 host->sg_tablesize = 32;
1831 host->max_id = max_id;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001832 host->this_id = 255;
1833 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07001834 host->unique_id = host->host_no;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001835 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001836 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001837 host->max_lun = MAX_LUNS;
1838 host->transportt = qla2xxx_transport_template;
1839
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001840 /* Set up the irqs */
1841 ret = qla2x00_request_irqs(ha, rsp);
1842 if (ret)
1843 goto probe_failed;
1844
1845 /* Alloc arrays of request and response ring ptrs */
1846 if (!qla2x00_alloc_queues(ha)) {
1847 qla_printk(KERN_WARNING, ha,
1848 "[ERROR] Failed to allocate memory for queue"
1849 " pointers\n");
1850 goto probe_failed;
1851 }
1852 ha->rsp_q_map[0] = rsp;
1853 ha->req_q_map[0] = req;
1854
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001855 if (qla2x00_initialize_adapter(base_vha)) {
1856 qla_printk(KERN_WARNING, ha,
1857 "Failed to initialize adapter\n");
1858
1859 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1860 "Adapter flags %x.\n",
1861 base_vha->host_no, base_vha->device_flags));
1862
1863 ret = -ENODEV;
1864 goto probe_failed;
1865 }
1866
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001867 /*
1868 * Startup the kernel thread for this host adapter
1869 */
1870 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1871 "%s_dpc", base_vha->host_str);
1872 if (IS_ERR(ha->dpc_thread)) {
1873 qla_printk(KERN_WARNING, ha,
1874 "Unable to start DPC thread!\n");
1875 ret = PTR_ERR(ha->dpc_thread);
1876 goto probe_failed;
1877 }
1878
1879 list_add_tail(&base_vha->list, &ha->vp_list);
1880 base_vha->host->irq = ha->pdev->irq;
1881
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001883 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
1885 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001886 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001888 base_vha->flags.init_done = 1;
1889 base_vha->flags.online = 1;
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001890
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001891 ret = scsi_add_host(host, &pdev->dev);
1892 if (ret)
1893 goto probe_failed;
1894
Andrew Vasquez048feec2008-09-11 22:19:45 -07001895 ha->isp_ops->enable_intrs(ha);
1896
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001897 scsi_scan_host(host);
1898
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001899 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001900
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001901 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001902
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001903 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001904
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 qla_printk(KERN_INFO, ha, "\n"
1906 " QLogic Fibre Channel HBA Driver: %s\n"
1907 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08001908 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1909 qla2x00_version_str, ha->model_number,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001910 ha->model_desc ? ha->model_desc : "", pdev->device,
1911 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
1912 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
1913 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 return 0;
1916
1917probe_failed:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001918 qla2x00_free_que(ha, req, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001919 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001921 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001923probe_hw_failed:
1924 if (ha->iobase)
1925 iounmap(ha->iobase);
1926
1927 pci_release_selected_regions(ha->pdev, ha->bars);
1928 kfree(ha);
1929 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001931probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001932 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001933 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935
Adrian Bunk4c993f72008-01-14 00:55:16 -08001936static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001937qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001939 scsi_qla_host_t *base_vha, *vha, *temp;
1940 struct qla_hw_data *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001942 base_vha = pci_get_drvdata(pdev);
1943 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001945 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
1946 if (vha && vha->fc_vport)
1947 fc_vport_terminate(vha->fc_vport);
1948 }
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07001949
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001950 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07001951
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001952 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001953
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001954 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001955
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001956 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001958 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05001959
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001960 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001962 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001964 scsi_host_put(base_vha->host);
1965
1966 if (ha->iobase)
1967 iounmap(ha->iobase);
1968
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001969 if (ha->mqiobase)
1970 iounmap(ha->mqiobase);
1971
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001972 pci_release_selected_regions(ha->pdev, ha->bars);
1973 kfree(ha);
1974 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975
Bernhard Walle665db932007-03-28 00:49:49 +02001976 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 pci_set_drvdata(pdev, NULL);
1978}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
1980static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001981qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001983 struct qla_hw_data *ha = vha->hw;
1984 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001985
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 /* Disable timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001987 if (vha->timer_active)
1988 qla2x00_stop_timer(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001990 vha->flags.online = 0;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001991
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 /* Kill the kernel thread for this host */
Christoph Hellwig39a11242006-02-14 18:46:22 +01001993 if (ha->dpc_thread) {
1994 struct task_struct *t = ha->dpc_thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
Christoph Hellwig39a11242006-02-14 18:46:22 +01001996 /*
1997 * qla2xxx_wake_dpc checks for ->dpc_thread
1998 * so we need to zero it out.
1999 */
2000 ha->dpc_thread = NULL;
2001 kthread_stop(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 }
2003
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002004 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002005 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002006
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002007 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002008 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002009
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002010 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002011 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002013 /* turn-off interrupts on the card */
2014 if (ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002015 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002016
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002017 qla2x00_free_irqs(vha);
2018
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002019 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002020
2021 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022}
2023
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002024static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002025qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002026 int defer)
2027{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002028 struct fc_rport *rport;
2029
2030 if (!fcport->rport)
2031 return;
2032
2033 rport = fcport->rport;
2034 if (defer) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002035 spin_lock_irq(vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002036 fcport->drport = rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002037 spin_unlock_irq(vha->host->host_lock);
2038 set_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
2039 qla2xxx_wake_dpc(vha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002040 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002041 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002042}
2043
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2046 *
2047 * Input: ha = adapter block pointer. fcport = port structure pointer.
2048 *
2049 * Return: None.
2050 *
2051 * Context:
2052 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002053void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002054 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002056 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002057 vha->vp_idx == fcport->vp_idx) {
2058 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2059 qla2x00_schedule_rport_del(vha, fcport, defer);
2060 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002061 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 * We may need to retry the login, so don't change the state of the
2063 * port but do the retries.
2064 */
2065 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2066 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2067
2068 if (!do_login)
2069 return;
2070
2071 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002072 fcport->login_retry = vha->hw->login_retry_count;
2073 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
2075 DEBUG(printk("scsi(%ld): Port login retry: "
2076 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2077 "id = 0x%04x retry cnt=%d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002078 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 fcport->port_name[0],
2080 fcport->port_name[1],
2081 fcport->port_name[2],
2082 fcport->port_name[3],
2083 fcport->port_name[4],
2084 fcport->port_name[5],
2085 fcport->port_name[6],
2086 fcport->port_name[7],
2087 fcport->loop_id,
2088 fcport->login_retry));
2089 }
2090}
2091
2092/*
2093 * qla2x00_mark_all_devices_lost
2094 * Updates fcport state when device goes offline.
2095 *
2096 * Input:
2097 * ha = adapter block pointer.
2098 * fcport = port structure pointer.
2099 *
2100 * Return:
2101 * None.
2102 *
2103 * Context:
2104 */
2105void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002106qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107{
2108 fc_port_t *fcport;
2109
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002110 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2111 if (vha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 /*
2114 * No point in marking the device as lost, if the device is
2115 * already DEAD.
2116 */
2117 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2118 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002119 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2120 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2121 qla2x00_schedule_rport_del(vha, fcport, defer);
2122 } else
2123 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 }
2125}
2126
2127/*
2128* qla2x00_mem_alloc
2129* Allocates adapter memory.
2130*
2131* Returns:
2132* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08002133* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002135static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002136qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2137 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138{
2139 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002141 ha->init_cb_size = sizeof(init_cb_t);
2142 if (IS_QLA2XXX_MIDTYPE(ha))
2143 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144
Andrew Vasqueze8711082008-01-31 12:33:48 -08002145 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002146 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002147 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002148 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002150 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2151 &ha->gid_list_dma, GFP_KERNEL);
2152 if (!ha->gid_list)
Andrew Vasqueze8711082008-01-31 12:33:48 -08002153 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154
Andrew Vasqueze8711082008-01-31 12:33:48 -08002155 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2156 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002157 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
Andrew Vasqueze8711082008-01-31 12:33:48 -08002159 /* Get memory for cached NVRAM */
2160 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2161 if (!ha->nvram)
2162 goto fail_free_srb_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002164 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2165 ha->pdev->device);
2166 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2167 DMA_POOL_SIZE, 8, 0);
2168 if (!ha->s_dma_pool)
2169 goto fail_free_nvram;
2170
Andrew Vasqueze8711082008-01-31 12:33:48 -08002171 /* Allocate memory for SNS commands */
2172 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002173 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002174 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002175 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002176 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002177 goto fail_dma_pool;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002178 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002179 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002180 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002181 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002182 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002183 goto fail_dma_pool;
2184 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002185 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002186 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002187 if (!ha->ct_sns)
2188 goto fail_free_ms_iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 }
2190
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002191 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002192 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2193 if (!*req) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002194 DEBUG(printk("Unable to allocate memory for req\n"));
2195 goto fail_req;
2196 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002197 (*req)->length = req_len;
2198 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2199 ((*req)->length + 1) * sizeof(request_t),
2200 &(*req)->dma, GFP_KERNEL);
2201 if (!(*req)->ring) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002202 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2203 goto fail_req_ring;
2204 }
2205 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002206 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2207 if (!*rsp) {
2208 qla_printk(KERN_WARNING, ha,
2209 "Unable to allocate memory for rsp\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002210 goto fail_rsp;
2211 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002212 (*rsp)->hw = ha;
2213 (*rsp)->length = rsp_len;
2214 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2215 ((*rsp)->length + 1) * sizeof(response_t),
2216 &(*rsp)->dma, GFP_KERNEL);
2217 if (!(*rsp)->ring) {
2218 qla_printk(KERN_WARNING, ha,
2219 "Unable to allocate memory for rsp_ring\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002220 goto fail_rsp_ring;
2221 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002222 (*req)->rsp = *rsp;
2223 (*rsp)->req = *req;
2224 /* Allocate memory for NVRAM data for vports */
2225 if (ha->nvram_npiv_size) {
2226 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2227 ha->nvram_npiv_size, GFP_KERNEL);
2228 if (!ha->npiv_info) {
2229 qla_printk(KERN_WARNING, ha,
2230 "Unable to allocate memory for npiv info\n");
2231 goto fail_npiv_info;
2232 }
2233 } else
2234 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002235
2236 INIT_LIST_HEAD(&ha->vp_list);
2237 return 1;
2238
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002239fail_npiv_info:
2240 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2241 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2242 (*rsp)->ring = NULL;
2243 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002244fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002245 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002246fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002247 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2248 sizeof(request_t), (*req)->ring, (*req)->dma);
2249 (*req)->ring = NULL;
2250 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002251fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002252 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002253fail_req:
2254 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2255 ha->ct_sns, ha->ct_sns_dma);
2256 ha->ct_sns = NULL;
2257 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002258fail_free_ms_iocb:
2259 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2260 ha->ms_iocb = NULL;
2261 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002262fail_dma_pool:
2263 dma_pool_destroy(ha->s_dma_pool);
2264 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002265fail_free_nvram:
2266 kfree(ha->nvram);
2267 ha->nvram = NULL;
2268fail_free_srb_mempool:
2269 mempool_destroy(ha->srb_mempool);
2270 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002271fail_free_gid_list:
2272 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002273 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002274 ha->gid_list = NULL;
2275 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002276fail_free_init_cb:
2277 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2278 ha->init_cb_dma);
2279 ha->init_cb = NULL;
2280 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002281fail:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002282 DEBUG(printk("%s: Memory allocation failure\n", __func__));
Andrew Vasqueze8711082008-01-31 12:33:48 -08002283 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284}
2285
2286/*
2287* qla2x00_mem_free
2288* Frees all adapter allocated memory.
2289*
2290* Input:
2291* ha = adapter block pointer.
2292*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08002293static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002294qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295{
Andrew Vasqueze8711082008-01-31 12:33:48 -08002296 if (ha->srb_mempool)
2297 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002299 if (ha->fce)
2300 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002301 ha->fce_dma);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002302
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002303 if (ha->fw_dump) {
2304 if (ha->eft)
2305 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002306 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002307 vfree(ha->fw_dump);
2308 }
2309
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 if (ha->sns_cmd)
2311 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002312 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313
2314 if (ha->ct_sns)
2315 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002316 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
Andrew Vasquez88729e52006-06-23 16:10:50 -07002318 if (ha->sfp_data)
2319 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2320
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 if (ha->ms_iocb)
2322 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2323
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 if (ha->s_dma_pool)
2325 dma_pool_destroy(ha->s_dma_pool);
2326
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002327
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 if (ha->gid_list)
2329 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002330 ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002333 if (ha->init_cb)
2334 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2335 ha->init_cb, ha->init_cb_dma);
2336 vfree(ha->optrom_buffer);
2337 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002338 kfree(ha->npiv_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339
Andrew Vasqueze8711082008-01-31 12:33:48 -08002340 ha->srb_mempool = NULL;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002341 ha->eft = NULL;
2342 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 ha->sns_cmd = NULL;
2344 ha->sns_cmd_dma = 0;
2345 ha->ct_sns = NULL;
2346 ha->ct_sns_dma = 0;
2347 ha->ms_iocb = NULL;
2348 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 ha->init_cb = NULL;
2350 ha->init_cb_dma = 0;
2351
2352 ha->s_dma_pool = NULL;
2353
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 ha->gid_list = NULL;
2355 ha->gid_list_dma = 0;
2356
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002358 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 ha->fw_dump_reading = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002360}
2361
2362struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2363 struct qla_hw_data *ha)
2364{
2365 struct Scsi_Host *host;
2366 struct scsi_qla_host *vha = NULL;
2367
2368 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2369 if (host == NULL) {
2370 printk(KERN_WARNING
2371 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2372 goto fail;
2373 }
2374
2375 /* Clear our data area */
2376 vha = shost_priv(host);
2377 memset(vha, 0, sizeof(scsi_qla_host_t));
2378
2379 vha->host = host;
2380 vha->host_no = host->host_no;
2381 vha->hw = ha;
2382
2383 INIT_LIST_HEAD(&vha->vp_fcports);
2384 INIT_LIST_HEAD(&vha->work_list);
2385 INIT_LIST_HEAD(&vha->list);
2386
2387 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2388 return vha;
2389
2390fail:
2391 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392}
2393
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002394static struct qla_work_evt *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002395qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002396 int locked)
2397{
2398 struct qla_work_evt *e;
2399
2400 e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
2401 GFP_KERNEL);
2402 if (!e)
2403 return NULL;
2404
2405 INIT_LIST_HEAD(&e->list);
2406 e->type = type;
2407 e->flags = QLA_EVT_FLAG_FREE;
2408 return e;
2409}
2410
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002411static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002412qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e, int locked)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002413{
Andrew Mortonbf6583b2008-07-24 08:31:48 -07002414 unsigned long uninitialized_var(flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002415 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002416
2417 if (!locked)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002418 spin_lock_irqsave(&ha->hardware_lock, flags);
2419 list_add_tail(&e->list, &vha->work_list);
2420 qla2xxx_wake_dpc(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002421 if (!locked)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002422 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002423 return QLA_SUCCESS;
2424}
2425
2426int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002427qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002428 u32 data)
2429{
2430 struct qla_work_evt *e;
2431
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002432 e = qla2x00_alloc_work(vha, QLA_EVT_AEN, 1);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002433 if (!e)
2434 return QLA_FUNCTION_FAILED;
2435
2436 e->u.aen.code = code;
2437 e->u.aen.data = data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002438 return qla2x00_post_work(vha, e, 1);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002439}
2440
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002441int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002442qla2x00_post_hwe_work(struct scsi_qla_host *vha, uint16_t code, uint16_t d1,
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002443 uint16_t d2, uint16_t d3)
2444{
2445 struct qla_work_evt *e;
2446
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002447 e = qla2x00_alloc_work(vha, QLA_EVT_HWE_LOG, 1);
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002448 if (!e)
2449 return QLA_FUNCTION_FAILED;
2450
2451 e->u.hwe.code = code;
2452 e->u.hwe.d1 = d1;
2453 e->u.hwe.d2 = d2;
2454 e->u.hwe.d3 = d3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002455 return qla2x00_post_work(vha, e, 1);
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002456}
2457
Andrew Vasquez0971de72008-04-03 13:13:18 -07002458static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002459qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002460{
2461 struct qla_work_evt *e;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002462 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002463
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002464 spin_lock_irq(&ha->hardware_lock);
2465 while (!list_empty(&vha->work_list)) {
2466 e = list_entry(vha->work_list.next, struct qla_work_evt, list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002467 list_del_init(&e->list);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002468 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002469
2470 switch (e->type) {
2471 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002472 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07002473 e->u.aen.code, e->u.aen.data);
2474 break;
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002475 case QLA_EVT_HWE_LOG:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002476 qla2xxx_hw_event_log(vha, e->u.hwe.code, e->u.hwe.d1,
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002477 e->u.hwe.d2, e->u.hwe.d3);
2478 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002479 }
2480 if (e->flags & QLA_EVT_FLAG_FREE)
2481 kfree(e);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002482 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002483 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002484 spin_unlock_irq(&ha->hardware_lock);
2485}
2486/* Relogins all the fcports of a vport
2487 * Context: dpc thread
2488 */
2489void qla2x00_relogin(struct scsi_qla_host *vha)
2490{
2491 fc_port_t *fcport;
2492 uint8_t status;
2493 uint16_t next_loopid = 0;
2494 struct qla_hw_data *ha = vha->hw;
2495
2496 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2497 /*
2498 * If the port is not ONLINE then try to login
2499 * to it if we haven't run out of retries.
2500 */
2501 if (atomic_read(&fcport->state) !=
2502 FCS_ONLINE && fcport->login_retry) {
2503
2504 if (fcport->flags & FCF_FABRIC_DEVICE) {
2505 if (fcport->flags & FCF_TAPE_PRESENT)
2506 ha->isp_ops->fabric_logout(vha,
2507 fcport->loop_id,
2508 fcport->d_id.b.domain,
2509 fcport->d_id.b.area,
2510 fcport->d_id.b.al_pa);
2511
2512 status = qla2x00_fabric_login(vha, fcport,
2513 &next_loopid);
2514 } else
2515 status = qla2x00_local_device_login(vha,
2516 fcport);
2517
2518 fcport->login_retry--;
2519 if (status == QLA_SUCCESS) {
2520 fcport->old_loop_id = fcport->loop_id;
2521
2522 DEBUG(printk("scsi(%ld): port login OK: logged "
2523 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2524
2525 qla2x00_update_fcport(vha, fcport);
2526
2527 } else if (status == 1) {
2528 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2529 /* retry the login again */
2530 DEBUG(printk("scsi(%ld): Retrying"
2531 " %d login again loop_id 0x%x\n",
2532 vha->host_no, fcport->login_retry,
2533 fcport->loop_id));
2534 } else {
2535 fcport->login_retry = 0;
2536 }
2537
2538 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2539 fcport->loop_id = FC_NO_LOOP_ID;
2540 }
2541 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2542 break;
2543 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07002544}
2545
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546/**************************************************************************
2547* qla2x00_do_dpc
2548* This kernel thread is a task that is schedule by the interrupt handler
2549* to perform the background processing for interrupts.
2550*
2551* Notes:
2552* This task always run in the context of a kernel thread. It
2553* is kick-off by the driver's detect code and starts up
2554* up one per adapter. It immediately goes to sleep and waits for
2555* some fibre event. When either the interrupt handler or
2556* the timer routine detects a event it will one of the task
2557* bits then wake us up.
2558**************************************************************************/
2559static int
2560qla2x00_do_dpc(void *data)
2561{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002562 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002563 scsi_qla_host_t *base_vha;
2564 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08002565
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002566 ha = (struct qla_hw_data *)data;
2567 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 set_user_nice(current, -20);
2570
Christoph Hellwig39a11242006-02-14 18:46:22 +01002571 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2573
Christoph Hellwig39a11242006-02-14 18:46:22 +01002574 set_current_state(TASK_INTERRUPTIBLE);
2575 schedule();
2576 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577
2578 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2579
2580 /* Initialization not yet finished. Don't do anything yet. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002581 if (!base_vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 continue;
2583
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002584 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585
2586 ha->dpc_active = 1;
2587
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 ha->dpc_active = 0;
2590 continue;
2591 }
2592
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002593 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002594
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002595 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2596 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597
2598 DEBUG(printk("scsi(%ld): dpc: sched "
2599 "qla2x00_abort_isp ha = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002600 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002602 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002604 if (qla2x00_abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 /* failed. retry later */
2606 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002607 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002609 clear_bit(ABORT_ISP_ACTIVE,
2610 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08002611 }
2612
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002614 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 }
2616
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002617 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2618 qla2x00_update_fcports(base_vha);
2619 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07002620 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002621
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002622 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2623 &base_vha->dpc_flags) &&
2624 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625
2626 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002627 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002629 qla2x00_rst_aen(base_vha);
2630 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 }
2632
2633 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002634 if ((test_and_clear_bit(RELOGIN_NEEDED,
2635 &base_vha->dpc_flags)) &&
2636 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2637 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638
2639 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002640 base_vha->host_no));
2641 qla2x00_relogin(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002644 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 }
2646
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002647 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2648 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649
2650 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002651 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652
2653 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002654 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002656 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002658 clear_bit(LOOP_RESYNC_ACTIVE,
2659 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 }
2661
2662 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002663 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 }
2665
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002666 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2667 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2668 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2669 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07002670 }
2671
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002673 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002675 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2676 &base_vha->dpc_flags))
2677 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002678
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002679 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002680
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 ha->dpc_active = 0;
2682 } /* End of while(1) */
2683
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002684 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685
2686 /*
2687 * Make sure that nobody tries to wake us up again.
2688 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 ha->dpc_active = 0;
2690
Christoph Hellwig39a11242006-02-14 18:46:22 +01002691 return 0;
2692}
2693
2694void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002695qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01002696{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002697 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002698 struct task_struct *t = ha->dpc_thread;
2699
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002700 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002701 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702}
2703
2704/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705* qla2x00_rst_aen
2706* Processes asynchronous reset.
2707*
2708* Input:
2709* ha = adapter block pointer.
2710*/
2711static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002712qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002714 if (vha->flags.online && !vha->flags.reset_active &&
2715 !atomic_read(&vha->loop_down_timer) &&
2716 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002718 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719
2720 /*
2721 * Issue marker command only when we are going to start
2722 * the I/O.
2723 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002724 vha->marker_needed = 1;
2725 } while (!atomic_read(&vha->loop_down_timer) &&
2726 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 }
2728}
2729
f4f051e2005-04-17 15:02:26 -05002730static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002731qla2x00_sp_free_dma(srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002732{
2733 struct scsi_cmnd *cmd = sp->cmd;
2734
2735 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002736 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05002737 sp->flags &= ~SRB_DMA_VALID;
2738 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002739 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002740}
2741
2742void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002743qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002744{
2745 struct scsi_cmnd *cmd = sp->cmd;
2746
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002747 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -05002748
f4f051e2005-04-17 15:02:26 -05002749 mempool_free(sp, ha->srb_mempool);
2750
2751 cmd->scsi_done(cmd);
2752}
bdf79622005-04-17 15:06:53 -05002753
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754/**************************************************************************
2755* qla2x00_timer
2756*
2757* Description:
2758* One second timer
2759*
2760* Context: Interrupt
2761***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002762void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002763qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 unsigned long cpu_flags = 0;
2766 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 int start_dpc = 0;
2768 int index;
2769 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002770 int t;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002771 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002772 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 /*
2774 * Ports - Port down timer.
2775 *
2776 * Whenever, a port is in the LOST state we start decrementing its port
2777 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002778 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 */
2780 t = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002781 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 if (fcport->port_type != FCT_TARGET)
2783 continue;
2784
2785 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2786
2787 if (atomic_read(&fcport->port_down_timer) == 0)
2788 continue;
2789
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002790 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002792
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002794 "%d remaining\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002795 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 t, atomic_read(&fcport->port_down_timer)));
2797 }
2798 t++;
2799 } /* End of for fcport */
2800
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801
2802 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002803 if (atomic_read(&vha->loop_down_timer) > 0 &&
2804 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
2805 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002807 if (atomic_read(&vha->loop_down_timer) ==
2808 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809
2810 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2811 "queues before time expire\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002812 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002814 if (!IS_QLA2100(ha) && vha->link_down_timeout)
2815 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816
2817 /* Schedule an ISP abort to return any tape commands. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002818 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002819 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002820 spin_lock_irqsave(&ha->hardware_lock,
2821 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002822 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002823 for (index = 1;
2824 index < MAX_OUTSTANDING_COMMANDS;
2825 index++) {
2826 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05002827
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002828 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002829 if (!sp)
2830 continue;
2831 sfcp = sp->fcport;
2832 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2833 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002835 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002836 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002837 break;
2838 }
2839 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002840 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002842 set_bit(ABORT_QUEUES_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 start_dpc++;
2844 }
2845
2846 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002847 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2849 "restarting queues.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002850 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002852 set_bit(RESTART_QUEUES_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 start_dpc++;
2854
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002855 if (!(vha->device_flags & DFLG_NO_CABLE) &&
2856 !vha->vp_idx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 DEBUG(printk("scsi(%ld): Loop down - "
2858 "aborting ISP.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002859 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 qla_printk(KERN_WARNING, ha,
2861 "Loop down - aborting ISP.\n");
2862
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002863 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 }
2865 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002866 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002867 vha->host_no,
2868 atomic_read(&vha->loop_down_timer)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 }
2870
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002871 /* Check if beacon LED needs to be blinked */
2872 if (ha->beacon_blink_led == 1) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002873 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002874 start_dpc++;
2875 }
2876
Andrew Vasquez550bf572008-04-24 15:21:23 -07002877 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002878 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07002879 start_dpc++;
2880
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002882 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
2883 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
2884 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002886 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
2887 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
2888 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
2889 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
2890 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002892 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893}
2894
Andrew Vasquez54333832005-11-09 15:49:04 -08002895/* Firmware interface routines. */
2896
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002897#define FW_BLOBS 6
Andrew Vasquez54333832005-11-09 15:49:04 -08002898#define FW_ISP21XX 0
2899#define FW_ISP22XX 1
2900#define FW_ISP2300 2
2901#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002902#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002903#define FW_ISP25XX 5
Andrew Vasquez54333832005-11-09 15:49:04 -08002904
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002905#define FW_FILE_ISP21XX "ql2100_fw.bin"
2906#define FW_FILE_ISP22XX "ql2200_fw.bin"
2907#define FW_FILE_ISP2300 "ql2300_fw.bin"
2908#define FW_FILE_ISP2322 "ql2322_fw.bin"
2909#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002910#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002911
Daniel Walkere1e82b62008-05-12 22:21:10 -07002912static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002913
2914static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002915 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
2916 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
2917 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
2918 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
2919 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002920 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08002921};
2922
2923struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002924qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08002925{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002926 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08002927 struct fw_blob *blob;
2928
2929 blob = NULL;
2930 if (IS_QLA2100(ha)) {
2931 blob = &qla_fw_blobs[FW_ISP21XX];
2932 } else if (IS_QLA2200(ha)) {
2933 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002934 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002935 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002936 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002937 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002938 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002939 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002940 } else if (IS_QLA25XX(ha)) {
2941 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08002942 }
2943
Daniel Walkere1e82b62008-05-12 22:21:10 -07002944 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002945 if (blob->fw)
2946 goto out;
2947
2948 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
2949 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002950 "(%s).\n", vha->host_no, blob->name));
Andrew Vasquez54333832005-11-09 15:49:04 -08002951 blob->fw = NULL;
2952 blob = NULL;
2953 goto out;
2954 }
2955
2956out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07002957 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002958 return blob;
2959}
2960
2961static void
2962qla2x00_release_firmware(void)
2963{
2964 int idx;
2965
Daniel Walkere1e82b62008-05-12 22:21:10 -07002966 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002967 for (idx = 0; idx < FW_BLOBS; idx++)
2968 if (qla_fw_blobs[idx].fw)
2969 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07002970 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002971}
2972
Seokmann Ju14e660e2007-09-20 14:07:36 -07002973static pci_ers_result_t
2974qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
2975{
2976 switch (state) {
2977 case pci_channel_io_normal:
2978 return PCI_ERS_RESULT_CAN_RECOVER;
2979 case pci_channel_io_frozen:
2980 pci_disable_device(pdev);
2981 return PCI_ERS_RESULT_NEED_RESET;
2982 case pci_channel_io_perm_failure:
2983 qla2x00_remove_one(pdev);
2984 return PCI_ERS_RESULT_DISCONNECT;
2985 }
2986 return PCI_ERS_RESULT_NEED_RESET;
2987}
2988
2989static pci_ers_result_t
2990qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
2991{
2992 int risc_paused = 0;
2993 uint32_t stat;
2994 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002995 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
2996 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07002997 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2998 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
2999
3000 spin_lock_irqsave(&ha->hardware_lock, flags);
3001 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3002 stat = RD_REG_DWORD(&reg->hccr);
3003 if (stat & HCCR_RISC_PAUSE)
3004 risc_paused = 1;
3005 } else if (IS_QLA23XX(ha)) {
3006 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
3007 if (stat & HSR_RISC_PAUSED)
3008 risc_paused = 1;
3009 } else if (IS_FWI2_CAPABLE(ha)) {
3010 stat = RD_REG_DWORD(&reg24->host_status);
3011 if (stat & HSRX_RISC_PAUSED)
3012 risc_paused = 1;
3013 }
3014 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3015
3016 if (risc_paused) {
3017 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3018 "Dumping firmware!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003019 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003020
3021 return PCI_ERS_RESULT_NEED_RESET;
3022 } else
3023 return PCI_ERS_RESULT_RECOVERED;
3024}
3025
3026static pci_ers_result_t
3027qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3028{
3029 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003030 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3031 struct qla_hw_data *ha = base_vha->hw;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003032 int rc;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003033
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003034 if (ha->mem_only)
3035 rc = pci_enable_device_mem(pdev);
3036 else
3037 rc = pci_enable_device(pdev);
3038
3039 if (rc) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07003040 qla_printk(KERN_WARNING, ha,
3041 "Can't re-enable PCI device after reset.\n");
3042
3043 return ret;
3044 }
3045 pci_set_master(pdev);
3046
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003047 if (ha->isp_ops->pci_config(base_vha))
Seokmann Ju14e660e2007-09-20 14:07:36 -07003048 return ret;
3049
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003050 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3051 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07003052 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003053 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003054
3055 return ret;
3056}
3057
3058static void
3059qla2xxx_pci_resume(struct pci_dev *pdev)
3060{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003061 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3062 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003063 int ret;
3064
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003065 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003066 if (ret != QLA_SUCCESS) {
3067 qla_printk(KERN_ERR, ha,
3068 "the device failed to resume I/O "
3069 "from slot/link_reset");
3070 }
3071 pci_cleanup_aer_uncorrect_error_status(pdev);
3072}
3073
3074static struct pci_error_handlers qla2xxx_err_handler = {
3075 .error_detected = qla2xxx_pci_error_detected,
3076 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3077 .slot_reset = qla2xxx_pci_slot_reset,
3078 .resume = qla2xxx_pci_resume,
3079};
3080
Andrew Vasquez54333832005-11-09 15:49:04 -08003081static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003082 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3083 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3084 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3085 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3086 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3087 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3088 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3089 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3090 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003091 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003092 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3093 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003094 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez54333832005-11-09 15:49:04 -08003095 { 0 },
3096};
3097MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3098
Andrew Vasquezfca29702005-07-06 10:31:47 -07003099static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07003100 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06003101 .driver = {
3102 .owner = THIS_MODULE,
3103 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07003104 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003105 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08003106 .remove = qla2x00_remove_one,
Seokmann Ju14e660e2007-09-20 14:07:36 -07003107 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07003108};
3109
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110/**
3111 * qla2x00_module_init - Module initialization.
3112 **/
3113static int __init
3114qla2x00_module_init(void)
3115{
Andrew Vasquezfca29702005-07-06 10:31:47 -07003116 int ret = 0;
3117
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003119 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09003120 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 if (srb_cachep == NULL) {
3122 printk(KERN_ERR
3123 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3124 return -ENOMEM;
3125 }
3126
3127 /* Derive version string. */
3128 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07003129 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07003130 strcat(qla2x00_version_str, "-debug");
3131
Andrew Vasquez1c97a122005-04-21 16:13:36 -04003132 qla2xxx_transport_template =
3133 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003134 if (!qla2xxx_transport_template) {
3135 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003137 }
3138 qla2xxx_transport_vport_template =
3139 fc_attach_transport(&qla2xxx_transport_vport_functions);
3140 if (!qla2xxx_transport_vport_template) {
3141 kmem_cache_destroy(srb_cachep);
3142 fc_release_transport(qla2xxx_transport_template);
3143 return -ENODEV;
3144 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07003146 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3147 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003148 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003149 if (ret) {
3150 kmem_cache_destroy(srb_cachep);
3151 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003152 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003153 }
3154 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155}
3156
3157/**
3158 * qla2x00_module_exit - Module cleanup.
3159 **/
3160static void __exit
3161qla2x00_module_exit(void)
3162{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003163 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08003164 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003165 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003167 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168}
3169
3170module_init(qla2x00_module_init);
3171module_exit(qla2x00_module_exit);
3172
3173MODULE_AUTHOR("QLogic Corporation");
3174MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3175MODULE_LICENSE("GPL");
3176MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003177MODULE_FIRMWARE(FW_FILE_ISP21XX);
3178MODULE_FIRMWARE(FW_FILE_ISP22XX);
3179MODULE_FIRMWARE(FW_FILE_ISP2300);
3180MODULE_FIRMWARE(FW_FILE_ISP2322);
3181MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08003182MODULE_FIRMWARE(FW_FILE_ISP25XX);