blob: 21dd182ad512214c7646299a1af4ad4f2e9d9e88 [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
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -070097 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 */
99static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500100static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800101static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
102static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500103static void qla2xxx_slave_destroy(struct scsi_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
105 void (*fn)(struct scsi_cmnd *));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700106static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
107 void (*fn)(struct scsi_cmnd *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static int qla2xxx_eh_abort(struct scsi_cmnd *);
109static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700110static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
112static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700114static int qla2x00_change_queue_depth(struct scsi_device *, int);
115static int qla2x00_change_queue_type(struct scsi_device *, int);
116
Adrian Bunka824ebb2008-01-17 09:02:15 -0800117static struct scsi_host_template qla2x00_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700119 .name = QLA2XXX_DRIVER_NAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 .queuecommand = qla2x00_queuecommand,
121
122 .eh_abort_handler = qla2xxx_eh_abort,
123 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700124 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
126 .eh_host_reset_handler = qla2xxx_eh_host_reset,
127
128 .slave_configure = qla2xxx_slave_configure,
129
f4f051e2005-04-17 15:02:26 -0500130 .slave_alloc = qla2xxx_slave_alloc,
131 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800132 .scan_finished = qla2xxx_scan_finished,
133 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700134 .change_queue_depth = qla2x00_change_queue_depth,
135 .change_queue_type = qla2x00_change_queue_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 .this_id = -1,
137 .cmd_per_lun = 3,
138 .use_clustering = ENABLE_CLUSTERING,
139 .sg_tablesize = SG_ALL,
140
141 /*
142 * The RISC allows for each command to transfer (2^32-1) bytes of data,
143 * which equates to 0x800000 sectors.
144 */
145 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700146 .shost_attrs = qla2x00_host_attrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147};
148
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700149struct scsi_host_template qla24xx_driver_template = {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700150 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700151 .name = QLA2XXX_DRIVER_NAME,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700152 .queuecommand = qla24xx_queuecommand,
153
154 .eh_abort_handler = qla2xxx_eh_abort,
155 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700156 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700157 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
158 .eh_host_reset_handler = qla2xxx_eh_host_reset,
159
160 .slave_configure = qla2xxx_slave_configure,
161
162 .slave_alloc = qla2xxx_slave_alloc,
163 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700164 .scan_finished = qla2xxx_scan_finished,
165 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700166 .change_queue_depth = qla2x00_change_queue_depth,
167 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700168 .this_id = -1,
169 .cmd_per_lun = 3,
170 .use_clustering = ENABLE_CLUSTERING,
171 .sg_tablesize = SG_ALL,
172
173 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700174 .shost_attrs = qla2x00_host_attrs,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700175};
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700178struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180/* TODO Convert to inlines
181 *
182 * Timer routines
183 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700185__inline__ void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
187{
188 init_timer(&ha->timer);
189 ha->timer.expires = jiffies + interval * HZ;
190 ha->timer.data = (unsigned long)ha;
191 ha->timer.function = (void (*)(unsigned long))func;
192 add_timer(&ha->timer);
193 ha->timer_active = 1;
194}
195
196static inline void
197qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
198{
199 mod_timer(&ha->timer, jiffies + interval * HZ);
200}
201
Adrian Bunka824ebb2008-01-17 09:02:15 -0800202static __inline__ void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203qla2x00_stop_timer(scsi_qla_host_t *ha)
204{
205 del_timer_sync(&ha->timer);
206 ha->timer_active = 0;
207}
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209static int qla2x00_do_dpc(void *data);
210
211static void qla2x00_rst_aen(scsi_qla_host_t *);
212
Andrew Vasqueze8711082008-01-31 12:33:48 -0800213static int qla2x00_mem_alloc(scsi_qla_host_t *);
Adrian Bunka824ebb2008-01-17 09:02:15 -0800214static void qla2x00_mem_free(scsi_qla_host_t *ha);
f4f051e2005-04-17 15:02:26 -0500215static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217/* -------------------------------------------------------------------------- */
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219static char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700220qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
222 static char *pci_bus_modes[] = {
223 "33", "66", "100", "133",
224 };
225 uint16_t pci_bus;
226
227 strcpy(str, "PCI");
228 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
229 if (pci_bus) {
230 strcat(str, "-X (");
231 strcat(str, pci_bus_modes[pci_bus]);
232 } else {
233 pci_bus = (ha->pci_attr & BIT_8) >> 8;
234 strcat(str, " (");
235 strcat(str, pci_bus_modes[pci_bus]);
236 }
237 strcat(str, " MHz)");
238
239 return (str);
240}
241
Andrew Vasquezfca29702005-07-06 10:31:47 -0700242static char *
243qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
244{
245 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
246 uint32_t pci_bus;
247 int pcie_reg;
248
249 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
250 if (pcie_reg) {
251 char lwstr[6];
252 uint16_t pcie_lstat, lspeed, lwidth;
253
254 pcie_reg += 0x12;
255 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
256 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
257 lwidth = (pcie_lstat &
258 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
259
260 strcpy(str, "PCIe (");
261 if (lspeed == 1)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700262 strcat(str, "2.5GT/s ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700263 else if (lspeed == 2)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700264 strcat(str, "5.0GT/s ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700265 else
266 strcat(str, "<unknown> ");
267 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
268 strcat(str, lwstr);
269
270 return str;
271 }
272
273 strcpy(str, "PCI");
274 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
275 if (pci_bus == 0 || pci_bus == 8) {
276 strcat(str, " (");
277 strcat(str, pci_bus_modes[pci_bus >> 3]);
278 } else {
279 strcat(str, "-X ");
280 if (pci_bus & BIT_2)
281 strcat(str, "Mode 2");
282 else
283 strcat(str, "Mode 1");
284 strcat(str, " (");
285 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
286 }
287 strcat(str, " MHz)");
288
289 return str;
290}
291
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800292static char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700293qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
295 char un_str[10];
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
298 ha->fw_minor_version,
299 ha->fw_subminor_version);
300
301 if (ha->fw_attributes & BIT_9) {
302 strcat(str, "FLX");
303 return (str);
304 }
305
306 switch (ha->fw_attributes & 0xFF) {
307 case 0x7:
308 strcat(str, "EF");
309 break;
310 case 0x17:
311 strcat(str, "TP");
312 break;
313 case 0x37:
314 strcat(str, "IP");
315 break;
316 case 0x77:
317 strcat(str, "VI");
318 break;
319 default:
320 sprintf(un_str, "(%x)", ha->fw_attributes);
321 strcat(str, un_str);
322 break;
323 }
324 if (ha->fw_attributes & 0x100)
325 strcat(str, "X");
326
327 return (str);
328}
329
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800330static char *
Andrew Vasquezfca29702005-07-06 10:31:47 -0700331qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
332{
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700333 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
334 ha->fw_minor_version,
335 ha->fw_subminor_version);
336
Andrew Vasquezfca29702005-07-06 10:31:47 -0700337 if (ha->fw_attributes & BIT_0)
338 strcat(str, "[Class 2] ");
339 if (ha->fw_attributes & BIT_1)
340 strcat(str, "[IP] ");
341 if (ha->fw_attributes & BIT_2)
342 strcat(str, "[Multi-ID] ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700343 if (ha->fw_attributes & BIT_3)
344 strcat(str, "[SB-2] ");
345 if (ha->fw_attributes & BIT_4)
346 strcat(str, "[T10 CRC] ");
347 if (ha->fw_attributes & BIT_5)
348 strcat(str, "[VI] ");
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700349 if (ha->fw_attributes & BIT_10)
350 strcat(str, "[84XX] ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700351 if (ha->fw_attributes & BIT_13)
352 strcat(str, "[Experimental]");
353 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700354}
355
356static inline srb_t *
357qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
358 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
359{
360 srb_t *sp;
361
362 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
363 if (!sp)
364 return sp;
365
Andrew Vasquezfca29702005-07-06 10:31:47 -0700366 sp->ha = ha;
367 sp->fcport = fcport;
368 sp->cmd = cmd;
369 sp->flags = 0;
370 CMD_SP(cmd) = (void *)sp;
371 cmd->scsi_done = done;
372
373 return sp;
374}
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376static int
f4f051e2005-04-17 15:02:26 -0500377qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700379 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500380 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400381 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
f4f051e2005-04-17 15:02:26 -0500382 srb_t *sp;
383 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Seokmann Ju14e660e2007-09-20 14:07:36 -0700385 if (unlikely(pci_channel_offline(ha->pdev))) {
386 cmd->result = DID_REQUEUE << 16;
387 goto qc_fail_command;
388 }
389
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400390 rval = fc_remote_port_chkready(rport);
391 if (rval) {
392 cmd->result = rval;
f4f051e2005-04-17 15:02:26 -0500393 goto qc_fail_command;
394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800396 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500397 if (fcport->drport)
398 goto qc_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800399
f4f051e2005-04-17 15:02:26 -0500400 if (atomic_read(&fcport->state) != FCS_ONLINE) {
401 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
402 atomic_read(&ha->loop_state) == LOOP_DEAD) {
403 cmd->result = DID_NO_CONNECT << 16;
404 goto qc_fail_command;
405 }
Mike Christie7b594132008-08-17 15:24:40 -0500406 goto qc_target_busy;
f4f051e2005-04-17 15:02:26 -0500407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 spin_unlock_irq(ha->host->host_lock);
410
Andrew Vasquezfca29702005-07-06 10:31:47 -0700411 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
412 if (!sp)
f4f051e2005-04-17 15:02:26 -0500413 goto qc_host_busy_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
f4f051e2005-04-17 15:02:26 -0500415 rval = qla2x00_start_scsi(sp);
416 if (rval != QLA_SUCCESS)
417 goto qc_host_busy_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 spin_lock_irq(ha->host->host_lock);
420
f4f051e2005-04-17 15:02:26 -0500421 return 0;
422
423qc_host_busy_free_sp:
424 qla2x00_sp_free_dma(ha, sp);
f4f051e2005-04-17 15:02:26 -0500425 mempool_free(sp, ha->srb_mempool);
426
427qc_host_busy_lock:
428 spin_lock_irq(ha->host->host_lock);
f4f051e2005-04-17 15:02:26 -0500429 return SCSI_MLQUEUE_HOST_BUSY;
430
Mike Christie7b594132008-08-17 15:24:40 -0500431qc_target_busy:
432 return SCSI_MLQUEUE_TARGET_BUSY;
433
f4f051e2005-04-17 15:02:26 -0500434qc_fail_command:
435 done(cmd);
436
437 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438}
439
Andrew Vasquezfca29702005-07-06 10:31:47 -0700440
441static int
442qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
443{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700444 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700445 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400446 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700447 srb_t *sp;
448 int rval;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700449 scsi_qla_host_t *pha = to_qla_parent(ha);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700450
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700451 if (unlikely(pci_channel_offline(pha->pdev))) {
Seokmann Ju14e660e2007-09-20 14:07:36 -0700452 cmd->result = DID_REQUEUE << 16;
453 goto qc24_fail_command;
454 }
455
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400456 rval = fc_remote_port_chkready(rport);
457 if (rval) {
458 cmd->result = rval;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700459 goto qc24_fail_command;
460 }
461
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800462 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500463 if (fcport->drport)
464 goto qc24_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800465
Andrew Vasquezfca29702005-07-06 10:31:47 -0700466 if (atomic_read(&fcport->state) != FCS_ONLINE) {
467 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700468 atomic_read(&pha->loop_state) == LOOP_DEAD) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700469 cmd->result = DID_NO_CONNECT << 16;
470 goto qc24_fail_command;
471 }
Mike Christie7b594132008-08-17 15:24:40 -0500472 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700473 }
474
475 spin_unlock_irq(ha->host->host_lock);
476
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700477 sp = qla2x00_get_new_sp(pha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700478 if (!sp)
479 goto qc24_host_busy_lock;
480
481 rval = qla24xx_start_scsi(sp);
482 if (rval != QLA_SUCCESS)
483 goto qc24_host_busy_free_sp;
484
485 spin_lock_irq(ha->host->host_lock);
486
487 return 0;
488
489qc24_host_busy_free_sp:
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700490 qla2x00_sp_free_dma(pha, sp);
491 mempool_free(sp, pha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700492
493qc24_host_busy_lock:
494 spin_lock_irq(ha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700495 return SCSI_MLQUEUE_HOST_BUSY;
496
Mike Christie7b594132008-08-17 15:24:40 -0500497qc24_target_busy:
498 return SCSI_MLQUEUE_TARGET_BUSY;
499
Andrew Vasquezfca29702005-07-06 10:31:47 -0700500qc24_fail_command:
501 done(cmd);
502
503 return 0;
504}
505
506
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507/*
508 * qla2x00_eh_wait_on_command
509 * Waits for the command to be returned by the Firmware for some
510 * max time.
511 *
512 * Input:
513 * ha = actual ha whose done queue will contain the command
514 * returned by firmware.
515 * cmd = Scsi Command to wait on.
516 * flag = Abort/Reset(Bus or Device Reset)
517 *
518 * Return:
519 * Not Found : 0
520 * Found : 1
521 */
522static int
523qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
524{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700525#define ABORT_POLLING_PERIOD 1000
526#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500527 unsigned long wait_iter = ABORT_WAIT_ITER;
528 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
f4f051e2005-04-17 15:02:26 -0500530 while (CMD_SP(cmd)) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700531 msleep(ABORT_POLLING_PERIOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
f4f051e2005-04-17 15:02:26 -0500533 if (--wait_iter)
534 break;
535 }
536 if (CMD_SP(cmd))
537 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
f4f051e2005-04-17 15:02:26 -0500539 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540}
541
542/*
543 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700544 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 * <= MAX_RETRIES_OF_ISP_ABORT or
546 * finally HBA is disabled ie marked offline
547 *
548 * Input:
549 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700550 *
551 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 * Does context switching-Release SPIN_LOCK
553 * (if any) before calling this routine.
554 *
555 * Return:
556 * Success (Adapter is online) : 0
557 * Failed (Adapter is offline/disabled) : 1
558 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800559int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
561{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700562 int return_status;
563 unsigned long wait_online;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700564 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700566 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700567 while (((test_bit(ISP_ABORT_NEEDED, &pha->dpc_flags)) ||
568 test_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags) ||
569 test_bit(ISP_ABORT_RETRY, &pha->dpc_flags) ||
570 pha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
572 msleep(1000);
573 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700574 if (pha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700575 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 else
577 return_status = QLA_FUNCTION_FAILED;
578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 return (return_status);
580}
581
582/*
583 * qla2x00_wait_for_loop_ready
584 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700585 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 * Input:
587 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700588 *
589 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 * Does context switching-Release SPIN_LOCK
591 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700592 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 *
594 * Return:
595 * Success (LOOP_READY) : 0
596 * Failed (LOOP_NOT_READY) : 1
597 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700598static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
600{
601 int return_status = QLA_SUCCESS;
602 unsigned long loop_timeout ;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700603 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700606 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700608 while ((!atomic_read(&pha->loop_down_timer) &&
609 atomic_read(&pha->loop_state) == LOOP_DOWN) ||
610 atomic_read(&pha->loop_state) != LOOP_READY) {
611 if (atomic_read(&pha->loop_state) == LOOP_DEAD) {
Ravi Anand57680082006-05-17 15:08:44 -0700612 return_status = QLA_FUNCTION_FAILED;
613 break;
614 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 msleep(1000);
616 if (time_after_eq(jiffies, loop_timeout)) {
617 return_status = QLA_FUNCTION_FAILED;
618 break;
619 }
620 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700621 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622}
623
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700624void
625qla2x00_abort_fcport_cmds(fc_port_t *fcport)
626{
627 int cnt;
628 unsigned long flags;
629 srb_t *sp;
630 scsi_qla_host_t *ha = fcport->ha;
631 scsi_qla_host_t *pha = to_qla_parent(ha);
632
633 spin_lock_irqsave(&pha->hardware_lock, flags);
634 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
635 sp = pha->outstanding_cmds[cnt];
636 if (!sp)
637 continue;
638 if (sp->fcport != fcport)
639 continue;
640
641 spin_unlock_irqrestore(&pha->hardware_lock, flags);
642 if (ha->isp_ops->abort_command(ha, sp)) {
643 DEBUG2(qla_printk(KERN_WARNING, ha,
644 "Abort failed -- %lx\n", sp->cmd->serial_number));
645 } else {
646 if (qla2x00_eh_wait_on_command(ha, sp->cmd) !=
647 QLA_SUCCESS)
648 DEBUG2(qla_printk(KERN_WARNING, ha,
649 "Abort failed while waiting -- %lx\n",
650 sp->cmd->serial_number));
651
652 }
653 spin_lock_irqsave(&pha->hardware_lock, flags);
654 }
655 spin_unlock_irqrestore(&pha->hardware_lock, flags);
656}
657
Andrew Vasquez07db5182006-10-02 12:00:49 -0700658static void
659qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
660{
661 struct Scsi_Host *shost = cmnd->device->host;
662 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
663 unsigned long flags;
664
665 spin_lock_irqsave(shost->host_lock, flags);
666 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
667 spin_unlock_irqrestore(shost->host_lock, flags);
668 msleep(1000);
669 spin_lock_irqsave(shost->host_lock, flags);
670 }
671 spin_unlock_irqrestore(shost->host_lock, flags);
672 return;
673}
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675/**************************************************************************
676* qla2xxx_eh_abort
677*
678* Description:
679* The abort function will abort the specified command.
680*
681* Input:
682* cmd = Linux SCSI command packet to be aborted.
683*
684* Returns:
685* Either SUCCESS or FAILED.
686*
687* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700688* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800690static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691qla2xxx_eh_abort(struct scsi_cmnd *cmd)
692{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700693 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500694 srb_t *sp;
695 int ret, i;
696 unsigned int id, lun;
697 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700698 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700699 int wait = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700700 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Andrew Vasquez07db5182006-10-02 12:00:49 -0700702 qla2x00_block_error_handler(cmd);
703
f4f051e2005-04-17 15:02:26 -0500704 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700705 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Michael Reed2ea00202006-04-27 16:25:30 -0700707 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
f4f051e2005-04-17 15:02:26 -0500709 id = cmd->device->id;
710 lun = cmd->device->lun;
711 serial = cmd->serial_number;
712
713 /* Check active list for command command. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700714 spin_lock_irqsave(&pha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500715 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700716 sp = pha->outstanding_cmds[i];
f4f051e2005-04-17 15:02:26 -0500717
718 if (sp == NULL)
719 continue;
720
721 if (sp->cmd != cmd)
722 continue;
723
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700724 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld.\n",
725 __func__, ha->host_no, sp, serial));
f4f051e2005-04-17 15:02:26 -0500726
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700727 spin_unlock_irqrestore(&pha->hardware_lock, flags);
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700728 if (ha->isp_ops->abort_command(ha, sp)) {
f4f051e2005-04-17 15:02:26 -0500729 DEBUG2(printk("%s(%ld): abort_command "
730 "mbx failed.\n", __func__, ha->host_no));
731 } else {
732 DEBUG3(printk("%s(%ld): abort_command "
733 "mbx success.\n", __func__, ha->host_no));
Michael Reed2ea00202006-04-27 16:25:30 -0700734 wait = 1;
f4f051e2005-04-17 15:02:26 -0500735 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700736 spin_lock_irqsave(&pha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500737
738 break;
739 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700740 spin_unlock_irqrestore(&pha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500741
742 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700743 if (wait) {
f4f051e2005-04-17 15:02:26 -0500744 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700745 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500746 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
747 "%x.\n", ha->host_no, id, lun, serial, ret);
Michael Reed2ea00202006-04-27 16:25:30 -0700748 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700752 qla_printk(KERN_INFO, ha,
Michael Reed2ea00202006-04-27 16:25:30 -0700753 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
754 ha->host_no, id, lun, wait, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
f4f051e2005-04-17 15:02:26 -0500756 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757}
758
Andrew Vasquez523ec772008-04-03 13:13:24 -0700759enum nexus_wait_type {
760 WAIT_HOST = 0,
761 WAIT_TARGET,
762 WAIT_LUN,
763};
764
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700766qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha, unsigned int t,
767 unsigned int l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700769 int cnt, match, status;
770 srb_t *sp;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700771 unsigned long flags;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700772 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Andrew Vasquez523ec772008-04-03 13:13:24 -0700774 status = QLA_SUCCESS;
775 spin_lock_irqsave(&pha->hardware_lock, flags);
776 for (cnt = 1; status == QLA_SUCCESS && cnt < MAX_OUTSTANDING_COMMANDS;
777 cnt++) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700778 sp = pha->outstanding_cmds[cnt];
Andrew Vasquez523ec772008-04-03 13:13:24 -0700779 if (!sp)
780 continue;
Andrew Vasquez19851f12008-08-13 21:37:00 -0700781
782 if (ha->vp_idx != sp->fcport->ha->vp_idx)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700783 continue;
784 match = 0;
785 switch (type) {
786 case WAIT_HOST:
787 match = 1;
788 break;
789 case WAIT_TARGET:
790 match = sp->cmd->device->id == t;
791 break;
792 case WAIT_LUN:
793 match = (sp->cmd->device->id == t &&
794 sp->cmd->device->lun == l);
795 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 }
Andrew Vasquez523ec772008-04-03 13:13:24 -0700797 if (!match)
798 continue;
799
800 spin_unlock_irqrestore(&pha->hardware_lock, flags);
801 status = qla2x00_eh_wait_on_command(ha, sp->cmd);
802 spin_lock_irqsave(&pha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 }
Andrew Vasquez523ec772008-04-03 13:13:24 -0700804 spin_unlock_irqrestore(&pha->hardware_lock, flags);
805
806 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807}
808
Andrew Vasquez523ec772008-04-03 13:13:24 -0700809static char *reset_errors[] = {
810 "HBA not online",
811 "HBA not ready",
812 "Task management failed",
813 "Waiting for command completions",
814};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
Andrew Vasquez523ec772008-04-03 13:13:24 -0700816static int
817__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
818 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int))
819{
820 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
821 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
822 int err;
823
824 qla2x00_block_error_handler(cmd);
825
826 if (!fcport)
827 return FAILED;
828
829 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
830 ha->host_no, cmd->device->id, cmd->device->lun, name);
831
832 err = 0;
833 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
834 goto eh_reset_failed;
835 err = 1;
836 if (qla2x00_wait_for_loop_ready(ha) != QLA_SUCCESS)
837 goto eh_reset_failed;
838 err = 2;
839 if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS)
840 goto eh_reset_failed;
841 err = 3;
842 if (qla2x00_eh_wait_for_pending_commands(ha, cmd->device->id,
843 cmd->device->lun, type) != QLA_SUCCESS)
844 goto eh_reset_failed;
845
846 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
847 ha->host_no, cmd->device->id, cmd->device->lun, name);
848
849 return SUCCESS;
850
851 eh_reset_failed:
852 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n",
853 ha->host_no, cmd->device->id, cmd->device->lun, name,
854 reset_errors[err]);
855 return FAILED;
856}
857
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800858static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
860{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700861 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Andrew Vasquez523ec772008-04-03 13:13:24 -0700863 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
864 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865}
866
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700868qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700870 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
Andrew Vasquez523ec772008-04-03 13:13:24 -0700872 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
873 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874}
875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876/**************************************************************************
877* qla2xxx_eh_bus_reset
878*
879* Description:
880* The bus reset function will reset the bus and abort any executing
881* commands.
882*
883* Input:
884* cmd = Linux SCSI command packet of the command that cause the
885* bus reset.
886*
887* Returns:
888* SUCCESS/FAILURE (defined as macro in scsi.h).
889*
890**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800891static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
893{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700894 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700895 scsi_qla_host_t *pha = to_qla_parent(ha);
bdf79622005-04-17 15:06:53 -0500896 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700897 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500898 unsigned int id, lun;
899 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
Andrew Vasquez07db5182006-10-02 12:00:49 -0700901 qla2x00_block_error_handler(cmd);
902
f4f051e2005-04-17 15:02:26 -0500903 id = cmd->device->id;
904 lun = cmd->device->lun;
905 serial = cmd->serial_number;
906
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700907 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500908 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500911 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
914 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500915 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 }
917
918 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500919 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
920 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 }
f4f051e2005-04-17 15:02:26 -0500922 if (ret == FAILED)
923 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700925 /* Flush outstanding commands. */
Andrew Vasquez523ec772008-04-03 13:13:24 -0700926 if (qla2x00_eh_wait_for_pending_commands(pha, 0, 0, WAIT_HOST) !=
927 QLA_SUCCESS)
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700928 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
f4f051e2005-04-17 15:02:26 -0500930eh_bus_reset_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500932 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
f4f051e2005-04-17 15:02:26 -0500934 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935}
936
937/**************************************************************************
938* qla2xxx_eh_host_reset
939*
940* Description:
941* The reset function will reset the Adapter.
942*
943* Input:
944* cmd = Linux SCSI command packet of the command that cause the
945* adapter reset.
946*
947* Returns:
948* Either SUCCESS or FAILED.
949*
950* Note:
951**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800952static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
954{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700955 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500956 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700957 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500958 unsigned int id, lun;
959 unsigned long serial;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700960 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Andrew Vasquez07db5182006-10-02 12:00:49 -0700962 qla2x00_block_error_handler(cmd);
963
f4f051e2005-04-17 15:02:26 -0500964 id = cmd->device->id;
965 lun = cmd->device->lun;
966 serial = cmd->serial_number;
967
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700968 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500969 return ret;
970
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500972 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500975 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 /*
978 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700979 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 * be completed and then issue big hammer.Otherwise
981 * it may cause I/O failure as big hammer marks the
982 * devices as lost kicking of the port_down_timer
983 * while dpc is stuck for the mailbox to complete.
984 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 qla2x00_wait_for_loop_ready(ha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700986 set_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
987 if (qla2x00_abort_isp(pha)) {
988 clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 /* failed. schedule dpc to try */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700990 set_bit(ISP_ABORT_NEEDED, &pha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
992 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500993 goto eh_host_reset_lock;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700994 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700995 clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 /* Waiting for our command in done_queue to be returned to OS.*/
Andrew Vasquez523ec772008-04-03 13:13:24 -0700998 if (qla2x00_eh_wait_for_pending_commands(pha, 0, 0, WAIT_HOST) ==
999 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001000 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001002 if (ha->parent)
1003 qla2x00_vp_abort_isp(ha);
1004
f4f051e2005-04-17 15:02:26 -05001005eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001006 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1007 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
f4f051e2005-04-17 15:02:26 -05001009 return ret;
1010}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
1012/*
1013* qla2x00_loop_reset
1014* Issue loop reset.
1015*
1016* Input:
1017* ha = adapter block pointer.
1018*
1019* Returns:
1020* 0 = success
1021*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001022int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023qla2x00_loop_reset(scsi_qla_host_t *ha)
1024{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001025 int ret;
bdf79622005-04-17 15:06:53 -05001026 struct fc_port *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001028 if (ha->flags.enable_lip_full_login) {
1029 ret = qla2x00_full_login_lip(ha);
1030 if (ret != QLA_SUCCESS) {
1031 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1032 "full_login_lip=%d.\n", __func__, ha->host_no,
1033 ret));
1034 }
1035 atomic_set(&ha->loop_state, LOOP_DOWN);
1036 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
1037 qla2x00_mark_all_devices_lost(ha, 0);
1038 qla2x00_wait_for_loop_ready(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 }
1040
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001041 if (ha->flags.enable_lip_reset) {
1042 ret = qla2x00_lip_reset(ha);
1043 if (ret != QLA_SUCCESS) {
1044 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1045 "lip_reset=%d.\n", __func__, ha->host_no, ret));
1046 }
1047 qla2x00_wait_for_loop_ready(ha);
1048 }
1049
1050 if (ha->flags.enable_target_reset) {
bdf79622005-04-17 15:06:53 -05001051 list_for_each_entry(fcport, &ha->fcports, list) {
1052 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 continue;
1054
Andrew Vasquez523ec772008-04-03 13:13:24 -07001055 ret = ha->isp_ops->target_reset(fcport, 0);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001056 if (ret != QLA_SUCCESS) {
1057 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1058 "target_reset=%d d_id=%x.\n", __func__,
1059 ha->host_no, ret, fcport->d_id.b24));
1060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 }
1062 }
1063
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 /* Issue marker command only when we are going to start the I/O */
1065 ha->marker_needed = 1;
1066
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001067 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068}
1069
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001070void
1071qla2x00_abort_all_cmds(scsi_qla_host_t *ha, int res)
1072{
1073 int cnt;
1074 unsigned long flags;
1075 srb_t *sp;
1076
1077 spin_lock_irqsave(&ha->hardware_lock, flags);
1078 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1079 sp = ha->outstanding_cmds[cnt];
1080 if (sp) {
1081 ha->outstanding_cmds[cnt] = NULL;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001082 sp->cmd->result = res;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001083 qla2x00_sp_compl(ha, sp);
1084 }
1085 }
1086 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1087}
1088
f4f051e2005-04-17 15:02:26 -05001089static int
1090qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
bdf79622005-04-17 15:06:53 -05001092 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001094 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001095 return -ENXIO;
1096
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001097 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001098
1099 return 0;
1100}
1101
1102static int
1103qla2xxx_slave_configure(struct scsi_device *sdev)
1104{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001105 scsi_qla_host_t *ha = shost_priv(sdev->host);
8482e1182005-04-17 15:04:54 -05001106 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1107
f4f051e2005-04-17 15:02:26 -05001108 if (sdev->tagged_supported)
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001109 scsi_activate_tcq(sdev, ha->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 else
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001111 scsi_deactivate_tcq(sdev, ha->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
Andrew Vasquez85821c92008-07-10 16:55:48 -07001113 rport->dev_loss_tmo = ha->port_down_retry_count;
8482e1182005-04-17 15:04:54 -05001114
f4f051e2005-04-17 15:02:26 -05001115 return 0;
1116}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
f4f051e2005-04-17 15:02:26 -05001118static void
1119qla2xxx_slave_destroy(struct scsi_device *sdev)
1120{
1121 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122}
1123
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001124static int
1125qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1126{
1127 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1128 return sdev->queue_depth;
1129}
1130
1131static int
1132qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1133{
1134 if (sdev->tagged_supported) {
1135 scsi_set_tag_type(sdev, tag_type);
1136 if (tag_type)
1137 scsi_activate_tcq(sdev, sdev->queue_depth);
1138 else
1139 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1140 } else
1141 tag_type = 0;
1142
1143 return tag_type;
1144}
1145
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146/**
1147 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1148 * @ha: HA context
1149 *
1150 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1151 * supported addressing method.
1152 */
1153static void
1154qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1155{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001156 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001159 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1160 /* Any upper-dword bits set? */
1161 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1162 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1163 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001165 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1166 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001167 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001170
1171 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1172 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173}
1174
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001175static void
1176qla2x00_enable_intrs(scsi_qla_host_t *ha)
1177{
1178 unsigned long flags = 0;
1179 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1180
1181 spin_lock_irqsave(&ha->hardware_lock, flags);
1182 ha->interrupts_on = 1;
1183 /* enable risc and host interrupts */
1184 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1185 RD_REG_WORD(&reg->ictrl);
1186 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1187
1188}
1189
1190static void
1191qla2x00_disable_intrs(scsi_qla_host_t *ha)
1192{
1193 unsigned long flags = 0;
1194 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1195
1196 spin_lock_irqsave(&ha->hardware_lock, flags);
1197 ha->interrupts_on = 0;
1198 /* disable risc and host interrupts */
1199 WRT_REG_WORD(&reg->ictrl, 0);
1200 RD_REG_WORD(&reg->ictrl);
1201 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1202}
1203
1204static void
1205qla24xx_enable_intrs(scsi_qla_host_t *ha)
1206{
1207 unsigned long flags = 0;
1208 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1209
1210 spin_lock_irqsave(&ha->hardware_lock, flags);
1211 ha->interrupts_on = 1;
1212 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1213 RD_REG_DWORD(&reg->ictrl);
1214 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1215}
1216
1217static void
1218qla24xx_disable_intrs(scsi_qla_host_t *ha)
1219{
1220 unsigned long flags = 0;
1221 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1222
1223 spin_lock_irqsave(&ha->hardware_lock, flags);
1224 ha->interrupts_on = 0;
1225 WRT_REG_DWORD(&reg->ictrl, 0);
1226 RD_REG_DWORD(&reg->ictrl);
1227 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1228}
1229
1230static struct isp_operations qla2100_isp_ops = {
1231 .pci_config = qla2100_pci_config,
1232 .reset_chip = qla2x00_reset_chip,
1233 .chip_diag = qla2x00_chip_diag,
1234 .config_rings = qla2x00_config_rings,
1235 .reset_adapter = qla2x00_reset_adapter,
1236 .nvram_config = qla2x00_nvram_config,
1237 .update_fw_options = qla2x00_update_fw_options,
1238 .load_risc = qla2x00_load_risc,
1239 .pci_info_str = qla2x00_pci_info_str,
1240 .fw_version_str = qla2x00_fw_version_str,
1241 .intr_handler = qla2100_intr_handler,
1242 .enable_intrs = qla2x00_enable_intrs,
1243 .disable_intrs = qla2x00_disable_intrs,
1244 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001245 .target_reset = qla2x00_abort_target,
1246 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001247 .fabric_login = qla2x00_login_fabric,
1248 .fabric_logout = qla2x00_fabric_logout,
1249 .calc_req_entries = qla2x00_calc_iocbs_32,
1250 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1251 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1252 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1253 .read_nvram = qla2x00_read_nvram_data,
1254 .write_nvram = qla2x00_write_nvram_data,
1255 .fw_dump = qla2100_fw_dump,
1256 .beacon_on = NULL,
1257 .beacon_off = NULL,
1258 .beacon_blink = NULL,
1259 .read_optrom = qla2x00_read_optrom_data,
1260 .write_optrom = qla2x00_write_optrom_data,
1261 .get_flash_version = qla2x00_get_flash_version,
1262};
1263
1264static struct isp_operations qla2300_isp_ops = {
1265 .pci_config = qla2300_pci_config,
1266 .reset_chip = qla2x00_reset_chip,
1267 .chip_diag = qla2x00_chip_diag,
1268 .config_rings = qla2x00_config_rings,
1269 .reset_adapter = qla2x00_reset_adapter,
1270 .nvram_config = qla2x00_nvram_config,
1271 .update_fw_options = qla2x00_update_fw_options,
1272 .load_risc = qla2x00_load_risc,
1273 .pci_info_str = qla2x00_pci_info_str,
1274 .fw_version_str = qla2x00_fw_version_str,
1275 .intr_handler = qla2300_intr_handler,
1276 .enable_intrs = qla2x00_enable_intrs,
1277 .disable_intrs = qla2x00_disable_intrs,
1278 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001279 .target_reset = qla2x00_abort_target,
1280 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001281 .fabric_login = qla2x00_login_fabric,
1282 .fabric_logout = qla2x00_fabric_logout,
1283 .calc_req_entries = qla2x00_calc_iocbs_32,
1284 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1285 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1286 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1287 .read_nvram = qla2x00_read_nvram_data,
1288 .write_nvram = qla2x00_write_nvram_data,
1289 .fw_dump = qla2300_fw_dump,
1290 .beacon_on = qla2x00_beacon_on,
1291 .beacon_off = qla2x00_beacon_off,
1292 .beacon_blink = qla2x00_beacon_blink,
1293 .read_optrom = qla2x00_read_optrom_data,
1294 .write_optrom = qla2x00_write_optrom_data,
1295 .get_flash_version = qla2x00_get_flash_version,
1296};
1297
1298static struct isp_operations qla24xx_isp_ops = {
1299 .pci_config = qla24xx_pci_config,
1300 .reset_chip = qla24xx_reset_chip,
1301 .chip_diag = qla24xx_chip_diag,
1302 .config_rings = qla24xx_config_rings,
1303 .reset_adapter = qla24xx_reset_adapter,
1304 .nvram_config = qla24xx_nvram_config,
1305 .update_fw_options = qla24xx_update_fw_options,
1306 .load_risc = qla24xx_load_risc,
1307 .pci_info_str = qla24xx_pci_info_str,
1308 .fw_version_str = qla24xx_fw_version_str,
1309 .intr_handler = qla24xx_intr_handler,
1310 .enable_intrs = qla24xx_enable_intrs,
1311 .disable_intrs = qla24xx_disable_intrs,
1312 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001313 .target_reset = qla24xx_abort_target,
1314 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001315 .fabric_login = qla24xx_login_fabric,
1316 .fabric_logout = qla24xx_fabric_logout,
1317 .calc_req_entries = NULL,
1318 .build_iocbs = NULL,
1319 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1320 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1321 .read_nvram = qla24xx_read_nvram_data,
1322 .write_nvram = qla24xx_write_nvram_data,
1323 .fw_dump = qla24xx_fw_dump,
1324 .beacon_on = qla24xx_beacon_on,
1325 .beacon_off = qla24xx_beacon_off,
1326 .beacon_blink = qla24xx_beacon_blink,
1327 .read_optrom = qla24xx_read_optrom_data,
1328 .write_optrom = qla24xx_write_optrom_data,
1329 .get_flash_version = qla24xx_get_flash_version,
1330};
1331
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001332static struct isp_operations qla25xx_isp_ops = {
1333 .pci_config = qla25xx_pci_config,
1334 .reset_chip = qla24xx_reset_chip,
1335 .chip_diag = qla24xx_chip_diag,
1336 .config_rings = qla24xx_config_rings,
1337 .reset_adapter = qla24xx_reset_adapter,
1338 .nvram_config = qla24xx_nvram_config,
1339 .update_fw_options = qla24xx_update_fw_options,
1340 .load_risc = qla24xx_load_risc,
1341 .pci_info_str = qla24xx_pci_info_str,
1342 .fw_version_str = qla24xx_fw_version_str,
1343 .intr_handler = qla24xx_intr_handler,
1344 .enable_intrs = qla24xx_enable_intrs,
1345 .disable_intrs = qla24xx_disable_intrs,
1346 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001347 .target_reset = qla24xx_abort_target,
1348 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001349 .fabric_login = qla24xx_login_fabric,
1350 .fabric_logout = qla24xx_fabric_logout,
1351 .calc_req_entries = NULL,
1352 .build_iocbs = NULL,
1353 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1354 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1355 .read_nvram = qla25xx_read_nvram_data,
1356 .write_nvram = qla25xx_write_nvram_data,
1357 .fw_dump = qla25xx_fw_dump,
1358 .beacon_on = qla24xx_beacon_on,
1359 .beacon_off = qla24xx_beacon_off,
1360 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001361 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001362 .write_optrom = qla24xx_write_optrom_data,
1363 .get_flash_version = qla24xx_get_flash_version,
1364};
1365
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001366static inline void
1367qla2x00_set_isp_flags(scsi_qla_host_t *ha)
1368{
1369 ha->device_type = DT_EXTENDED_IDS;
1370 switch (ha->pdev->device) {
1371 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1372 ha->device_type |= DT_ISP2100;
1373 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001374 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001375 break;
1376 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1377 ha->device_type |= DT_ISP2200;
1378 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001379 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001380 break;
1381 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1382 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001383 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001384 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001385 break;
1386 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1387 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001388 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001389 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001390 break;
1391 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1392 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001393 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001394 if (ha->pdev->subsystem_vendor == 0x1028 &&
1395 ha->pdev->subsystem_device == 0x0170)
1396 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001397 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001398 break;
1399 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1400 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001401 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001402 break;
1403 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1404 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001405 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001406 break;
1407 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1408 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001409 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001410 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001411 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001412 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001413 break;
1414 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1415 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001416 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001417 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001418 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001419 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001420 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001421 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1422 ha->device_type |= DT_ISP8432;
1423 ha->device_type |= DT_ZIO_SUPPORTED;
1424 ha->device_type |= DT_FWI2;
1425 ha->device_type |= DT_IIDMA;
1426 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1427 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001428 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1429 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001430 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001431 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001432 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001433 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1434 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001435 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001436 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001437 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001438 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1439 ha->device_type |= DT_ISP2532;
1440 ha->device_type |= DT_ZIO_SUPPORTED;
1441 ha->device_type |= DT_FWI2;
1442 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001443 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1444 break;
1445 }
1446}
1447
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448static int
1449qla2x00_iospace_config(scsi_qla_host_t *ha)
1450{
Andrew Vasquez37765412008-01-17 09:02:09 -08001451 resource_size_t pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Andrew Vasquez285d0322007-10-19 15:59:17 -07001453 if (pci_request_selected_regions(ha->pdev, ha->bars,
1454 QLA2XXX_DRIVER_NAME)) {
1455 qla_printk(KERN_WARNING, ha,
1456 "Failed to reserve PIO/MMIO regions (%s)\n",
1457 pci_name(ha->pdev));
1458
1459 goto iospace_error_exit;
1460 }
1461 if (!(ha->bars & 1))
1462 goto skip_pio;
1463
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1465 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001466 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1467 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 qla_printk(KERN_WARNING, ha,
1469 "Invalid PCI I/O region size (%s)...\n",
1470 pci_name(ha->pdev));
1471 pio = 0;
1472 }
1473 } else {
1474 qla_printk(KERN_WARNING, ha,
1475 "region #0 not a PIO resource (%s)...\n",
1476 pci_name(ha->pdev));
1477 pio = 0;
1478 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001479 ha->pio_address = pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Andrew Vasquez285d0322007-10-19 15:59:17 -07001481skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001483 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 qla_printk(KERN_ERR, ha,
Andrew Vasquez37765412008-01-17 09:02:09 -08001485 "region #1 not an MMIO resource (%s), aborting\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 pci_name(ha->pdev));
1487 goto iospace_error_exit;
1488 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001489 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 qla_printk(KERN_ERR, ha,
1491 "Invalid PCI mem region size (%s), aborting\n",
1492 pci_name(ha->pdev));
1493 goto iospace_error_exit;
1494 }
1495
Andrew Vasquez37765412008-01-17 09:02:09 -08001496 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 if (!ha->iobase) {
1498 qla_printk(KERN_ERR, ha,
1499 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1500
1501 goto iospace_error_exit;
1502 }
1503
1504 return (0);
1505
1506iospace_error_exit:
1507 return (-ENOMEM);
1508}
1509
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001510static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001511qla2xxx_scan_start(struct Scsi_Host *shost)
1512{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001513 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001514
1515 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1516 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1517 set_bit(RSCN_UPDATE, &ha->dpc_flags);
Andrew Vasquez272976c2008-09-11 21:22:50 -07001518 set_bit(NPIV_CONFIG_NEEDED, &ha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001519}
1520
1521static int
1522qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1523{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001524 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001525
1526 if (!ha->host)
1527 return 1;
1528 if (time > ha->loop_reset_delay * HZ)
1529 return 1;
1530
1531 return atomic_read(&ha->loop_state) == LOOP_READY;
1532}
1533
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534/*
1535 * PCI driver interface
1536 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001537static int __devinit
1538qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001540 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 struct Scsi_Host *host;
1542 scsi_qla_host_t *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001543 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001545 struct scsi_host_template *sht;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001546 int bars, mem_only = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Andrew Vasquez285d0322007-10-19 15:59:17 -07001548 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1549 sht = &qla2x00_driver_template;
1550 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1551 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001552 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001553 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1554 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1555 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532) {
1556 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1557 sht = &qla24xx_driver_template;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001558 mem_only = 1;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001559 }
1560
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001561 if (mem_only) {
1562 if (pci_enable_device_mem(pdev))
1563 goto probe_out;
1564 } else {
1565 if (pci_enable_device(pdev))
1566 goto probe_out;
1567 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
Jesse Barnes09276782008-10-18 17:33:19 -07001569 /* This may fail but that's ok */
1570 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07001571
Andrew Vasquez54333832005-11-09 15:49:04 -08001572 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 if (host == NULL) {
1574 printk(KERN_WARNING
1575 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1576 goto probe_disable_device;
1577 }
1578
1579 /* Clear our data area */
Andrew Vasquezf363b942007-09-20 14:07:45 -07001580 ha = shost_priv(host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 memset(ha, 0, sizeof(scsi_qla_host_t));
1582
1583 ha->pdev = pdev;
1584 ha->host = host;
1585 ha->host_no = host->host_no;
Andrew Vasquezcb630672006-05-17 15:09:45 -07001586 sprintf(ha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, ha->host_no);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001587 ha->parent = NULL;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001588 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001589 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001590 spin_lock_init(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001592 /* Set ISP-type information. */
1593 qla2x00_set_isp_flags(ha);
1594
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 /* Configure PCI I/O space */
1596 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001597 if (ret)
1598 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08001601 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1602 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001605 ha->init_cb_size = sizeof(init_cb_t);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001606 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER + ha->vp_idx;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001607 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001608 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001610 ha->max_q_depth = MAX_Q_DEPTH;
1611 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1612 ha->max_q_depth = ql2xmaxqdepth;
1613
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001614 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 if (IS_QLA2100(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001616 host->max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1618 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1619 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1620 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1621 host->sg_tablesize = 32;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001622 ha->gid_list_info_size = 4;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001623 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 } else if (IS_QLA2200(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001625 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1627 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1628 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1629 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001630 ha->gid_list_info_size = 4;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001631 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001632 } else if (IS_QLA23XX(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001633 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1635 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1636 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1637 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001638 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001639 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1640 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001641 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001642 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07001643 host->max_id = MAX_TARGETS_2200;
1644 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1645 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1646 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1647 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001648 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1649 ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001650 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001651 ha->optrom_size = OPTROM_SIZE_24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001652 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001653 } else if (IS_QLA25XX(ha)) {
1654 host->max_id = MAX_TARGETS_2200;
1655 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1656 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1657 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1658 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1659 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1660 ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
1661 ha->gid_list_info_size = 8;
1662 ha->optrom_size = OPTROM_SIZE_25XX;
1663 ha->isp_ops = &qla25xx_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 }
1665 host->can_queue = ha->request_q_length + 128;
1666
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07001667 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001668 init_completion(&ha->mbx_cmd_comp);
1669 complete(&ha->mbx_cmd_comp);
1670 init_completion(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
1672 INIT_LIST_HEAD(&ha->list);
1673 INIT_LIST_HEAD(&ha->fcports);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001674 INIT_LIST_HEAD(&ha->vp_list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07001675 INIT_LIST_HEAD(&ha->work_list);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001676
1677 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 qla2x00_config_dma_addressing(ha);
1680 if (qla2x00_mem_alloc(ha)) {
1681 qla_printk(KERN_WARNING, ha,
1682 "[ERROR] Failed to allocate memory for adapter\n");
1683
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001684 ret = -ENOMEM;
1685 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 }
1687
Andrew Vasquez765140b2007-05-07 07:42:58 -07001688 if (qla2x00_initialize_adapter(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 qla_printk(KERN_WARNING, ha,
1690 "Failed to initialize adapter\n");
1691
1692 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1693 "Adapter flags %x.\n",
1694 ha->host_no, ha->device_flags));
1695
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001696 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 goto probe_failed;
1698 }
1699
1700 /*
1701 * Startup the kernel thread for this host adapter
1702 */
Christoph Hellwig39a11242006-02-14 18:46:22 +01001703 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1704 "%s_dpc", ha->host_str);
1705 if (IS_ERR(ha->dpc_thread)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 qla_printk(KERN_WARNING, ha,
1707 "Unable to start DPC thread!\n");
Christoph Hellwig39a11242006-02-14 18:46:22 +01001708 ret = PTR_ERR(ha->dpc_thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 goto probe_failed;
1710 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001712 host->this_id = 255;
1713 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07001714 host->unique_id = host->host_no;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001715 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001716 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001717 host->max_lun = MAX_LUNS;
1718 host->transportt = qla2xxx_transport_template;
1719
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001720 ret = qla2x00_request_irqs(ha);
1721 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
1724 /* Initialized the timer */
1725 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1726
1727 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1728 ha->host_no, ha));
1729
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001730 pci_set_drvdata(pdev, ha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001731
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 ha->flags.init_done = 1;
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001733 ha->flags.online = 1;
1734
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001735 ret = scsi_add_host(host, &pdev->dev);
1736 if (ret)
1737 goto probe_failed;
1738
Andrew Vasquez048feec2008-09-11 22:19:45 -07001739 ha->isp_ops->enable_intrs(ha);
1740
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001741 scsi_scan_host(host);
1742
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001743 qla2x00_alloc_sysfs_attr(ha);
1744
1745 qla2x00_init_host_attr(ha);
1746
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001747 qla2x00_dfs_setup(ha);
1748
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 qla_printk(KERN_INFO, ha, "\n"
1750 " QLogic Fibre Channel HBA Driver: %s\n"
1751 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08001752 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1753 qla2x00_version_str, ha->model_number,
1754 ha->model_desc ? ha->model_desc: "", pdev->device,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001755 ha->isp_ops->pci_info_str(ha, pci_info), pci_name(pdev),
Andrew Vasquez54333832005-11-09 15:49:04 -08001756 ha->flags.enable_64bit_addressing ? '+': '-', ha->host_no,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001757 ha->isp_ops->fw_version_str(ha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 return 0;
1760
1761probe_failed:
1762 qla2x00_free_device(ha);
1763
1764 scsi_host_put(host);
1765
1766probe_disable_device:
1767 pci_disable_device(pdev);
1768
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001769probe_out:
1770 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
Adrian Bunk4c993f72008-01-14 00:55:16 -08001773static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001774qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775{
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07001776 scsi_qla_host_t *ha, *vha, *temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
1778 ha = pci_get_drvdata(pdev);
1779
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07001780 list_for_each_entry_safe(vha, temp, &ha->vp_list, vp_list)
1781 fc_vport_terminate(vha->fc_vport);
1782
1783 set_bit(UNLOADING, &ha->dpc_flags);
1784
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001785 qla2x00_dfs_remove(ha);
1786
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001787 qla84xx_put_chip(ha);
1788
8482e1182005-04-17 15:04:54 -05001789 qla2x00_free_sysfs_attr(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
bdf79622005-04-17 15:06:53 -05001791 fc_remove_host(ha->host);
1792
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 scsi_remove_host(ha->host);
1794
1795 qla2x00_free_device(ha);
1796
1797 scsi_host_put(ha->host);
1798
Bernhard Walle665db932007-03-28 00:49:49 +02001799 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 pci_set_drvdata(pdev, NULL);
1801}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802
1803static void
1804qla2x00_free_device(scsi_qla_host_t *ha)
1805{
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001806 qla2x00_abort_all_cmds(ha, DID_NO_CONNECT << 16);
1807
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 /* Disable timer */
1809 if (ha->timer_active)
1810 qla2x00_stop_timer(ha);
1811
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001812 ha->flags.online = 0;
1813
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 /* Kill the kernel thread for this host */
Christoph Hellwig39a11242006-02-14 18:46:22 +01001815 if (ha->dpc_thread) {
1816 struct task_struct *t = ha->dpc_thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817
Christoph Hellwig39a11242006-02-14 18:46:22 +01001818 /*
1819 * qla2xxx_wake_dpc checks for ->dpc_thread
1820 * so we need to zero it out.
1821 */
1822 ha->dpc_thread = NULL;
1823 kthread_stop(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 }
1825
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001826 if (ha->flags.fce_enabled)
1827 qla2x00_disable_fce_trace(ha, NULL, NULL);
1828
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001829 if (ha->eft)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08001830 qla2x00_disable_eft_trace(ha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001831
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001832 /* Stop currently executing firmware. */
Andrew Vasquez18c6c122006-10-13 09:33:38 -07001833 qla2x00_try_to_stop_firmware(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001835 /* turn-off interrupts on the card */
1836 if (ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001837 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001838
1839 qla2x00_mem_free(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001841 qla2x00_free_irqs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
1843 /* release io space registers */
1844 if (ha->iobase)
1845 iounmap(ha->iobase);
Andrew Vasquez285d0322007-10-19 15:59:17 -07001846 pci_release_selected_regions(ha->pdev, ha->bars);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847}
1848
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001849static inline void
1850qla2x00_schedule_rport_del(struct scsi_qla_host *ha, fc_port_t *fcport,
1851 int defer)
1852{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001853 struct fc_rport *rport;
Seokmann Ju5de1f702008-07-10 16:55:58 -07001854 scsi_qla_host_t *pha = to_qla_parent(ha);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001855
1856 if (!fcport->rport)
1857 return;
1858
1859 rport = fcport->rport;
1860 if (defer) {
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001861 spin_lock_irq(ha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001862 fcport->drport = rport;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001863 spin_unlock_irq(ha->host->host_lock);
Seokmann Ju5de1f702008-07-10 16:55:58 -07001864 set_bit(FCPORT_UPDATE_NEEDED, &pha->dpc_flags);
1865 qla2xxx_wake_dpc(pha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001866 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001867 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001868}
1869
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1872 *
1873 * Input: ha = adapter block pointer. fcport = port structure pointer.
1874 *
1875 * Return: None.
1876 *
1877 * Context:
1878 */
1879void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001880 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001882 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1883 ha->vp_idx == fcport->vp_idx)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001884 qla2x00_schedule_rport_del(ha, fcport, defer);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001885
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001886 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 * We may need to retry the login, so don't change the state of the
1888 * port but do the retries.
1889 */
1890 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1891 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1892
1893 if (!do_login)
1894 return;
1895
1896 if (fcport->login_retry == 0) {
1897 fcport->login_retry = ha->login_retry_count;
1898 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1899
1900 DEBUG(printk("scsi(%ld): Port login retry: "
1901 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1902 "id = 0x%04x retry cnt=%d\n",
1903 ha->host_no,
1904 fcport->port_name[0],
1905 fcport->port_name[1],
1906 fcport->port_name[2],
1907 fcport->port_name[3],
1908 fcport->port_name[4],
1909 fcport->port_name[5],
1910 fcport->port_name[6],
1911 fcport->port_name[7],
1912 fcport->loop_id,
1913 fcport->login_retry));
1914 }
1915}
1916
1917/*
1918 * qla2x00_mark_all_devices_lost
1919 * Updates fcport state when device goes offline.
1920 *
1921 * Input:
1922 * ha = adapter block pointer.
1923 * fcport = port structure pointer.
1924 *
1925 * Return:
1926 * None.
1927 *
1928 * Context:
1929 */
1930void
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001931qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932{
1933 fc_port_t *fcport;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001934 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001936 list_for_each_entry(fcport, &pha->fcports, list) {
Seokmann Ju8f0d6432008-07-10 16:55:56 -07001937 if (ha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 /*
1940 * No point in marking the device as lost, if the device is
1941 * already DEAD.
1942 */
1943 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1944 continue;
Seokmann Ju8f0d6432008-07-10 16:55:56 -07001945 if (atomic_read(&fcport->state) == FCS_ONLINE)
1946 qla2x00_schedule_rport_del(ha, fcport, defer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1948 }
1949}
1950
1951/*
1952* qla2x00_mem_alloc
1953* Allocates adapter memory.
1954*
1955* Returns:
1956* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08001957* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08001959static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960qla2x00_mem_alloc(scsi_qla_host_t *ha)
1961{
1962 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
Andrew Vasqueze8711082008-01-31 12:33:48 -08001964 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
1965 (ha->request_q_length + 1) * sizeof(request_t), &ha->request_dma,
1966 GFP_KERNEL);
1967 if (!ha->request_ring)
1968 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969
Andrew Vasqueze8711082008-01-31 12:33:48 -08001970 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1971 (ha->response_q_length + 1) * sizeof(response_t),
1972 &ha->response_dma, GFP_KERNEL);
1973 if (!ha->response_ring)
1974 goto fail_free_request_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975
Andrew Vasqueze8711082008-01-31 12:33:48 -08001976 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1977 &ha->gid_list_dma, GFP_KERNEL);
1978 if (!ha->gid_list)
1979 goto fail_free_response_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
Andrew Vasqueze8711082008-01-31 12:33:48 -08001981 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
1982 &ha->init_cb_dma, GFP_KERNEL);
1983 if (!ha->init_cb)
1984 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985
Andrew Vasqueze8711082008-01-31 12:33:48 -08001986 snprintf(name, sizeof(name), "%s_%ld", QLA2XXX_DRIVER_NAME,
1987 ha->host_no);
1988 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
1989 DMA_POOL_SIZE, 8, 0);
1990 if (!ha->s_dma_pool)
1991 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992
Andrew Vasqueze8711082008-01-31 12:33:48 -08001993 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
1994 if (!ha->srb_mempool)
1995 goto fail_free_s_dma_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
Andrew Vasqueze8711082008-01-31 12:33:48 -08001997 /* Get memory for cached NVRAM */
1998 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
1999 if (!ha->nvram)
2000 goto fail_free_srb_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
Andrew Vasqueze8711082008-01-31 12:33:48 -08002002 /* Allocate memory for SNS commands */
2003 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2004 /* Get consistent memory allocated for SNS commands */
2005 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2006 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
2007 if (!ha->sns_cmd)
2008 goto fail_free_nvram;
2009 } else {
2010 /* Get consistent memory allocated for MS IOCB */
2011 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2012 &ha->ms_iocb_dma);
2013 if (!ha->ms_iocb)
2014 goto fail_free_nvram;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015
Andrew Vasqueze8711082008-01-31 12:33:48 -08002016 /* Get consistent memory allocated for CT SNS commands */
2017 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2018 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
2019 if (!ha->ct_sns)
2020 goto fail_free_ms_iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 }
2022
Andrew Vasqueze8711082008-01-31 12:33:48 -08002023 return 0;
2024
2025fail_free_ms_iocb:
2026 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2027 ha->ms_iocb = NULL;
2028 ha->ms_iocb_dma = 0;
2029fail_free_nvram:
2030 kfree(ha->nvram);
2031 ha->nvram = NULL;
2032fail_free_srb_mempool:
2033 mempool_destroy(ha->srb_mempool);
2034 ha->srb_mempool = NULL;
2035fail_free_s_dma_pool:
2036 dma_pool_destroy(ha->s_dma_pool);
2037 ha->s_dma_pool = NULL;
2038fail_free_init_cb:
2039 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2040 ha->init_cb_dma);
2041 ha->init_cb = NULL;
2042 ha->init_cb_dma = 0;
2043fail_free_gid_list:
2044 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2045 ha->gid_list_dma);
2046 ha->gid_list = NULL;
2047 ha->gid_list_dma = 0;
2048fail_free_response_ring:
2049 dma_free_coherent(&ha->pdev->dev, (ha->response_q_length + 1) *
2050 sizeof(response_t), ha->response_ring, ha->response_dma);
2051 ha->response_ring = NULL;
2052 ha->response_dma = 0;
2053fail_free_request_ring:
2054 dma_free_coherent(&ha->pdev->dev, (ha->request_q_length + 1) *
2055 sizeof(request_t), ha->request_ring, ha->request_dma);
2056 ha->request_ring = NULL;
2057 ha->request_dma = 0;
2058fail:
2059 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060}
2061
2062/*
2063* qla2x00_mem_free
2064* Frees all adapter allocated memory.
2065*
2066* Input:
2067* ha = adapter block pointer.
2068*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08002069static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070qla2x00_mem_free(scsi_qla_host_t *ha)
2071{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 struct list_head *fcpl, *fcptemp;
2073 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
Andrew Vasqueze8711082008-01-31 12:33:48 -08002075 if (ha->srb_mempool)
2076 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002078 if (ha->fce)
2079 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2080 ha->fce_dma);
2081
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002082 if (ha->fw_dump) {
2083 if (ha->eft)
2084 dma_free_coherent(&ha->pdev->dev,
2085 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2086 vfree(ha->fw_dump);
2087 }
2088
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 if (ha->sns_cmd)
2090 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2091 ha->sns_cmd, ha->sns_cmd_dma);
2092
2093 if (ha->ct_sns)
2094 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2095 ha->ct_sns, ha->ct_sns_dma);
2096
Andrew Vasquez88729e52006-06-23 16:10:50 -07002097 if (ha->sfp_data)
2098 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2099
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 if (ha->ms_iocb)
2101 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2102
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 if (ha->s_dma_pool)
2104 dma_pool_destroy(ha->s_dma_pool);
2105
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002106 if (ha->init_cb)
2107 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2108 ha->init_cb, ha->init_cb_dma);
2109
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 if (ha->gid_list)
2111 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2112 ha->gid_list_dma);
2113
2114 if (ha->response_ring)
2115 dma_free_coherent(&ha->pdev->dev,
2116 (ha->response_q_length + 1) * sizeof(response_t),
2117 ha->response_ring, ha->response_dma);
2118
2119 if (ha->request_ring)
2120 dma_free_coherent(&ha->pdev->dev,
2121 (ha->request_q_length + 1) * sizeof(request_t),
2122 ha->request_ring, ha->request_dma);
2123
Andrew Vasqueze8711082008-01-31 12:33:48 -08002124 ha->srb_mempool = NULL;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002125 ha->eft = NULL;
2126 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 ha->sns_cmd = NULL;
2128 ha->sns_cmd_dma = 0;
2129 ha->ct_sns = NULL;
2130 ha->ct_sns_dma = 0;
2131 ha->ms_iocb = NULL;
2132 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 ha->init_cb = NULL;
2134 ha->init_cb_dma = 0;
2135
2136 ha->s_dma_pool = NULL;
2137
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 ha->gid_list = NULL;
2139 ha->gid_list_dma = 0;
2140
2141 ha->response_ring = NULL;
2142 ha->response_dma = 0;
2143 ha->request_ring = NULL;
2144 ha->request_dma = 0;
2145
2146 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2147 fcport = list_entry(fcpl, fc_port_t, list);
2148
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 /* fc ports */
2150 list_del_init(&fcport->list);
2151 kfree(fcport);
2152 }
2153 INIT_LIST_HEAD(&ha->fcports);
2154
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002156 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 ha->fw_dump_reading = 0;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002158
2159 vfree(ha->optrom_buffer);
Seokmann Ju53772a22007-07-30 11:01:07 -07002160 kfree(ha->nvram);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161}
2162
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002163static struct qla_work_evt *
Andrew Vasquez0971de72008-04-03 13:13:18 -07002164qla2x00_alloc_work(struct scsi_qla_host *ha, enum qla_work_type type,
2165 int locked)
2166{
2167 struct qla_work_evt *e;
2168
2169 e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
2170 GFP_KERNEL);
2171 if (!e)
2172 return NULL;
2173
2174 INIT_LIST_HEAD(&e->list);
2175 e->type = type;
2176 e->flags = QLA_EVT_FLAG_FREE;
2177 return e;
2178}
2179
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002180static int
Andrew Vasquez0971de72008-04-03 13:13:18 -07002181qla2x00_post_work(struct scsi_qla_host *ha, struct qla_work_evt *e, int locked)
2182{
Andrew Mortonbf6583b2008-07-24 08:31:48 -07002183 unsigned long uninitialized_var(flags);
Seokmann Ju08b95a12008-05-19 14:25:40 -07002184 scsi_qla_host_t *pha = to_qla_parent(ha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002185
2186 if (!locked)
Seokmann Ju08b95a12008-05-19 14:25:40 -07002187 spin_lock_irqsave(&pha->hardware_lock, flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002188 list_add_tail(&e->list, &ha->work_list);
2189 qla2xxx_wake_dpc(ha);
2190 if (!locked)
Seokmann Ju08b95a12008-05-19 14:25:40 -07002191 spin_unlock_irqrestore(&pha->hardware_lock, flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002192 return QLA_SUCCESS;
2193}
2194
2195int
2196qla2x00_post_aen_work(struct scsi_qla_host *ha, enum fc_host_event_code code,
2197 u32 data)
2198{
2199 struct qla_work_evt *e;
2200
2201 e = qla2x00_alloc_work(ha, QLA_EVT_AEN, 1);
2202 if (!e)
2203 return QLA_FUNCTION_FAILED;
2204
2205 e->u.aen.code = code;
2206 e->u.aen.data = data;
2207 return qla2x00_post_work(ha, e, 1);
2208}
2209
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002210int
2211qla2x00_post_hwe_work(struct scsi_qla_host *ha, uint16_t code, uint16_t d1,
2212 uint16_t d2, uint16_t d3)
2213{
2214 struct qla_work_evt *e;
2215
2216 e = qla2x00_alloc_work(ha, QLA_EVT_HWE_LOG, 1);
2217 if (!e)
2218 return QLA_FUNCTION_FAILED;
2219
2220 e->u.hwe.code = code;
2221 e->u.hwe.d1 = d1;
2222 e->u.hwe.d2 = d2;
2223 e->u.hwe.d3 = d3;
2224 return qla2x00_post_work(ha, e, 1);
2225}
2226
Andrew Vasquez0971de72008-04-03 13:13:18 -07002227static void
2228qla2x00_do_work(struct scsi_qla_host *ha)
2229{
2230 struct qla_work_evt *e;
Seokmann Ju08b95a12008-05-19 14:25:40 -07002231 scsi_qla_host_t *pha = to_qla_parent(ha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002232
Seokmann Ju08b95a12008-05-19 14:25:40 -07002233 spin_lock_irq(&pha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002234 while (!list_empty(&ha->work_list)) {
2235 e = list_entry(ha->work_list.next, struct qla_work_evt, list);
2236 list_del_init(&e->list);
Seokmann Ju08b95a12008-05-19 14:25:40 -07002237 spin_unlock_irq(&pha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002238
2239 switch (e->type) {
2240 case QLA_EVT_AEN:
2241 fc_host_post_event(ha->host, fc_get_event_number(),
2242 e->u.aen.code, e->u.aen.data);
2243 break;
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002244 case QLA_EVT_HWE_LOG:
2245 qla2xxx_hw_event_log(ha, e->u.hwe.code, e->u.hwe.d1,
2246 e->u.hwe.d2, e->u.hwe.d3);
2247 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002248 }
2249 if (e->flags & QLA_EVT_FLAG_FREE)
2250 kfree(e);
Seokmann Ju08b95a12008-05-19 14:25:40 -07002251 spin_lock_irq(&pha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002252 }
Seokmann Ju08b95a12008-05-19 14:25:40 -07002253 spin_unlock_irq(&pha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002254}
2255
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256/**************************************************************************
2257* qla2x00_do_dpc
2258* This kernel thread is a task that is schedule by the interrupt handler
2259* to perform the background processing for interrupts.
2260*
2261* Notes:
2262* This task always run in the context of a kernel thread. It
2263* is kick-off by the driver's detect code and starts up
2264* up one per adapter. It immediately goes to sleep and waits for
2265* some fibre event. When either the interrupt handler or
2266* the timer routine detects a event it will one of the task
2267* bits then wake us up.
2268**************************************************************************/
2269static int
2270qla2x00_do_dpc(void *data)
2271{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002272 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 scsi_qla_host_t *ha;
2274 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 uint8_t status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 uint16_t next_loopid;
Seokmann Ju99363ef2008-01-31 12:33:51 -08002277 struct scsi_qla_host *vha;
2278 int i;
2279
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
2281 ha = (scsi_qla_host_t *)data;
2282
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 set_user_nice(current, -20);
2284
Christoph Hellwig39a11242006-02-14 18:46:22 +01002285 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2287
Christoph Hellwig39a11242006-02-14 18:46:22 +01002288 set_current_state(TASK_INTERRUPTIBLE);
2289 schedule();
2290 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
2292 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2293
2294 /* Initialization not yet finished. Don't do anything yet. */
Christoph Hellwig39a11242006-02-14 18:46:22 +01002295 if (!ha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 continue;
2297
2298 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2299
2300 ha->dpc_active = 1;
2301
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 ha->dpc_active = 0;
2304 continue;
2305 }
2306
Andrew Vasquez0971de72008-04-03 13:13:18 -07002307 qla2x00_do_work(ha);
2308
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2310
2311 DEBUG(printk("scsi(%ld): dpc: sched "
2312 "qla2x00_abort_isp ha = %p\n",
2313 ha->host_no, ha));
2314 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2315 &ha->dpc_flags))) {
2316
2317 if (qla2x00_abort_isp(ha)) {
2318 /* failed. retry later */
2319 set_bit(ISP_ABORT_NEEDED,
2320 &ha->dpc_flags);
2321 }
2322 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2323 }
Seokmann Ju99363ef2008-01-31 12:33:51 -08002324
2325 for_each_mapped_vp_idx(ha, i) {
2326 list_for_each_entry(vha, &ha->vp_list,
2327 vp_list) {
2328 if (i == vha->vp_idx) {
2329 set_bit(ISP_ABORT_NEEDED,
2330 &vha->dpc_flags);
2331 break;
2332 }
2333 }
2334 }
2335
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2337 ha->host_no));
2338 }
2339
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07002340 if (test_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags)) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002341 qla2x00_update_fcports(ha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07002342 clear_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags);
2343 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002344
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2346 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2347
2348 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2349 ha->host_no));
2350
2351 qla2x00_rst_aen(ha);
2352 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2353 }
2354
2355 /* Retry each device up to login retry count */
2356 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2357 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2358 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2359
2360 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2361 ha->host_no));
2362
2363 next_loopid = 0;
2364 list_for_each_entry(fcport, &ha->fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 /*
2366 * If the port is not ONLINE then try to login
2367 * to it if we haven't run out of retries.
2368 */
2369 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2370 fcport->login_retry) {
2371
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 if (fcport->flags & FCF_FABRIC_DEVICE) {
2373 if (fcport->flags &
2374 FCF_TAPE_PRESENT)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002375 ha->isp_ops->fabric_logout(
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002376 ha, fcport->loop_id,
2377 fcport->d_id.b.domain,
2378 fcport->d_id.b.area,
2379 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 status = qla2x00_fabric_login(
2381 ha, fcport, &next_loopid);
2382 } else
2383 status =
2384 qla2x00_local_device_login(
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08002385 ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386
Ravi Anand63a86512007-09-20 14:07:40 -07002387 fcport->login_retry--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 if (status == QLA_SUCCESS) {
2389 fcport->old_loop_id = fcport->loop_id;
2390
2391 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2392 ha->host_no, fcport->loop_id));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002393
andrew.vasquez@qlogic.com052c40c2006-01-20 14:53:19 -08002394 qla2x00_update_fcport(ha,
2395 fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 } else if (status == 1) {
2397 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2398 /* retry the login again */
2399 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2400 ha->host_no,
2401 fcport->login_retry, fcport->loop_id));
2402 } else {
2403 fcport->login_retry = 0;
2404 }
Andrew Vasquez666301e2008-04-24 15:21:30 -07002405 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
Ravi Anand63a86512007-09-20 14:07:40 -07002406 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 }
2408 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2409 break;
2410 }
2411 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2412 ha->host_no));
2413 }
2414
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2416
2417 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2418 ha->host_no));
2419
2420 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2421 &ha->dpc_flags))) {
2422
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002423 rval = qla2x00_loop_resync(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424
2425 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2426 }
2427
2428 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2429 ha->host_no));
2430 }
2431
Andrew Vasquez272976c2008-09-11 21:22:50 -07002432 if (test_bit(NPIV_CONFIG_NEEDED, &ha->dpc_flags) &&
2433 atomic_read(&ha->loop_state) == LOOP_READY) {
2434 clear_bit(NPIV_CONFIG_NEEDED, &ha->dpc_flags);
2435 qla2xxx_flash_npiv_conf(ha);
2436 }
2437
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002439 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002441 if (test_and_clear_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags))
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002442 ha->isp_ops->beacon_blink(ha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002443
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002444 qla2x00_do_dpc_all_vps(ha);
2445
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 ha->dpc_active = 0;
2447 } /* End of while(1) */
2448
2449 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2450
2451 /*
2452 * Make sure that nobody tries to wake us up again.
2453 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 ha->dpc_active = 0;
2455
Christoph Hellwig39a11242006-02-14 18:46:22 +01002456 return 0;
2457}
2458
2459void
2460qla2xxx_wake_dpc(scsi_qla_host_t *ha)
2461{
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002462 struct task_struct *t = ha->dpc_thread;
2463
2464 if (!test_bit(UNLOADING, &ha->dpc_flags) && t)
2465 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466}
2467
2468/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469* qla2x00_rst_aen
2470* Processes asynchronous reset.
2471*
2472* Input:
2473* ha = adapter block pointer.
2474*/
2475static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002476qla2x00_rst_aen(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477{
2478 if (ha->flags.online && !ha->flags.reset_active &&
2479 !atomic_read(&ha->loop_down_timer) &&
2480 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2481 do {
2482 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2483
2484 /*
2485 * Issue marker command only when we are going to start
2486 * the I/O.
2487 */
2488 ha->marker_needed = 1;
2489 } while (!atomic_read(&ha->loop_down_timer) &&
2490 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2491 }
2492}
2493
f4f051e2005-04-17 15:02:26 -05002494static void
2495qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2496{
2497 struct scsi_cmnd *cmd = sp->cmd;
2498
2499 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002500 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05002501 sp->flags &= ~SRB_DMA_VALID;
2502 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002503 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002504}
2505
2506void
2507qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2508{
2509 struct scsi_cmnd *cmd = sp->cmd;
2510
2511 qla2x00_sp_free_dma(ha, sp);
2512
f4f051e2005-04-17 15:02:26 -05002513 mempool_free(sp, ha->srb_mempool);
2514
2515 cmd->scsi_done(cmd);
2516}
bdf79622005-04-17 15:06:53 -05002517
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518/**************************************************************************
2519* qla2x00_timer
2520*
2521* Description:
2522* One second timer
2523*
2524* Context: Interrupt
2525***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002526void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527qla2x00_timer(scsi_qla_host_t *ha)
2528{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 unsigned long cpu_flags = 0;
2530 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 int start_dpc = 0;
2532 int index;
2533 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002534 int t;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002535 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536
2537 /*
2538 * Ports - Port down timer.
2539 *
2540 * Whenever, a port is in the LOST state we start decrementing its port
2541 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002542 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 */
2544 t = 0;
2545 list_for_each_entry(fcport, &ha->fcports, list) {
2546 if (fcport->port_type != FCT_TARGET)
2547 continue;
2548
2549 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2550
2551 if (atomic_read(&fcport->port_down_timer) == 0)
2552 continue;
2553
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002554 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002556
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002558 "%d remaining\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 ha->host_no,
2560 t, atomic_read(&fcport->port_down_timer)));
2561 }
2562 t++;
2563 } /* End of for fcport */
2564
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565
2566 /* Loop down handler. */
2567 if (atomic_read(&ha->loop_down_timer) > 0 &&
2568 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2569
2570 if (atomic_read(&ha->loop_down_timer) ==
2571 ha->loop_down_abort_time) {
2572
2573 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2574 "queues before time expire\n",
2575 ha->host_no));
2576
2577 if (!IS_QLA2100(ha) && ha->link_down_timeout)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002578 atomic_set(&ha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579
2580 /* Schedule an ISP abort to return any tape commands. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002581 /* NPIV - scan physical port only */
2582 if (!ha->parent) {
2583 spin_lock_irqsave(&ha->hardware_lock,
2584 cpu_flags);
2585 for (index = 1;
2586 index < MAX_OUTSTANDING_COMMANDS;
2587 index++) {
2588 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05002589
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002590 sp = ha->outstanding_cmds[index];
2591 if (!sp)
2592 continue;
2593 sfcp = sp->fcport;
2594 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2595 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002597 set_bit(ISP_ABORT_NEEDED,
2598 &ha->dpc_flags);
2599 break;
2600 }
2601 spin_unlock_irqrestore(&ha->hardware_lock,
2602 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2605 start_dpc++;
2606 }
2607
2608 /* if the loop has been down for 4 minutes, reinit adapter */
2609 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2610 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2611 "restarting queues.\n",
2612 ha->host_no));
2613
2614 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2615 start_dpc++;
2616
Seokmann Ju463717e2008-04-03 13:13:29 -07002617 if (!(ha->device_flags & DFLG_NO_CABLE) &&
2618 !ha->parent) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 DEBUG(printk("scsi(%ld): Loop down - "
2620 "aborting ISP.\n",
2621 ha->host_no));
2622 qla_printk(KERN_WARNING, ha,
2623 "Loop down - aborting ISP.\n");
2624
2625 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2626 }
2627 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002628 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 ha->host_no,
2630 atomic_read(&ha->loop_down_timer)));
2631 }
2632
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002633 /* Check if beacon LED needs to be blinked */
2634 if (ha->beacon_blink_led == 1) {
2635 set_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags);
2636 start_dpc++;
2637 }
2638
Andrew Vasquez550bf572008-04-24 15:21:23 -07002639 /* Process any deferred work. */
2640 if (!list_empty(&ha->work_list))
2641 start_dpc++;
2642
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 /* Schedule the DPC routine if needed */
2644 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2645 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002646 test_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 start_dpc ||
f4f051e2005-04-17 15:02:26 -05002648 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002649 test_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags) ||
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002650 test_bit(VP_DPC_NEEDED, &ha->dpc_flags) ||
Christoph Hellwig39a11242006-02-14 18:46:22 +01002651 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002652 qla2xxx_wake_dpc(pha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653
2654 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2655}
2656
Andrew Vasquez54333832005-11-09 15:49:04 -08002657/* Firmware interface routines. */
2658
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002659#define FW_BLOBS 6
Andrew Vasquez54333832005-11-09 15:49:04 -08002660#define FW_ISP21XX 0
2661#define FW_ISP22XX 1
2662#define FW_ISP2300 2
2663#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002664#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002665#define FW_ISP25XX 5
Andrew Vasquez54333832005-11-09 15:49:04 -08002666
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002667#define FW_FILE_ISP21XX "ql2100_fw.bin"
2668#define FW_FILE_ISP22XX "ql2200_fw.bin"
2669#define FW_FILE_ISP2300 "ql2300_fw.bin"
2670#define FW_FILE_ISP2322 "ql2322_fw.bin"
2671#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002672#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002673
Daniel Walkere1e82b62008-05-12 22:21:10 -07002674static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002675
2676static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002677 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
2678 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
2679 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
2680 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
2681 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002682 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08002683};
2684
2685struct fw_blob *
2686qla2x00_request_firmware(scsi_qla_host_t *ha)
2687{
2688 struct fw_blob *blob;
2689
2690 blob = NULL;
2691 if (IS_QLA2100(ha)) {
2692 blob = &qla_fw_blobs[FW_ISP21XX];
2693 } else if (IS_QLA2200(ha)) {
2694 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002695 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002696 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002697 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002698 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002699 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002700 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002701 } else if (IS_QLA25XX(ha)) {
2702 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08002703 }
2704
Daniel Walkere1e82b62008-05-12 22:21:10 -07002705 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002706 if (blob->fw)
2707 goto out;
2708
2709 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
2710 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
2711 "(%s).\n", ha->host_no, blob->name));
2712 blob->fw = NULL;
2713 blob = NULL;
2714 goto out;
2715 }
2716
2717out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07002718 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002719 return blob;
2720}
2721
2722static void
2723qla2x00_release_firmware(void)
2724{
2725 int idx;
2726
Daniel Walkere1e82b62008-05-12 22:21:10 -07002727 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002728 for (idx = 0; idx < FW_BLOBS; idx++)
2729 if (qla_fw_blobs[idx].fw)
2730 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07002731 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002732}
2733
Seokmann Ju14e660e2007-09-20 14:07:36 -07002734static pci_ers_result_t
2735qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
2736{
2737 switch (state) {
2738 case pci_channel_io_normal:
2739 return PCI_ERS_RESULT_CAN_RECOVER;
2740 case pci_channel_io_frozen:
2741 pci_disable_device(pdev);
2742 return PCI_ERS_RESULT_NEED_RESET;
2743 case pci_channel_io_perm_failure:
2744 qla2x00_remove_one(pdev);
2745 return PCI_ERS_RESULT_DISCONNECT;
2746 }
2747 return PCI_ERS_RESULT_NEED_RESET;
2748}
2749
2750static pci_ers_result_t
2751qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
2752{
2753 int risc_paused = 0;
2754 uint32_t stat;
2755 unsigned long flags;
2756 scsi_qla_host_t *ha = pci_get_drvdata(pdev);
2757 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2758 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
2759
2760 spin_lock_irqsave(&ha->hardware_lock, flags);
2761 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
2762 stat = RD_REG_DWORD(&reg->hccr);
2763 if (stat & HCCR_RISC_PAUSE)
2764 risc_paused = 1;
2765 } else if (IS_QLA23XX(ha)) {
2766 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
2767 if (stat & HSR_RISC_PAUSED)
2768 risc_paused = 1;
2769 } else if (IS_FWI2_CAPABLE(ha)) {
2770 stat = RD_REG_DWORD(&reg24->host_status);
2771 if (stat & HSRX_RISC_PAUSED)
2772 risc_paused = 1;
2773 }
2774 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2775
2776 if (risc_paused) {
2777 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
2778 "Dumping firmware!\n");
2779 ha->isp_ops->fw_dump(ha, 0);
2780
2781 return PCI_ERS_RESULT_NEED_RESET;
2782 } else
2783 return PCI_ERS_RESULT_RECOVERED;
2784}
2785
2786static pci_ers_result_t
2787qla2xxx_pci_slot_reset(struct pci_dev *pdev)
2788{
2789 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
2790 scsi_qla_host_t *ha = pci_get_drvdata(pdev);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002791 int rc;
Seokmann Ju14e660e2007-09-20 14:07:36 -07002792
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002793 if (ha->mem_only)
2794 rc = pci_enable_device_mem(pdev);
2795 else
2796 rc = pci_enable_device(pdev);
2797
2798 if (rc) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07002799 qla_printk(KERN_WARNING, ha,
2800 "Can't re-enable PCI device after reset.\n");
2801
2802 return ret;
2803 }
2804 pci_set_master(pdev);
2805
2806 if (ha->isp_ops->pci_config(ha))
2807 return ret;
2808
2809 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2810 if (qla2x00_abort_isp(ha)== QLA_SUCCESS)
2811 ret = PCI_ERS_RESULT_RECOVERED;
2812 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2813
2814 return ret;
2815}
2816
2817static void
2818qla2xxx_pci_resume(struct pci_dev *pdev)
2819{
2820 scsi_qla_host_t *ha = pci_get_drvdata(pdev);
2821 int ret;
2822
2823 ret = qla2x00_wait_for_hba_online(ha);
2824 if (ret != QLA_SUCCESS) {
2825 qla_printk(KERN_ERR, ha,
2826 "the device failed to resume I/O "
2827 "from slot/link_reset");
2828 }
2829 pci_cleanup_aer_uncorrect_error_status(pdev);
2830}
2831
2832static struct pci_error_handlers qla2xxx_err_handler = {
2833 .error_detected = qla2xxx_pci_error_detected,
2834 .mmio_enabled = qla2xxx_pci_mmio_enabled,
2835 .slot_reset = qla2xxx_pci_slot_reset,
2836 .resume = qla2xxx_pci_resume,
2837};
2838
Andrew Vasquez54333832005-11-09 15:49:04 -08002839static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07002840 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
2841 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
2842 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
2843 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
2844 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
2845 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
2846 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
2847 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
2848 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002849 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07002850 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
2851 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002852 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez54333832005-11-09 15:49:04 -08002853 { 0 },
2854};
2855MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2856
Andrew Vasquezfca29702005-07-06 10:31:47 -07002857static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07002858 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06002859 .driver = {
2860 .owner = THIS_MODULE,
2861 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07002862 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002863 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08002864 .remove = qla2x00_remove_one,
Seokmann Ju14e660e2007-09-20 14:07:36 -07002865 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07002866};
2867
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868/**
2869 * qla2x00_module_init - Module initialization.
2870 **/
2871static int __init
2872qla2x00_module_init(void)
2873{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002874 int ret = 0;
2875
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002877 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09002878 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 if (srb_cachep == NULL) {
2880 printk(KERN_ERR
2881 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2882 return -ENOMEM;
2883 }
2884
2885 /* Derive version string. */
2886 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002887 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07002888 strcat(qla2x00_version_str, "-debug");
2889
Andrew Vasquez1c97a122005-04-21 16:13:36 -04002890 qla2xxx_transport_template =
2891 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002892 if (!qla2xxx_transport_template) {
2893 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002895 }
2896 qla2xxx_transport_vport_template =
2897 fc_attach_transport(&qla2xxx_transport_vport_functions);
2898 if (!qla2xxx_transport_vport_template) {
2899 kmem_cache_destroy(srb_cachep);
2900 fc_release_transport(qla2xxx_transport_template);
2901 return -ENODEV;
2902 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07002904 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
2905 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002906 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002907 if (ret) {
2908 kmem_cache_destroy(srb_cachep);
2909 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002910 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002911 }
2912 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913}
2914
2915/**
2916 * qla2x00_module_exit - Module cleanup.
2917 **/
2918static void __exit
2919qla2x00_module_exit(void)
2920{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002921 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08002922 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002923 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002925 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926}
2927
2928module_init(qla2x00_module_init);
2929module_exit(qla2x00_module_exit);
2930
2931MODULE_AUTHOR("QLogic Corporation");
2932MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2933MODULE_LICENSE("GPL");
2934MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002935MODULE_FIRMWARE(FW_FILE_ISP21XX);
2936MODULE_FIRMWARE(FW_FILE_ISP22XX);
2937MODULE_FIRMWARE(FW_FILE_ISP2300);
2938MODULE_FIRMWARE(FW_FILE_ISP2322);
2939MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08002940MODULE_FIRMWARE(FW_FILE_ISP25XX);