blob: 9c3a57fa506062f6e042c0ba8579fe423dca1ed6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
8
9#include <linux/moduleparam.h>
10#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/delay.h>
Christoph Hellwig39a11242006-02-14 18:46:22 +010012#include <linux/kthread.h>
Daniel Walkere1e82b62008-05-12 22:21:10 -070013#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#include <scsi/scsi_tcq.h>
16#include <scsi/scsicam.h>
17#include <scsi/scsi_transport.h>
18#include <scsi/scsi_transport_fc.h>
19
20/*
21 * Driver version
22 */
23char qla2x00_version_str[40];
24
25/*
26 * SRB allocation cache
27 */
Christoph Lametere18b8902006-12-06 20:33:20 -080028static struct kmem_cache *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030int ql2xlogintimeout = 20;
31module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
32MODULE_PARM_DESC(ql2xlogintimeout,
33 "Login timeout value in seconds.");
34
Andrew Vasqueza7b61842007-05-07 07:42:59 -070035int qlport_down_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
37MODULE_PARM_DESC(qlport_down_retry,
Jesper Juhl900d9f92006-06-30 02:33:07 -070038 "Maximum number of command retries to a port that returns "
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 "a PORT-DOWN status.");
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041int ql2xplogiabsentdevice;
42module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
43MODULE_PARM_DESC(ql2xplogiabsentdevice,
44 "Option to enable PLOGI to devices that are not present after "
Jesper Juhl900d9f92006-06-30 02:33:07 -070045 "a Fabric scan. This is needed for several broken switches. "
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048int ql2xloginretrycount = 0;
49module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
50MODULE_PARM_DESC(ql2xloginretrycount,
51 "Specify an alternate value for the NVRAM login retry count.");
52
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070053int ql2xallocfwdump = 1;
54module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
55MODULE_PARM_DESC(ql2xallocfwdump,
56 "Option to enable allocation of memory for a firmware dump "
57 "during HBA initialization. Memory allocation requirements "
58 "vary by ISP type. Default is 1 - allocate memory.");
59
Andrew Vasquez11010fe2006-10-06 09:54:59 -070060int ql2xextended_error_logging;
Andrew Vasquez27d94032007-03-12 10:41:30 -070061module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070062MODULE_PARM_DESC(ql2xextended_error_logging,
Andrew Vasquez01819442006-06-23 16:11:10 -070063 "Option to enable extended error logging, "
64 "Default is 0 - no logging. 1 - log errors.");
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066static void qla2x00_free_device(scsi_qla_host_t *);
67
68static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
69
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -070070int ql2xfdmienable=1;
Andrew Vasquezcca53352005-08-26 19:08:30 -070071module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
72MODULE_PARM_DESC(ql2xfdmienable,
73 "Enables FDMI registratons "
74 "Default is 0 - no FDMI. 1 - perfom FDMI.");
75
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070076#define MAX_Q_DEPTH 32
77static int ql2xmaxqdepth = MAX_Q_DEPTH;
78module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
79MODULE_PARM_DESC(ql2xmaxqdepth,
80 "Maximum queue depth to report for target devices.");
81
82int ql2xqfullrampup = 120;
83module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR);
84MODULE_PARM_DESC(ql2xqfullrampup,
85 "Number of seconds to wait to begin to ramp-up the queue "
86 "depth for a device after a queue-full condition has been "
87 "detected. Default is 120 seconds.");
88
Andrew Vasqueze5896bd2008-07-10 16:55:52 -070089int ql2xiidmaenable=1;
90module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
91MODULE_PARM_DESC(ql2xiidmaenable,
92 "Enables iIDMA settings "
93 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
94
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -070097 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 */
99static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500100static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800101static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
102static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500103static void qla2xxx_slave_destroy(struct scsi_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
105 void (*fn)(struct scsi_cmnd *));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700106static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
107 void (*fn)(struct scsi_cmnd *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static int qla2xxx_eh_abort(struct scsi_cmnd *);
109static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700110static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
112static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700114static int qla2x00_change_queue_depth(struct scsi_device *, int);
115static int qla2x00_change_queue_type(struct scsi_device *, int);
116
Adrian Bunka824ebb2008-01-17 09:02:15 -0800117static struct scsi_host_template qla2x00_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700119 .name = QLA2XXX_DRIVER_NAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 .queuecommand = qla2x00_queuecommand,
121
122 .eh_abort_handler = qla2xxx_eh_abort,
123 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700124 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
126 .eh_host_reset_handler = qla2xxx_eh_host_reset,
127
128 .slave_configure = qla2xxx_slave_configure,
129
f4f051e2005-04-17 15:02:26 -0500130 .slave_alloc = qla2xxx_slave_alloc,
131 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800132 .scan_finished = qla2xxx_scan_finished,
133 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700134 .change_queue_depth = qla2x00_change_queue_depth,
135 .change_queue_type = qla2x00_change_queue_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 .this_id = -1,
137 .cmd_per_lun = 3,
138 .use_clustering = ENABLE_CLUSTERING,
139 .sg_tablesize = SG_ALL,
140
141 /*
142 * The RISC allows for each command to transfer (2^32-1) bytes of data,
143 * which equates to 0x800000 sectors.
144 */
145 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700146 .shost_attrs = qla2x00_host_attrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147};
148
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700149struct scsi_host_template qla24xx_driver_template = {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700150 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700151 .name = QLA2XXX_DRIVER_NAME,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700152 .queuecommand = qla24xx_queuecommand,
153
154 .eh_abort_handler = qla2xxx_eh_abort,
155 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700156 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700157 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
158 .eh_host_reset_handler = qla2xxx_eh_host_reset,
159
160 .slave_configure = qla2xxx_slave_configure,
161
162 .slave_alloc = qla2xxx_slave_alloc,
163 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700164 .scan_finished = qla2xxx_scan_finished,
165 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700166 .change_queue_depth = qla2x00_change_queue_depth,
167 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700168 .this_id = -1,
169 .cmd_per_lun = 3,
170 .use_clustering = ENABLE_CLUSTERING,
171 .sg_tablesize = SG_ALL,
172
173 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700174 .shost_attrs = qla2x00_host_attrs,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700175};
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700178struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180/* TODO Convert to inlines
181 *
182 * Timer routines
183 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700185__inline__ void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
187{
188 init_timer(&ha->timer);
189 ha->timer.expires = jiffies + interval * HZ;
190 ha->timer.data = (unsigned long)ha;
191 ha->timer.function = (void (*)(unsigned long))func;
192 add_timer(&ha->timer);
193 ha->timer_active = 1;
194}
195
196static inline void
197qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
198{
199 mod_timer(&ha->timer, jiffies + interval * HZ);
200}
201
Adrian Bunka824ebb2008-01-17 09:02:15 -0800202static __inline__ void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203qla2x00_stop_timer(scsi_qla_host_t *ha)
204{
205 del_timer_sync(&ha->timer);
206 ha->timer_active = 0;
207}
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209static int qla2x00_do_dpc(void *data);
210
211static void qla2x00_rst_aen(scsi_qla_host_t *);
212
Andrew Vasqueze8711082008-01-31 12:33:48 -0800213static int qla2x00_mem_alloc(scsi_qla_host_t *);
Adrian Bunka824ebb2008-01-17 09:02:15 -0800214static void qla2x00_mem_free(scsi_qla_host_t *ha);
f4f051e2005-04-17 15:02:26 -0500215static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217/* -------------------------------------------------------------------------- */
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219static char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700220qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
222 static char *pci_bus_modes[] = {
223 "33", "66", "100", "133",
224 };
225 uint16_t pci_bus;
226
227 strcpy(str, "PCI");
228 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
229 if (pci_bus) {
230 strcat(str, "-X (");
231 strcat(str, pci_bus_modes[pci_bus]);
232 } else {
233 pci_bus = (ha->pci_attr & BIT_8) >> 8;
234 strcat(str, " (");
235 strcat(str, pci_bus_modes[pci_bus]);
236 }
237 strcat(str, " MHz)");
238
239 return (str);
240}
241
Andrew Vasquezfca29702005-07-06 10:31:47 -0700242static char *
243qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
244{
245 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
246 uint32_t pci_bus;
247 int pcie_reg;
248
249 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
250 if (pcie_reg) {
251 char lwstr[6];
252 uint16_t pcie_lstat, lspeed, lwidth;
253
254 pcie_reg += 0x12;
255 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
256 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
257 lwidth = (pcie_lstat &
258 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
259
260 strcpy(str, "PCIe (");
261 if (lspeed == 1)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700262 strcat(str, "2.5GT/s ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700263 else if (lspeed == 2)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700264 strcat(str, "5.0GT/s ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700265 else
266 strcat(str, "<unknown> ");
267 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
268 strcat(str, lwstr);
269
270 return str;
271 }
272
273 strcpy(str, "PCI");
274 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
275 if (pci_bus == 0 || pci_bus == 8) {
276 strcat(str, " (");
277 strcat(str, pci_bus_modes[pci_bus >> 3]);
278 } else {
279 strcat(str, "-X ");
280 if (pci_bus & BIT_2)
281 strcat(str, "Mode 2");
282 else
283 strcat(str, "Mode 1");
284 strcat(str, " (");
285 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
286 }
287 strcat(str, " MHz)");
288
289 return str;
290}
291
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800292static char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700293qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
295 char un_str[10];
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
298 ha->fw_minor_version,
299 ha->fw_subminor_version);
300
301 if (ha->fw_attributes & BIT_9) {
302 strcat(str, "FLX");
303 return (str);
304 }
305
306 switch (ha->fw_attributes & 0xFF) {
307 case 0x7:
308 strcat(str, "EF");
309 break;
310 case 0x17:
311 strcat(str, "TP");
312 break;
313 case 0x37:
314 strcat(str, "IP");
315 break;
316 case 0x77:
317 strcat(str, "VI");
318 break;
319 default:
320 sprintf(un_str, "(%x)", ha->fw_attributes);
321 strcat(str, un_str);
322 break;
323 }
324 if (ha->fw_attributes & 0x100)
325 strcat(str, "X");
326
327 return (str);
328}
329
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800330static char *
Andrew Vasquezfca29702005-07-06 10:31:47 -0700331qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
332{
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700333 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
334 ha->fw_minor_version,
335 ha->fw_subminor_version);
336
Andrew Vasquezfca29702005-07-06 10:31:47 -0700337 if (ha->fw_attributes & BIT_0)
338 strcat(str, "[Class 2] ");
339 if (ha->fw_attributes & BIT_1)
340 strcat(str, "[IP] ");
341 if (ha->fw_attributes & BIT_2)
342 strcat(str, "[Multi-ID] ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700343 if (ha->fw_attributes & BIT_3)
344 strcat(str, "[SB-2] ");
345 if (ha->fw_attributes & BIT_4)
346 strcat(str, "[T10 CRC] ");
347 if (ha->fw_attributes & BIT_5)
348 strcat(str, "[VI] ");
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700349 if (ha->fw_attributes & BIT_10)
350 strcat(str, "[84XX] ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700351 if (ha->fw_attributes & BIT_13)
352 strcat(str, "[Experimental]");
353 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700354}
355
356static inline srb_t *
357qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
358 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
359{
360 srb_t *sp;
361
362 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
363 if (!sp)
364 return sp;
365
Andrew Vasquezfca29702005-07-06 10:31:47 -0700366 sp->ha = ha;
367 sp->fcport = fcport;
368 sp->cmd = cmd;
369 sp->flags = 0;
370 CMD_SP(cmd) = (void *)sp;
371 cmd->scsi_done = done;
372
373 return sp;
374}
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376static int
f4f051e2005-04-17 15:02:26 -0500377qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700379 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500380 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400381 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
f4f051e2005-04-17 15:02:26 -0500382 srb_t *sp;
383 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Seokmann Ju14e660e2007-09-20 14:07:36 -0700385 if (unlikely(pci_channel_offline(ha->pdev))) {
386 cmd->result = DID_REQUEUE << 16;
387 goto qc_fail_command;
388 }
389
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400390 rval = fc_remote_port_chkready(rport);
391 if (rval) {
392 cmd->result = rval;
f4f051e2005-04-17 15:02:26 -0500393 goto qc_fail_command;
394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800396 /* Close window on fcport/rport state-transitioning. */
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700397 if (fcport->drport) {
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800398 cmd->result = DID_IMM_RETRY << 16;
399 goto qc_fail_command;
400 }
401
f4f051e2005-04-17 15:02:26 -0500402 if (atomic_read(&fcport->state) != FCS_ONLINE) {
403 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
404 atomic_read(&ha->loop_state) == LOOP_DEAD) {
405 cmd->result = DID_NO_CONNECT << 16;
406 goto qc_fail_command;
407 }
408 goto qc_host_busy;
409 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411 spin_unlock_irq(ha->host->host_lock);
412
Andrew Vasquezfca29702005-07-06 10:31:47 -0700413 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
414 if (!sp)
f4f051e2005-04-17 15:02:26 -0500415 goto qc_host_busy_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
f4f051e2005-04-17 15:02:26 -0500417 rval = qla2x00_start_scsi(sp);
418 if (rval != QLA_SUCCESS)
419 goto qc_host_busy_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 spin_lock_irq(ha->host->host_lock);
422
f4f051e2005-04-17 15:02:26 -0500423 return 0;
424
425qc_host_busy_free_sp:
426 qla2x00_sp_free_dma(ha, sp);
f4f051e2005-04-17 15:02:26 -0500427 mempool_free(sp, ha->srb_mempool);
428
429qc_host_busy_lock:
430 spin_lock_irq(ha->host->host_lock);
431
432qc_host_busy:
433 return SCSI_MLQUEUE_HOST_BUSY;
434
435qc_fail_command:
436 done(cmd);
437
438 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439}
440
Andrew Vasquezfca29702005-07-06 10:31:47 -0700441
442static int
443qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
444{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700445 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700446 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400447 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700448 srb_t *sp;
449 int rval;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700450 scsi_qla_host_t *pha = to_qla_parent(ha);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700451
Seokmann Ju14e660e2007-09-20 14:07:36 -0700452 if (unlikely(pci_channel_offline(ha->pdev))) {
453 cmd->result = DID_REQUEUE << 16;
454 goto qc24_fail_command;
455 }
456
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400457 rval = fc_remote_port_chkready(rport);
458 if (rval) {
459 cmd->result = rval;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700460 goto qc24_fail_command;
461 }
462
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800463 /* Close window on fcport/rport state-transitioning. */
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700464 if (fcport->drport) {
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800465 cmd->result = DID_IMM_RETRY << 16;
466 goto qc24_fail_command;
467 }
468
Andrew Vasquezfca29702005-07-06 10:31:47 -0700469 if (atomic_read(&fcport->state) != FCS_ONLINE) {
470 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700471 atomic_read(&pha->loop_state) == LOOP_DEAD) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700472 cmd->result = DID_NO_CONNECT << 16;
473 goto qc24_fail_command;
474 }
475 goto qc24_host_busy;
476 }
477
478 spin_unlock_irq(ha->host->host_lock);
479
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700480 sp = qla2x00_get_new_sp(pha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700481 if (!sp)
482 goto qc24_host_busy_lock;
483
484 rval = qla24xx_start_scsi(sp);
485 if (rval != QLA_SUCCESS)
486 goto qc24_host_busy_free_sp;
487
488 spin_lock_irq(ha->host->host_lock);
489
490 return 0;
491
492qc24_host_busy_free_sp:
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700493 qla2x00_sp_free_dma(pha, sp);
494 mempool_free(sp, pha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700495
496qc24_host_busy_lock:
497 spin_lock_irq(ha->host->host_lock);
498
499qc24_host_busy:
500 return SCSI_MLQUEUE_HOST_BUSY;
501
502qc24_fail_command:
503 done(cmd);
504
505 return 0;
506}
507
508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509/*
510 * qla2x00_eh_wait_on_command
511 * Waits for the command to be returned by the Firmware for some
512 * max time.
513 *
514 * Input:
515 * ha = actual ha whose done queue will contain the command
516 * returned by firmware.
517 * cmd = Scsi Command to wait on.
518 * flag = Abort/Reset(Bus or Device Reset)
519 *
520 * Return:
521 * Not Found : 0
522 * Found : 1
523 */
524static int
525qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
526{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700527#define ABORT_POLLING_PERIOD 1000
528#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500529 unsigned long wait_iter = ABORT_WAIT_ITER;
530 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
f4f051e2005-04-17 15:02:26 -0500532 while (CMD_SP(cmd)) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700533 msleep(ABORT_POLLING_PERIOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
f4f051e2005-04-17 15:02:26 -0500535 if (--wait_iter)
536 break;
537 }
538 if (CMD_SP(cmd))
539 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
f4f051e2005-04-17 15:02:26 -0500541 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542}
543
544/*
545 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700546 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 * <= MAX_RETRIES_OF_ISP_ABORT or
548 * finally HBA is disabled ie marked offline
549 *
550 * Input:
551 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700552 *
553 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 * Does context switching-Release SPIN_LOCK
555 * (if any) before calling this routine.
556 *
557 * Return:
558 * Success (Adapter is online) : 0
559 * Failed (Adapter is offline/disabled) : 1
560 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800561int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
563{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700564 int return_status;
565 unsigned long wait_online;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700566 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700568 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700569 while (((test_bit(ISP_ABORT_NEEDED, &pha->dpc_flags)) ||
570 test_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags) ||
571 test_bit(ISP_ABORT_RETRY, &pha->dpc_flags) ||
572 pha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
574 msleep(1000);
575 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700576 if (pha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700577 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 else
579 return_status = QLA_FUNCTION_FAILED;
580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 return (return_status);
582}
583
584/*
585 * qla2x00_wait_for_loop_ready
586 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700587 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 * Input:
589 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700590 *
591 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 * Does context switching-Release SPIN_LOCK
593 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700594 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 *
596 * Return:
597 * Success (LOOP_READY) : 0
598 * Failed (LOOP_NOT_READY) : 1
599 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700600static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
602{
603 int return_status = QLA_SUCCESS;
604 unsigned long loop_timeout ;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700605 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
607 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700608 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700610 while ((!atomic_read(&pha->loop_down_timer) &&
611 atomic_read(&pha->loop_state) == LOOP_DOWN) ||
612 atomic_read(&pha->loop_state) != LOOP_READY) {
613 if (atomic_read(&pha->loop_state) == LOOP_DEAD) {
Ravi Anand57680082006-05-17 15:08:44 -0700614 return_status = QLA_FUNCTION_FAILED;
615 break;
616 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 msleep(1000);
618 if (time_after_eq(jiffies, loop_timeout)) {
619 return_status = QLA_FUNCTION_FAILED;
620 break;
621 }
622 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700623 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624}
625
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700626void
627qla2x00_abort_fcport_cmds(fc_port_t *fcport)
628{
629 int cnt;
630 unsigned long flags;
631 srb_t *sp;
632 scsi_qla_host_t *ha = fcport->ha;
633 scsi_qla_host_t *pha = to_qla_parent(ha);
634
635 spin_lock_irqsave(&pha->hardware_lock, flags);
636 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
637 sp = pha->outstanding_cmds[cnt];
638 if (!sp)
639 continue;
640 if (sp->fcport != fcport)
641 continue;
642
643 spin_unlock_irqrestore(&pha->hardware_lock, flags);
644 if (ha->isp_ops->abort_command(ha, sp)) {
645 DEBUG2(qla_printk(KERN_WARNING, ha,
646 "Abort failed -- %lx\n", sp->cmd->serial_number));
647 } else {
648 if (qla2x00_eh_wait_on_command(ha, sp->cmd) !=
649 QLA_SUCCESS)
650 DEBUG2(qla_printk(KERN_WARNING, ha,
651 "Abort failed while waiting -- %lx\n",
652 sp->cmd->serial_number));
653
654 }
655 spin_lock_irqsave(&pha->hardware_lock, flags);
656 }
657 spin_unlock_irqrestore(&pha->hardware_lock, flags);
658}
659
Andrew Vasquez07db5182006-10-02 12:00:49 -0700660static void
661qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
662{
663 struct Scsi_Host *shost = cmnd->device->host;
664 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
665 unsigned long flags;
666
667 spin_lock_irqsave(shost->host_lock, flags);
668 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
669 spin_unlock_irqrestore(shost->host_lock, flags);
670 msleep(1000);
671 spin_lock_irqsave(shost->host_lock, flags);
672 }
673 spin_unlock_irqrestore(shost->host_lock, flags);
674 return;
675}
676
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677/**************************************************************************
678* qla2xxx_eh_abort
679*
680* Description:
681* The abort function will abort the specified command.
682*
683* Input:
684* cmd = Linux SCSI command packet to be aborted.
685*
686* Returns:
687* Either SUCCESS or FAILED.
688*
689* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700690* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800692static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693qla2xxx_eh_abort(struct scsi_cmnd *cmd)
694{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700695 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500696 srb_t *sp;
697 int ret, i;
698 unsigned int id, lun;
699 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700700 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700701 int wait = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700702 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Andrew Vasquez07db5182006-10-02 12:00:49 -0700704 qla2x00_block_error_handler(cmd);
705
f4f051e2005-04-17 15:02:26 -0500706 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700707 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Michael Reed2ea00202006-04-27 16:25:30 -0700709 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
f4f051e2005-04-17 15:02:26 -0500711 id = cmd->device->id;
712 lun = cmd->device->lun;
713 serial = cmd->serial_number;
714
715 /* Check active list for command command. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700716 spin_lock_irqsave(&pha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500717 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700718 sp = pha->outstanding_cmds[i];
f4f051e2005-04-17 15:02:26 -0500719
720 if (sp == NULL)
721 continue;
722
723 if (sp->cmd != cmd)
724 continue;
725
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700726 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld.\n",
727 __func__, ha->host_no, sp, serial));
f4f051e2005-04-17 15:02:26 -0500728
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700729 spin_unlock_irqrestore(&pha->hardware_lock, flags);
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700730 if (ha->isp_ops->abort_command(ha, sp)) {
f4f051e2005-04-17 15:02:26 -0500731 DEBUG2(printk("%s(%ld): abort_command "
732 "mbx failed.\n", __func__, ha->host_no));
733 } else {
734 DEBUG3(printk("%s(%ld): abort_command "
735 "mbx success.\n", __func__, ha->host_no));
Michael Reed2ea00202006-04-27 16:25:30 -0700736 wait = 1;
f4f051e2005-04-17 15:02:26 -0500737 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700738 spin_lock_irqsave(&pha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500739
740 break;
741 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700742 spin_unlock_irqrestore(&pha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500743
744 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700745 if (wait) {
f4f051e2005-04-17 15:02:26 -0500746 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700747 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500748 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
749 "%x.\n", ha->host_no, id, lun, serial, ret);
Michael Reed2ea00202006-04-27 16:25:30 -0700750 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500751 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700754 qla_printk(KERN_INFO, ha,
Michael Reed2ea00202006-04-27 16:25:30 -0700755 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
756 ha->host_no, id, lun, wait, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
f4f051e2005-04-17 15:02:26 -0500758 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759}
760
Andrew Vasquez523ec772008-04-03 13:13:24 -0700761enum nexus_wait_type {
762 WAIT_HOST = 0,
763 WAIT_TARGET,
764 WAIT_LUN,
765};
766
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700768qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha, unsigned int t,
769 unsigned int l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700771 int cnt, match, status;
772 srb_t *sp;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700773 unsigned long flags;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700774 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Andrew Vasquez523ec772008-04-03 13:13:24 -0700776 status = QLA_SUCCESS;
777 spin_lock_irqsave(&pha->hardware_lock, flags);
778 for (cnt = 1; status == QLA_SUCCESS && cnt < MAX_OUTSTANDING_COMMANDS;
779 cnt++) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700780 sp = pha->outstanding_cmds[cnt];
Andrew Vasquez523ec772008-04-03 13:13:24 -0700781 if (!sp)
782 continue;
783 if (ha->vp_idx != sp->ha->vp_idx)
784 continue;
785 match = 0;
786 switch (type) {
787 case WAIT_HOST:
788 match = 1;
789 break;
790 case WAIT_TARGET:
791 match = sp->cmd->device->id == t;
792 break;
793 case WAIT_LUN:
794 match = (sp->cmd->device->id == t &&
795 sp->cmd->device->lun == l);
796 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 }
Andrew Vasquez523ec772008-04-03 13:13:24 -0700798 if (!match)
799 continue;
800
801 spin_unlock_irqrestore(&pha->hardware_lock, flags);
802 status = qla2x00_eh_wait_on_command(ha, sp->cmd);
803 spin_lock_irqsave(&pha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 }
Andrew Vasquez523ec772008-04-03 13:13:24 -0700805 spin_unlock_irqrestore(&pha->hardware_lock, flags);
806
807 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808}
809
Andrew Vasquez523ec772008-04-03 13:13:24 -0700810static char *reset_errors[] = {
811 "HBA not online",
812 "HBA not ready",
813 "Task management failed",
814 "Waiting for command completions",
815};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Andrew Vasquez523ec772008-04-03 13:13:24 -0700817static int
818__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
819 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int))
820{
821 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
822 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
823 int err;
824
825 qla2x00_block_error_handler(cmd);
826
827 if (!fcport)
828 return FAILED;
829
830 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
831 ha->host_no, cmd->device->id, cmd->device->lun, name);
832
833 err = 0;
834 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
835 goto eh_reset_failed;
836 err = 1;
837 if (qla2x00_wait_for_loop_ready(ha) != QLA_SUCCESS)
838 goto eh_reset_failed;
839 err = 2;
840 if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS)
841 goto eh_reset_failed;
842 err = 3;
843 if (qla2x00_eh_wait_for_pending_commands(ha, cmd->device->id,
844 cmd->device->lun, type) != QLA_SUCCESS)
845 goto eh_reset_failed;
846
847 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
848 ha->host_no, cmd->device->id, cmd->device->lun, name);
849
850 return SUCCESS;
851
852 eh_reset_failed:
853 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n",
854 ha->host_no, cmd->device->id, cmd->device->lun, name,
855 reset_errors[err]);
856 return FAILED;
857}
858
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800859static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
861{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700862 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
Andrew Vasquez523ec772008-04-03 13:13:24 -0700864 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
865 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866}
867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700869qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700871 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Andrew Vasquez523ec772008-04-03 13:13:24 -0700873 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
874 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875}
876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877/**************************************************************************
878* qla2xxx_eh_bus_reset
879*
880* Description:
881* The bus reset function will reset the bus and abort any executing
882* commands.
883*
884* Input:
885* cmd = Linux SCSI command packet of the command that cause the
886* bus reset.
887*
888* Returns:
889* SUCCESS/FAILURE (defined as macro in scsi.h).
890*
891**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800892static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
894{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700895 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700896 scsi_qla_host_t *pha = to_qla_parent(ha);
bdf79622005-04-17 15:06:53 -0500897 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700898 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500899 unsigned int id, lun;
900 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
Andrew Vasquez07db5182006-10-02 12:00:49 -0700902 qla2x00_block_error_handler(cmd);
903
f4f051e2005-04-17 15:02:26 -0500904 id = cmd->device->id;
905 lun = cmd->device->lun;
906 serial = cmd->serial_number;
907
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700908 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500909 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
911 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500912 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
915 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500916 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 }
918
919 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500920 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
921 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 }
f4f051e2005-04-17 15:02:26 -0500923 if (ret == FAILED)
924 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700926 /* Flush outstanding commands. */
Andrew Vasquez523ec772008-04-03 13:13:24 -0700927 if (qla2x00_eh_wait_for_pending_commands(pha, 0, 0, WAIT_HOST) !=
928 QLA_SUCCESS)
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700929 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
f4f051e2005-04-17 15:02:26 -0500931eh_bus_reset_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500933 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
f4f051e2005-04-17 15:02:26 -0500935 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936}
937
938/**************************************************************************
939* qla2xxx_eh_host_reset
940*
941* Description:
942* The reset function will reset the Adapter.
943*
944* Input:
945* cmd = Linux SCSI command packet of the command that cause the
946* adapter reset.
947*
948* Returns:
949* Either SUCCESS or FAILED.
950*
951* Note:
952**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800953static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
955{
Andrew Vasquezf363b942007-09-20 14:07:45 -0700956 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500957 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700958 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500959 unsigned int id, lun;
960 unsigned long serial;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700961 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
Andrew Vasquez07db5182006-10-02 12:00:49 -0700963 qla2x00_block_error_handler(cmd);
964
f4f051e2005-04-17 15:02:26 -0500965 id = cmd->device->id;
966 lun = cmd->device->lun;
967 serial = cmd->serial_number;
968
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700969 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500970 return ret;
971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500973 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500976 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
978 /*
979 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700980 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 * be completed and then issue big hammer.Otherwise
982 * it may cause I/O failure as big hammer marks the
983 * devices as lost kicking of the port_down_timer
984 * while dpc is stuck for the mailbox to complete.
985 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 qla2x00_wait_for_loop_ready(ha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700987 set_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
988 if (qla2x00_abort_isp(pha)) {
989 clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 /* failed. schedule dpc to try */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700991 set_bit(ISP_ABORT_NEEDED, &pha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
993 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500994 goto eh_host_reset_lock;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700995 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700996 clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 /* Waiting for our command in done_queue to be returned to OS.*/
Andrew Vasquez523ec772008-04-03 13:13:24 -0700999 if (qla2x00_eh_wait_for_pending_commands(pha, 0, 0, WAIT_HOST) ==
1000 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001001 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001003 if (ha->parent)
1004 qla2x00_vp_abort_isp(ha);
1005
f4f051e2005-04-17 15:02:26 -05001006eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001007 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1008 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
f4f051e2005-04-17 15:02:26 -05001010 return ret;
1011}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
1013/*
1014* qla2x00_loop_reset
1015* Issue loop reset.
1016*
1017* Input:
1018* ha = adapter block pointer.
1019*
1020* Returns:
1021* 0 = success
1022*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001023int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024qla2x00_loop_reset(scsi_qla_host_t *ha)
1025{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001026 int ret;
bdf79622005-04-17 15:06:53 -05001027 struct fc_port *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001029 if (ha->flags.enable_lip_full_login) {
1030 ret = qla2x00_full_login_lip(ha);
1031 if (ret != QLA_SUCCESS) {
1032 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1033 "full_login_lip=%d.\n", __func__, ha->host_no,
1034 ret));
1035 }
1036 atomic_set(&ha->loop_state, LOOP_DOWN);
1037 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
1038 qla2x00_mark_all_devices_lost(ha, 0);
1039 qla2x00_wait_for_loop_ready(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 }
1041
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001042 if (ha->flags.enable_lip_reset) {
1043 ret = qla2x00_lip_reset(ha);
1044 if (ret != QLA_SUCCESS) {
1045 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1046 "lip_reset=%d.\n", __func__, ha->host_no, ret));
1047 }
1048 qla2x00_wait_for_loop_ready(ha);
1049 }
1050
1051 if (ha->flags.enable_target_reset) {
bdf79622005-04-17 15:06:53 -05001052 list_for_each_entry(fcport, &ha->fcports, list) {
1053 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 continue;
1055
Andrew Vasquez523ec772008-04-03 13:13:24 -07001056 ret = ha->isp_ops->target_reset(fcport, 0);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001057 if (ret != QLA_SUCCESS) {
1058 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1059 "target_reset=%d d_id=%x.\n", __func__,
1060 ha->host_no, ret, fcport->d_id.b24));
1061 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
1063 }
1064
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 /* Issue marker command only when we are going to start the I/O */
1066 ha->marker_needed = 1;
1067
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001068 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069}
1070
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001071void
1072qla2x00_abort_all_cmds(scsi_qla_host_t *ha, int res)
1073{
1074 int cnt;
1075 unsigned long flags;
1076 srb_t *sp;
1077
1078 spin_lock_irqsave(&ha->hardware_lock, flags);
1079 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1080 sp = ha->outstanding_cmds[cnt];
1081 if (sp) {
1082 ha->outstanding_cmds[cnt] = NULL;
1083 sp->flags = 0;
1084 sp->cmd->result = res;
1085 sp->cmd->host_scribble = (unsigned char *)NULL;
1086 qla2x00_sp_compl(ha, sp);
1087 }
1088 }
1089 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1090}
1091
f4f051e2005-04-17 15:02:26 -05001092static int
1093qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094{
bdf79622005-04-17 15:06:53 -05001095 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001097 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001098 return -ENXIO;
1099
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001100 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001101
1102 return 0;
1103}
1104
1105static int
1106qla2xxx_slave_configure(struct scsi_device *sdev)
1107{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001108 scsi_qla_host_t *ha = shost_priv(sdev->host);
8482e1182005-04-17 15:04:54 -05001109 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1110
f4f051e2005-04-17 15:02:26 -05001111 if (sdev->tagged_supported)
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001112 scsi_activate_tcq(sdev, ha->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 else
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001114 scsi_deactivate_tcq(sdev, ha->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
Andrew Vasquez85821c92008-07-10 16:55:48 -07001116 rport->dev_loss_tmo = ha->port_down_retry_count;
8482e1182005-04-17 15:04:54 -05001117
f4f051e2005-04-17 15:02:26 -05001118 return 0;
1119}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
f4f051e2005-04-17 15:02:26 -05001121static void
1122qla2xxx_slave_destroy(struct scsi_device *sdev)
1123{
1124 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125}
1126
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001127static int
1128qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1129{
1130 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1131 return sdev->queue_depth;
1132}
1133
1134static int
1135qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1136{
1137 if (sdev->tagged_supported) {
1138 scsi_set_tag_type(sdev, tag_type);
1139 if (tag_type)
1140 scsi_activate_tcq(sdev, sdev->queue_depth);
1141 else
1142 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1143 } else
1144 tag_type = 0;
1145
1146 return tag_type;
1147}
1148
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149/**
1150 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1151 * @ha: HA context
1152 *
1153 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1154 * supported addressing method.
1155 */
1156static void
1157qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1158{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001159 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001162 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1163 /* Any upper-dword bits set? */
1164 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1165 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1166 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001168 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1169 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001170 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001173
1174 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1175 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176}
1177
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001178static void
1179qla2x00_enable_intrs(scsi_qla_host_t *ha)
1180{
1181 unsigned long flags = 0;
1182 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1183
1184 spin_lock_irqsave(&ha->hardware_lock, flags);
1185 ha->interrupts_on = 1;
1186 /* enable risc and host interrupts */
1187 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1188 RD_REG_WORD(&reg->ictrl);
1189 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1190
1191}
1192
1193static void
1194qla2x00_disable_intrs(scsi_qla_host_t *ha)
1195{
1196 unsigned long flags = 0;
1197 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1198
1199 spin_lock_irqsave(&ha->hardware_lock, flags);
1200 ha->interrupts_on = 0;
1201 /* disable risc and host interrupts */
1202 WRT_REG_WORD(&reg->ictrl, 0);
1203 RD_REG_WORD(&reg->ictrl);
1204 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1205}
1206
1207static void
1208qla24xx_enable_intrs(scsi_qla_host_t *ha)
1209{
1210 unsigned long flags = 0;
1211 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1212
1213 spin_lock_irqsave(&ha->hardware_lock, flags);
1214 ha->interrupts_on = 1;
1215 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1216 RD_REG_DWORD(&reg->ictrl);
1217 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1218}
1219
1220static void
1221qla24xx_disable_intrs(scsi_qla_host_t *ha)
1222{
1223 unsigned long flags = 0;
1224 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1225
1226 spin_lock_irqsave(&ha->hardware_lock, flags);
1227 ha->interrupts_on = 0;
1228 WRT_REG_DWORD(&reg->ictrl, 0);
1229 RD_REG_DWORD(&reg->ictrl);
1230 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1231}
1232
1233static struct isp_operations qla2100_isp_ops = {
1234 .pci_config = qla2100_pci_config,
1235 .reset_chip = qla2x00_reset_chip,
1236 .chip_diag = qla2x00_chip_diag,
1237 .config_rings = qla2x00_config_rings,
1238 .reset_adapter = qla2x00_reset_adapter,
1239 .nvram_config = qla2x00_nvram_config,
1240 .update_fw_options = qla2x00_update_fw_options,
1241 .load_risc = qla2x00_load_risc,
1242 .pci_info_str = qla2x00_pci_info_str,
1243 .fw_version_str = qla2x00_fw_version_str,
1244 .intr_handler = qla2100_intr_handler,
1245 .enable_intrs = qla2x00_enable_intrs,
1246 .disable_intrs = qla2x00_disable_intrs,
1247 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001248 .target_reset = qla2x00_abort_target,
1249 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001250 .fabric_login = qla2x00_login_fabric,
1251 .fabric_logout = qla2x00_fabric_logout,
1252 .calc_req_entries = qla2x00_calc_iocbs_32,
1253 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1254 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1255 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1256 .read_nvram = qla2x00_read_nvram_data,
1257 .write_nvram = qla2x00_write_nvram_data,
1258 .fw_dump = qla2100_fw_dump,
1259 .beacon_on = NULL,
1260 .beacon_off = NULL,
1261 .beacon_blink = NULL,
1262 .read_optrom = qla2x00_read_optrom_data,
1263 .write_optrom = qla2x00_write_optrom_data,
1264 .get_flash_version = qla2x00_get_flash_version,
1265};
1266
1267static struct isp_operations qla2300_isp_ops = {
1268 .pci_config = qla2300_pci_config,
1269 .reset_chip = qla2x00_reset_chip,
1270 .chip_diag = qla2x00_chip_diag,
1271 .config_rings = qla2x00_config_rings,
1272 .reset_adapter = qla2x00_reset_adapter,
1273 .nvram_config = qla2x00_nvram_config,
1274 .update_fw_options = qla2x00_update_fw_options,
1275 .load_risc = qla2x00_load_risc,
1276 .pci_info_str = qla2x00_pci_info_str,
1277 .fw_version_str = qla2x00_fw_version_str,
1278 .intr_handler = qla2300_intr_handler,
1279 .enable_intrs = qla2x00_enable_intrs,
1280 .disable_intrs = qla2x00_disable_intrs,
1281 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001282 .target_reset = qla2x00_abort_target,
1283 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001284 .fabric_login = qla2x00_login_fabric,
1285 .fabric_logout = qla2x00_fabric_logout,
1286 .calc_req_entries = qla2x00_calc_iocbs_32,
1287 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1288 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1289 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1290 .read_nvram = qla2x00_read_nvram_data,
1291 .write_nvram = qla2x00_write_nvram_data,
1292 .fw_dump = qla2300_fw_dump,
1293 .beacon_on = qla2x00_beacon_on,
1294 .beacon_off = qla2x00_beacon_off,
1295 .beacon_blink = qla2x00_beacon_blink,
1296 .read_optrom = qla2x00_read_optrom_data,
1297 .write_optrom = qla2x00_write_optrom_data,
1298 .get_flash_version = qla2x00_get_flash_version,
1299};
1300
1301static struct isp_operations qla24xx_isp_ops = {
1302 .pci_config = qla24xx_pci_config,
1303 .reset_chip = qla24xx_reset_chip,
1304 .chip_diag = qla24xx_chip_diag,
1305 .config_rings = qla24xx_config_rings,
1306 .reset_adapter = qla24xx_reset_adapter,
1307 .nvram_config = qla24xx_nvram_config,
1308 .update_fw_options = qla24xx_update_fw_options,
1309 .load_risc = qla24xx_load_risc,
1310 .pci_info_str = qla24xx_pci_info_str,
1311 .fw_version_str = qla24xx_fw_version_str,
1312 .intr_handler = qla24xx_intr_handler,
1313 .enable_intrs = qla24xx_enable_intrs,
1314 .disable_intrs = qla24xx_disable_intrs,
1315 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001316 .target_reset = qla24xx_abort_target,
1317 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001318 .fabric_login = qla24xx_login_fabric,
1319 .fabric_logout = qla24xx_fabric_logout,
1320 .calc_req_entries = NULL,
1321 .build_iocbs = NULL,
1322 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1323 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1324 .read_nvram = qla24xx_read_nvram_data,
1325 .write_nvram = qla24xx_write_nvram_data,
1326 .fw_dump = qla24xx_fw_dump,
1327 .beacon_on = qla24xx_beacon_on,
1328 .beacon_off = qla24xx_beacon_off,
1329 .beacon_blink = qla24xx_beacon_blink,
1330 .read_optrom = qla24xx_read_optrom_data,
1331 .write_optrom = qla24xx_write_optrom_data,
1332 .get_flash_version = qla24xx_get_flash_version,
1333};
1334
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001335static struct isp_operations qla25xx_isp_ops = {
1336 .pci_config = qla25xx_pci_config,
1337 .reset_chip = qla24xx_reset_chip,
1338 .chip_diag = qla24xx_chip_diag,
1339 .config_rings = qla24xx_config_rings,
1340 .reset_adapter = qla24xx_reset_adapter,
1341 .nvram_config = qla24xx_nvram_config,
1342 .update_fw_options = qla24xx_update_fw_options,
1343 .load_risc = qla24xx_load_risc,
1344 .pci_info_str = qla24xx_pci_info_str,
1345 .fw_version_str = qla24xx_fw_version_str,
1346 .intr_handler = qla24xx_intr_handler,
1347 .enable_intrs = qla24xx_enable_intrs,
1348 .disable_intrs = qla24xx_disable_intrs,
1349 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001350 .target_reset = qla24xx_abort_target,
1351 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001352 .fabric_login = qla24xx_login_fabric,
1353 .fabric_logout = qla24xx_fabric_logout,
1354 .calc_req_entries = NULL,
1355 .build_iocbs = NULL,
1356 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1357 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1358 .read_nvram = qla25xx_read_nvram_data,
1359 .write_nvram = qla25xx_write_nvram_data,
1360 .fw_dump = qla25xx_fw_dump,
1361 .beacon_on = qla24xx_beacon_on,
1362 .beacon_off = qla24xx_beacon_off,
1363 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001364 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001365 .write_optrom = qla24xx_write_optrom_data,
1366 .get_flash_version = qla24xx_get_flash_version,
1367};
1368
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001369static inline void
1370qla2x00_set_isp_flags(scsi_qla_host_t *ha)
1371{
1372 ha->device_type = DT_EXTENDED_IDS;
1373 switch (ha->pdev->device) {
1374 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1375 ha->device_type |= DT_ISP2100;
1376 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001377 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001378 break;
1379 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1380 ha->device_type |= DT_ISP2200;
1381 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001382 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001383 break;
1384 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1385 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001386 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001387 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001388 break;
1389 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1390 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001391 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001392 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001393 break;
1394 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1395 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001396 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001397 if (ha->pdev->subsystem_vendor == 0x1028 &&
1398 ha->pdev->subsystem_device == 0x0170)
1399 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001400 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001401 break;
1402 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1403 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001404 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001405 break;
1406 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1407 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001408 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001409 break;
1410 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1411 ha->device_type |= DT_ISP2422;
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;
1417 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1418 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001419 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001420 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001421 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001422 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001423 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001424 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1425 ha->device_type |= DT_ISP8432;
1426 ha->device_type |= DT_ZIO_SUPPORTED;
1427 ha->device_type |= DT_FWI2;
1428 ha->device_type |= DT_IIDMA;
1429 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1430 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001431 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1432 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001433 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001434 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001435 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001436 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1437 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001438 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001439 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001440 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001441 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1442 ha->device_type |= DT_ISP2532;
1443 ha->device_type |= DT_ZIO_SUPPORTED;
1444 ha->device_type |= DT_FWI2;
1445 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001446 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1447 break;
1448 }
1449}
1450
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451static int
1452qla2x00_iospace_config(scsi_qla_host_t *ha)
1453{
Andrew Vasquez37765412008-01-17 09:02:09 -08001454 resource_size_t pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Andrew Vasquez285d0322007-10-19 15:59:17 -07001456 if (pci_request_selected_regions(ha->pdev, ha->bars,
1457 QLA2XXX_DRIVER_NAME)) {
1458 qla_printk(KERN_WARNING, ha,
1459 "Failed to reserve PIO/MMIO regions (%s)\n",
1460 pci_name(ha->pdev));
1461
1462 goto iospace_error_exit;
1463 }
1464 if (!(ha->bars & 1))
1465 goto skip_pio;
1466
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1468 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001469 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1470 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 qla_printk(KERN_WARNING, ha,
1472 "Invalid PCI I/O region size (%s)...\n",
1473 pci_name(ha->pdev));
1474 pio = 0;
1475 }
1476 } else {
1477 qla_printk(KERN_WARNING, ha,
1478 "region #0 not a PIO resource (%s)...\n",
1479 pci_name(ha->pdev));
1480 pio = 0;
1481 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001482 ha->pio_address = pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Andrew Vasquez285d0322007-10-19 15:59:17 -07001484skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001486 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 qla_printk(KERN_ERR, ha,
Andrew Vasquez37765412008-01-17 09:02:09 -08001488 "region #1 not an MMIO resource (%s), aborting\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 pci_name(ha->pdev));
1490 goto iospace_error_exit;
1491 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001492 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 qla_printk(KERN_ERR, ha,
1494 "Invalid PCI mem region size (%s), aborting\n",
1495 pci_name(ha->pdev));
1496 goto iospace_error_exit;
1497 }
1498
Andrew Vasquez37765412008-01-17 09:02:09 -08001499 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 if (!ha->iobase) {
1501 qla_printk(KERN_ERR, ha,
1502 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1503
1504 goto iospace_error_exit;
1505 }
1506
1507 return (0);
1508
1509iospace_error_exit:
1510 return (-ENOMEM);
1511}
1512
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001513static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001514qla2xxx_scan_start(struct Scsi_Host *shost)
1515{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001516 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001517
1518 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1519 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1520 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1521}
1522
1523static int
1524qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1525{
Andrew Vasquezf363b942007-09-20 14:07:45 -07001526 scsi_qla_host_t *ha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001527
1528 if (!ha->host)
1529 return 1;
1530 if (time > ha->loop_reset_delay * HZ)
1531 return 1;
1532
1533 return atomic_read(&ha->loop_state) == LOOP_READY;
1534}
1535
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536/*
1537 * PCI driver interface
1538 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001539static int __devinit
1540qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001542 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 struct Scsi_Host *host;
1544 scsi_qla_host_t *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001545 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001547 struct scsi_host_template *sht;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001548 int bars, mem_only = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Andrew Vasquez285d0322007-10-19 15:59:17 -07001550 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1551 sht = &qla2x00_driver_template;
1552 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1553 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001554 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001555 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1556 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1557 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532) {
1558 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1559 sht = &qla24xx_driver_template;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001560 mem_only = 1;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001561 }
1562
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001563 if (mem_only) {
1564 if (pci_enable_device_mem(pdev))
1565 goto probe_out;
1566 } else {
1567 if (pci_enable_device(pdev))
1568 goto probe_out;
1569 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
Seokmann Ju14e660e2007-09-20 14:07:36 -07001571 if (pci_find_aer_capability(pdev))
1572 if (pci_enable_pcie_error_reporting(pdev))
1573 goto probe_out;
1574
Andrew Vasquez54333832005-11-09 15:49:04 -08001575 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 if (host == NULL) {
1577 printk(KERN_WARNING
1578 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1579 goto probe_disable_device;
1580 }
1581
1582 /* Clear our data area */
Andrew Vasquezf363b942007-09-20 14:07:45 -07001583 ha = shost_priv(host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 memset(ha, 0, sizeof(scsi_qla_host_t));
1585
1586 ha->pdev = pdev;
1587 ha->host = host;
1588 ha->host_no = host->host_no;
Andrew Vasquezcb630672006-05-17 15:09:45 -07001589 sprintf(ha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, ha->host_no);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001590 ha->parent = NULL;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001591 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001592 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001593 spin_lock_init(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001595 /* Set ISP-type information. */
1596 qla2x00_set_isp_flags(ha);
1597
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 /* Configure PCI I/O space */
1599 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001600 if (ret)
1601 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08001604 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1605 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001608 ha->init_cb_size = sizeof(init_cb_t);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001609 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER + ha->vp_idx;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001610 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001611 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001613 ha->max_q_depth = MAX_Q_DEPTH;
1614 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1615 ha->max_q_depth = ql2xmaxqdepth;
1616
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001617 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 if (IS_QLA2100(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001619 host->max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1621 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1622 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1623 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1624 host->sg_tablesize = 32;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001625 ha->gid_list_info_size = 4;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001626 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 } else if (IS_QLA2200(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001628 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1630 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1631 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1632 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001633 ha->gid_list_info_size = 4;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001634 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001635 } else if (IS_QLA23XX(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001636 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1638 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1639 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1640 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001641 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001642 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1643 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001644 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001645 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07001646 host->max_id = MAX_TARGETS_2200;
1647 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1648 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1649 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1650 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001651 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1652 ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001653 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001654 ha->optrom_size = OPTROM_SIZE_24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001655 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001656 } else if (IS_QLA25XX(ha)) {
1657 host->max_id = MAX_TARGETS_2200;
1658 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1659 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1660 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1661 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1662 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1663 ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
1664 ha->gid_list_info_size = 8;
1665 ha->optrom_size = OPTROM_SIZE_25XX;
1666 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001667 ha->hw_event_start = PCI_FUNC(pdev->devfn) ?
1668 FA_HW_EVENT1_ADDR: FA_HW_EVENT0_ADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 }
1670 host->can_queue = ha->request_q_length + 128;
1671
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07001672 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001673 init_completion(&ha->mbx_cmd_comp);
1674 complete(&ha->mbx_cmd_comp);
1675 init_completion(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676
1677 INIT_LIST_HEAD(&ha->list);
1678 INIT_LIST_HEAD(&ha->fcports);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001679 INIT_LIST_HEAD(&ha->vp_list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07001680 INIT_LIST_HEAD(&ha->work_list);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001681
1682 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 qla2x00_config_dma_addressing(ha);
1685 if (qla2x00_mem_alloc(ha)) {
1686 qla_printk(KERN_WARNING, ha,
1687 "[ERROR] Failed to allocate memory for adapter\n");
1688
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001689 ret = -ENOMEM;
1690 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 }
1692
Andrew Vasquez765140b2007-05-07 07:42:58 -07001693 if (qla2x00_initialize_adapter(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 qla_printk(KERN_WARNING, ha,
1695 "Failed to initialize adapter\n");
1696
1697 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1698 "Adapter flags %x.\n",
1699 ha->host_no, ha->device_flags));
1700
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001701 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 goto probe_failed;
1703 }
1704
1705 /*
1706 * Startup the kernel thread for this host adapter
1707 */
Christoph Hellwig39a11242006-02-14 18:46:22 +01001708 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1709 "%s_dpc", ha->host_str);
1710 if (IS_ERR(ha->dpc_thread)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 qla_printk(KERN_WARNING, ha,
1712 "Unable to start DPC thread!\n");
Christoph Hellwig39a11242006-02-14 18:46:22 +01001713 ret = PTR_ERR(ha->dpc_thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 goto probe_failed;
1715 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001717 host->this_id = 255;
1718 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07001719 host->unique_id = host->host_no;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001720 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001721 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001722 host->max_lun = MAX_LUNS;
1723 host->transportt = qla2xxx_transport_template;
1724
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001725 ret = qla2x00_request_irqs(ha);
1726 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728
1729 /* Initialized the timer */
1730 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1731
1732 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1733 ha->host_no, ha));
1734
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001735 pci_set_drvdata(pdev, ha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001736
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 ha->flags.init_done = 1;
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001738 ha->flags.online = 1;
1739
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001740 ret = scsi_add_host(host, &pdev->dev);
1741 if (ret)
1742 goto probe_failed;
1743
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001744 scsi_scan_host(host);
1745
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001746 qla2x00_alloc_sysfs_attr(ha);
1747
1748 qla2x00_init_host_attr(ha);
1749
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001750 qla2x00_dfs_setup(ha);
1751
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 qla_printk(KERN_INFO, ha, "\n"
1753 " QLogic Fibre Channel HBA Driver: %s\n"
1754 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08001755 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1756 qla2x00_version_str, ha->model_number,
1757 ha->model_desc ? ha->model_desc: "", pdev->device,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001758 ha->isp_ops->pci_info_str(ha, pci_info), pci_name(pdev),
Andrew Vasquez54333832005-11-09 15:49:04 -08001759 ha->flags.enable_64bit_addressing ? '+': '-', ha->host_no,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001760 ha->isp_ops->fw_version_str(ha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 return 0;
1763
1764probe_failed:
1765 qla2x00_free_device(ha);
1766
1767 scsi_host_put(host);
1768
1769probe_disable_device:
1770 pci_disable_device(pdev);
1771
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001772probe_out:
1773 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775
Adrian Bunk4c993f72008-01-14 00:55:16 -08001776static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001777qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778{
1779 scsi_qla_host_t *ha;
1780
1781 ha = pci_get_drvdata(pdev);
1782
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001783 qla2x00_dfs_remove(ha);
1784
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001785 qla84xx_put_chip(ha);
1786
8482e1182005-04-17 15:04:54 -05001787 qla2x00_free_sysfs_attr(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
bdf79622005-04-17 15:06:53 -05001789 fc_remove_host(ha->host);
1790
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 scsi_remove_host(ha->host);
1792
1793 qla2x00_free_device(ha);
1794
1795 scsi_host_put(ha->host);
1796
Bernhard Walle665db932007-03-28 00:49:49 +02001797 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 pci_set_drvdata(pdev, NULL);
1799}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800
1801static void
1802qla2x00_free_device(scsi_qla_host_t *ha)
1803{
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001804 qla2x00_abort_all_cmds(ha, DID_NO_CONNECT << 16);
1805
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 /* Disable timer */
1807 if (ha->timer_active)
1808 qla2x00_stop_timer(ha);
1809
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001810 ha->flags.online = 0;
1811
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 /* Kill the kernel thread for this host */
Christoph Hellwig39a11242006-02-14 18:46:22 +01001813 if (ha->dpc_thread) {
1814 struct task_struct *t = ha->dpc_thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815
Christoph Hellwig39a11242006-02-14 18:46:22 +01001816 /*
1817 * qla2xxx_wake_dpc checks for ->dpc_thread
1818 * so we need to zero it out.
1819 */
1820 ha->dpc_thread = NULL;
1821 kthread_stop(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 }
1823
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001824 if (ha->flags.fce_enabled)
1825 qla2x00_disable_fce_trace(ha, NULL, NULL);
1826
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001827 if (ha->eft)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08001828 qla2x00_disable_eft_trace(ha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001829
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001830 /* Stop currently executing firmware. */
Andrew Vasquez18c6c122006-10-13 09:33:38 -07001831 qla2x00_try_to_stop_firmware(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001833 /* turn-off interrupts on the card */
1834 if (ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001835 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001836
1837 qla2x00_mem_free(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001839 qla2x00_free_irqs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
1841 /* release io space registers */
1842 if (ha->iobase)
1843 iounmap(ha->iobase);
Andrew Vasquez285d0322007-10-19 15:59:17 -07001844 pci_release_selected_regions(ha->pdev, ha->bars);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845}
1846
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001847static inline void
1848qla2x00_schedule_rport_del(struct scsi_qla_host *ha, fc_port_t *fcport,
1849 int defer)
1850{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001851 struct fc_rport *rport;
1852
1853 if (!fcport->rport)
1854 return;
1855
1856 rport = fcport->rport;
1857 if (defer) {
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001858 spin_lock_irq(ha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001859 fcport->drport = rport;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001860 spin_unlock_irq(ha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001861 set_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001862 qla2xxx_wake_dpc(ha);
1863 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001864 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001865}
1866
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1869 *
1870 * Input: ha = adapter block pointer. fcport = port structure pointer.
1871 *
1872 * Return: None.
1873 *
1874 * Context:
1875 */
1876void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001877 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001879 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1880 ha->vp_idx == fcport->vp_idx)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001881 qla2x00_schedule_rport_del(ha, fcport, defer);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001882
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001883 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 * We may need to retry the login, so don't change the state of the
1885 * port but do the retries.
1886 */
1887 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1888 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1889
1890 if (!do_login)
1891 return;
1892
1893 if (fcport->login_retry == 0) {
1894 fcport->login_retry = ha->login_retry_count;
1895 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1896
1897 DEBUG(printk("scsi(%ld): Port login retry: "
1898 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1899 "id = 0x%04x retry cnt=%d\n",
1900 ha->host_no,
1901 fcport->port_name[0],
1902 fcport->port_name[1],
1903 fcport->port_name[2],
1904 fcport->port_name[3],
1905 fcport->port_name[4],
1906 fcport->port_name[5],
1907 fcport->port_name[6],
1908 fcport->port_name[7],
1909 fcport->loop_id,
1910 fcport->login_retry));
1911 }
1912}
1913
1914/*
1915 * qla2x00_mark_all_devices_lost
1916 * Updates fcport state when device goes offline.
1917 *
1918 * Input:
1919 * ha = adapter block pointer.
1920 * fcport = port structure pointer.
1921 *
1922 * Return:
1923 * None.
1924 *
1925 * Context:
1926 */
1927void
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001928qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929{
1930 fc_port_t *fcport;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001931 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001933 list_for_each_entry(fcport, &pha->fcports, list) {
1934 if (ha->vp_idx != 0 && ha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 /*
1937 * No point in marking the device as lost, if the device is
1938 * already DEAD.
1939 */
1940 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1941 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001942 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1943 if (defer)
1944 qla2x00_schedule_rport_del(ha, fcport, defer);
1945 else if (ha->vp_idx == fcport->vp_idx)
1946 qla2x00_schedule_rport_del(ha, fcport, defer);
1947 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1949 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001950
Christoph Hellwig39a11242006-02-14 18:46:22 +01001951 if (defer)
1952 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953}
1954
1955/*
1956* qla2x00_mem_alloc
1957* Allocates adapter memory.
1958*
1959* Returns:
1960* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08001961* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08001963static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964qla2x00_mem_alloc(scsi_qla_host_t *ha)
1965{
1966 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
Andrew Vasqueze8711082008-01-31 12:33:48 -08001968 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
1969 (ha->request_q_length + 1) * sizeof(request_t), &ha->request_dma,
1970 GFP_KERNEL);
1971 if (!ha->request_ring)
1972 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
Andrew Vasqueze8711082008-01-31 12:33:48 -08001974 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1975 (ha->response_q_length + 1) * sizeof(response_t),
1976 &ha->response_dma, GFP_KERNEL);
1977 if (!ha->response_ring)
1978 goto fail_free_request_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
Andrew Vasqueze8711082008-01-31 12:33:48 -08001980 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1981 &ha->gid_list_dma, GFP_KERNEL);
1982 if (!ha->gid_list)
1983 goto fail_free_response_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984
Andrew Vasqueze8711082008-01-31 12:33:48 -08001985 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
1986 &ha->init_cb_dma, GFP_KERNEL);
1987 if (!ha->init_cb)
1988 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
Andrew Vasqueze8711082008-01-31 12:33:48 -08001990 snprintf(name, sizeof(name), "%s_%ld", QLA2XXX_DRIVER_NAME,
1991 ha->host_no);
1992 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
1993 DMA_POOL_SIZE, 8, 0);
1994 if (!ha->s_dma_pool)
1995 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
Andrew Vasqueze8711082008-01-31 12:33:48 -08001997 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
1998 if (!ha->srb_mempool)
1999 goto fail_free_s_dma_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
Andrew Vasqueze8711082008-01-31 12:33:48 -08002001 /* Get memory for cached NVRAM */
2002 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2003 if (!ha->nvram)
2004 goto fail_free_srb_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
Andrew Vasqueze8711082008-01-31 12:33:48 -08002006 /* Allocate memory for SNS commands */
2007 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2008 /* Get consistent memory allocated for SNS commands */
2009 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2010 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
2011 if (!ha->sns_cmd)
2012 goto fail_free_nvram;
2013 } else {
2014 /* Get consistent memory allocated for MS IOCB */
2015 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2016 &ha->ms_iocb_dma);
2017 if (!ha->ms_iocb)
2018 goto fail_free_nvram;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019
Andrew Vasqueze8711082008-01-31 12:33:48 -08002020 /* Get consistent memory allocated for CT SNS commands */
2021 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2022 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
2023 if (!ha->ct_sns)
2024 goto fail_free_ms_iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 }
2026
Andrew Vasqueze8711082008-01-31 12:33:48 -08002027 return 0;
2028
2029fail_free_ms_iocb:
2030 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2031 ha->ms_iocb = NULL;
2032 ha->ms_iocb_dma = 0;
2033fail_free_nvram:
2034 kfree(ha->nvram);
2035 ha->nvram = NULL;
2036fail_free_srb_mempool:
2037 mempool_destroy(ha->srb_mempool);
2038 ha->srb_mempool = NULL;
2039fail_free_s_dma_pool:
2040 dma_pool_destroy(ha->s_dma_pool);
2041 ha->s_dma_pool = NULL;
2042fail_free_init_cb:
2043 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2044 ha->init_cb_dma);
2045 ha->init_cb = NULL;
2046 ha->init_cb_dma = 0;
2047fail_free_gid_list:
2048 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2049 ha->gid_list_dma);
2050 ha->gid_list = NULL;
2051 ha->gid_list_dma = 0;
2052fail_free_response_ring:
2053 dma_free_coherent(&ha->pdev->dev, (ha->response_q_length + 1) *
2054 sizeof(response_t), ha->response_ring, ha->response_dma);
2055 ha->response_ring = NULL;
2056 ha->response_dma = 0;
2057fail_free_request_ring:
2058 dma_free_coherent(&ha->pdev->dev, (ha->request_q_length + 1) *
2059 sizeof(request_t), ha->request_ring, ha->request_dma);
2060 ha->request_ring = NULL;
2061 ha->request_dma = 0;
2062fail:
2063 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064}
2065
2066/*
2067* qla2x00_mem_free
2068* Frees all adapter allocated memory.
2069*
2070* Input:
2071* ha = adapter block pointer.
2072*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08002073static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074qla2x00_mem_free(scsi_qla_host_t *ha)
2075{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 struct list_head *fcpl, *fcptemp;
2077 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078
Andrew Vasqueze8711082008-01-31 12:33:48 -08002079 if (ha->srb_mempool)
2080 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002082 if (ha->fce)
2083 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2084 ha->fce_dma);
2085
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002086 if (ha->fw_dump) {
2087 if (ha->eft)
2088 dma_free_coherent(&ha->pdev->dev,
2089 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2090 vfree(ha->fw_dump);
2091 }
2092
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 if (ha->sns_cmd)
2094 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2095 ha->sns_cmd, ha->sns_cmd_dma);
2096
2097 if (ha->ct_sns)
2098 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2099 ha->ct_sns, ha->ct_sns_dma);
2100
Andrew Vasquez88729e52006-06-23 16:10:50 -07002101 if (ha->sfp_data)
2102 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2103
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 if (ha->ms_iocb)
2105 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2106
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 if (ha->s_dma_pool)
2108 dma_pool_destroy(ha->s_dma_pool);
2109
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002110 if (ha->init_cb)
2111 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2112 ha->init_cb, ha->init_cb_dma);
2113
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 if (ha->gid_list)
2115 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2116 ha->gid_list_dma);
2117
2118 if (ha->response_ring)
2119 dma_free_coherent(&ha->pdev->dev,
2120 (ha->response_q_length + 1) * sizeof(response_t),
2121 ha->response_ring, ha->response_dma);
2122
2123 if (ha->request_ring)
2124 dma_free_coherent(&ha->pdev->dev,
2125 (ha->request_q_length + 1) * sizeof(request_t),
2126 ha->request_ring, ha->request_dma);
2127
Andrew Vasqueze8711082008-01-31 12:33:48 -08002128 ha->srb_mempool = NULL;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002129 ha->eft = NULL;
2130 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 ha->sns_cmd = NULL;
2132 ha->sns_cmd_dma = 0;
2133 ha->ct_sns = NULL;
2134 ha->ct_sns_dma = 0;
2135 ha->ms_iocb = NULL;
2136 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 ha->init_cb = NULL;
2138 ha->init_cb_dma = 0;
2139
2140 ha->s_dma_pool = NULL;
2141
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 ha->gid_list = NULL;
2143 ha->gid_list_dma = 0;
2144
2145 ha->response_ring = NULL;
2146 ha->response_dma = 0;
2147 ha->request_ring = NULL;
2148 ha->request_dma = 0;
2149
2150 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2151 fcport = list_entry(fcpl, fc_port_t, list);
2152
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 /* fc ports */
2154 list_del_init(&fcport->list);
2155 kfree(fcport);
2156 }
2157 INIT_LIST_HEAD(&ha->fcports);
2158
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002160 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 ha->fw_dump_reading = 0;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002162
2163 vfree(ha->optrom_buffer);
Seokmann Ju53772a22007-07-30 11:01:07 -07002164 kfree(ha->nvram);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165}
2166
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002167static struct qla_work_evt *
Andrew Vasquez0971de72008-04-03 13:13:18 -07002168qla2x00_alloc_work(struct scsi_qla_host *ha, enum qla_work_type type,
2169 int locked)
2170{
2171 struct qla_work_evt *e;
2172
2173 e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
2174 GFP_KERNEL);
2175 if (!e)
2176 return NULL;
2177
2178 INIT_LIST_HEAD(&e->list);
2179 e->type = type;
2180 e->flags = QLA_EVT_FLAG_FREE;
2181 return e;
2182}
2183
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002184static int
Andrew Vasquez0971de72008-04-03 13:13:18 -07002185qla2x00_post_work(struct scsi_qla_host *ha, struct qla_work_evt *e, int locked)
2186{
2187 unsigned long flags;
Seokmann Ju08b95a12008-05-19 14:25:40 -07002188 scsi_qla_host_t *pha = to_qla_parent(ha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002189
2190 if (!locked)
Seokmann Ju08b95a12008-05-19 14:25:40 -07002191 spin_lock_irqsave(&pha->hardware_lock, flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002192 list_add_tail(&e->list, &ha->work_list);
2193 qla2xxx_wake_dpc(ha);
2194 if (!locked)
Seokmann Ju08b95a12008-05-19 14:25:40 -07002195 spin_unlock_irqrestore(&pha->hardware_lock, flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002196 return QLA_SUCCESS;
2197}
2198
2199int
2200qla2x00_post_aen_work(struct scsi_qla_host *ha, enum fc_host_event_code code,
2201 u32 data)
2202{
2203 struct qla_work_evt *e;
2204
2205 e = qla2x00_alloc_work(ha, QLA_EVT_AEN, 1);
2206 if (!e)
2207 return QLA_FUNCTION_FAILED;
2208
2209 e->u.aen.code = code;
2210 e->u.aen.data = data;
2211 return qla2x00_post_work(ha, e, 1);
2212}
2213
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002214int
2215qla2x00_post_hwe_work(struct scsi_qla_host *ha, uint16_t code, uint16_t d1,
2216 uint16_t d2, uint16_t d3)
2217{
2218 struct qla_work_evt *e;
2219
2220 e = qla2x00_alloc_work(ha, QLA_EVT_HWE_LOG, 1);
2221 if (!e)
2222 return QLA_FUNCTION_FAILED;
2223
2224 e->u.hwe.code = code;
2225 e->u.hwe.d1 = d1;
2226 e->u.hwe.d2 = d2;
2227 e->u.hwe.d3 = d3;
2228 return qla2x00_post_work(ha, e, 1);
2229}
2230
Andrew Vasquez0971de72008-04-03 13:13:18 -07002231static void
2232qla2x00_do_work(struct scsi_qla_host *ha)
2233{
2234 struct qla_work_evt *e;
Seokmann Ju08b95a12008-05-19 14:25:40 -07002235 scsi_qla_host_t *pha = to_qla_parent(ha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002236
Seokmann Ju08b95a12008-05-19 14:25:40 -07002237 spin_lock_irq(&pha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002238 while (!list_empty(&ha->work_list)) {
2239 e = list_entry(ha->work_list.next, struct qla_work_evt, list);
2240 list_del_init(&e->list);
Seokmann Ju08b95a12008-05-19 14:25:40 -07002241 spin_unlock_irq(&pha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002242
2243 switch (e->type) {
2244 case QLA_EVT_AEN:
2245 fc_host_post_event(ha->host, fc_get_event_number(),
2246 e->u.aen.code, e->u.aen.data);
2247 break;
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002248 case QLA_EVT_HWE_LOG:
2249 qla2xxx_hw_event_log(ha, e->u.hwe.code, e->u.hwe.d1,
2250 e->u.hwe.d2, e->u.hwe.d3);
2251 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002252 }
2253 if (e->flags & QLA_EVT_FLAG_FREE)
2254 kfree(e);
Seokmann Ju08b95a12008-05-19 14:25:40 -07002255 spin_lock_irq(&pha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002256 }
Seokmann Ju08b95a12008-05-19 14:25:40 -07002257 spin_unlock_irq(&pha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002258}
2259
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260/**************************************************************************
2261* qla2x00_do_dpc
2262* This kernel thread is a task that is schedule by the interrupt handler
2263* to perform the background processing for interrupts.
2264*
2265* Notes:
2266* This task always run in the context of a kernel thread. It
2267* is kick-off by the driver's detect code and starts up
2268* up one per adapter. It immediately goes to sleep and waits for
2269* some fibre event. When either the interrupt handler or
2270* the timer routine detects a event it will one of the task
2271* bits then wake us up.
2272**************************************************************************/
2273static int
2274qla2x00_do_dpc(void *data)
2275{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002276 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 scsi_qla_host_t *ha;
2278 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 uint8_t status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 uint16_t next_loopid;
Seokmann Ju99363ef2008-01-31 12:33:51 -08002281 struct scsi_qla_host *vha;
2282 int i;
2283
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284
2285 ha = (scsi_qla_host_t *)data;
2286
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 set_user_nice(current, -20);
2288
Christoph Hellwig39a11242006-02-14 18:46:22 +01002289 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2291
Christoph Hellwig39a11242006-02-14 18:46:22 +01002292 set_current_state(TASK_INTERRUPTIBLE);
2293 schedule();
2294 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295
2296 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2297
2298 /* Initialization not yet finished. Don't do anything yet. */
Christoph Hellwig39a11242006-02-14 18:46:22 +01002299 if (!ha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 continue;
2301
2302 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2303
2304 ha->dpc_active = 1;
2305
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 ha->dpc_active = 0;
2308 continue;
2309 }
2310
Andrew Vasquez0971de72008-04-03 13:13:18 -07002311 qla2x00_do_work(ha);
2312
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2314
2315 DEBUG(printk("scsi(%ld): dpc: sched "
2316 "qla2x00_abort_isp ha = %p\n",
2317 ha->host_no, ha));
2318 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2319 &ha->dpc_flags))) {
2320
2321 if (qla2x00_abort_isp(ha)) {
2322 /* failed. retry later */
2323 set_bit(ISP_ABORT_NEEDED,
2324 &ha->dpc_flags);
2325 }
2326 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2327 }
Seokmann Ju99363ef2008-01-31 12:33:51 -08002328
2329 for_each_mapped_vp_idx(ha, i) {
2330 list_for_each_entry(vha, &ha->vp_list,
2331 vp_list) {
2332 if (i == vha->vp_idx) {
2333 set_bit(ISP_ABORT_NEEDED,
2334 &vha->dpc_flags);
2335 break;
2336 }
2337 }
2338 }
2339
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2341 ha->host_no));
2342 }
2343
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002344 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags))
2345 qla2x00_update_fcports(ha);
2346
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2348 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2349
2350 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2351 ha->host_no));
2352
2353 qla2x00_rst_aen(ha);
2354 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2355 }
2356
2357 /* Retry each device up to login retry count */
2358 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2359 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2360 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2361
2362 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2363 ha->host_no));
2364
2365 next_loopid = 0;
2366 list_for_each_entry(fcport, &ha->fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 /*
2368 * If the port is not ONLINE then try to login
2369 * to it if we haven't run out of retries.
2370 */
2371 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2372 fcport->login_retry) {
2373
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 if (fcport->flags & FCF_FABRIC_DEVICE) {
2375 if (fcport->flags &
2376 FCF_TAPE_PRESENT)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002377 ha->isp_ops->fabric_logout(
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002378 ha, fcport->loop_id,
2379 fcport->d_id.b.domain,
2380 fcport->d_id.b.area,
2381 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 status = qla2x00_fabric_login(
2383 ha, fcport, &next_loopid);
2384 } else
2385 status =
2386 qla2x00_local_device_login(
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08002387 ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388
Ravi Anand63a86512007-09-20 14:07:40 -07002389 fcport->login_retry--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 if (status == QLA_SUCCESS) {
2391 fcport->old_loop_id = fcport->loop_id;
2392
2393 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2394 ha->host_no, fcport->loop_id));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002395
andrew.vasquez@qlogic.com052c40c2006-01-20 14:53:19 -08002396 qla2x00_update_fcport(ha,
2397 fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 } else if (status == 1) {
2399 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2400 /* retry the login again */
2401 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2402 ha->host_no,
2403 fcport->login_retry, fcport->loop_id));
2404 } else {
2405 fcport->login_retry = 0;
2406 }
Andrew Vasquez666301e2008-04-24 15:21:30 -07002407 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
Ravi Anand63a86512007-09-20 14:07:40 -07002408 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 }
2410 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2411 break;
2412 }
2413 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2414 ha->host_no));
2415 }
2416
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2418
2419 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2420 ha->host_no));
2421
2422 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2423 &ha->dpc_flags))) {
2424
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002425 rval = qla2x00_loop_resync(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426
2427 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2428 }
2429
2430 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2431 ha->host_no));
2432 }
2433
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002435 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002437 if (test_and_clear_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags))
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002438 ha->isp_ops->beacon_blink(ha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002439
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002440 qla2x00_do_dpc_all_vps(ha);
2441
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 ha->dpc_active = 0;
2443 } /* End of while(1) */
2444
2445 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2446
2447 /*
2448 * Make sure that nobody tries to wake us up again.
2449 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 ha->dpc_active = 0;
2451
Christoph Hellwig39a11242006-02-14 18:46:22 +01002452 return 0;
2453}
2454
2455void
2456qla2xxx_wake_dpc(scsi_qla_host_t *ha)
2457{
2458 if (ha->dpc_thread)
2459 wake_up_process(ha->dpc_thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460}
2461
2462/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463* qla2x00_rst_aen
2464* Processes asynchronous reset.
2465*
2466* Input:
2467* ha = adapter block pointer.
2468*/
2469static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002470qla2x00_rst_aen(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471{
2472 if (ha->flags.online && !ha->flags.reset_active &&
2473 !atomic_read(&ha->loop_down_timer) &&
2474 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2475 do {
2476 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2477
2478 /*
2479 * Issue marker command only when we are going to start
2480 * the I/O.
2481 */
2482 ha->marker_needed = 1;
2483 } while (!atomic_read(&ha->loop_down_timer) &&
2484 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2485 }
2486}
2487
f4f051e2005-04-17 15:02:26 -05002488static void
2489qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2490{
2491 struct scsi_cmnd *cmd = sp->cmd;
2492
2493 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002494 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05002495 sp->flags &= ~SRB_DMA_VALID;
2496 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002497 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002498}
2499
2500void
2501qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2502{
2503 struct scsi_cmnd *cmd = sp->cmd;
2504
2505 qla2x00_sp_free_dma(ha, sp);
2506
f4f051e2005-04-17 15:02:26 -05002507 mempool_free(sp, ha->srb_mempool);
2508
2509 cmd->scsi_done(cmd);
2510}
bdf79622005-04-17 15:06:53 -05002511
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512/**************************************************************************
2513* qla2x00_timer
2514*
2515* Description:
2516* One second timer
2517*
2518* Context: Interrupt
2519***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002520void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521qla2x00_timer(scsi_qla_host_t *ha)
2522{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 unsigned long cpu_flags = 0;
2524 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 int start_dpc = 0;
2526 int index;
2527 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002528 int t;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002529 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530
2531 /*
2532 * Ports - Port down timer.
2533 *
2534 * Whenever, a port is in the LOST state we start decrementing its port
2535 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002536 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 */
2538 t = 0;
2539 list_for_each_entry(fcport, &ha->fcports, list) {
2540 if (fcport->port_type != FCT_TARGET)
2541 continue;
2542
2543 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2544
2545 if (atomic_read(&fcport->port_down_timer) == 0)
2546 continue;
2547
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002548 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002550
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002552 "%d remaining\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 ha->host_no,
2554 t, atomic_read(&fcport->port_down_timer)));
2555 }
2556 t++;
2557 } /* End of for fcport */
2558
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559
2560 /* Loop down handler. */
2561 if (atomic_read(&ha->loop_down_timer) > 0 &&
2562 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2563
2564 if (atomic_read(&ha->loop_down_timer) ==
2565 ha->loop_down_abort_time) {
2566
2567 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2568 "queues before time expire\n",
2569 ha->host_no));
2570
2571 if (!IS_QLA2100(ha) && ha->link_down_timeout)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002572 atomic_set(&ha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573
2574 /* Schedule an ISP abort to return any tape commands. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002575 /* NPIV - scan physical port only */
2576 if (!ha->parent) {
2577 spin_lock_irqsave(&ha->hardware_lock,
2578 cpu_flags);
2579 for (index = 1;
2580 index < MAX_OUTSTANDING_COMMANDS;
2581 index++) {
2582 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05002583
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002584 sp = ha->outstanding_cmds[index];
2585 if (!sp)
2586 continue;
2587 sfcp = sp->fcport;
2588 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2589 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002591 set_bit(ISP_ABORT_NEEDED,
2592 &ha->dpc_flags);
2593 break;
2594 }
2595 spin_unlock_irqrestore(&ha->hardware_lock,
2596 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2599 start_dpc++;
2600 }
2601
2602 /* if the loop has been down for 4 minutes, reinit adapter */
2603 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2604 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2605 "restarting queues.\n",
2606 ha->host_no));
2607
2608 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2609 start_dpc++;
2610
Seokmann Ju463717e2008-04-03 13:13:29 -07002611 if (!(ha->device_flags & DFLG_NO_CABLE) &&
2612 !ha->parent) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 DEBUG(printk("scsi(%ld): Loop down - "
2614 "aborting ISP.\n",
2615 ha->host_no));
2616 qla_printk(KERN_WARNING, ha,
2617 "Loop down - aborting ISP.\n");
2618
2619 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2620 }
2621 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002622 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 ha->host_no,
2624 atomic_read(&ha->loop_down_timer)));
2625 }
2626
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002627 /* Check if beacon LED needs to be blinked */
2628 if (ha->beacon_blink_led == 1) {
2629 set_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags);
2630 start_dpc++;
2631 }
2632
Andrew Vasquez550bf572008-04-24 15:21:23 -07002633 /* Process any deferred work. */
2634 if (!list_empty(&ha->work_list))
2635 start_dpc++;
2636
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 /* Schedule the DPC routine if needed */
2638 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2639 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002640 test_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 start_dpc ||
f4f051e2005-04-17 15:02:26 -05002642 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002643 test_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags) ||
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002644 test_bit(VP_DPC_NEEDED, &ha->dpc_flags) ||
Christoph Hellwig39a11242006-02-14 18:46:22 +01002645 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002646 qla2xxx_wake_dpc(pha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
2648 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2649}
2650
Andrew Vasquez54333832005-11-09 15:49:04 -08002651/* Firmware interface routines. */
2652
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002653#define FW_BLOBS 6
Andrew Vasquez54333832005-11-09 15:49:04 -08002654#define FW_ISP21XX 0
2655#define FW_ISP22XX 1
2656#define FW_ISP2300 2
2657#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002658#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002659#define FW_ISP25XX 5
Andrew Vasquez54333832005-11-09 15:49:04 -08002660
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002661#define FW_FILE_ISP21XX "ql2100_fw.bin"
2662#define FW_FILE_ISP22XX "ql2200_fw.bin"
2663#define FW_FILE_ISP2300 "ql2300_fw.bin"
2664#define FW_FILE_ISP2322 "ql2322_fw.bin"
2665#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002666#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002667
Daniel Walkere1e82b62008-05-12 22:21:10 -07002668static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002669
2670static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002671 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
2672 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
2673 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
2674 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
2675 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002676 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08002677};
2678
2679struct fw_blob *
2680qla2x00_request_firmware(scsi_qla_host_t *ha)
2681{
2682 struct fw_blob *blob;
2683
2684 blob = NULL;
2685 if (IS_QLA2100(ha)) {
2686 blob = &qla_fw_blobs[FW_ISP21XX];
2687 } else if (IS_QLA2200(ha)) {
2688 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002689 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002690 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002691 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002692 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002693 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002694 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002695 } else if (IS_QLA25XX(ha)) {
2696 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08002697 }
2698
Daniel Walkere1e82b62008-05-12 22:21:10 -07002699 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002700 if (blob->fw)
2701 goto out;
2702
2703 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
2704 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
2705 "(%s).\n", ha->host_no, blob->name));
2706 blob->fw = NULL;
2707 blob = NULL;
2708 goto out;
2709 }
2710
2711out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07002712 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002713 return blob;
2714}
2715
2716static void
2717qla2x00_release_firmware(void)
2718{
2719 int idx;
2720
Daniel Walkere1e82b62008-05-12 22:21:10 -07002721 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002722 for (idx = 0; idx < FW_BLOBS; idx++)
2723 if (qla_fw_blobs[idx].fw)
2724 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07002725 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002726}
2727
Seokmann Ju14e660e2007-09-20 14:07:36 -07002728static pci_ers_result_t
2729qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
2730{
2731 switch (state) {
2732 case pci_channel_io_normal:
2733 return PCI_ERS_RESULT_CAN_RECOVER;
2734 case pci_channel_io_frozen:
2735 pci_disable_device(pdev);
2736 return PCI_ERS_RESULT_NEED_RESET;
2737 case pci_channel_io_perm_failure:
2738 qla2x00_remove_one(pdev);
2739 return PCI_ERS_RESULT_DISCONNECT;
2740 }
2741 return PCI_ERS_RESULT_NEED_RESET;
2742}
2743
2744static pci_ers_result_t
2745qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
2746{
2747 int risc_paused = 0;
2748 uint32_t stat;
2749 unsigned long flags;
2750 scsi_qla_host_t *ha = pci_get_drvdata(pdev);
2751 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2752 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
2753
2754 spin_lock_irqsave(&ha->hardware_lock, flags);
2755 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
2756 stat = RD_REG_DWORD(&reg->hccr);
2757 if (stat & HCCR_RISC_PAUSE)
2758 risc_paused = 1;
2759 } else if (IS_QLA23XX(ha)) {
2760 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
2761 if (stat & HSR_RISC_PAUSED)
2762 risc_paused = 1;
2763 } else if (IS_FWI2_CAPABLE(ha)) {
2764 stat = RD_REG_DWORD(&reg24->host_status);
2765 if (stat & HSRX_RISC_PAUSED)
2766 risc_paused = 1;
2767 }
2768 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2769
2770 if (risc_paused) {
2771 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
2772 "Dumping firmware!\n");
2773 ha->isp_ops->fw_dump(ha, 0);
2774
2775 return PCI_ERS_RESULT_NEED_RESET;
2776 } else
2777 return PCI_ERS_RESULT_RECOVERED;
2778}
2779
2780static pci_ers_result_t
2781qla2xxx_pci_slot_reset(struct pci_dev *pdev)
2782{
2783 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
2784 scsi_qla_host_t *ha = pci_get_drvdata(pdev);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002785 int rc;
Seokmann Ju14e660e2007-09-20 14:07:36 -07002786
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002787 if (ha->mem_only)
2788 rc = pci_enable_device_mem(pdev);
2789 else
2790 rc = pci_enable_device(pdev);
2791
2792 if (rc) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07002793 qla_printk(KERN_WARNING, ha,
2794 "Can't re-enable PCI device after reset.\n");
2795
2796 return ret;
2797 }
2798 pci_set_master(pdev);
2799
2800 if (ha->isp_ops->pci_config(ha))
2801 return ret;
2802
2803 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2804 if (qla2x00_abort_isp(ha)== QLA_SUCCESS)
2805 ret = PCI_ERS_RESULT_RECOVERED;
2806 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2807
2808 return ret;
2809}
2810
2811static void
2812qla2xxx_pci_resume(struct pci_dev *pdev)
2813{
2814 scsi_qla_host_t *ha = pci_get_drvdata(pdev);
2815 int ret;
2816
2817 ret = qla2x00_wait_for_hba_online(ha);
2818 if (ret != QLA_SUCCESS) {
2819 qla_printk(KERN_ERR, ha,
2820 "the device failed to resume I/O "
2821 "from slot/link_reset");
2822 }
2823 pci_cleanup_aer_uncorrect_error_status(pdev);
2824}
2825
2826static struct pci_error_handlers qla2xxx_err_handler = {
2827 .error_detected = qla2xxx_pci_error_detected,
2828 .mmio_enabled = qla2xxx_pci_mmio_enabled,
2829 .slot_reset = qla2xxx_pci_slot_reset,
2830 .resume = qla2xxx_pci_resume,
2831};
2832
Andrew Vasquez54333832005-11-09 15:49:04 -08002833static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07002834 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
2835 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
2836 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
2837 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
2838 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
2839 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
2840 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
2841 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
2842 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002843 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07002844 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
2845 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002846 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez54333832005-11-09 15:49:04 -08002847 { 0 },
2848};
2849MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2850
Andrew Vasquezfca29702005-07-06 10:31:47 -07002851static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07002852 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06002853 .driver = {
2854 .owner = THIS_MODULE,
2855 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07002856 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002857 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08002858 .remove = qla2x00_remove_one,
Seokmann Ju14e660e2007-09-20 14:07:36 -07002859 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07002860};
2861
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862/**
2863 * qla2x00_module_init - Module initialization.
2864 **/
2865static int __init
2866qla2x00_module_init(void)
2867{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002868 int ret = 0;
2869
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002871 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09002872 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 if (srb_cachep == NULL) {
2874 printk(KERN_ERR
2875 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2876 return -ENOMEM;
2877 }
2878
2879 /* Derive version string. */
2880 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002881 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07002882 strcat(qla2x00_version_str, "-debug");
2883
Andrew Vasquez1c97a122005-04-21 16:13:36 -04002884 qla2xxx_transport_template =
2885 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002886 if (!qla2xxx_transport_template) {
2887 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002889 }
2890 qla2xxx_transport_vport_template =
2891 fc_attach_transport(&qla2xxx_transport_vport_functions);
2892 if (!qla2xxx_transport_vport_template) {
2893 kmem_cache_destroy(srb_cachep);
2894 fc_release_transport(qla2xxx_transport_template);
2895 return -ENODEV;
2896 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07002898 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
2899 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002900 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002901 if (ret) {
2902 kmem_cache_destroy(srb_cachep);
2903 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002904 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002905 }
2906 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907}
2908
2909/**
2910 * qla2x00_module_exit - Module cleanup.
2911 **/
2912static void __exit
2913qla2x00_module_exit(void)
2914{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002915 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08002916 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002917 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002919 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920}
2921
2922module_init(qla2x00_module_init);
2923module_exit(qla2x00_module_exit);
2924
2925MODULE_AUTHOR("QLogic Corporation");
2926MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2927MODULE_LICENSE("GPL");
2928MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002929MODULE_FIRMWARE(FW_FILE_ISP21XX);
2930MODULE_FIRMWARE(FW_FILE_ISP22XX);
2931MODULE_FIRMWARE(FW_FILE_ISP2300);
2932MODULE_FIRMWARE(FW_FILE_ISP2322);
2933MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08002934MODULE_FIRMWARE(FW_FILE_ISP25XX);