blob: e98d502d649e0297fcede42f45e844946ac85887 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070089/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -070090 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 */
92static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -050093static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -080094static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
95static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -050096static void qla2xxx_slave_destroy(struct scsi_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
98 void (*fn)(struct scsi_cmnd *));
Andrew Vasquezfca29702005-07-06 10:31:47 -070099static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
100 void (*fn)(struct scsi_cmnd *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101static int qla2xxx_eh_abort(struct scsi_cmnd *);
102static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700103static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
105static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700107static int qla2x00_change_queue_depth(struct scsi_device *, int);
108static int qla2x00_change_queue_type(struct scsi_device *, int);
109
Adrian Bunka824ebb2008-01-17 09:02:15 -0800110static struct scsi_host_template qla2x00_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700112 .name = QLA2XXX_DRIVER_NAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 .queuecommand = qla2x00_queuecommand,
114
115 .eh_abort_handler = qla2xxx_eh_abort,
116 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700117 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
119 .eh_host_reset_handler = qla2xxx_eh_host_reset,
120
121 .slave_configure = qla2xxx_slave_configure,
122
f4f051e2005-04-17 15:02:26 -0500123 .slave_alloc = qla2xxx_slave_alloc,
124 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800125 .scan_finished = qla2xxx_scan_finished,
126 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700127 .change_queue_depth = qla2x00_change_queue_depth,
128 .change_queue_type = qla2x00_change_queue_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 .this_id = -1,
130 .cmd_per_lun = 3,
131 .use_clustering = ENABLE_CLUSTERING,
132 .sg_tablesize = SG_ALL,
133
134 /*
135 * The RISC allows for each command to transfer (2^32-1) bytes of data,
136 * which equates to 0x800000 sectors.
137 */
138 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700139 .shost_attrs = qla2x00_host_attrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140};
141
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700142struct scsi_host_template qla24xx_driver_template = {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700143 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700144 .name = QLA2XXX_DRIVER_NAME,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700145 .queuecommand = qla24xx_queuecommand,
146
147 .eh_abort_handler = qla2xxx_eh_abort,
148 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700149 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700150 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
151 .eh_host_reset_handler = qla2xxx_eh_host_reset,
152
153 .slave_configure = qla2xxx_slave_configure,
154
155 .slave_alloc = qla2xxx_slave_alloc,
156 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700157 .scan_finished = qla2xxx_scan_finished,
158 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700159 .change_queue_depth = qla2x00_change_queue_depth,
160 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700161 .this_id = -1,
162 .cmd_per_lun = 3,
163 .use_clustering = ENABLE_CLUSTERING,
164 .sg_tablesize = SG_ALL,
165
166 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700167 .shost_attrs = qla2x00_host_attrs,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700168};
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700171struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173/* TODO Convert to inlines
174 *
175 * Timer routines
176 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700178__inline__ void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
180{
181 init_timer(&ha->timer);
182 ha->timer.expires = jiffies + interval * HZ;
183 ha->timer.data = (unsigned long)ha;
184 ha->timer.function = (void (*)(unsigned long))func;
185 add_timer(&ha->timer);
186 ha->timer_active = 1;
187}
188
189static inline void
190qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
191{
192 mod_timer(&ha->timer, jiffies + interval * HZ);
193}
194
Adrian Bunka824ebb2008-01-17 09:02:15 -0800195static __inline__ void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196qla2x00_stop_timer(scsi_qla_host_t *ha)
197{
198 del_timer_sync(&ha->timer);
199 ha->timer_active = 0;
200}
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202static int qla2x00_do_dpc(void *data);
203
204static void qla2x00_rst_aen(scsi_qla_host_t *);
205
Andrew Vasqueze8711082008-01-31 12:33:48 -0800206static int qla2x00_mem_alloc(scsi_qla_host_t *);
Adrian Bunka824ebb2008-01-17 09:02:15 -0800207static void qla2x00_mem_free(scsi_qla_host_t *ha);
f4f051e2005-04-17 15:02:26 -0500208static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210/* -------------------------------------------------------------------------- */
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212static char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700213qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
215 static char *pci_bus_modes[] = {
216 "33", "66", "100", "133",
217 };
218 uint16_t pci_bus;
219
220 strcpy(str, "PCI");
221 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
222 if (pci_bus) {
223 strcat(str, "-X (");
224 strcat(str, pci_bus_modes[pci_bus]);
225 } else {
226 pci_bus = (ha->pci_attr & BIT_8) >> 8;
227 strcat(str, " (");
228 strcat(str, pci_bus_modes[pci_bus]);
229 }
230 strcat(str, " MHz)");
231
232 return (str);
233}
234
Andrew Vasquezfca29702005-07-06 10:31:47 -0700235static char *
236qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
237{
238 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
239 uint32_t pci_bus;
240 int pcie_reg;
241
242 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
243 if (pcie_reg) {
244 char lwstr[6];
245 uint16_t pcie_lstat, lspeed, lwidth;
246
247 pcie_reg += 0x12;
248 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
249 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
250 lwidth = (pcie_lstat &
251 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
252
253 strcpy(str, "PCIe (");
254 if (lspeed == 1)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700255 strcat(str, "2.5GT/s ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700256 else if (lspeed == 2)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700257 strcat(str, "5.0GT/s ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700258 else
259 strcat(str, "<unknown> ");
260 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
261 strcat(str, lwstr);
262
263 return str;
264 }
265
266 strcpy(str, "PCI");
267 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
268 if (pci_bus == 0 || pci_bus == 8) {
269 strcat(str, " (");
270 strcat(str, pci_bus_modes[pci_bus >> 3]);
271 } else {
272 strcat(str, "-X ");
273 if (pci_bus & BIT_2)
274 strcat(str, "Mode 2");
275 else
276 strcat(str, "Mode 1");
277 strcat(str, " (");
278 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
279 }
280 strcat(str, " MHz)");
281
282 return str;
283}
284
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800285static char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700286qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 char un_str[10];
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
291 ha->fw_minor_version,
292 ha->fw_subminor_version);
293
294 if (ha->fw_attributes & BIT_9) {
295 strcat(str, "FLX");
296 return (str);
297 }
298
299 switch (ha->fw_attributes & 0xFF) {
300 case 0x7:
301 strcat(str, "EF");
302 break;
303 case 0x17:
304 strcat(str, "TP");
305 break;
306 case 0x37:
307 strcat(str, "IP");
308 break;
309 case 0x77:
310 strcat(str, "VI");
311 break;
312 default:
313 sprintf(un_str, "(%x)", ha->fw_attributes);
314 strcat(str, un_str);
315 break;
316 }
317 if (ha->fw_attributes & 0x100)
318 strcat(str, "X");
319
320 return (str);
321}
322
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800323static char *
Andrew Vasquezfca29702005-07-06 10:31:47 -0700324qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
325{
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700326 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
327 ha->fw_minor_version,
328 ha->fw_subminor_version);
329
Andrew Vasquezfca29702005-07-06 10:31:47 -0700330 if (ha->fw_attributes & BIT_0)
331 strcat(str, "[Class 2] ");
332 if (ha->fw_attributes & BIT_1)
333 strcat(str, "[IP] ");
334 if (ha->fw_attributes & BIT_2)
335 strcat(str, "[Multi-ID] ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700336 if (ha->fw_attributes & BIT_3)
337 strcat(str, "[SB-2] ");
338 if (ha->fw_attributes & BIT_4)
339 strcat(str, "[T10 CRC] ");
340 if (ha->fw_attributes & BIT_5)
341 strcat(str, "[VI] ");
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700342 if (ha->fw_attributes & BIT_10)
343 strcat(str, "[84XX] ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700344 if (ha->fw_attributes & BIT_13)
345 strcat(str, "[Experimental]");
346 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700347}
348
349static inline srb_t *
350qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
351 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
352{
353 srb_t *sp;
354
355 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
356 if (!sp)
357 return sp;
358
Andrew Vasquezfca29702005-07-06 10:31:47 -0700359 sp->ha = ha;
360 sp->fcport = fcport;
361 sp->cmd = cmd;
362 sp->flags = 0;
363 CMD_SP(cmd) = (void *)sp;
364 cmd->scsi_done = done;
365
366 return sp;
367}
368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369static int
f4f051e2005-04-17 15:02:26 -0500370qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700372 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500373 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400374 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
f4f051e2005-04-17 15:02:26 -0500375 srb_t *sp;
376 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Seokmann Ju14e660e2007-09-20 14:07:36 -0700378 if (unlikely(pci_channel_offline(ha->pdev))) {
379 cmd->result = DID_REQUEUE << 16;
380 goto qc_fail_command;
381 }
382
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400383 rval = fc_remote_port_chkready(rport);
384 if (rval) {
385 cmd->result = rval;
f4f051e2005-04-17 15:02:26 -0500386 goto qc_fail_command;
387 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800389 /* Close window on fcport/rport state-transitioning. */
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700390 if (fcport->drport) {
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800391 cmd->result = DID_IMM_RETRY << 16;
392 goto qc_fail_command;
393 }
394
f4f051e2005-04-17 15:02:26 -0500395 if (atomic_read(&fcport->state) != FCS_ONLINE) {
396 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
397 atomic_read(&ha->loop_state) == LOOP_DEAD) {
398 cmd->result = DID_NO_CONNECT << 16;
399 goto qc_fail_command;
400 }
401 goto qc_host_busy;
402 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404 spin_unlock_irq(ha->host->host_lock);
405
Andrew Vasquezfca29702005-07-06 10:31:47 -0700406 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
407 if (!sp)
f4f051e2005-04-17 15:02:26 -0500408 goto qc_host_busy_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
f4f051e2005-04-17 15:02:26 -0500410 rval = qla2x00_start_scsi(sp);
411 if (rval != QLA_SUCCESS)
412 goto qc_host_busy_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 spin_lock_irq(ha->host->host_lock);
415
f4f051e2005-04-17 15:02:26 -0500416 return 0;
417
418qc_host_busy_free_sp:
419 qla2x00_sp_free_dma(ha, sp);
f4f051e2005-04-17 15:02:26 -0500420 mempool_free(sp, ha->srb_mempool);
421
422qc_host_busy_lock:
423 spin_lock_irq(ha->host->host_lock);
424
425qc_host_busy:
426 return SCSI_MLQUEUE_HOST_BUSY;
427
428qc_fail_command:
429 done(cmd);
430
431 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432}
433
Andrew Vasquezfca29702005-07-06 10:31:47 -0700434
435static int
436qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
437{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700438 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700439 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400440 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700441 srb_t *sp;
442 int rval;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700443 scsi_qla_host_t *pha = to_qla_parent(ha);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700444
Seokmann Ju14e660e2007-09-20 14:07:36 -0700445 if (unlikely(pci_channel_offline(ha->pdev))) {
446 cmd->result = DID_REQUEUE << 16;
447 goto qc24_fail_command;
448 }
449
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400450 rval = fc_remote_port_chkready(rport);
451 if (rval) {
452 cmd->result = rval;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700453 goto qc24_fail_command;
454 }
455
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800456 /* Close window on fcport/rport state-transitioning. */
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700457 if (fcport->drport) {
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800458 cmd->result = DID_IMM_RETRY << 16;
459 goto qc24_fail_command;
460 }
461
Andrew Vasquezfca29702005-07-06 10:31:47 -0700462 if (atomic_read(&fcport->state) != FCS_ONLINE) {
463 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700464 atomic_read(&pha->loop_state) == LOOP_DEAD) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700465 cmd->result = DID_NO_CONNECT << 16;
466 goto qc24_fail_command;
467 }
468 goto qc24_host_busy;
469 }
470
471 spin_unlock_irq(ha->host->host_lock);
472
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700473 sp = qla2x00_get_new_sp(pha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700474 if (!sp)
475 goto qc24_host_busy_lock;
476
477 rval = qla24xx_start_scsi(sp);
478 if (rval != QLA_SUCCESS)
479 goto qc24_host_busy_free_sp;
480
481 spin_lock_irq(ha->host->host_lock);
482
483 return 0;
484
485qc24_host_busy_free_sp:
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700486 qla2x00_sp_free_dma(pha, sp);
487 mempool_free(sp, pha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700488
489qc24_host_busy_lock:
490 spin_lock_irq(ha->host->host_lock);
491
492qc24_host_busy:
493 return SCSI_MLQUEUE_HOST_BUSY;
494
495qc24_fail_command:
496 done(cmd);
497
498 return 0;
499}
500
501
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502/*
503 * qla2x00_eh_wait_on_command
504 * Waits for the command to be returned by the Firmware for some
505 * max time.
506 *
507 * Input:
508 * ha = actual ha whose done queue will contain the command
509 * returned by firmware.
510 * cmd = Scsi Command to wait on.
511 * flag = Abort/Reset(Bus or Device Reset)
512 *
513 * Return:
514 * Not Found : 0
515 * Found : 1
516 */
517static int
518qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
519{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700520#define ABORT_POLLING_PERIOD 1000
521#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500522 unsigned long wait_iter = ABORT_WAIT_ITER;
523 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
f4f051e2005-04-17 15:02:26 -0500525 while (CMD_SP(cmd)) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700526 msleep(ABORT_POLLING_PERIOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
f4f051e2005-04-17 15:02:26 -0500528 if (--wait_iter)
529 break;
530 }
531 if (CMD_SP(cmd))
532 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
f4f051e2005-04-17 15:02:26 -0500534 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535}
536
537/*
538 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700539 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 * <= MAX_RETRIES_OF_ISP_ABORT or
541 * finally HBA is disabled ie marked offline
542 *
543 * Input:
544 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700545 *
546 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 * Does context switching-Release SPIN_LOCK
548 * (if any) before calling this routine.
549 *
550 * Return:
551 * Success (Adapter is online) : 0
552 * Failed (Adapter is offline/disabled) : 1
553 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800554int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
556{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700557 int return_status;
558 unsigned long wait_online;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700559 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700561 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700562 while (((test_bit(ISP_ABORT_NEEDED, &pha->dpc_flags)) ||
563 test_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags) ||
564 test_bit(ISP_ABORT_RETRY, &pha->dpc_flags) ||
565 pha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
567 msleep(1000);
568 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700569 if (pha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700570 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 else
572 return_status = QLA_FUNCTION_FAILED;
573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 return (return_status);
575}
576
577/*
578 * qla2x00_wait_for_loop_ready
579 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700580 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 * Input:
582 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700583 *
584 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 * Does context switching-Release SPIN_LOCK
586 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700587 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 *
589 * Return:
590 * Success (LOOP_READY) : 0
591 * Failed (LOOP_NOT_READY) : 1
592 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700593static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
595{
596 int return_status = QLA_SUCCESS;
597 unsigned long loop_timeout ;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700598 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
600 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700601 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700603 while ((!atomic_read(&pha->loop_down_timer) &&
604 atomic_read(&pha->loop_state) == LOOP_DOWN) ||
605 atomic_read(&pha->loop_state) != LOOP_READY) {
606 if (atomic_read(&pha->loop_state) == LOOP_DEAD) {
Ravi Anand57680082006-05-17 15:08:44 -0700607 return_status = QLA_FUNCTION_FAILED;
608 break;
609 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 msleep(1000);
611 if (time_after_eq(jiffies, loop_timeout)) {
612 return_status = QLA_FUNCTION_FAILED;
613 break;
614 }
615 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700616 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617}
618
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700619void
620qla2x00_abort_fcport_cmds(fc_port_t *fcport)
621{
622 int cnt;
623 unsigned long flags;
624 srb_t *sp;
625 scsi_qla_host_t *ha = fcport->ha;
626 scsi_qla_host_t *pha = to_qla_parent(ha);
627
628 spin_lock_irqsave(&pha->hardware_lock, flags);
629 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
630 sp = pha->outstanding_cmds[cnt];
631 if (!sp)
632 continue;
633 if (sp->fcport != fcport)
634 continue;
635
636 spin_unlock_irqrestore(&pha->hardware_lock, flags);
637 if (ha->isp_ops->abort_command(ha, sp)) {
638 DEBUG2(qla_printk(KERN_WARNING, ha,
639 "Abort failed -- %lx\n", sp->cmd->serial_number));
640 } else {
641 if (qla2x00_eh_wait_on_command(ha, sp->cmd) !=
642 QLA_SUCCESS)
643 DEBUG2(qla_printk(KERN_WARNING, ha,
644 "Abort failed while waiting -- %lx\n",
645 sp->cmd->serial_number));
646
647 }
648 spin_lock_irqsave(&pha->hardware_lock, flags);
649 }
650 spin_unlock_irqrestore(&pha->hardware_lock, flags);
651}
652
Andrew Vasquez07db5182006-10-02 12:00:49 -0700653static void
654qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
655{
656 struct Scsi_Host *shost = cmnd->device->host;
657 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
658 unsigned long flags;
659
660 spin_lock_irqsave(shost->host_lock, flags);
661 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
662 spin_unlock_irqrestore(shost->host_lock, flags);
663 msleep(1000);
664 spin_lock_irqsave(shost->host_lock, flags);
665 }
666 spin_unlock_irqrestore(shost->host_lock, flags);
667 return;
668}
669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670/**************************************************************************
671* qla2xxx_eh_abort
672*
673* Description:
674* The abort function will abort the specified command.
675*
676* Input:
677* cmd = Linux SCSI command packet to be aborted.
678*
679* Returns:
680* Either SUCCESS or FAILED.
681*
682* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700683* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800685static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686qla2xxx_eh_abort(struct scsi_cmnd *cmd)
687{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700688 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500689 srb_t *sp;
690 int ret, i;
691 unsigned int id, lun;
692 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700693 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700694 int wait = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700695 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Andrew Vasquez07db5182006-10-02 12:00:49 -0700697 qla2x00_block_error_handler(cmd);
698
f4f051e2005-04-17 15:02:26 -0500699 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700700 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Michael Reed2ea00202006-04-27 16:25:30 -0700702 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
f4f051e2005-04-17 15:02:26 -0500704 id = cmd->device->id;
705 lun = cmd->device->lun;
706 serial = cmd->serial_number;
707
708 /* Check active list for command command. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700709 spin_lock_irqsave(&pha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500710 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700711 sp = pha->outstanding_cmds[i];
f4f051e2005-04-17 15:02:26 -0500712
713 if (sp == NULL)
714 continue;
715
716 if (sp->cmd != cmd)
717 continue;
718
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700719 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld.\n",
720 __func__, ha->host_no, sp, serial));
f4f051e2005-04-17 15:02:26 -0500721
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700722 spin_unlock_irqrestore(&pha->hardware_lock, flags);
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700723 if (ha->isp_ops->abort_command(ha, sp)) {
f4f051e2005-04-17 15:02:26 -0500724 DEBUG2(printk("%s(%ld): abort_command "
725 "mbx failed.\n", __func__, ha->host_no));
726 } else {
727 DEBUG3(printk("%s(%ld): abort_command "
728 "mbx success.\n", __func__, ha->host_no));
Michael Reed2ea00202006-04-27 16:25:30 -0700729 wait = 1;
f4f051e2005-04-17 15:02:26 -0500730 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700731 spin_lock_irqsave(&pha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500732
733 break;
734 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700735 spin_unlock_irqrestore(&pha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500736
737 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700738 if (wait) {
f4f051e2005-04-17 15:02:26 -0500739 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700740 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500741 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
742 "%x.\n", ha->host_no, id, lun, serial, ret);
Michael Reed2ea00202006-04-27 16:25:30 -0700743 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500744 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700747 qla_printk(KERN_INFO, ha,
Michael Reed2ea00202006-04-27 16:25:30 -0700748 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
749 ha->host_no, id, lun, wait, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
f4f051e2005-04-17 15:02:26 -0500751 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752}
753
Andrew Vasquez523ec772008-04-03 13:13:24 -0700754enum nexus_wait_type {
755 WAIT_HOST = 0,
756 WAIT_TARGET,
757 WAIT_LUN,
758};
759
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700761qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha, unsigned int t,
762 unsigned int l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700764 int cnt, match, status;
765 srb_t *sp;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700766 unsigned long flags;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700767 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Andrew Vasquez523ec772008-04-03 13:13:24 -0700769 status = QLA_SUCCESS;
770 spin_lock_irqsave(&pha->hardware_lock, flags);
771 for (cnt = 1; status == QLA_SUCCESS && cnt < MAX_OUTSTANDING_COMMANDS;
772 cnt++) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700773 sp = pha->outstanding_cmds[cnt];
Andrew Vasquez523ec772008-04-03 13:13:24 -0700774 if (!sp)
775 continue;
776 if (ha->vp_idx != sp->ha->vp_idx)
777 continue;
778 match = 0;
779 switch (type) {
780 case WAIT_HOST:
781 match = 1;
782 break;
783 case WAIT_TARGET:
784 match = sp->cmd->device->id == t;
785 break;
786 case WAIT_LUN:
787 match = (sp->cmd->device->id == t &&
788 sp->cmd->device->lun == l);
789 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 }
Andrew Vasquez523ec772008-04-03 13:13:24 -0700791 if (!match)
792 continue;
793
794 spin_unlock_irqrestore(&pha->hardware_lock, flags);
795 status = qla2x00_eh_wait_on_command(ha, sp->cmd);
796 spin_lock_irqsave(&pha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 }
Andrew Vasquez523ec772008-04-03 13:13:24 -0700798 spin_unlock_irqrestore(&pha->hardware_lock, flags);
799
800 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801}
802
Andrew Vasquez523ec772008-04-03 13:13:24 -0700803static char *reset_errors[] = {
804 "HBA not online",
805 "HBA not ready",
806 "Task management failed",
807 "Waiting for command completions",
808};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Andrew Vasquez523ec772008-04-03 13:13:24 -0700810static int
811__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
812 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int))
813{
814 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
815 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
816 int err;
817
818 qla2x00_block_error_handler(cmd);
819
820 if (!fcport)
821 return FAILED;
822
823 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
824 ha->host_no, cmd->device->id, cmd->device->lun, name);
825
826 err = 0;
827 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
828 goto eh_reset_failed;
829 err = 1;
830 if (qla2x00_wait_for_loop_ready(ha) != QLA_SUCCESS)
831 goto eh_reset_failed;
832 err = 2;
833 if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS)
834 goto eh_reset_failed;
835 err = 3;
836 if (qla2x00_eh_wait_for_pending_commands(ha, cmd->device->id,
837 cmd->device->lun, type) != QLA_SUCCESS)
838 goto eh_reset_failed;
839
840 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
841 ha->host_no, cmd->device->id, cmd->device->lun, name);
842
843 return SUCCESS;
844
845 eh_reset_failed:
846 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n",
847 ha->host_no, cmd->device->id, cmd->device->lun, name,
848 reset_errors[err]);
849 return FAILED;
850}
851
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800852static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
854{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700855 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Andrew Vasquez523ec772008-04-03 13:13:24 -0700857 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
858 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859}
860
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700862qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700864 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Andrew Vasquez523ec772008-04-03 13:13:24 -0700866 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
867 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868}
869
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870/**************************************************************************
871* qla2xxx_eh_bus_reset
872*
873* Description:
874* The bus reset function will reset the bus and abort any executing
875* commands.
876*
877* Input:
878* cmd = Linux SCSI command packet of the command that cause the
879* bus reset.
880*
881* Returns:
882* SUCCESS/FAILURE (defined as macro in scsi.h).
883*
884**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800885static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
887{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700888 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700889 scsi_qla_host_t *pha = to_qla_parent(ha);
bdf79622005-04-17 15:06:53 -0500890 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700891 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500892 unsigned int id, lun;
893 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
Andrew Vasquez07db5182006-10-02 12:00:49 -0700895 qla2x00_block_error_handler(cmd);
896
f4f051e2005-04-17 15:02:26 -0500897 id = cmd->device->id;
898 lun = cmd->device->lun;
899 serial = cmd->serial_number;
900
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700901 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500902 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
904 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500905 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
908 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500909 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 }
911
912 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500913 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
914 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 }
f4f051e2005-04-17 15:02:26 -0500916 if (ret == FAILED)
917 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700919 /* Flush outstanding commands. */
Andrew Vasquez523ec772008-04-03 13:13:24 -0700920 if (qla2x00_eh_wait_for_pending_commands(pha, 0, 0, WAIT_HOST) !=
921 QLA_SUCCESS)
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700922 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
f4f051e2005-04-17 15:02:26 -0500924eh_bus_reset_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500926 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
f4f051e2005-04-17 15:02:26 -0500928 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929}
930
931/**************************************************************************
932* qla2xxx_eh_host_reset
933*
934* Description:
935* The reset function will reset the Adapter.
936*
937* Input:
938* cmd = Linux SCSI command packet of the command that cause the
939* adapter reset.
940*
941* Returns:
942* Either SUCCESS or FAILED.
943*
944* Note:
945**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800946static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
948{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700949 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500950 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700951 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500952 unsigned int id, lun;
953 unsigned long serial;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700954 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Andrew Vasquez07db5182006-10-02 12:00:49 -0700956 qla2x00_block_error_handler(cmd);
957
f4f051e2005-04-17 15:02:26 -0500958 id = cmd->device->id;
959 lun = cmd->device->lun;
960 serial = cmd->serial_number;
961
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700962 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500963 return ret;
964
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500966 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500969 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
971 /*
972 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700973 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 * be completed and then issue big hammer.Otherwise
975 * it may cause I/O failure as big hammer marks the
976 * devices as lost kicking of the port_down_timer
977 * while dpc is stuck for the mailbox to complete.
978 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 qla2x00_wait_for_loop_ready(ha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700980 set_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
981 if (qla2x00_abort_isp(pha)) {
982 clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 /* failed. schedule dpc to try */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700984 set_bit(ISP_ABORT_NEEDED, &pha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
986 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500987 goto eh_host_reset_lock;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700988 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700989 clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 /* Waiting for our command in done_queue to be returned to OS.*/
Andrew Vasquez523ec772008-04-03 13:13:24 -0700992 if (qla2x00_eh_wait_for_pending_commands(pha, 0, 0, WAIT_HOST) ==
993 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500994 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700996 if (ha->parent)
997 qla2x00_vp_abort_isp(ha);
998
f4f051e2005-04-17 15:02:26 -0500999eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001000 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1001 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
f4f051e2005-04-17 15:02:26 -05001003 return ret;
1004}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
1006/*
1007* qla2x00_loop_reset
1008* Issue loop reset.
1009*
1010* Input:
1011* ha = adapter block pointer.
1012*
1013* Returns:
1014* 0 = success
1015*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001016int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017qla2x00_loop_reset(scsi_qla_host_t *ha)
1018{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001019 int ret;
bdf79622005-04-17 15:06:53 -05001020 struct fc_port *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001022 if (ha->flags.enable_lip_full_login) {
1023 ret = qla2x00_full_login_lip(ha);
1024 if (ret != QLA_SUCCESS) {
1025 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1026 "full_login_lip=%d.\n", __func__, ha->host_no,
1027 ret));
1028 }
1029 atomic_set(&ha->loop_state, LOOP_DOWN);
1030 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
1031 qla2x00_mark_all_devices_lost(ha, 0);
1032 qla2x00_wait_for_loop_ready(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
1034
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001035 if (ha->flags.enable_lip_reset) {
1036 ret = qla2x00_lip_reset(ha);
1037 if (ret != QLA_SUCCESS) {
1038 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1039 "lip_reset=%d.\n", __func__, ha->host_no, ret));
1040 }
1041 qla2x00_wait_for_loop_ready(ha);
1042 }
1043
1044 if (ha->flags.enable_target_reset) {
bdf79622005-04-17 15:06:53 -05001045 list_for_each_entry(fcport, &ha->fcports, list) {
1046 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 continue;
1048
Andrew Vasquez523ec772008-04-03 13:13:24 -07001049 ret = ha->isp_ops->target_reset(fcport, 0);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001050 if (ret != QLA_SUCCESS) {
1051 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1052 "target_reset=%d d_id=%x.\n", __func__,
1053 ha->host_no, ret, fcport->d_id.b24));
1054 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 }
1056 }
1057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 /* Issue marker command only when we are going to start the I/O */
1059 ha->marker_needed = 1;
1060
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001061 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062}
1063
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001064void
1065qla2x00_abort_all_cmds(scsi_qla_host_t *ha, int res)
1066{
1067 int cnt;
1068 unsigned long flags;
1069 srb_t *sp;
1070
1071 spin_lock_irqsave(&ha->hardware_lock, flags);
1072 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1073 sp = ha->outstanding_cmds[cnt];
1074 if (sp) {
1075 ha->outstanding_cmds[cnt] = NULL;
1076 sp->flags = 0;
1077 sp->cmd->result = res;
1078 sp->cmd->host_scribble = (unsigned char *)NULL;
1079 qla2x00_sp_compl(ha, sp);
1080 }
1081 }
1082 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1083}
1084
f4f051e2005-04-17 15:02:26 -05001085static int
1086qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087{
bdf79622005-04-17 15:06:53 -05001088 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001090 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001091 return -ENXIO;
1092
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001093 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001094
1095 return 0;
1096}
1097
1098static int
1099qla2xxx_slave_configure(struct scsi_device *sdev)
1100{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001101 scsi_qla_host_t *ha = shost_priv(sdev->host);
8482e1182005-04-17 15:04:54 -05001102 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1103
f4f051e2005-04-17 15:02:26 -05001104 if (sdev->tagged_supported)
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001105 scsi_activate_tcq(sdev, ha->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 else
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001107 scsi_deactivate_tcq(sdev, ha->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
Andrew Vasquez85821c92008-07-10 16:55:48 -07001109 rport->dev_loss_tmo = ha->port_down_retry_count;
8482e1182005-04-17 15:04:54 -05001110
f4f051e2005-04-17 15:02:26 -05001111 return 0;
1112}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
f4f051e2005-04-17 15:02:26 -05001114static void
1115qla2xxx_slave_destroy(struct scsi_device *sdev)
1116{
1117 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118}
1119
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001120static int
1121qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1122{
1123 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1124 return sdev->queue_depth;
1125}
1126
1127static int
1128qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1129{
1130 if (sdev->tagged_supported) {
1131 scsi_set_tag_type(sdev, tag_type);
1132 if (tag_type)
1133 scsi_activate_tcq(sdev, sdev->queue_depth);
1134 else
1135 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1136 } else
1137 tag_type = 0;
1138
1139 return tag_type;
1140}
1141
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142/**
1143 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1144 * @ha: HA context
1145 *
1146 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1147 * supported addressing method.
1148 */
1149static void
1150qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1151{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001152 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001155 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1156 /* Any upper-dword bits set? */
1157 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1158 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1159 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001161 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1162 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001163 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001166
1167 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1168 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169}
1170
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001171static void
1172qla2x00_enable_intrs(scsi_qla_host_t *ha)
1173{
1174 unsigned long flags = 0;
1175 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1176
1177 spin_lock_irqsave(&ha->hardware_lock, flags);
1178 ha->interrupts_on = 1;
1179 /* enable risc and host interrupts */
1180 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1181 RD_REG_WORD(&reg->ictrl);
1182 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1183
1184}
1185
1186static void
1187qla2x00_disable_intrs(scsi_qla_host_t *ha)
1188{
1189 unsigned long flags = 0;
1190 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1191
1192 spin_lock_irqsave(&ha->hardware_lock, flags);
1193 ha->interrupts_on = 0;
1194 /* disable risc and host interrupts */
1195 WRT_REG_WORD(&reg->ictrl, 0);
1196 RD_REG_WORD(&reg->ictrl);
1197 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1198}
1199
1200static void
1201qla24xx_enable_intrs(scsi_qla_host_t *ha)
1202{
1203 unsigned long flags = 0;
1204 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1205
1206 spin_lock_irqsave(&ha->hardware_lock, flags);
1207 ha->interrupts_on = 1;
1208 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1209 RD_REG_DWORD(&reg->ictrl);
1210 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1211}
1212
1213static void
1214qla24xx_disable_intrs(scsi_qla_host_t *ha)
1215{
1216 unsigned long flags = 0;
1217 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1218
1219 spin_lock_irqsave(&ha->hardware_lock, flags);
1220 ha->interrupts_on = 0;
1221 WRT_REG_DWORD(&reg->ictrl, 0);
1222 RD_REG_DWORD(&reg->ictrl);
1223 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1224}
1225
1226static struct isp_operations qla2100_isp_ops = {
1227 .pci_config = qla2100_pci_config,
1228 .reset_chip = qla2x00_reset_chip,
1229 .chip_diag = qla2x00_chip_diag,
1230 .config_rings = qla2x00_config_rings,
1231 .reset_adapter = qla2x00_reset_adapter,
1232 .nvram_config = qla2x00_nvram_config,
1233 .update_fw_options = qla2x00_update_fw_options,
1234 .load_risc = qla2x00_load_risc,
1235 .pci_info_str = qla2x00_pci_info_str,
1236 .fw_version_str = qla2x00_fw_version_str,
1237 .intr_handler = qla2100_intr_handler,
1238 .enable_intrs = qla2x00_enable_intrs,
1239 .disable_intrs = qla2x00_disable_intrs,
1240 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001241 .target_reset = qla2x00_abort_target,
1242 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001243 .fabric_login = qla2x00_login_fabric,
1244 .fabric_logout = qla2x00_fabric_logout,
1245 .calc_req_entries = qla2x00_calc_iocbs_32,
1246 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1247 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1248 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1249 .read_nvram = qla2x00_read_nvram_data,
1250 .write_nvram = qla2x00_write_nvram_data,
1251 .fw_dump = qla2100_fw_dump,
1252 .beacon_on = NULL,
1253 .beacon_off = NULL,
1254 .beacon_blink = NULL,
1255 .read_optrom = qla2x00_read_optrom_data,
1256 .write_optrom = qla2x00_write_optrom_data,
1257 .get_flash_version = qla2x00_get_flash_version,
1258};
1259
1260static struct isp_operations qla2300_isp_ops = {
1261 .pci_config = qla2300_pci_config,
1262 .reset_chip = qla2x00_reset_chip,
1263 .chip_diag = qla2x00_chip_diag,
1264 .config_rings = qla2x00_config_rings,
1265 .reset_adapter = qla2x00_reset_adapter,
1266 .nvram_config = qla2x00_nvram_config,
1267 .update_fw_options = qla2x00_update_fw_options,
1268 .load_risc = qla2x00_load_risc,
1269 .pci_info_str = qla2x00_pci_info_str,
1270 .fw_version_str = qla2x00_fw_version_str,
1271 .intr_handler = qla2300_intr_handler,
1272 .enable_intrs = qla2x00_enable_intrs,
1273 .disable_intrs = qla2x00_disable_intrs,
1274 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001275 .target_reset = qla2x00_abort_target,
1276 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001277 .fabric_login = qla2x00_login_fabric,
1278 .fabric_logout = qla2x00_fabric_logout,
1279 .calc_req_entries = qla2x00_calc_iocbs_32,
1280 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1281 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1282 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1283 .read_nvram = qla2x00_read_nvram_data,
1284 .write_nvram = qla2x00_write_nvram_data,
1285 .fw_dump = qla2300_fw_dump,
1286 .beacon_on = qla2x00_beacon_on,
1287 .beacon_off = qla2x00_beacon_off,
1288 .beacon_blink = qla2x00_beacon_blink,
1289 .read_optrom = qla2x00_read_optrom_data,
1290 .write_optrom = qla2x00_write_optrom_data,
1291 .get_flash_version = qla2x00_get_flash_version,
1292};
1293
1294static struct isp_operations qla24xx_isp_ops = {
1295 .pci_config = qla24xx_pci_config,
1296 .reset_chip = qla24xx_reset_chip,
1297 .chip_diag = qla24xx_chip_diag,
1298 .config_rings = qla24xx_config_rings,
1299 .reset_adapter = qla24xx_reset_adapter,
1300 .nvram_config = qla24xx_nvram_config,
1301 .update_fw_options = qla24xx_update_fw_options,
1302 .load_risc = qla24xx_load_risc,
1303 .pci_info_str = qla24xx_pci_info_str,
1304 .fw_version_str = qla24xx_fw_version_str,
1305 .intr_handler = qla24xx_intr_handler,
1306 .enable_intrs = qla24xx_enable_intrs,
1307 .disable_intrs = qla24xx_disable_intrs,
1308 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001309 .target_reset = qla24xx_abort_target,
1310 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001311 .fabric_login = qla24xx_login_fabric,
1312 .fabric_logout = qla24xx_fabric_logout,
1313 .calc_req_entries = NULL,
1314 .build_iocbs = NULL,
1315 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1316 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1317 .read_nvram = qla24xx_read_nvram_data,
1318 .write_nvram = qla24xx_write_nvram_data,
1319 .fw_dump = qla24xx_fw_dump,
1320 .beacon_on = qla24xx_beacon_on,
1321 .beacon_off = qla24xx_beacon_off,
1322 .beacon_blink = qla24xx_beacon_blink,
1323 .read_optrom = qla24xx_read_optrom_data,
1324 .write_optrom = qla24xx_write_optrom_data,
1325 .get_flash_version = qla24xx_get_flash_version,
1326};
1327
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001328static struct isp_operations qla25xx_isp_ops = {
1329 .pci_config = qla25xx_pci_config,
1330 .reset_chip = qla24xx_reset_chip,
1331 .chip_diag = qla24xx_chip_diag,
1332 .config_rings = qla24xx_config_rings,
1333 .reset_adapter = qla24xx_reset_adapter,
1334 .nvram_config = qla24xx_nvram_config,
1335 .update_fw_options = qla24xx_update_fw_options,
1336 .load_risc = qla24xx_load_risc,
1337 .pci_info_str = qla24xx_pci_info_str,
1338 .fw_version_str = qla24xx_fw_version_str,
1339 .intr_handler = qla24xx_intr_handler,
1340 .enable_intrs = qla24xx_enable_intrs,
1341 .disable_intrs = qla24xx_disable_intrs,
1342 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001343 .target_reset = qla24xx_abort_target,
1344 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001345 .fabric_login = qla24xx_login_fabric,
1346 .fabric_logout = qla24xx_fabric_logout,
1347 .calc_req_entries = NULL,
1348 .build_iocbs = NULL,
1349 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1350 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1351 .read_nvram = qla25xx_read_nvram_data,
1352 .write_nvram = qla25xx_write_nvram_data,
1353 .fw_dump = qla25xx_fw_dump,
1354 .beacon_on = qla24xx_beacon_on,
1355 .beacon_off = qla24xx_beacon_off,
1356 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001357 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001358 .write_optrom = qla24xx_write_optrom_data,
1359 .get_flash_version = qla24xx_get_flash_version,
1360};
1361
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001362static inline void
1363qla2x00_set_isp_flags(scsi_qla_host_t *ha)
1364{
1365 ha->device_type = DT_EXTENDED_IDS;
1366 switch (ha->pdev->device) {
1367 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1368 ha->device_type |= DT_ISP2100;
1369 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001370 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001371 break;
1372 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1373 ha->device_type |= DT_ISP2200;
1374 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001375 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001376 break;
1377 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1378 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001379 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001380 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001381 break;
1382 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1383 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001384 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001385 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001386 break;
1387 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1388 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001389 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001390 if (ha->pdev->subsystem_vendor == 0x1028 &&
1391 ha->pdev->subsystem_device == 0x0170)
1392 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001393 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001394 break;
1395 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1396 ha->device_type |= DT_ISP6312;
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_ISP6322:
1400 ha->device_type |= DT_ISP6322;
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_ISP2422:
1404 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001405 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001406 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001407 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001408 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001409 break;
1410 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1411 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001412 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001413 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001414 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001415 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001416 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001417 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1418 ha->device_type |= DT_ISP8432;
1419 ha->device_type |= DT_ZIO_SUPPORTED;
1420 ha->device_type |= DT_FWI2;
1421 ha->device_type |= DT_IIDMA;
1422 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1423 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001424 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1425 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001426 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001427 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001428 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001429 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1430 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001431 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001432 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001433 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001434 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1435 ha->device_type |= DT_ISP2532;
1436 ha->device_type |= DT_ZIO_SUPPORTED;
1437 ha->device_type |= DT_FWI2;
1438 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001439 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1440 break;
1441 }
1442}
1443
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444static int
1445qla2x00_iospace_config(scsi_qla_host_t *ha)
1446{
Andrew Vasquez37765412008-01-17 09:02:09 -08001447 resource_size_t pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Andrew Vasquez285d0322007-10-19 15:59:17 -07001449 if (pci_request_selected_regions(ha->pdev, ha->bars,
1450 QLA2XXX_DRIVER_NAME)) {
1451 qla_printk(KERN_WARNING, ha,
1452 "Failed to reserve PIO/MMIO regions (%s)\n",
1453 pci_name(ha->pdev));
1454
1455 goto iospace_error_exit;
1456 }
1457 if (!(ha->bars & 1))
1458 goto skip_pio;
1459
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1461 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001462 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1463 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 qla_printk(KERN_WARNING, ha,
1465 "Invalid PCI I/O region size (%s)...\n",
1466 pci_name(ha->pdev));
1467 pio = 0;
1468 }
1469 } else {
1470 qla_printk(KERN_WARNING, ha,
1471 "region #0 not a PIO resource (%s)...\n",
1472 pci_name(ha->pdev));
1473 pio = 0;
1474 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001475 ha->pio_address = pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Andrew Vasquez285d0322007-10-19 15:59:17 -07001477skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001479 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 qla_printk(KERN_ERR, ha,
Andrew Vasquez37765412008-01-17 09:02:09 -08001481 "region #1 not an MMIO resource (%s), aborting\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 pci_name(ha->pdev));
1483 goto iospace_error_exit;
1484 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001485 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 qla_printk(KERN_ERR, ha,
1487 "Invalid PCI mem region size (%s), aborting\n",
1488 pci_name(ha->pdev));
1489 goto iospace_error_exit;
1490 }
1491
Andrew Vasquez37765412008-01-17 09:02:09 -08001492 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 if (!ha->iobase) {
1494 qla_printk(KERN_ERR, ha,
1495 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1496
1497 goto iospace_error_exit;
1498 }
1499
1500 return (0);
1501
1502iospace_error_exit:
1503 return (-ENOMEM);
1504}
1505
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001506static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001507qla2xxx_scan_start(struct Scsi_Host *shost)
1508{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001509 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001510
1511 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1512 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1513 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1514}
1515
1516static int
1517qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1518{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001519 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001520
1521 if (!ha->host)
1522 return 1;
1523 if (time > ha->loop_reset_delay * HZ)
1524 return 1;
1525
1526 return atomic_read(&ha->loop_state) == LOOP_READY;
1527}
1528
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529/*
1530 * PCI driver interface
1531 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001532static int __devinit
1533qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001535 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 struct Scsi_Host *host;
1537 scsi_qla_host_t *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001538 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001540 struct scsi_host_template *sht;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001541 int bars, mem_only = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
Andrew Vasquez285d0322007-10-19 15:59:17 -07001543 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1544 sht = &qla2x00_driver_template;
1545 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1546 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001547 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001548 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1549 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1550 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532) {
1551 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1552 sht = &qla24xx_driver_template;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001553 mem_only = 1;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001554 }
1555
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001556 if (mem_only) {
1557 if (pci_enable_device_mem(pdev))
1558 goto probe_out;
1559 } else {
1560 if (pci_enable_device(pdev))
1561 goto probe_out;
1562 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
Seokmann Ju14e660e2007-09-20 14:07:36 -07001564 if (pci_find_aer_capability(pdev))
1565 if (pci_enable_pcie_error_reporting(pdev))
1566 goto probe_out;
1567
Andrew Vasquez54333832005-11-09 15:49:04 -08001568 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 if (host == NULL) {
1570 printk(KERN_WARNING
1571 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1572 goto probe_disable_device;
1573 }
1574
1575 /* Clear our data area */
Andrew Vasquezf363b942007-09-20 14:07:45 -07001576 ha = shost_priv(host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 memset(ha, 0, sizeof(scsi_qla_host_t));
1578
1579 ha->pdev = pdev;
1580 ha->host = host;
1581 ha->host_no = host->host_no;
Andrew Vasquezcb630672006-05-17 15:09:45 -07001582 sprintf(ha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, ha->host_no);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001583 ha->parent = NULL;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001584 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001585 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001586 spin_lock_init(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001588 /* Set ISP-type information. */
1589 qla2x00_set_isp_flags(ha);
1590
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 /* Configure PCI I/O space */
1592 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001593 if (ret)
1594 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08001597 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1598 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001601 ha->init_cb_size = sizeof(init_cb_t);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001602 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER + ha->vp_idx;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001603 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001604 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001606 ha->max_q_depth = MAX_Q_DEPTH;
1607 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1608 ha->max_q_depth = ql2xmaxqdepth;
1609
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001610 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 if (IS_QLA2100(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001612 host->max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1614 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1615 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1616 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1617 host->sg_tablesize = 32;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001618 ha->gid_list_info_size = 4;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001619 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 } else if (IS_QLA2200(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001621 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1623 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1624 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1625 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001626 ha->gid_list_info_size = 4;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001627 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001628 } else if (IS_QLA23XX(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001629 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1631 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1632 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1633 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001634 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001635 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1636 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001637 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001638 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07001639 host->max_id = MAX_TARGETS_2200;
1640 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1641 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1642 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1643 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001644 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1645 ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001646 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001647 ha->optrom_size = OPTROM_SIZE_24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001648 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001649 } else if (IS_QLA25XX(ha)) {
1650 host->max_id = MAX_TARGETS_2200;
1651 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1652 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1653 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1654 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1655 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1656 ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
1657 ha->gid_list_info_size = 8;
1658 ha->optrom_size = OPTROM_SIZE_25XX;
1659 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001660 ha->hw_event_start = PCI_FUNC(pdev->devfn) ?
1661 FA_HW_EVENT1_ADDR: FA_HW_EVENT0_ADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 }
1663 host->can_queue = ha->request_q_length + 128;
1664
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07001665 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001666 init_completion(&ha->mbx_cmd_comp);
1667 complete(&ha->mbx_cmd_comp);
1668 init_completion(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
1670 INIT_LIST_HEAD(&ha->list);
1671 INIT_LIST_HEAD(&ha->fcports);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001672 INIT_LIST_HEAD(&ha->vp_list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07001673 INIT_LIST_HEAD(&ha->work_list);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001674
1675 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 qla2x00_config_dma_addressing(ha);
1678 if (qla2x00_mem_alloc(ha)) {
1679 qla_printk(KERN_WARNING, ha,
1680 "[ERROR] Failed to allocate memory for adapter\n");
1681
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001682 ret = -ENOMEM;
1683 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 }
1685
Andrew Vasquez765140b2007-05-07 07:42:58 -07001686 if (qla2x00_initialize_adapter(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 qla_printk(KERN_WARNING, ha,
1688 "Failed to initialize adapter\n");
1689
1690 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1691 "Adapter flags %x.\n",
1692 ha->host_no, ha->device_flags));
1693
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001694 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 goto probe_failed;
1696 }
1697
1698 /*
1699 * Startup the kernel thread for this host adapter
1700 */
Christoph Hellwig39a11242006-02-14 18:46:22 +01001701 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1702 "%s_dpc", ha->host_str);
1703 if (IS_ERR(ha->dpc_thread)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 qla_printk(KERN_WARNING, ha,
1705 "Unable to start DPC thread!\n");
Christoph Hellwig39a11242006-02-14 18:46:22 +01001706 ret = PTR_ERR(ha->dpc_thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 goto probe_failed;
1708 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001710 host->this_id = 255;
1711 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07001712 host->unique_id = host->host_no;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001713 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001714 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001715 host->max_lun = MAX_LUNS;
1716 host->transportt = qla2xxx_transport_template;
1717
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001718 ret = qla2x00_request_irqs(ha);
1719 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
1722 /* Initialized the timer */
1723 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1724
1725 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1726 ha->host_no, ha));
1727
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001728 pci_set_drvdata(pdev, ha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001729
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 ha->flags.init_done = 1;
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001731 ha->flags.online = 1;
1732
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001733 ret = scsi_add_host(host, &pdev->dev);
1734 if (ret)
1735 goto probe_failed;
1736
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001737 scsi_scan_host(host);
1738
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001739 qla2x00_alloc_sysfs_attr(ha);
1740
1741 qla2x00_init_host_attr(ha);
1742
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001743 qla2x00_dfs_setup(ha);
1744
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 qla_printk(KERN_INFO, ha, "\n"
1746 " QLogic Fibre Channel HBA Driver: %s\n"
1747 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08001748 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1749 qla2x00_version_str, ha->model_number,
1750 ha->model_desc ? ha->model_desc: "", pdev->device,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001751 ha->isp_ops->pci_info_str(ha, pci_info), pci_name(pdev),
Andrew Vasquez54333832005-11-09 15:49:04 -08001752 ha->flags.enable_64bit_addressing ? '+': '-', ha->host_no,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001753 ha->isp_ops->fw_version_str(ha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 return 0;
1756
1757probe_failed:
1758 qla2x00_free_device(ha);
1759
1760 scsi_host_put(host);
1761
1762probe_disable_device:
1763 pci_disable_device(pdev);
1764
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001765probe_out:
1766 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768
Adrian Bunk4c993f72008-01-14 00:55:16 -08001769static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001770qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771{
1772 scsi_qla_host_t *ha;
1773
1774 ha = pci_get_drvdata(pdev);
1775
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001776 qla2x00_dfs_remove(ha);
1777
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001778 qla84xx_put_chip(ha);
1779
8482e1182005-04-17 15:04:54 -05001780 qla2x00_free_sysfs_attr(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
bdf79622005-04-17 15:06:53 -05001782 fc_remove_host(ha->host);
1783
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 scsi_remove_host(ha->host);
1785
1786 qla2x00_free_device(ha);
1787
1788 scsi_host_put(ha->host);
1789
Bernhard Walle665db932007-03-28 00:49:49 +02001790 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 pci_set_drvdata(pdev, NULL);
1792}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
1794static void
1795qla2x00_free_device(scsi_qla_host_t *ha)
1796{
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001797 qla2x00_abort_all_cmds(ha, DID_NO_CONNECT << 16);
1798
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 /* Disable timer */
1800 if (ha->timer_active)
1801 qla2x00_stop_timer(ha);
1802
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001803 ha->flags.online = 0;
1804
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 /* Kill the kernel thread for this host */
Christoph Hellwig39a11242006-02-14 18:46:22 +01001806 if (ha->dpc_thread) {
1807 struct task_struct *t = ha->dpc_thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
Christoph Hellwig39a11242006-02-14 18:46:22 +01001809 /*
1810 * qla2xxx_wake_dpc checks for ->dpc_thread
1811 * so we need to zero it out.
1812 */
1813 ha->dpc_thread = NULL;
1814 kthread_stop(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 }
1816
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001817 if (ha->flags.fce_enabled)
1818 qla2x00_disable_fce_trace(ha, NULL, NULL);
1819
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001820 if (ha->eft)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08001821 qla2x00_disable_eft_trace(ha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001822
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001823 /* Stop currently executing firmware. */
Andrew Vasquez18c6c122006-10-13 09:33:38 -07001824 qla2x00_try_to_stop_firmware(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001826 /* turn-off interrupts on the card */
1827 if (ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001828 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001829
1830 qla2x00_mem_free(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001832 qla2x00_free_irqs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
1834 /* release io space registers */
1835 if (ha->iobase)
1836 iounmap(ha->iobase);
Andrew Vasquez285d0322007-10-19 15:59:17 -07001837 pci_release_selected_regions(ha->pdev, ha->bars);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838}
1839
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001840static inline void
1841qla2x00_schedule_rport_del(struct scsi_qla_host *ha, fc_port_t *fcport,
1842 int defer)
1843{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001844 struct fc_rport *rport;
1845
1846 if (!fcport->rport)
1847 return;
1848
1849 rport = fcport->rport;
1850 if (defer) {
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001851 spin_lock_irq(ha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001852 fcport->drport = rport;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001853 spin_unlock_irq(ha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001854 set_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001855 qla2xxx_wake_dpc(ha);
1856 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001857 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001858}
1859
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1862 *
1863 * Input: ha = adapter block pointer. fcport = port structure pointer.
1864 *
1865 * Return: None.
1866 *
1867 * Context:
1868 */
1869void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001870 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001872 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1873 ha->vp_idx == fcport->vp_idx)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001874 qla2x00_schedule_rport_del(ha, fcport, defer);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001875
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001876 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 * We may need to retry the login, so don't change the state of the
1878 * port but do the retries.
1879 */
1880 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1881 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1882
1883 if (!do_login)
1884 return;
1885
1886 if (fcport->login_retry == 0) {
1887 fcport->login_retry = ha->login_retry_count;
1888 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1889
1890 DEBUG(printk("scsi(%ld): Port login retry: "
1891 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1892 "id = 0x%04x retry cnt=%d\n",
1893 ha->host_no,
1894 fcport->port_name[0],
1895 fcport->port_name[1],
1896 fcport->port_name[2],
1897 fcport->port_name[3],
1898 fcport->port_name[4],
1899 fcport->port_name[5],
1900 fcport->port_name[6],
1901 fcport->port_name[7],
1902 fcport->loop_id,
1903 fcport->login_retry));
1904 }
1905}
1906
1907/*
1908 * qla2x00_mark_all_devices_lost
1909 * Updates fcport state when device goes offline.
1910 *
1911 * Input:
1912 * ha = adapter block pointer.
1913 * fcport = port structure pointer.
1914 *
1915 * Return:
1916 * None.
1917 *
1918 * Context:
1919 */
1920void
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001921qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922{
1923 fc_port_t *fcport;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001924 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001926 list_for_each_entry(fcport, &pha->fcports, list) {
1927 if (ha->vp_idx != 0 && ha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 /*
1930 * No point in marking the device as lost, if the device is
1931 * already DEAD.
1932 */
1933 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1934 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001935 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1936 if (defer)
1937 qla2x00_schedule_rport_del(ha, fcport, defer);
1938 else if (ha->vp_idx == fcport->vp_idx)
1939 qla2x00_schedule_rport_del(ha, fcport, defer);
1940 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1942 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001943
Christoph Hellwig39a11242006-02-14 18:46:22 +01001944 if (defer)
1945 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946}
1947
1948/*
1949* qla2x00_mem_alloc
1950* Allocates adapter memory.
1951*
1952* Returns:
1953* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08001954* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08001956static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957qla2x00_mem_alloc(scsi_qla_host_t *ha)
1958{
1959 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
Andrew Vasqueze8711082008-01-31 12:33:48 -08001961 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
1962 (ha->request_q_length + 1) * sizeof(request_t), &ha->request_dma,
1963 GFP_KERNEL);
1964 if (!ha->request_ring)
1965 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966
Andrew Vasqueze8711082008-01-31 12:33:48 -08001967 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1968 (ha->response_q_length + 1) * sizeof(response_t),
1969 &ha->response_dma, GFP_KERNEL);
1970 if (!ha->response_ring)
1971 goto fail_free_request_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
Andrew Vasqueze8711082008-01-31 12:33:48 -08001973 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1974 &ha->gid_list_dma, GFP_KERNEL);
1975 if (!ha->gid_list)
1976 goto fail_free_response_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
Andrew Vasqueze8711082008-01-31 12:33:48 -08001978 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
1979 &ha->init_cb_dma, GFP_KERNEL);
1980 if (!ha->init_cb)
1981 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982
Andrew Vasqueze8711082008-01-31 12:33:48 -08001983 snprintf(name, sizeof(name), "%s_%ld", QLA2XXX_DRIVER_NAME,
1984 ha->host_no);
1985 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
1986 DMA_POOL_SIZE, 8, 0);
1987 if (!ha->s_dma_pool)
1988 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
Andrew Vasqueze8711082008-01-31 12:33:48 -08001990 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
1991 if (!ha->srb_mempool)
1992 goto fail_free_s_dma_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
Andrew Vasqueze8711082008-01-31 12:33:48 -08001994 /* Get memory for cached NVRAM */
1995 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
1996 if (!ha->nvram)
1997 goto fail_free_srb_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
Andrew Vasqueze8711082008-01-31 12:33:48 -08001999 /* Allocate memory for SNS commands */
2000 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2001 /* Get consistent memory allocated for SNS commands */
2002 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2003 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
2004 if (!ha->sns_cmd)
2005 goto fail_free_nvram;
2006 } else {
2007 /* Get consistent memory allocated for MS IOCB */
2008 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2009 &ha->ms_iocb_dma);
2010 if (!ha->ms_iocb)
2011 goto fail_free_nvram;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012
Andrew Vasqueze8711082008-01-31 12:33:48 -08002013 /* Get consistent memory allocated for CT SNS commands */
2014 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2015 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
2016 if (!ha->ct_sns)
2017 goto fail_free_ms_iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 }
2019
Andrew Vasqueze8711082008-01-31 12:33:48 -08002020 return 0;
2021
2022fail_free_ms_iocb:
2023 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2024 ha->ms_iocb = NULL;
2025 ha->ms_iocb_dma = 0;
2026fail_free_nvram:
2027 kfree(ha->nvram);
2028 ha->nvram = NULL;
2029fail_free_srb_mempool:
2030 mempool_destroy(ha->srb_mempool);
2031 ha->srb_mempool = NULL;
2032fail_free_s_dma_pool:
2033 dma_pool_destroy(ha->s_dma_pool);
2034 ha->s_dma_pool = NULL;
2035fail_free_init_cb:
2036 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2037 ha->init_cb_dma);
2038 ha->init_cb = NULL;
2039 ha->init_cb_dma = 0;
2040fail_free_gid_list:
2041 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2042 ha->gid_list_dma);
2043 ha->gid_list = NULL;
2044 ha->gid_list_dma = 0;
2045fail_free_response_ring:
2046 dma_free_coherent(&ha->pdev->dev, (ha->response_q_length + 1) *
2047 sizeof(response_t), ha->response_ring, ha->response_dma);
2048 ha->response_ring = NULL;
2049 ha->response_dma = 0;
2050fail_free_request_ring:
2051 dma_free_coherent(&ha->pdev->dev, (ha->request_q_length + 1) *
2052 sizeof(request_t), ha->request_ring, ha->request_dma);
2053 ha->request_ring = NULL;
2054 ha->request_dma = 0;
2055fail:
2056 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057}
2058
2059/*
2060* qla2x00_mem_free
2061* Frees all adapter allocated memory.
2062*
2063* Input:
2064* ha = adapter block pointer.
2065*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08002066static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067qla2x00_mem_free(scsi_qla_host_t *ha)
2068{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 struct list_head *fcpl, *fcptemp;
2070 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
Andrew Vasqueze8711082008-01-31 12:33:48 -08002072 if (ha->srb_mempool)
2073 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002075 if (ha->fce)
2076 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2077 ha->fce_dma);
2078
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002079 if (ha->fw_dump) {
2080 if (ha->eft)
2081 dma_free_coherent(&ha->pdev->dev,
2082 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2083 vfree(ha->fw_dump);
2084 }
2085
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 if (ha->sns_cmd)
2087 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2088 ha->sns_cmd, ha->sns_cmd_dma);
2089
2090 if (ha->ct_sns)
2091 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2092 ha->ct_sns, ha->ct_sns_dma);
2093
Andrew Vasquez88729e52006-06-23 16:10:50 -07002094 if (ha->sfp_data)
2095 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2096
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 if (ha->ms_iocb)
2098 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2099
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 if (ha->s_dma_pool)
2101 dma_pool_destroy(ha->s_dma_pool);
2102
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002103 if (ha->init_cb)
2104 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2105 ha->init_cb, ha->init_cb_dma);
2106
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 if (ha->gid_list)
2108 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2109 ha->gid_list_dma);
2110
2111 if (ha->response_ring)
2112 dma_free_coherent(&ha->pdev->dev,
2113 (ha->response_q_length + 1) * sizeof(response_t),
2114 ha->response_ring, ha->response_dma);
2115
2116 if (ha->request_ring)
2117 dma_free_coherent(&ha->pdev->dev,
2118 (ha->request_q_length + 1) * sizeof(request_t),
2119 ha->request_ring, ha->request_dma);
2120
Andrew Vasqueze8711082008-01-31 12:33:48 -08002121 ha->srb_mempool = NULL;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002122 ha->eft = NULL;
2123 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 ha->sns_cmd = NULL;
2125 ha->sns_cmd_dma = 0;
2126 ha->ct_sns = NULL;
2127 ha->ct_sns_dma = 0;
2128 ha->ms_iocb = NULL;
2129 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 ha->init_cb = NULL;
2131 ha->init_cb_dma = 0;
2132
2133 ha->s_dma_pool = NULL;
2134
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 ha->gid_list = NULL;
2136 ha->gid_list_dma = 0;
2137
2138 ha->response_ring = NULL;
2139 ha->response_dma = 0;
2140 ha->request_ring = NULL;
2141 ha->request_dma = 0;
2142
2143 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2144 fcport = list_entry(fcpl, fc_port_t, list);
2145
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 /* fc ports */
2147 list_del_init(&fcport->list);
2148 kfree(fcport);
2149 }
2150 INIT_LIST_HEAD(&ha->fcports);
2151
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002153 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 ha->fw_dump_reading = 0;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002155
2156 vfree(ha->optrom_buffer);
Seokmann Ju53772a22007-07-30 11:01:07 -07002157 kfree(ha->nvram);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158}
2159
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002160static struct qla_work_evt *
Andrew Vasquez0971de72008-04-03 13:13:18 -07002161qla2x00_alloc_work(struct scsi_qla_host *ha, enum qla_work_type type,
2162 int locked)
2163{
2164 struct qla_work_evt *e;
2165
2166 e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
2167 GFP_KERNEL);
2168 if (!e)
2169 return NULL;
2170
2171 INIT_LIST_HEAD(&e->list);
2172 e->type = type;
2173 e->flags = QLA_EVT_FLAG_FREE;
2174 return e;
2175}
2176
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002177static int
Andrew Vasquez0971de72008-04-03 13:13:18 -07002178qla2x00_post_work(struct scsi_qla_host *ha, struct qla_work_evt *e, int locked)
2179{
2180 unsigned long flags;
Seokmann Ju08b95a12008-05-19 14:25:40 -07002181 scsi_qla_host_t *pha = to_qla_parent(ha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002182
2183 if (!locked)
Seokmann Ju08b95a12008-05-19 14:25:40 -07002184 spin_lock_irqsave(&pha->hardware_lock, flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002185 list_add_tail(&e->list, &ha->work_list);
2186 qla2xxx_wake_dpc(ha);
2187 if (!locked)
Seokmann Ju08b95a12008-05-19 14:25:40 -07002188 spin_unlock_irqrestore(&pha->hardware_lock, flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002189 return QLA_SUCCESS;
2190}
2191
2192int
2193qla2x00_post_aen_work(struct scsi_qla_host *ha, enum fc_host_event_code code,
2194 u32 data)
2195{
2196 struct qla_work_evt *e;
2197
2198 e = qla2x00_alloc_work(ha, QLA_EVT_AEN, 1);
2199 if (!e)
2200 return QLA_FUNCTION_FAILED;
2201
2202 e->u.aen.code = code;
2203 e->u.aen.data = data;
2204 return qla2x00_post_work(ha, e, 1);
2205}
2206
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002207int
2208qla2x00_post_hwe_work(struct scsi_qla_host *ha, uint16_t code, uint16_t d1,
2209 uint16_t d2, uint16_t d3)
2210{
2211 struct qla_work_evt *e;
2212
2213 e = qla2x00_alloc_work(ha, QLA_EVT_HWE_LOG, 1);
2214 if (!e)
2215 return QLA_FUNCTION_FAILED;
2216
2217 e->u.hwe.code = code;
2218 e->u.hwe.d1 = d1;
2219 e->u.hwe.d2 = d2;
2220 e->u.hwe.d3 = d3;
2221 return qla2x00_post_work(ha, e, 1);
2222}
2223
Andrew Vasquez0971de72008-04-03 13:13:18 -07002224static void
2225qla2x00_do_work(struct scsi_qla_host *ha)
2226{
2227 struct qla_work_evt *e;
Seokmann Ju08b95a12008-05-19 14:25:40 -07002228 scsi_qla_host_t *pha = to_qla_parent(ha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002229
Seokmann Ju08b95a12008-05-19 14:25:40 -07002230 spin_lock_irq(&pha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002231 while (!list_empty(&ha->work_list)) {
2232 e = list_entry(ha->work_list.next, struct qla_work_evt, list);
2233 list_del_init(&e->list);
Seokmann Ju08b95a12008-05-19 14:25:40 -07002234 spin_unlock_irq(&pha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002235
2236 switch (e->type) {
2237 case QLA_EVT_AEN:
2238 fc_host_post_event(ha->host, fc_get_event_number(),
2239 e->u.aen.code, e->u.aen.data);
2240 break;
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002241 case QLA_EVT_HWE_LOG:
2242 qla2xxx_hw_event_log(ha, e->u.hwe.code, e->u.hwe.d1,
2243 e->u.hwe.d2, e->u.hwe.d3);
2244 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002245 }
2246 if (e->flags & QLA_EVT_FLAG_FREE)
2247 kfree(e);
Seokmann Ju08b95a12008-05-19 14:25:40 -07002248 spin_lock_irq(&pha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002249 }
Seokmann Ju08b95a12008-05-19 14:25:40 -07002250 spin_unlock_irq(&pha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002251}
2252
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253/**************************************************************************
2254* qla2x00_do_dpc
2255* This kernel thread is a task that is schedule by the interrupt handler
2256* to perform the background processing for interrupts.
2257*
2258* Notes:
2259* This task always run in the context of a kernel thread. It
2260* is kick-off by the driver's detect code and starts up
2261* up one per adapter. It immediately goes to sleep and waits for
2262* some fibre event. When either the interrupt handler or
2263* the timer routine detects a event it will one of the task
2264* bits then wake us up.
2265**************************************************************************/
2266static int
2267qla2x00_do_dpc(void *data)
2268{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002269 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 scsi_qla_host_t *ha;
2271 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 uint8_t status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 uint16_t next_loopid;
Seokmann Ju99363ef2008-01-31 12:33:51 -08002274 struct scsi_qla_host *vha;
2275 int i;
2276
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277
2278 ha = (scsi_qla_host_t *)data;
2279
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 set_user_nice(current, -20);
2281
Christoph Hellwig39a11242006-02-14 18:46:22 +01002282 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2284
Christoph Hellwig39a11242006-02-14 18:46:22 +01002285 set_current_state(TASK_INTERRUPTIBLE);
2286 schedule();
2287 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288
2289 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2290
2291 /* Initialization not yet finished. Don't do anything yet. */
Christoph Hellwig39a11242006-02-14 18:46:22 +01002292 if (!ha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 continue;
2294
2295 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2296
2297 ha->dpc_active = 1;
2298
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 ha->dpc_active = 0;
2301 continue;
2302 }
2303
Andrew Vasquez0971de72008-04-03 13:13:18 -07002304 qla2x00_do_work(ha);
2305
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2307
2308 DEBUG(printk("scsi(%ld): dpc: sched "
2309 "qla2x00_abort_isp ha = %p\n",
2310 ha->host_no, ha));
2311 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2312 &ha->dpc_flags))) {
2313
2314 if (qla2x00_abort_isp(ha)) {
2315 /* failed. retry later */
2316 set_bit(ISP_ABORT_NEEDED,
2317 &ha->dpc_flags);
2318 }
2319 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2320 }
Seokmann Ju99363ef2008-01-31 12:33:51 -08002321
2322 for_each_mapped_vp_idx(ha, i) {
2323 list_for_each_entry(vha, &ha->vp_list,
2324 vp_list) {
2325 if (i == vha->vp_idx) {
2326 set_bit(ISP_ABORT_NEEDED,
2327 &vha->dpc_flags);
2328 break;
2329 }
2330 }
2331 }
2332
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2334 ha->host_no));
2335 }
2336
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002337 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags))
2338 qla2x00_update_fcports(ha);
2339
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2341 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2342
2343 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2344 ha->host_no));
2345
2346 qla2x00_rst_aen(ha);
2347 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2348 }
2349
2350 /* Retry each device up to login retry count */
2351 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2352 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2353 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2354
2355 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2356 ha->host_no));
2357
2358 next_loopid = 0;
2359 list_for_each_entry(fcport, &ha->fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 /*
2361 * If the port is not ONLINE then try to login
2362 * to it if we haven't run out of retries.
2363 */
2364 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2365 fcport->login_retry) {
2366
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 if (fcport->flags & FCF_FABRIC_DEVICE) {
2368 if (fcport->flags &
2369 FCF_TAPE_PRESENT)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002370 ha->isp_ops->fabric_logout(
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002371 ha, fcport->loop_id,
2372 fcport->d_id.b.domain,
2373 fcport->d_id.b.area,
2374 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 status = qla2x00_fabric_login(
2376 ha, fcport, &next_loopid);
2377 } else
2378 status =
2379 qla2x00_local_device_login(
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08002380 ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
Ravi Anand63a86512007-09-20 14:07:40 -07002382 fcport->login_retry--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 if (status == QLA_SUCCESS) {
2384 fcport->old_loop_id = fcport->loop_id;
2385
2386 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2387 ha->host_no, fcport->loop_id));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002388
andrew.vasquez@qlogic.com052c40c2006-01-20 14:53:19 -08002389 qla2x00_update_fcport(ha,
2390 fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 } else if (status == 1) {
2392 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2393 /* retry the login again */
2394 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2395 ha->host_no,
2396 fcport->login_retry, fcport->loop_id));
2397 } else {
2398 fcport->login_retry = 0;
2399 }
Andrew Vasquez666301e2008-04-24 15:21:30 -07002400 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
Ravi Anand63a86512007-09-20 14:07:40 -07002401 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 }
2403 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2404 break;
2405 }
2406 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2407 ha->host_no));
2408 }
2409
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2411
2412 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2413 ha->host_no));
2414
2415 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2416 &ha->dpc_flags))) {
2417
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002418 rval = qla2x00_loop_resync(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
2420 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2421 }
2422
2423 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2424 ha->host_no));
2425 }
2426
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002428 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002430 if (test_and_clear_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags))
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002431 ha->isp_ops->beacon_blink(ha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002432
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002433 qla2x00_do_dpc_all_vps(ha);
2434
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 ha->dpc_active = 0;
2436 } /* End of while(1) */
2437
2438 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2439
2440 /*
2441 * Make sure that nobody tries to wake us up again.
2442 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 ha->dpc_active = 0;
2444
Christoph Hellwig39a11242006-02-14 18:46:22 +01002445 return 0;
2446}
2447
2448void
2449qla2xxx_wake_dpc(scsi_qla_host_t *ha)
2450{
2451 if (ha->dpc_thread)
2452 wake_up_process(ha->dpc_thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453}
2454
2455/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456* qla2x00_rst_aen
2457* Processes asynchronous reset.
2458*
2459* Input:
2460* ha = adapter block pointer.
2461*/
2462static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002463qla2x00_rst_aen(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464{
2465 if (ha->flags.online && !ha->flags.reset_active &&
2466 !atomic_read(&ha->loop_down_timer) &&
2467 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2468 do {
2469 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2470
2471 /*
2472 * Issue marker command only when we are going to start
2473 * the I/O.
2474 */
2475 ha->marker_needed = 1;
2476 } while (!atomic_read(&ha->loop_down_timer) &&
2477 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2478 }
2479}
2480
f4f051e2005-04-17 15:02:26 -05002481static void
2482qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2483{
2484 struct scsi_cmnd *cmd = sp->cmd;
2485
2486 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002487 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05002488 sp->flags &= ~SRB_DMA_VALID;
2489 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002490 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002491}
2492
2493void
2494qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2495{
2496 struct scsi_cmnd *cmd = sp->cmd;
2497
2498 qla2x00_sp_free_dma(ha, sp);
2499
f4f051e2005-04-17 15:02:26 -05002500 mempool_free(sp, ha->srb_mempool);
2501
2502 cmd->scsi_done(cmd);
2503}
bdf79622005-04-17 15:06:53 -05002504
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505/**************************************************************************
2506* qla2x00_timer
2507*
2508* Description:
2509* One second timer
2510*
2511* Context: Interrupt
2512***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002513void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514qla2x00_timer(scsi_qla_host_t *ha)
2515{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 unsigned long cpu_flags = 0;
2517 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 int start_dpc = 0;
2519 int index;
2520 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002521 int t;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002522 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523
2524 /*
2525 * Ports - Port down timer.
2526 *
2527 * Whenever, a port is in the LOST state we start decrementing its port
2528 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002529 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 */
2531 t = 0;
2532 list_for_each_entry(fcport, &ha->fcports, list) {
2533 if (fcport->port_type != FCT_TARGET)
2534 continue;
2535
2536 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2537
2538 if (atomic_read(&fcport->port_down_timer) == 0)
2539 continue;
2540
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002541 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002543
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002545 "%d remaining\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 ha->host_no,
2547 t, atomic_read(&fcport->port_down_timer)));
2548 }
2549 t++;
2550 } /* End of for fcport */
2551
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552
2553 /* Loop down handler. */
2554 if (atomic_read(&ha->loop_down_timer) > 0 &&
2555 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2556
2557 if (atomic_read(&ha->loop_down_timer) ==
2558 ha->loop_down_abort_time) {
2559
2560 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2561 "queues before time expire\n",
2562 ha->host_no));
2563
2564 if (!IS_QLA2100(ha) && ha->link_down_timeout)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002565 atomic_set(&ha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566
2567 /* Schedule an ISP abort to return any tape commands. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002568 /* NPIV - scan physical port only */
2569 if (!ha->parent) {
2570 spin_lock_irqsave(&ha->hardware_lock,
2571 cpu_flags);
2572 for (index = 1;
2573 index < MAX_OUTSTANDING_COMMANDS;
2574 index++) {
2575 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05002576
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002577 sp = ha->outstanding_cmds[index];
2578 if (!sp)
2579 continue;
2580 sfcp = sp->fcport;
2581 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2582 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002584 set_bit(ISP_ABORT_NEEDED,
2585 &ha->dpc_flags);
2586 break;
2587 }
2588 spin_unlock_irqrestore(&ha->hardware_lock,
2589 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2592 start_dpc++;
2593 }
2594
2595 /* if the loop has been down for 4 minutes, reinit adapter */
2596 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2597 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2598 "restarting queues.\n",
2599 ha->host_no));
2600
2601 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2602 start_dpc++;
2603
Seokmann Ju463717e2008-04-03 13:13:29 -07002604 if (!(ha->device_flags & DFLG_NO_CABLE) &&
2605 !ha->parent) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 DEBUG(printk("scsi(%ld): Loop down - "
2607 "aborting ISP.\n",
2608 ha->host_no));
2609 qla_printk(KERN_WARNING, ha,
2610 "Loop down - aborting ISP.\n");
2611
2612 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2613 }
2614 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002615 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 ha->host_no,
2617 atomic_read(&ha->loop_down_timer)));
2618 }
2619
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002620 /* Check if beacon LED needs to be blinked */
2621 if (ha->beacon_blink_led == 1) {
2622 set_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags);
2623 start_dpc++;
2624 }
2625
Andrew Vasquez550bf572008-04-24 15:21:23 -07002626 /* Process any deferred work. */
2627 if (!list_empty(&ha->work_list))
2628 start_dpc++;
2629
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 /* Schedule the DPC routine if needed */
2631 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2632 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002633 test_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 start_dpc ||
f4f051e2005-04-17 15:02:26 -05002635 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002636 test_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags) ||
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002637 test_bit(VP_DPC_NEEDED, &ha->dpc_flags) ||
Christoph Hellwig39a11242006-02-14 18:46:22 +01002638 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002639 qla2xxx_wake_dpc(pha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640
2641 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2642}
2643
Andrew Vasquez54333832005-11-09 15:49:04 -08002644/* Firmware interface routines. */
2645
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002646#define FW_BLOBS 6
Andrew Vasquez54333832005-11-09 15:49:04 -08002647#define FW_ISP21XX 0
2648#define FW_ISP22XX 1
2649#define FW_ISP2300 2
2650#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002651#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002652#define FW_ISP25XX 5
Andrew Vasquez54333832005-11-09 15:49:04 -08002653
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002654#define FW_FILE_ISP21XX "ql2100_fw.bin"
2655#define FW_FILE_ISP22XX "ql2200_fw.bin"
2656#define FW_FILE_ISP2300 "ql2300_fw.bin"
2657#define FW_FILE_ISP2322 "ql2322_fw.bin"
2658#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002659#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002660
Daniel Walkere1e82b62008-05-12 22:21:10 -07002661static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002662
2663static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002664 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
2665 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
2666 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
2667 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
2668 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002669 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08002670};
2671
2672struct fw_blob *
2673qla2x00_request_firmware(scsi_qla_host_t *ha)
2674{
2675 struct fw_blob *blob;
2676
2677 blob = NULL;
2678 if (IS_QLA2100(ha)) {
2679 blob = &qla_fw_blobs[FW_ISP21XX];
2680 } else if (IS_QLA2200(ha)) {
2681 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002682 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002683 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002684 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002685 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002686 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002687 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002688 } else if (IS_QLA25XX(ha)) {
2689 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08002690 }
2691
Daniel Walkere1e82b62008-05-12 22:21:10 -07002692 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002693 if (blob->fw)
2694 goto out;
2695
2696 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
2697 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
2698 "(%s).\n", ha->host_no, blob->name));
2699 blob->fw = NULL;
2700 blob = NULL;
2701 goto out;
2702 }
2703
2704out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07002705 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002706 return blob;
2707}
2708
2709static void
2710qla2x00_release_firmware(void)
2711{
2712 int idx;
2713
Daniel Walkere1e82b62008-05-12 22:21:10 -07002714 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002715 for (idx = 0; idx < FW_BLOBS; idx++)
2716 if (qla_fw_blobs[idx].fw)
2717 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07002718 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002719}
2720
Seokmann Ju14e660e2007-09-20 14:07:36 -07002721static pci_ers_result_t
2722qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
2723{
2724 switch (state) {
2725 case pci_channel_io_normal:
2726 return PCI_ERS_RESULT_CAN_RECOVER;
2727 case pci_channel_io_frozen:
2728 pci_disable_device(pdev);
2729 return PCI_ERS_RESULT_NEED_RESET;
2730 case pci_channel_io_perm_failure:
2731 qla2x00_remove_one(pdev);
2732 return PCI_ERS_RESULT_DISCONNECT;
2733 }
2734 return PCI_ERS_RESULT_NEED_RESET;
2735}
2736
2737static pci_ers_result_t
2738qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
2739{
2740 int risc_paused = 0;
2741 uint32_t stat;
2742 unsigned long flags;
2743 scsi_qla_host_t *ha = pci_get_drvdata(pdev);
2744 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2745 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
2746
2747 spin_lock_irqsave(&ha->hardware_lock, flags);
2748 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
2749 stat = RD_REG_DWORD(&reg->hccr);
2750 if (stat & HCCR_RISC_PAUSE)
2751 risc_paused = 1;
2752 } else if (IS_QLA23XX(ha)) {
2753 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
2754 if (stat & HSR_RISC_PAUSED)
2755 risc_paused = 1;
2756 } else if (IS_FWI2_CAPABLE(ha)) {
2757 stat = RD_REG_DWORD(&reg24->host_status);
2758 if (stat & HSRX_RISC_PAUSED)
2759 risc_paused = 1;
2760 }
2761 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2762
2763 if (risc_paused) {
2764 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
2765 "Dumping firmware!\n");
2766 ha->isp_ops->fw_dump(ha, 0);
2767
2768 return PCI_ERS_RESULT_NEED_RESET;
2769 } else
2770 return PCI_ERS_RESULT_RECOVERED;
2771}
2772
2773static pci_ers_result_t
2774qla2xxx_pci_slot_reset(struct pci_dev *pdev)
2775{
2776 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
2777 scsi_qla_host_t *ha = pci_get_drvdata(pdev);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002778 int rc;
Seokmann Ju14e660e2007-09-20 14:07:36 -07002779
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002780 if (ha->mem_only)
2781 rc = pci_enable_device_mem(pdev);
2782 else
2783 rc = pci_enable_device(pdev);
2784
2785 if (rc) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07002786 qla_printk(KERN_WARNING, ha,
2787 "Can't re-enable PCI device after reset.\n");
2788
2789 return ret;
2790 }
2791 pci_set_master(pdev);
2792
2793 if (ha->isp_ops->pci_config(ha))
2794 return ret;
2795
2796 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2797 if (qla2x00_abort_isp(ha)== QLA_SUCCESS)
2798 ret = PCI_ERS_RESULT_RECOVERED;
2799 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2800
2801 return ret;
2802}
2803
2804static void
2805qla2xxx_pci_resume(struct pci_dev *pdev)
2806{
2807 scsi_qla_host_t *ha = pci_get_drvdata(pdev);
2808 int ret;
2809
2810 ret = qla2x00_wait_for_hba_online(ha);
2811 if (ret != QLA_SUCCESS) {
2812 qla_printk(KERN_ERR, ha,
2813 "the device failed to resume I/O "
2814 "from slot/link_reset");
2815 }
2816 pci_cleanup_aer_uncorrect_error_status(pdev);
2817}
2818
2819static struct pci_error_handlers qla2xxx_err_handler = {
2820 .error_detected = qla2xxx_pci_error_detected,
2821 .mmio_enabled = qla2xxx_pci_mmio_enabled,
2822 .slot_reset = qla2xxx_pci_slot_reset,
2823 .resume = qla2xxx_pci_resume,
2824};
2825
Andrew Vasquez54333832005-11-09 15:49:04 -08002826static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07002827 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
2828 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
2829 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
2830 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
2831 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
2832 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
2833 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
2834 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
2835 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002836 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07002837 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
2838 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002839 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez54333832005-11-09 15:49:04 -08002840 { 0 },
2841};
2842MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2843
Andrew Vasquezfca29702005-07-06 10:31:47 -07002844static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07002845 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06002846 .driver = {
2847 .owner = THIS_MODULE,
2848 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07002849 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002850 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08002851 .remove = qla2x00_remove_one,
Seokmann Ju14e660e2007-09-20 14:07:36 -07002852 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07002853};
2854
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855/**
2856 * qla2x00_module_init - Module initialization.
2857 **/
2858static int __init
2859qla2x00_module_init(void)
2860{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002861 int ret = 0;
2862
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002864 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09002865 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 if (srb_cachep == NULL) {
2867 printk(KERN_ERR
2868 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2869 return -ENOMEM;
2870 }
2871
2872 /* Derive version string. */
2873 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002874 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07002875 strcat(qla2x00_version_str, "-debug");
2876
Andrew Vasquez1c97a122005-04-21 16:13:36 -04002877 qla2xxx_transport_template =
2878 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002879 if (!qla2xxx_transport_template) {
2880 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002882 }
2883 qla2xxx_transport_vport_template =
2884 fc_attach_transport(&qla2xxx_transport_vport_functions);
2885 if (!qla2xxx_transport_vport_template) {
2886 kmem_cache_destroy(srb_cachep);
2887 fc_release_transport(qla2xxx_transport_template);
2888 return -ENODEV;
2889 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07002891 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
2892 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002893 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002894 if (ret) {
2895 kmem_cache_destroy(srb_cachep);
2896 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002897 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002898 }
2899 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900}
2901
2902/**
2903 * qla2x00_module_exit - Module cleanup.
2904 **/
2905static void __exit
2906qla2x00_module_exit(void)
2907{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002908 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08002909 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002910 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002912 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913}
2914
2915module_init(qla2x00_module_init);
2916module_exit(qla2x00_module_exit);
2917
2918MODULE_AUTHOR("QLogic Corporation");
2919MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2920MODULE_LICENSE("GPL");
2921MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002922MODULE_FIRMWARE(FW_FILE_ISP21XX);
2923MODULE_FIRMWARE(FW_FILE_ISP22XX);
2924MODULE_FIRMWARE(FW_FILE_ISP2300);
2925MODULE_FIRMWARE(FW_FILE_ISP2322);
2926MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08002927MODULE_FIRMWARE(FW_FILE_ISP25XX);