blob: f6365884c97b2d8e49d7f9ea8b786d12a3058659 [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
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800186qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800188 init_timer(&vha->timer);
189 vha->timer.expires = jiffies + interval * HZ;
190 vha->timer.data = (unsigned long)vha;
191 vha->timer.function = (void (*)(unsigned long))func;
192 add_timer(&vha->timer);
193 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194}
195
196static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800197qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800199 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200}
201
Adrian Bunka824ebb2008-01-17 09:02:15 -0800202static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800203qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800205 del_timer_sync(&vha->timer);
206 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
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
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800213static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t);
214static void qla2x00_mem_free(struct qla_hw_data *);
215static void qla2x00_sp_free_dma(srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217/* -------------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800219qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800221 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 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 *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800243qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700244{
245 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800246 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700247 uint32_t pci_bus;
248 int pcie_reg;
249
250 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
251 if (pcie_reg) {
252 char lwstr[6];
253 uint16_t pcie_lstat, lspeed, lwidth;
254
255 pcie_reg += 0x12;
256 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
257 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
258 lwidth = (pcie_lstat &
259 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
260
261 strcpy(str, "PCIe (");
262 if (lspeed == 1)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700263 strcat(str, "2.5GT/s ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700264 else if (lspeed == 2)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700265 strcat(str, "5.0GT/s ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700266 else
267 strcat(str, "<unknown> ");
268 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
269 strcat(str, lwstr);
270
271 return str;
272 }
273
274 strcpy(str, "PCI");
275 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
276 if (pci_bus == 0 || pci_bus == 8) {
277 strcat(str, " (");
278 strcat(str, pci_bus_modes[pci_bus >> 3]);
279 } else {
280 strcat(str, "-X ");
281 if (pci_bus & BIT_2)
282 strcat(str, "Mode 2");
283 else
284 strcat(str, "Mode 1");
285 strcat(str, " (");
286 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
287 }
288 strcat(str, " MHz)");
289
290 return str;
291}
292
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800293static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800294qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
296 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800297 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
300 ha->fw_minor_version,
301 ha->fw_subminor_version);
302
303 if (ha->fw_attributes & BIT_9) {
304 strcat(str, "FLX");
305 return (str);
306 }
307
308 switch (ha->fw_attributes & 0xFF) {
309 case 0x7:
310 strcat(str, "EF");
311 break;
312 case 0x17:
313 strcat(str, "TP");
314 break;
315 case 0x37:
316 strcat(str, "IP");
317 break;
318 case 0x77:
319 strcat(str, "VI");
320 break;
321 default:
322 sprintf(un_str, "(%x)", ha->fw_attributes);
323 strcat(str, un_str);
324 break;
325 }
326 if (ha->fw_attributes & 0x100)
327 strcat(str, "X");
328
329 return (str);
330}
331
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800332static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800333qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700334{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800335 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700336 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
337 ha->fw_minor_version,
338 ha->fw_subminor_version);
339
Andrew Vasquezfca29702005-07-06 10:31:47 -0700340 if (ha->fw_attributes & BIT_0)
341 strcat(str, "[Class 2] ");
342 if (ha->fw_attributes & BIT_1)
343 strcat(str, "[IP] ");
344 if (ha->fw_attributes & BIT_2)
345 strcat(str, "[Multi-ID] ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700346 if (ha->fw_attributes & BIT_3)
347 strcat(str, "[SB-2] ");
348 if (ha->fw_attributes & BIT_4)
349 strcat(str, "[T10 CRC] ");
350 if (ha->fw_attributes & BIT_5)
351 strcat(str, "[VI] ");
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700352 if (ha->fw_attributes & BIT_10)
353 strcat(str, "[84XX] ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700354 if (ha->fw_attributes & BIT_13)
355 strcat(str, "[Experimental]");
356 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700357}
358
359static inline srb_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800360qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700361 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
362{
363 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800364 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700365
366 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
367 if (!sp)
368 return sp;
369
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800370 sp->vha = vha;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700371 sp->fcport = fcport;
372 sp->cmd = cmd;
373 sp->flags = 0;
374 CMD_SP(cmd) = (void *)sp;
375 cmd->scsi_done = done;
376
377 return sp;
378}
379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380static int
f4f051e2005-04-17 15:02:26 -0500381qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800383 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500384 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400385 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800386 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500387 srb_t *sp;
388 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Seokmann Ju14e660e2007-09-20 14:07:36 -0700390 if (unlikely(pci_channel_offline(ha->pdev))) {
391 cmd->result = DID_REQUEUE << 16;
392 goto qc_fail_command;
393 }
394
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400395 rval = fc_remote_port_chkready(rport);
396 if (rval) {
397 cmd->result = rval;
f4f051e2005-04-17 15:02:26 -0500398 goto qc_fail_command;
399 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800401 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500402 if (fcport->drport)
403 goto qc_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800404
f4f051e2005-04-17 15:02:26 -0500405 if (atomic_read(&fcport->state) != FCS_ONLINE) {
406 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800407 atomic_read(&vha->loop_state) == LOOP_DEAD) {
f4f051e2005-04-17 15:02:26 -0500408 cmd->result = DID_NO_CONNECT << 16;
409 goto qc_fail_command;
410 }
Mike Christie7b594132008-08-17 15:24:40 -0500411 goto qc_target_busy;
f4f051e2005-04-17 15:02:26 -0500412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800414 spin_unlock_irq(vha->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800416 sp = qla2x00_get_new_sp(vha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700417 if (!sp)
f4f051e2005-04-17 15:02:26 -0500418 goto qc_host_busy_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800420 rval = ha->isp_ops->start_scsi(sp);
f4f051e2005-04-17 15:02:26 -0500421 if (rval != QLA_SUCCESS)
422 goto qc_host_busy_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800424 spin_lock_irq(vha->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
f4f051e2005-04-17 15:02:26 -0500426 return 0;
427
428qc_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800429 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -0500430 mempool_free(sp, ha->srb_mempool);
431
432qc_host_busy_lock:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800433 spin_lock_irq(vha->host->host_lock);
f4f051e2005-04-17 15:02:26 -0500434 return SCSI_MLQUEUE_HOST_BUSY;
435
Mike Christie7b594132008-08-17 15:24:40 -0500436qc_target_busy:
437 return SCSI_MLQUEUE_TARGET_BUSY;
438
f4f051e2005-04-17 15:02:26 -0500439qc_fail_command:
440 done(cmd);
441
442 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443}
444
Andrew Vasquezfca29702005-07-06 10:31:47 -0700445
446static int
447qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
448{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800449 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700450 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400451 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800452 struct qla_hw_data *ha = vha->hw;
453 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700454 srb_t *sp;
455 int rval;
456
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800457 if (unlikely(pci_channel_offline(ha->pdev))) {
Seokmann Ju14e660e2007-09-20 14:07:36 -0700458 cmd->result = DID_REQUEUE << 16;
459 goto qc24_fail_command;
460 }
461
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400462 rval = fc_remote_port_chkready(rport);
463 if (rval) {
464 cmd->result = rval;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700465 goto qc24_fail_command;
466 }
467
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800468 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500469 if (fcport->drport)
470 goto qc24_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800471
Andrew Vasquezfca29702005-07-06 10:31:47 -0700472 if (atomic_read(&fcport->state) != FCS_ONLINE) {
473 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800474 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700475 cmd->result = DID_NO_CONNECT << 16;
476 goto qc24_fail_command;
477 }
Mike Christie7b594132008-08-17 15:24:40 -0500478 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700479 }
480
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800481 spin_unlock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700482
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800483 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700484 if (!sp)
485 goto qc24_host_busy_lock;
486
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800487 rval = ha->isp_ops->start_scsi(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700488 if (rval != QLA_SUCCESS)
489 goto qc24_host_busy_free_sp;
490
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800491 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700492
493 return 0;
494
495qc24_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800496 qla2x00_sp_free_dma(sp);
497 mempool_free(sp, ha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700498
499qc24_host_busy_lock:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800500 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700501 return SCSI_MLQUEUE_HOST_BUSY;
502
Mike Christie7b594132008-08-17 15:24:40 -0500503qc24_target_busy:
504 return SCSI_MLQUEUE_TARGET_BUSY;
505
Andrew Vasquezfca29702005-07-06 10:31:47 -0700506qc24_fail_command:
507 done(cmd);
508
509 return 0;
510}
511
512
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513/*
514 * qla2x00_eh_wait_on_command
515 * Waits for the command to be returned by the Firmware for some
516 * max time.
517 *
518 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 *
521 * Return:
522 * Not Found : 0
523 * Found : 1
524 */
525static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800526qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700528#define ABORT_POLLING_PERIOD 1000
529#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500530 unsigned long wait_iter = ABORT_WAIT_ITER;
531 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
f4f051e2005-04-17 15:02:26 -0500533 while (CMD_SP(cmd)) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700534 msleep(ABORT_POLLING_PERIOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
f4f051e2005-04-17 15:02:26 -0500536 if (--wait_iter)
537 break;
538 }
539 if (CMD_SP(cmd))
540 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
f4f051e2005-04-17 15:02:26 -0500542 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543}
544
545/*
546 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700547 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 * <= MAX_RETRIES_OF_ISP_ABORT or
549 * finally HBA is disabled ie marked offline
550 *
551 * Input:
552 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700553 *
554 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 * Does context switching-Release SPIN_LOCK
556 * (if any) before calling this routine.
557 *
558 * Return:
559 * Success (Adapter is online) : 0
560 * Failed (Adapter is offline/disabled) : 1
561 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800562int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800563qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700565 int return_status;
566 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800567 struct qla_hw_data *ha = vha->hw;
568 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700570 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800571 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
572 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
573 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
574 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576 msleep(1000);
577 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800578 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700579 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 else
581 return_status = QLA_FUNCTION_FAILED;
582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 return (return_status);
584}
585
586/*
587 * qla2x00_wait_for_loop_ready
588 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700589 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 * Input:
591 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700592 *
593 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 * Does context switching-Release SPIN_LOCK
595 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700596 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 *
598 * Return:
599 * Success (LOOP_READY) : 0
600 * Failed (LOOP_NOT_READY) : 1
601 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700602static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800603qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
605 int return_status = QLA_SUCCESS;
606 unsigned long loop_timeout ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800607 struct qla_hw_data *ha = vha->hw;
608 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
610 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700611 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800613 while ((!atomic_read(&base_vha->loop_down_timer) &&
614 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
615 atomic_read(&base_vha->loop_state) != LOOP_READY) {
616 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Ravi Anand57680082006-05-17 15:08:44 -0700617 return_status = QLA_FUNCTION_FAILED;
618 break;
619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 msleep(1000);
621 if (time_after_eq(jiffies, loop_timeout)) {
622 return_status = QLA_FUNCTION_FAILED;
623 break;
624 }
625 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700626 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627}
628
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700629void
630qla2x00_abort_fcport_cmds(fc_port_t *fcport)
631{
632 int cnt;
633 unsigned long flags;
634 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800635 scsi_qla_host_t *vha = fcport->vha;
636 struct qla_hw_data *ha = vha->hw;
637 struct req_que *req = ha->req;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700638
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800639 spin_lock_irqsave(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700640 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800641 sp = req->outstanding_cmds[cnt];
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700642 if (!sp)
643 continue;
644 if (sp->fcport != fcport)
645 continue;
646
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800647 spin_unlock_irqrestore(&ha->hardware_lock, flags);
648 if (ha->isp_ops->abort_command(vha, sp)) {
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700649 DEBUG2(qla_printk(KERN_WARNING, ha,
650 "Abort failed -- %lx\n", sp->cmd->serial_number));
651 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800652 if (qla2x00_eh_wait_on_command(sp->cmd) !=
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700653 QLA_SUCCESS)
654 DEBUG2(qla_printk(KERN_WARNING, ha,
655 "Abort failed while waiting -- %lx\n",
656 sp->cmd->serial_number));
657
658 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800659 spin_lock_irqsave(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700660 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800661 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700662}
663
Andrew Vasquez07db5182006-10-02 12:00:49 -0700664static void
665qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
666{
667 struct Scsi_Host *shost = cmnd->device->host;
668 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
669 unsigned long flags;
670
671 spin_lock_irqsave(shost->host_lock, flags);
672 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
673 spin_unlock_irqrestore(shost->host_lock, flags);
674 msleep(1000);
675 spin_lock_irqsave(shost->host_lock, flags);
676 }
677 spin_unlock_irqrestore(shost->host_lock, flags);
678 return;
679}
680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681/**************************************************************************
682* qla2xxx_eh_abort
683*
684* Description:
685* The abort function will abort the specified command.
686*
687* Input:
688* cmd = Linux SCSI command packet to be aborted.
689*
690* Returns:
691* Either SUCCESS or FAILED.
692*
693* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700694* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800696static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697qla2xxx_eh_abort(struct scsi_cmnd *cmd)
698{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800699 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500700 srb_t *sp;
701 int ret, i;
702 unsigned int id, lun;
703 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700704 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700705 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800706 struct qla_hw_data *ha = vha->hw;
707 struct req_que *req = ha->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Andrew Vasquez07db5182006-10-02 12:00:49 -0700709 qla2x00_block_error_handler(cmd);
710
f4f051e2005-04-17 15:02:26 -0500711 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700712 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Michael Reed2ea00202006-04-27 16:25:30 -0700714 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
f4f051e2005-04-17 15:02:26 -0500716 id = cmd->device->id;
717 lun = cmd->device->lun;
718 serial = cmd->serial_number;
719
720 /* Check active list for command command. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800721 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500722 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800723 sp = req->outstanding_cmds[i];
f4f051e2005-04-17 15:02:26 -0500724
725 if (sp == NULL)
726 continue;
727
728 if (sp->cmd != cmd)
729 continue;
730
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700731 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800732 __func__, vha->host_no, sp, serial));
f4f051e2005-04-17 15:02:26 -0500733
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800734 spin_unlock_irqrestore(&ha->hardware_lock, flags);
735 if (ha->isp_ops->abort_command(vha, sp)) {
f4f051e2005-04-17 15:02:26 -0500736 DEBUG2(printk("%s(%ld): abort_command "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800737 "mbx failed.\n", __func__, vha->host_no));
Michael Reed5bff55d2008-10-24 15:13:47 -0700738 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500739 } else {
740 DEBUG3(printk("%s(%ld): abort_command "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800741 "mbx success.\n", __func__, vha->host_no));
Michael Reed2ea00202006-04-27 16:25:30 -0700742 wait = 1;
f4f051e2005-04-17 15:02:26 -0500743 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800744 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500745
746 break;
747 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800748 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500749
750 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700751 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800752 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700753 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500754 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800755 "%x.\n", vha->host_no, id, lun, serial, ret);
Michael Reed2ea00202006-04-27 16:25:30 -0700756 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700760 qla_printk(KERN_INFO, ha,
Michael Reed2ea00202006-04-27 16:25:30 -0700761 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800762 vha->host_no, id, lun, wait, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
f4f051e2005-04-17 15:02:26 -0500764 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765}
766
Andrew Vasquez523ec772008-04-03 13:13:24 -0700767enum nexus_wait_type {
768 WAIT_HOST = 0,
769 WAIT_TARGET,
770 WAIT_LUN,
771};
772
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800774qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700775 unsigned int l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700777 int cnt, match, status;
778 srb_t *sp;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700779 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800780 struct qla_hw_data *ha = vha->hw;
781 struct req_que *req = ha->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Andrew Vasquez523ec772008-04-03 13:13:24 -0700783 status = QLA_SUCCESS;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800784 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700785 for (cnt = 1; status == QLA_SUCCESS && cnt < MAX_OUTSTANDING_COMMANDS;
786 cnt++) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800787 sp = req->outstanding_cmds[cnt];
Andrew Vasquez523ec772008-04-03 13:13:24 -0700788 if (!sp)
789 continue;
Andrew Vasquez19851f12008-08-13 21:37:00 -0700790
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800791 if (vha->vp_idx != sp->fcport->vha->vp_idx)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700792 continue;
793 match = 0;
794 switch (type) {
795 case WAIT_HOST:
796 match = 1;
797 break;
798 case WAIT_TARGET:
799 match = sp->cmd->device->id == t;
800 break;
801 case WAIT_LUN:
802 match = (sp->cmd->device->id == t &&
803 sp->cmd->device->lun == l);
804 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 }
Andrew Vasquez523ec772008-04-03 13:13:24 -0700806 if (!match)
807 continue;
808
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800809 spin_unlock_irqrestore(&ha->hardware_lock, flags);
810 status = qla2x00_eh_wait_on_command(sp->cmd);
811 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800813 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700814
815 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816}
817
Andrew Vasquez523ec772008-04-03 13:13:24 -0700818static char *reset_errors[] = {
819 "HBA not online",
820 "HBA not ready",
821 "Task management failed",
822 "Waiting for command completions",
823};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
Andrew Vasquez523ec772008-04-03 13:13:24 -0700825static int
826__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
827 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int))
828{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800829 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700830 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
831 int err;
832
833 qla2x00_block_error_handler(cmd);
834
835 if (!fcport)
836 return FAILED;
837
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800838 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
839 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700840
841 err = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800842 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700843 goto eh_reset_failed;
844 err = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800845 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700846 goto eh_reset_failed;
847 err = 2;
848 if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS)
849 goto eh_reset_failed;
850 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800851 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700852 cmd->device->lun, type) != QLA_SUCCESS)
853 goto eh_reset_failed;
854
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800855 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
856 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700857
858 return SUCCESS;
859
860 eh_reset_failed:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800861 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
862 , vha->host_no, cmd->device->id, cmd->device->lun, name,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700863 reset_errors[err]);
864 return FAILED;
865}
866
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800867static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
869{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800870 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
871 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Andrew Vasquez523ec772008-04-03 13:13:24 -0700873 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
874 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875}
876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700878qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800880 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
881 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
Andrew Vasquez523ec772008-04-03 13:13:24 -0700883 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
884 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885}
886
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887/**************************************************************************
888* qla2xxx_eh_bus_reset
889*
890* Description:
891* The bus reset function will reset the bus and abort any executing
892* commands.
893*
894* Input:
895* cmd = Linux SCSI command packet of the command that cause the
896* bus reset.
897*
898* Returns:
899* SUCCESS/FAILURE (defined as macro in scsi.h).
900*
901**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800902static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
904{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800905 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500906 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700907 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500908 unsigned int id, lun;
909 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Andrew Vasquez07db5182006-10-02 12:00:49 -0700911 qla2x00_block_error_handler(cmd);
912
f4f051e2005-04-17 15:02:26 -0500913 id = cmd->device->id;
914 lun = cmd->device->lun;
915 serial = cmd->serial_number;
916
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700917 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500918 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800920 qla_printk(KERN_INFO, vha->hw,
Anirban Chakraborty749af3d2008-11-14 13:48:12 -0800921 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800923 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500925 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 }
927
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800928 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
929 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500930 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 }
f4f051e2005-04-17 15:02:26 -0500932 if (ret == FAILED)
933 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700935 /* Flush outstanding commands. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800936 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Andrew Vasquez523ec772008-04-03 13:13:24 -0700937 QLA_SUCCESS)
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700938 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
f4f051e2005-04-17 15:02:26 -0500940eh_bus_reset_done:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800941 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500942 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
f4f051e2005-04-17 15:02:26 -0500944 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945}
946
947/**************************************************************************
948* qla2xxx_eh_host_reset
949*
950* Description:
951* The reset function will reset the Adapter.
952*
953* Input:
954* cmd = Linux SCSI command packet of the command that cause the
955* adapter reset.
956*
957* Returns:
958* Either SUCCESS or FAILED.
959*
960* Note:
961**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800962static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
964{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800965 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500966 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800967 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700968 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500969 unsigned int id, lun;
970 unsigned long serial;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800971 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Andrew Vasquez07db5182006-10-02 12:00:49 -0700973 qla2x00_block_error_handler(cmd);
974
f4f051e2005-04-17 15:02:26 -0500975 id = cmd->device->id;
976 lun = cmd->device->lun;
977 serial = cmd->serial_number;
978
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700979 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500980 return ret;
981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 qla_printk(KERN_INFO, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800983 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800985 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500986 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
988 /*
989 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700990 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 * be completed and then issue big hammer.Otherwise
992 * it may cause I/O failure as big hammer marks the
993 * devices as lost kicking of the port_down_timer
994 * while dpc is stuck for the mailbox to complete.
995 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800996 qla2x00_wait_for_loop_ready(vha);
997 if (vha != base_vha) {
998 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -0500999 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001000 } else {
1001 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1002 if (qla2x00_abort_isp(base_vha)) {
1003 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1004 /* failed. schedule dpc to try */
1005 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1006
1007 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1008 goto eh_host_reset_lock;
1009 }
1010 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001011 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001013 /* Waiting for command to be returned to OS.*/
1014 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
1015 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001016 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
f4f051e2005-04-17 15:02:26 -05001018eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001019 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1020 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
f4f051e2005-04-17 15:02:26 -05001022 return ret;
1023}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
1025/*
1026* qla2x00_loop_reset
1027* Issue loop reset.
1028*
1029* Input:
1030* ha = adapter block pointer.
1031*
1032* Returns:
1033* 0 = success
1034*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001035int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001036qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001038 int ret;
bdf79622005-04-17 15:06:53 -05001039 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001040 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001042 if (ha->flags.enable_lip_full_login && !vha->vp_idx) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001043 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001044 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001045 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001046 "full_login_lip=%d.\n", __func__, vha->host_no,
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001047 ret));
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001048 }
1049 atomic_set(&vha->loop_state, LOOP_DOWN);
1050 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1051 qla2x00_mark_all_devices_lost(vha, 0);
1052 qla2x00_wait_for_loop_ready(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
1054
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001055 if (ha->flags.enable_lip_reset && !vha->vp_idx) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001056 ret = qla2x00_lip_reset(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001057 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001058 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001059 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1060 } else
1061 qla2x00_wait_for_loop_ready(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001062 }
1063
1064 if (ha->flags.enable_target_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001065 list_for_each_entry(fcport, &vha->vp_fcports, list) {
bdf79622005-04-17 15:06:53 -05001066 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 continue;
1068
Andrew Vasquez523ec772008-04-03 13:13:24 -07001069 ret = ha->isp_ops->target_reset(fcport, 0);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001070 if (ret != QLA_SUCCESS) {
1071 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1072 "target_reset=%d d_id=%x.\n", __func__,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001073 vha->host_no, ret, fcport->d_id.b24));
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 }
1076 }
1077
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001079 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001081 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082}
1083
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001084void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001085qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001086{
1087 int cnt;
1088 unsigned long flags;
1089 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001090 struct qla_hw_data *ha = vha->hw;
1091 struct req_que *req = ha->req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001092
1093 spin_lock_irqsave(&ha->hardware_lock, flags);
1094 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001095 sp = req->outstanding_cmds[cnt];
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001096 if (sp) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001097 req->outstanding_cmds[cnt] = NULL;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001098 sp->cmd->result = res;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001099 qla2x00_sp_compl(vha, sp);
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001100 }
1101 }
1102 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1103}
1104
f4f051e2005-04-17 15:02:26 -05001105static int
1106qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107{
bdf79622005-04-17 15:06:53 -05001108 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001110 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001111 return -ENXIO;
1112
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001113 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001114
1115 return 0;
1116}
1117
1118static int
1119qla2xxx_slave_configure(struct scsi_device *sdev)
1120{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001121 scsi_qla_host_t *vha = shost_priv(sdev->host);
1122 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05001123 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1124
f4f051e2005-04-17 15:02:26 -05001125 if (sdev->tagged_supported)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001126 scsi_activate_tcq(sdev, ha->req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001128 scsi_deactivate_tcq(sdev, ha->req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Andrew Vasquez85821c92008-07-10 16:55:48 -07001130 rport->dev_loss_tmo = ha->port_down_retry_count;
8482e1182005-04-17 15:04:54 -05001131
f4f051e2005-04-17 15:02:26 -05001132 return 0;
1133}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
f4f051e2005-04-17 15:02:26 -05001135static void
1136qla2xxx_slave_destroy(struct scsi_device *sdev)
1137{
1138 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001141static int
1142qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1143{
1144 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1145 return sdev->queue_depth;
1146}
1147
1148static int
1149qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1150{
1151 if (sdev->tagged_supported) {
1152 scsi_set_tag_type(sdev, tag_type);
1153 if (tag_type)
1154 scsi_activate_tcq(sdev, sdev->queue_depth);
1155 else
1156 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1157 } else
1158 tag_type = 0;
1159
1160 return tag_type;
1161}
1162
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163/**
1164 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1165 * @ha: HA context
1166 *
1167 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1168 * supported addressing method.
1169 */
1170static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001171qla2x00_config_dma_addressing(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001173 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001174 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001177 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1178 /* Any upper-dword bits set? */
1179 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1180 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1181 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001183 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1184 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001185 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001188
1189 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1190 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191}
1192
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001193static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001194qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001195{
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 = 1;
1201 /* enable risc and host interrupts */
1202 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1203 RD_REG_WORD(&reg->ictrl);
1204 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1205
1206}
1207
1208static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001209qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001210{
1211 unsigned long flags = 0;
1212 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1213
1214 spin_lock_irqsave(&ha->hardware_lock, flags);
1215 ha->interrupts_on = 0;
1216 /* disable risc and host interrupts */
1217 WRT_REG_WORD(&reg->ictrl, 0);
1218 RD_REG_WORD(&reg->ictrl);
1219 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1220}
1221
1222static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001223qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001224{
1225 unsigned long flags = 0;
1226 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1227
1228 spin_lock_irqsave(&ha->hardware_lock, flags);
1229 ha->interrupts_on = 1;
1230 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1231 RD_REG_DWORD(&reg->ictrl);
1232 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1233}
1234
1235static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001236qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001237{
1238 unsigned long flags = 0;
1239 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1240
1241 spin_lock_irqsave(&ha->hardware_lock, flags);
1242 ha->interrupts_on = 0;
1243 WRT_REG_DWORD(&reg->ictrl, 0);
1244 RD_REG_DWORD(&reg->ictrl);
1245 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1246}
1247
1248static struct isp_operations qla2100_isp_ops = {
1249 .pci_config = qla2100_pci_config,
1250 .reset_chip = qla2x00_reset_chip,
1251 .chip_diag = qla2x00_chip_diag,
1252 .config_rings = qla2x00_config_rings,
1253 .reset_adapter = qla2x00_reset_adapter,
1254 .nvram_config = qla2x00_nvram_config,
1255 .update_fw_options = qla2x00_update_fw_options,
1256 .load_risc = qla2x00_load_risc,
1257 .pci_info_str = qla2x00_pci_info_str,
1258 .fw_version_str = qla2x00_fw_version_str,
1259 .intr_handler = qla2100_intr_handler,
1260 .enable_intrs = qla2x00_enable_intrs,
1261 .disable_intrs = qla2x00_disable_intrs,
1262 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001263 .target_reset = qla2x00_abort_target,
1264 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001265 .fabric_login = qla2x00_login_fabric,
1266 .fabric_logout = qla2x00_fabric_logout,
1267 .calc_req_entries = qla2x00_calc_iocbs_32,
1268 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1269 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1270 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1271 .read_nvram = qla2x00_read_nvram_data,
1272 .write_nvram = qla2x00_write_nvram_data,
1273 .fw_dump = qla2100_fw_dump,
1274 .beacon_on = NULL,
1275 .beacon_off = NULL,
1276 .beacon_blink = NULL,
1277 .read_optrom = qla2x00_read_optrom_data,
1278 .write_optrom = qla2x00_write_optrom_data,
1279 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001280 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001281};
1282
1283static struct isp_operations qla2300_isp_ops = {
1284 .pci_config = qla2300_pci_config,
1285 .reset_chip = qla2x00_reset_chip,
1286 .chip_diag = qla2x00_chip_diag,
1287 .config_rings = qla2x00_config_rings,
1288 .reset_adapter = qla2x00_reset_adapter,
1289 .nvram_config = qla2x00_nvram_config,
1290 .update_fw_options = qla2x00_update_fw_options,
1291 .load_risc = qla2x00_load_risc,
1292 .pci_info_str = qla2x00_pci_info_str,
1293 .fw_version_str = qla2x00_fw_version_str,
1294 .intr_handler = qla2300_intr_handler,
1295 .enable_intrs = qla2x00_enable_intrs,
1296 .disable_intrs = qla2x00_disable_intrs,
1297 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001298 .target_reset = qla2x00_abort_target,
1299 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001300 .fabric_login = qla2x00_login_fabric,
1301 .fabric_logout = qla2x00_fabric_logout,
1302 .calc_req_entries = qla2x00_calc_iocbs_32,
1303 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1304 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1305 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1306 .read_nvram = qla2x00_read_nvram_data,
1307 .write_nvram = qla2x00_write_nvram_data,
1308 .fw_dump = qla2300_fw_dump,
1309 .beacon_on = qla2x00_beacon_on,
1310 .beacon_off = qla2x00_beacon_off,
1311 .beacon_blink = qla2x00_beacon_blink,
1312 .read_optrom = qla2x00_read_optrom_data,
1313 .write_optrom = qla2x00_write_optrom_data,
1314 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001315 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001316};
1317
1318static struct isp_operations qla24xx_isp_ops = {
1319 .pci_config = qla24xx_pci_config,
1320 .reset_chip = qla24xx_reset_chip,
1321 .chip_diag = qla24xx_chip_diag,
1322 .config_rings = qla24xx_config_rings,
1323 .reset_adapter = qla24xx_reset_adapter,
1324 .nvram_config = qla24xx_nvram_config,
1325 .update_fw_options = qla24xx_update_fw_options,
1326 .load_risc = qla24xx_load_risc,
1327 .pci_info_str = qla24xx_pci_info_str,
1328 .fw_version_str = qla24xx_fw_version_str,
1329 .intr_handler = qla24xx_intr_handler,
1330 .enable_intrs = qla24xx_enable_intrs,
1331 .disable_intrs = qla24xx_disable_intrs,
1332 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001333 .target_reset = qla24xx_abort_target,
1334 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001335 .fabric_login = qla24xx_login_fabric,
1336 .fabric_logout = qla24xx_fabric_logout,
1337 .calc_req_entries = NULL,
1338 .build_iocbs = NULL,
1339 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1340 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1341 .read_nvram = qla24xx_read_nvram_data,
1342 .write_nvram = qla24xx_write_nvram_data,
1343 .fw_dump = qla24xx_fw_dump,
1344 .beacon_on = qla24xx_beacon_on,
1345 .beacon_off = qla24xx_beacon_off,
1346 .beacon_blink = qla24xx_beacon_blink,
1347 .read_optrom = qla24xx_read_optrom_data,
1348 .write_optrom = qla24xx_write_optrom_data,
1349 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001350 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001351};
1352
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001353static struct isp_operations qla25xx_isp_ops = {
1354 .pci_config = qla25xx_pci_config,
1355 .reset_chip = qla24xx_reset_chip,
1356 .chip_diag = qla24xx_chip_diag,
1357 .config_rings = qla24xx_config_rings,
1358 .reset_adapter = qla24xx_reset_adapter,
1359 .nvram_config = qla24xx_nvram_config,
1360 .update_fw_options = qla24xx_update_fw_options,
1361 .load_risc = qla24xx_load_risc,
1362 .pci_info_str = qla24xx_pci_info_str,
1363 .fw_version_str = qla24xx_fw_version_str,
1364 .intr_handler = qla24xx_intr_handler,
1365 .enable_intrs = qla24xx_enable_intrs,
1366 .disable_intrs = qla24xx_disable_intrs,
1367 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001368 .target_reset = qla24xx_abort_target,
1369 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001370 .fabric_login = qla24xx_login_fabric,
1371 .fabric_logout = qla24xx_fabric_logout,
1372 .calc_req_entries = NULL,
1373 .build_iocbs = NULL,
1374 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1375 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1376 .read_nvram = qla25xx_read_nvram_data,
1377 .write_nvram = qla25xx_write_nvram_data,
1378 .fw_dump = qla25xx_fw_dump,
1379 .beacon_on = qla24xx_beacon_on,
1380 .beacon_off = qla24xx_beacon_off,
1381 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001382 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001383 .write_optrom = qla24xx_write_optrom_data,
1384 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001385 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001386};
1387
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001388static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001389qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001390{
1391 ha->device_type = DT_EXTENDED_IDS;
1392 switch (ha->pdev->device) {
1393 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1394 ha->device_type |= DT_ISP2100;
1395 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001396 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001397 break;
1398 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1399 ha->device_type |= DT_ISP2200;
1400 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001401 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001402 break;
1403 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1404 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001405 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001406 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001407 break;
1408 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1409 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001410 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001411 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001412 break;
1413 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1414 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001415 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001416 if (ha->pdev->subsystem_vendor == 0x1028 &&
1417 ha->pdev->subsystem_device == 0x0170)
1418 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001419 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001420 break;
1421 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1422 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001423 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001424 break;
1425 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1426 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001427 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001428 break;
1429 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1430 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001431 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001432 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001433 ha->device_type |= DT_IIDMA;
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;
1436 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1437 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001438 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001439 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001440 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001441 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001442 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001443 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1444 ha->device_type |= DT_ISP8432;
1445 ha->device_type |= DT_ZIO_SUPPORTED;
1446 ha->device_type |= DT_FWI2;
1447 ha->device_type |= DT_IIDMA;
1448 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1449 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001450 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1451 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001452 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001453 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001454 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001455 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1456 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001457 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001458 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001459 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001460 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1461 ha->device_type |= DT_ISP2532;
1462 ha->device_type |= DT_ZIO_SUPPORTED;
1463 ha->device_type |= DT_FWI2;
1464 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001465 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1466 break;
1467 }
1468}
1469
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001471qla2x00_iospace_config(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472{
Andrew Vasquez37765412008-01-17 09:02:09 -08001473 resource_size_t pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Andrew Vasquez285d0322007-10-19 15:59:17 -07001475 if (pci_request_selected_regions(ha->pdev, ha->bars,
1476 QLA2XXX_DRIVER_NAME)) {
1477 qla_printk(KERN_WARNING, ha,
1478 "Failed to reserve PIO/MMIO regions (%s)\n",
1479 pci_name(ha->pdev));
1480
1481 goto iospace_error_exit;
1482 }
1483 if (!(ha->bars & 1))
1484 goto skip_pio;
1485
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1487 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001488 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1489 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 qla_printk(KERN_WARNING, ha,
1491 "Invalid PCI I/O region size (%s)...\n",
1492 pci_name(ha->pdev));
1493 pio = 0;
1494 }
1495 } else {
1496 qla_printk(KERN_WARNING, ha,
1497 "region #0 not a PIO resource (%s)...\n",
1498 pci_name(ha->pdev));
1499 pio = 0;
1500 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001501 ha->pio_address = pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Andrew Vasquez285d0322007-10-19 15:59:17 -07001503skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001505 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 qla_printk(KERN_ERR, ha,
Andrew Vasquez37765412008-01-17 09:02:09 -08001507 "region #1 not an MMIO resource (%s), aborting\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 pci_name(ha->pdev));
1509 goto iospace_error_exit;
1510 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001511 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 qla_printk(KERN_ERR, ha,
1513 "Invalid PCI mem region size (%s), aborting\n",
1514 pci_name(ha->pdev));
1515 goto iospace_error_exit;
1516 }
1517
Andrew Vasquez37765412008-01-17 09:02:09 -08001518 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 if (!ha->iobase) {
1520 qla_printk(KERN_ERR, ha,
1521 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1522
1523 goto iospace_error_exit;
1524 }
1525
1526 return (0);
1527
1528iospace_error_exit:
1529 return (-ENOMEM);
1530}
1531
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001532static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001533qla2xxx_scan_start(struct Scsi_Host *shost)
1534{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001535 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001536
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001537 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1538 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1539 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1540 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001541}
1542
1543static int
1544qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1545{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001546 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001547
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001548 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001549 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001550 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001551 return 1;
1552
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001553 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001554}
1555
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556/*
1557 * PCI driver interface
1558 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001559static int __devinit
1560qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001562 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001564 scsi_qla_host_t *base_vha = NULL;
1565 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001566 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001568 struct scsi_host_template *sht;
Anirban Chakrabortyc51da4e2008-11-10 15:53:20 -08001569 int bars, max_id, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001570 uint16_t req_length = 0, rsp_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
Andrew Vasquez285d0322007-10-19 15:59:17 -07001572 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1573 sht = &qla2x00_driver_template;
1574 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1575 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001576 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001577 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1578 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1579 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532) {
1580 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1581 sht = &qla24xx_driver_template;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001582 mem_only = 1;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001583 }
1584
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001585 if (mem_only) {
1586 if (pci_enable_device_mem(pdev))
1587 goto probe_out;
1588 } else {
1589 if (pci_enable_device(pdev))
1590 goto probe_out;
1591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
Jesse Barnes09276782008-10-18 17:33:19 -07001593 /* This may fail but that's ok */
1594 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07001595
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001596 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1597 if (!ha) {
1598 DEBUG(printk("Unable to allocate memory for ha\n"));
1599 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001601 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602
1603 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07001604 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001605 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001606 spin_lock_init(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001608 /* Set ISP-type information. */
1609 qla2x00_set_isp_flags(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 /* Configure PCI I/O space */
1611 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001612 if (ret)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001613 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08001616 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1617 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001620 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001621 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001622 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001624 /* Assign ISP specific operations. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001625 max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 if (IS_QLA2100(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001627 max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001629 req_length = REQUEST_ENTRY_CNT_2100;
1630 rsp_length = RESPONSE_ENTRY_CNT_2100;
1631 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001632 ha->gid_list_info_size = 4;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001633 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 } else if (IS_QLA2200(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001636 req_length = REQUEST_ENTRY_CNT_2200;
1637 rsp_length = RESPONSE_ENTRY_CNT_2100;
1638 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001639 ha->gid_list_info_size = 4;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001640 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001641 } else if (IS_QLA23XX(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001643 req_length = REQUEST_ENTRY_CNT_2200;
1644 rsp_length = RESPONSE_ENTRY_CNT_2300;
1645 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001646 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001647 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1648 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001649 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001650 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07001651 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001652 req_length = REQUEST_ENTRY_CNT_24XX;
1653 rsp_length = RESPONSE_ENTRY_CNT_2300;
1654 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001655 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001656 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001657 ha->optrom_size = OPTROM_SIZE_24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001658 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001659 } else if (IS_QLA25XX(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001660 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001661 req_length = REQUEST_ENTRY_CNT_24XX;
1662 rsp_length = RESPONSE_ENTRY_CNT_2300;
1663 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001664 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001665 ha->gid_list_info_size = 8;
1666 ha->optrom_size = OPTROM_SIZE_25XX;
1667 ha->isp_ops = &qla25xx_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07001670 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001671 init_completion(&ha->mbx_cmd_comp);
1672 complete(&ha->mbx_cmd_comp);
1673 init_completion(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001675 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001677 ret = qla2x00_mem_alloc(ha, req_length, rsp_length);
1678 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 qla_printk(KERN_WARNING, ha,
1680 "[ERROR] Failed to allocate memory for adapter\n");
1681
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001682 goto probe_hw_failed;
1683 }
1684
1685 ha->req->max_q_depth = MAX_Q_DEPTH;
1686 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1687 ha->req->max_q_depth = ql2xmaxqdepth;
1688
1689 base_vha = qla2x00_create_host(sht, ha);
1690 if (!base_vha) {
1691 qla_printk(KERN_WARNING, ha,
1692 "[ERROR] Failed to allocate memory for scsi_host\n");
1693
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001694 ret = -ENOMEM;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001695 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 }
1697
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001698 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001700 qla2x00_config_dma_addressing(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001702 host = base_vha->host;
1703 host->can_queue = ha->req->length + 128;
1704 if (IS_QLA2XXX_MIDTYPE(ha)) {
1705 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
1706 } else {
1707 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1708 base_vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001710 if (IS_QLA2100(ha))
1711 host->sg_tablesize = 32;
1712 host->max_id = max_id;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001713 host->this_id = 255;
1714 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07001715 host->unique_id = host->host_no;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001716 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001717 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001718 host->max_lun = MAX_LUNS;
1719 host->transportt = qla2xxx_transport_template;
1720
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001721 if (qla2x00_initialize_adapter(base_vha)) {
1722 qla_printk(KERN_WARNING, ha,
1723 "Failed to initialize adapter\n");
1724
1725 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1726 "Adapter flags %x.\n",
1727 base_vha->host_no, base_vha->device_flags));
1728
1729 ret = -ENODEV;
1730 goto probe_failed;
1731 }
1732
1733 /* Set up the irqs */
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001734 ret = qla2x00_request_irqs(ha);
1735 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001738 /*
1739 * Startup the kernel thread for this host adapter
1740 */
1741 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1742 "%s_dpc", base_vha->host_str);
1743 if (IS_ERR(ha->dpc_thread)) {
1744 qla_printk(KERN_WARNING, ha,
1745 "Unable to start DPC thread!\n");
1746 ret = PTR_ERR(ha->dpc_thread);
1747 goto probe_failed;
1748 }
1749
1750 list_add_tail(&base_vha->list, &ha->vp_list);
1751 base_vha->host->irq = ha->pdev->irq;
1752
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001754 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
1756 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001757 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001759 base_vha->flags.init_done = 1;
1760 base_vha->flags.online = 1;
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001761
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001762 ret = scsi_add_host(host, &pdev->dev);
1763 if (ret)
1764 goto probe_failed;
1765
Andrew Vasquez048feec2008-09-11 22:19:45 -07001766 ha->isp_ops->enable_intrs(ha);
1767
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001768 scsi_scan_host(host);
1769
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001770 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001771
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001772 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001773
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001774 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001775
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 qla_printk(KERN_INFO, ha, "\n"
1777 " QLogic Fibre Channel HBA Driver: %s\n"
1778 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08001779 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1780 qla2x00_version_str, ha->model_number,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001781 ha->model_desc ? ha->model_desc : "", pdev->device,
1782 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
1783 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
1784 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 return 0;
1787
1788probe_failed:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001789 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001791 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001793probe_hw_failed:
1794 if (ha->iobase)
1795 iounmap(ha->iobase);
1796
1797 pci_release_selected_regions(ha->pdev, ha->bars);
1798 kfree(ha);
1799 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001801probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001802 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001803 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805
Adrian Bunk4c993f72008-01-14 00:55:16 -08001806static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001807qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001809 scsi_qla_host_t *base_vha, *vha, *temp;
1810 struct qla_hw_data *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001812 base_vha = pci_get_drvdata(pdev);
1813 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001815 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
1816 if (vha && vha->fc_vport)
1817 fc_vport_terminate(vha->fc_vport);
1818 }
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07001819
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001820 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07001821
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001822 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001823
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001824 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001825
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001826 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001828 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05001829
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001830 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001832 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001834 scsi_host_put(base_vha->host);
1835
1836 if (ha->iobase)
1837 iounmap(ha->iobase);
1838
1839 pci_release_selected_regions(ha->pdev, ha->bars);
1840 kfree(ha);
1841 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
Bernhard Walle665db932007-03-28 00:49:49 +02001843 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 pci_set_drvdata(pdev, NULL);
1845}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
1847static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001848qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001850 struct qla_hw_data *ha = vha->hw;
1851 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001852
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 /* Disable timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001854 if (vha->timer_active)
1855 qla2x00_stop_timer(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001857 vha->flags.online = 0;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001858
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 /* Kill the kernel thread for this host */
Christoph Hellwig39a11242006-02-14 18:46:22 +01001860 if (ha->dpc_thread) {
1861 struct task_struct *t = ha->dpc_thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862
Christoph Hellwig39a11242006-02-14 18:46:22 +01001863 /*
1864 * qla2xxx_wake_dpc checks for ->dpc_thread
1865 * so we need to zero it out.
1866 */
1867 ha->dpc_thread = NULL;
1868 kthread_stop(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 }
1870
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001871 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001872 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001873
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001874 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001875 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001876
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001877 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001878 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001880 /* turn-off interrupts on the card */
1881 if (ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001882 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001883
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001884 qla2x00_free_irqs(vha);
1885
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001886 qla2x00_mem_free(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887}
1888
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001889static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001890qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001891 int defer)
1892{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001893 struct fc_rport *rport;
1894
1895 if (!fcport->rport)
1896 return;
1897
1898 rport = fcport->rport;
1899 if (defer) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001900 spin_lock_irq(vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001901 fcport->drport = rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001902 spin_unlock_irq(vha->host->host_lock);
1903 set_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
1904 qla2xxx_wake_dpc(vha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07001905 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001906 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001907}
1908
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1911 *
1912 * Input: ha = adapter block pointer. fcport = port structure pointer.
1913 *
1914 * Return: None.
1915 *
1916 * Context:
1917 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001918void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001919 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001921 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001922 vha->vp_idx == fcport->vp_idx) {
1923 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1924 qla2x00_schedule_rport_del(vha, fcport, defer);
1925 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001926 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 * We may need to retry the login, so don't change the state of the
1928 * port but do the retries.
1929 */
1930 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1931 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1932
1933 if (!do_login)
1934 return;
1935
1936 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001937 fcport->login_retry = vha->hw->login_retry_count;
1938 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939
1940 DEBUG(printk("scsi(%ld): Port login retry: "
1941 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1942 "id = 0x%04x retry cnt=%d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001943 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 fcport->port_name[0],
1945 fcport->port_name[1],
1946 fcport->port_name[2],
1947 fcport->port_name[3],
1948 fcport->port_name[4],
1949 fcport->port_name[5],
1950 fcport->port_name[6],
1951 fcport->port_name[7],
1952 fcport->loop_id,
1953 fcport->login_retry));
1954 }
1955}
1956
1957/*
1958 * qla2x00_mark_all_devices_lost
1959 * Updates fcport state when device goes offline.
1960 *
1961 * Input:
1962 * ha = adapter block pointer.
1963 * fcport = port structure pointer.
1964 *
1965 * Return:
1966 * None.
1967 *
1968 * Context:
1969 */
1970void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001971qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972{
1973 fc_port_t *fcport;
1974
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001975 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1976 if (vha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 /*
1979 * No point in marking the device as lost, if the device is
1980 * already DEAD.
1981 */
1982 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1983 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001984 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1985 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1986 qla2x00_schedule_rport_del(vha, fcport, defer);
1987 } else
1988 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 }
1990}
1991
1992/*
1993* qla2x00_mem_alloc
1994* Allocates adapter memory.
1995*
1996* Returns:
1997* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08001998* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002000static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002001qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002{
2003 char name[16];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002004 struct req_que *req = NULL;
2005 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002007 ha->init_cb_size = sizeof(init_cb_t);
2008 if (IS_QLA2XXX_MIDTYPE(ha))
2009 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010
Andrew Vasqueze8711082008-01-31 12:33:48 -08002011 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002012 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002013 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002014 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002016 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2017 &ha->gid_list_dma, GFP_KERNEL);
2018 if (!ha->gid_list)
Andrew Vasqueze8711082008-01-31 12:33:48 -08002019 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020
Andrew Vasqueze8711082008-01-31 12:33:48 -08002021 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2022 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002023 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
Andrew Vasqueze8711082008-01-31 12:33:48 -08002025 /* Get memory for cached NVRAM */
2026 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2027 if (!ha->nvram)
2028 goto fail_free_srb_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002030 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2031 ha->pdev->device);
2032 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2033 DMA_POOL_SIZE, 8, 0);
2034 if (!ha->s_dma_pool)
2035 goto fail_free_nvram;
2036
Andrew Vasqueze8711082008-01-31 12:33:48 -08002037 /* Allocate memory for SNS commands */
2038 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002039 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002040 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002041 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002042 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002043 goto fail_dma_pool;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002044 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002045 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002046 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002047 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002048 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002049 goto fail_dma_pool;
2050 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002051 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002053 if (!ha->ct_sns)
2054 goto fail_free_ms_iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 }
2056
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002057 /* Allocate memory for request ring */
2058 req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2059 if (!req) {
2060 DEBUG(printk("Unable to allocate memory for req\n"));
2061 goto fail_req;
2062 }
2063 ha->req = req;
2064 req->length = req_len;
2065 req->ring = dma_alloc_coherent(&ha->pdev->dev,
2066 (req->length + 1) * sizeof(request_t),
2067 &req->dma, GFP_KERNEL);
2068 if (!req->ring) {
2069 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2070 goto fail_req_ring;
2071 }
2072 /* Allocate memory for response ring */
2073 rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2074 if (!rsp) {
2075 DEBUG(printk("Unable to allocate memory for rsp\n"));
2076 goto fail_rsp;
2077 }
2078 ha->rsp = rsp;
2079 rsp->hw = ha;
2080 rsp->length = rsp_len;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002081
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002082 rsp->ring = dma_alloc_coherent(&ha->pdev->dev,
2083 (rsp->length + 1) * sizeof(response_t),
2084 &rsp->dma, GFP_KERNEL);
2085 if (!rsp->ring) {
2086 DEBUG(printk("Unable to allocate memory for rsp_ring\n"));
2087 goto fail_rsp_ring;
2088 }
2089
2090 INIT_LIST_HEAD(&ha->vp_list);
2091 return 1;
2092
2093fail_rsp_ring:
2094 kfree(rsp);
2095 ha->rsp = NULL;
2096fail_rsp:
2097 dma_free_coherent(&ha->pdev->dev, (req->length + 1) *
2098 sizeof(request_t), req->ring, req->dma);
2099 req->ring = NULL;
2100 req->dma = 0;
2101fail_req_ring:
2102 kfree(req);
2103 ha->req = NULL;
2104fail_req:
2105 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2106 ha->ct_sns, ha->ct_sns_dma);
2107 ha->ct_sns = NULL;
2108 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002109fail_free_ms_iocb:
2110 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2111 ha->ms_iocb = NULL;
2112 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002113fail_dma_pool:
2114 dma_pool_destroy(ha->s_dma_pool);
2115 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002116fail_free_nvram:
2117 kfree(ha->nvram);
2118 ha->nvram = NULL;
2119fail_free_srb_mempool:
2120 mempool_destroy(ha->srb_mempool);
2121 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002122fail_free_gid_list:
2123 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002124 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002125 ha->gid_list = NULL;
2126 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002127fail_free_init_cb:
2128 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2129 ha->init_cb_dma);
2130 ha->init_cb = NULL;
2131 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002132fail:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002133 DEBUG(printk("%s: Memory allocation failure\n", __func__));
Andrew Vasqueze8711082008-01-31 12:33:48 -08002134 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135}
2136
2137/*
2138* qla2x00_mem_free
2139* Frees all adapter allocated memory.
2140*
2141* Input:
2142* ha = adapter block pointer.
2143*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08002144static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002145qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002147 struct req_que *req = ha->req;
2148 struct rsp_que *rsp = ha->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
Andrew Vasqueze8711082008-01-31 12:33:48 -08002150 if (ha->srb_mempool)
2151 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002153 if (ha->fce)
2154 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002155 ha->fce_dma);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002156
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002157 if (ha->fw_dump) {
2158 if (ha->eft)
2159 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002160 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002161 vfree(ha->fw_dump);
2162 }
2163
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 if (ha->sns_cmd)
2165 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002166 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
2168 if (ha->ct_sns)
2169 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002170 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171
Andrew Vasquez88729e52006-06-23 16:10:50 -07002172 if (ha->sfp_data)
2173 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2174
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 if (ha->ms_iocb)
2176 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2177
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 if (ha->s_dma_pool)
2179 dma_pool_destroy(ha->s_dma_pool);
2180
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002181
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 if (ha->gid_list)
2183 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002184 ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002187 if (ha->init_cb)
2188 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2189 ha->init_cb, ha->init_cb_dma);
2190 vfree(ha->optrom_buffer);
2191 kfree(ha->nvram);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192
Andrew Vasqueze8711082008-01-31 12:33:48 -08002193 ha->srb_mempool = NULL;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002194 ha->eft = NULL;
2195 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 ha->sns_cmd = NULL;
2197 ha->sns_cmd_dma = 0;
2198 ha->ct_sns = NULL;
2199 ha->ct_sns_dma = 0;
2200 ha->ms_iocb = NULL;
2201 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 ha->init_cb = NULL;
2203 ha->init_cb_dma = 0;
2204
2205 ha->s_dma_pool = NULL;
2206
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 ha->gid_list = NULL;
2208 ha->gid_list_dma = 0;
2209
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002211 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 ha->fw_dump_reading = 0;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002213
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002214 if (rsp) {
2215 if (rsp->ring)
2216 dma_free_coherent(&ha->pdev->dev,
2217 (rsp->length + 1) * sizeof(response_t),
2218 rsp->ring, rsp->dma);
2219
2220 kfree(rsp);
2221 rsp = NULL;
2222 }
2223
2224 if (req) {
2225 if (req->ring)
2226 dma_free_coherent(&ha->pdev->dev,
2227 (req->length + 1) * sizeof(request_t),
2228 req->ring, req->dma);
2229
2230 kfree(req);
2231 req = NULL;
2232 }
2233}
2234
2235struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2236 struct qla_hw_data *ha)
2237{
2238 struct Scsi_Host *host;
2239 struct scsi_qla_host *vha = NULL;
2240
2241 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2242 if (host == NULL) {
2243 printk(KERN_WARNING
2244 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2245 goto fail;
2246 }
2247
2248 /* Clear our data area */
2249 vha = shost_priv(host);
2250 memset(vha, 0, sizeof(scsi_qla_host_t));
2251
2252 vha->host = host;
2253 vha->host_no = host->host_no;
2254 vha->hw = ha;
2255
2256 INIT_LIST_HEAD(&vha->vp_fcports);
2257 INIT_LIST_HEAD(&vha->work_list);
2258 INIT_LIST_HEAD(&vha->list);
2259
2260 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2261 return vha;
2262
2263fail:
2264 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265}
2266
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002267static struct qla_work_evt *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002268qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002269 int locked)
2270{
2271 struct qla_work_evt *e;
2272
2273 e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
2274 GFP_KERNEL);
2275 if (!e)
2276 return NULL;
2277
2278 INIT_LIST_HEAD(&e->list);
2279 e->type = type;
2280 e->flags = QLA_EVT_FLAG_FREE;
2281 return e;
2282}
2283
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002284static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002285qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e, int locked)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002286{
Andrew Mortonbf6583b2008-07-24 08:31:48 -07002287 unsigned long uninitialized_var(flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002288 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002289
2290 if (!locked)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002291 spin_lock_irqsave(&ha->hardware_lock, flags);
2292 list_add_tail(&e->list, &vha->work_list);
2293 qla2xxx_wake_dpc(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002294 if (!locked)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002295 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002296 return QLA_SUCCESS;
2297}
2298
2299int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002300qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002301 u32 data)
2302{
2303 struct qla_work_evt *e;
2304
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002305 e = qla2x00_alloc_work(vha, QLA_EVT_AEN, 1);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002306 if (!e)
2307 return QLA_FUNCTION_FAILED;
2308
2309 e->u.aen.code = code;
2310 e->u.aen.data = data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002311 return qla2x00_post_work(vha, e, 1);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002312}
2313
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002314int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002315qla2x00_post_hwe_work(struct scsi_qla_host *vha, uint16_t code, uint16_t d1,
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002316 uint16_t d2, uint16_t d3)
2317{
2318 struct qla_work_evt *e;
2319
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002320 e = qla2x00_alloc_work(vha, QLA_EVT_HWE_LOG, 1);
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002321 if (!e)
2322 return QLA_FUNCTION_FAILED;
2323
2324 e->u.hwe.code = code;
2325 e->u.hwe.d1 = d1;
2326 e->u.hwe.d2 = d2;
2327 e->u.hwe.d3 = d3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002328 return qla2x00_post_work(vha, e, 1);
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002329}
2330
Andrew Vasquez0971de72008-04-03 13:13:18 -07002331static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002332qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002333{
2334 struct qla_work_evt *e;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002335 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002336
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002337 spin_lock_irq(&ha->hardware_lock);
2338 while (!list_empty(&vha->work_list)) {
2339 e = list_entry(vha->work_list.next, struct qla_work_evt, list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002340 list_del_init(&e->list);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002341 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002342
2343 switch (e->type) {
2344 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002345 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07002346 e->u.aen.code, e->u.aen.data);
2347 break;
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002348 case QLA_EVT_HWE_LOG:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002349 qla2xxx_hw_event_log(vha, e->u.hwe.code, e->u.hwe.d1,
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07002350 e->u.hwe.d2, e->u.hwe.d3);
2351 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002352 }
2353 if (e->flags & QLA_EVT_FLAG_FREE)
2354 kfree(e);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002355 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002356 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002357 spin_unlock_irq(&ha->hardware_lock);
2358}
2359/* Relogins all the fcports of a vport
2360 * Context: dpc thread
2361 */
2362void qla2x00_relogin(struct scsi_qla_host *vha)
2363{
2364 fc_port_t *fcport;
2365 uint8_t status;
2366 uint16_t next_loopid = 0;
2367 struct qla_hw_data *ha = vha->hw;
2368
2369 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2370 /*
2371 * If the port is not ONLINE then try to login
2372 * to it if we haven't run out of retries.
2373 */
2374 if (atomic_read(&fcport->state) !=
2375 FCS_ONLINE && fcport->login_retry) {
2376
2377 if (fcport->flags & FCF_FABRIC_DEVICE) {
2378 if (fcport->flags & FCF_TAPE_PRESENT)
2379 ha->isp_ops->fabric_logout(vha,
2380 fcport->loop_id,
2381 fcport->d_id.b.domain,
2382 fcport->d_id.b.area,
2383 fcport->d_id.b.al_pa);
2384
2385 status = qla2x00_fabric_login(vha, fcport,
2386 &next_loopid);
2387 } else
2388 status = qla2x00_local_device_login(vha,
2389 fcport);
2390
2391 fcport->login_retry--;
2392 if (status == QLA_SUCCESS) {
2393 fcport->old_loop_id = fcport->loop_id;
2394
2395 DEBUG(printk("scsi(%ld): port login OK: logged "
2396 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2397
2398 qla2x00_update_fcport(vha, fcport);
2399
2400 } else if (status == 1) {
2401 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2402 /* retry the login again */
2403 DEBUG(printk("scsi(%ld): Retrying"
2404 " %d login again loop_id 0x%x\n",
2405 vha->host_no, fcport->login_retry,
2406 fcport->loop_id));
2407 } else {
2408 fcport->login_retry = 0;
2409 }
2410
2411 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2412 fcport->loop_id = FC_NO_LOOP_ID;
2413 }
2414 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2415 break;
2416 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07002417}
2418
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419/**************************************************************************
2420* qla2x00_do_dpc
2421* This kernel thread is a task that is schedule by the interrupt handler
2422* to perform the background processing for interrupts.
2423*
2424* Notes:
2425* This task always run in the context of a kernel thread. It
2426* is kick-off by the driver's detect code and starts up
2427* up one per adapter. It immediately goes to sleep and waits for
2428* some fibre event. When either the interrupt handler or
2429* the timer routine detects a event it will one of the task
2430* bits then wake us up.
2431**************************************************************************/
2432static int
2433qla2x00_do_dpc(void *data)
2434{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002435 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002436 scsi_qla_host_t *base_vha;
2437 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08002438
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002439 ha = (struct qla_hw_data *)data;
2440 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 set_user_nice(current, -20);
2443
Christoph Hellwig39a11242006-02-14 18:46:22 +01002444 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2446
Christoph Hellwig39a11242006-02-14 18:46:22 +01002447 set_current_state(TASK_INTERRUPTIBLE);
2448 schedule();
2449 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
2451 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2452
2453 /* Initialization not yet finished. Don't do anything yet. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002454 if (!base_vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 continue;
2456
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002457 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458
2459 ha->dpc_active = 1;
2460
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 ha->dpc_active = 0;
2463 continue;
2464 }
2465
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002466 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002467
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002468 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2469 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470
2471 DEBUG(printk("scsi(%ld): dpc: sched "
2472 "qla2x00_abort_isp ha = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002475 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002477 if (qla2x00_abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 /* failed. retry later */
2479 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002480 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002482 clear_bit(ABORT_ISP_ACTIVE,
2483 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08002484 }
2485
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002487 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 }
2489
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002490 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2491 qla2x00_update_fcports(base_vha);
2492 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07002493 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002494
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002495 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2496 &base_vha->dpc_flags) &&
2497 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498
2499 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002500 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002502 qla2x00_rst_aen(base_vha);
2503 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 }
2505
2506 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002507 if ((test_and_clear_bit(RELOGIN_NEEDED,
2508 &base_vha->dpc_flags)) &&
2509 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2510 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
2512 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002513 base_vha->host_no));
2514 qla2x00_relogin(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002517 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 }
2519
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002520 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2521 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522
2523 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002524 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525
2526 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002527 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002529 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002531 clear_bit(LOOP_RESYNC_ACTIVE,
2532 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 }
2534
2535 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002536 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 }
2538
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002539 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2540 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2541 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2542 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07002543 }
2544
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002546 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002548 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2549 &base_vha->dpc_flags))
2550 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002551
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002552 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002553
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 ha->dpc_active = 0;
2555 } /* End of while(1) */
2556
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002557 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558
2559 /*
2560 * Make sure that nobody tries to wake us up again.
2561 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 ha->dpc_active = 0;
2563
Christoph Hellwig39a11242006-02-14 18:46:22 +01002564 return 0;
2565}
2566
2567void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002568qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01002569{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002570 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002571 struct task_struct *t = ha->dpc_thread;
2572
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002573 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002574 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575}
2576
2577/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578* qla2x00_rst_aen
2579* Processes asynchronous reset.
2580*
2581* Input:
2582* ha = adapter block pointer.
2583*/
2584static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002585qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002587 if (vha->flags.online && !vha->flags.reset_active &&
2588 !atomic_read(&vha->loop_down_timer) &&
2589 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002591 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592
2593 /*
2594 * Issue marker command only when we are going to start
2595 * the I/O.
2596 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002597 vha->marker_needed = 1;
2598 } while (!atomic_read(&vha->loop_down_timer) &&
2599 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 }
2601}
2602
f4f051e2005-04-17 15:02:26 -05002603static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002604qla2x00_sp_free_dma(srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002605{
2606 struct scsi_cmnd *cmd = sp->cmd;
2607
2608 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002609 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05002610 sp->flags &= ~SRB_DMA_VALID;
2611 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002612 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002613}
2614
2615void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002616qla2x00_sp_compl(scsi_qla_host_t *vha, srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002617{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002618 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -05002619 struct scsi_cmnd *cmd = sp->cmd;
2620
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002621 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -05002622
f4f051e2005-04-17 15:02:26 -05002623 mempool_free(sp, ha->srb_mempool);
2624
2625 cmd->scsi_done(cmd);
2626}
bdf79622005-04-17 15:06:53 -05002627
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628/**************************************************************************
2629* qla2x00_timer
2630*
2631* Description:
2632* One second timer
2633*
2634* Context: Interrupt
2635***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002636void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002637qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 unsigned long cpu_flags = 0;
2640 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 int start_dpc = 0;
2642 int index;
2643 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002644 int t;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002645 struct qla_hw_data *ha = vha->hw;
2646 struct req_que *req = ha->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 /*
2648 * Ports - Port down timer.
2649 *
2650 * Whenever, a port is in the LOST state we start decrementing its port
2651 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002652 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 */
2654 t = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002655 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 if (fcport->port_type != FCT_TARGET)
2657 continue;
2658
2659 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2660
2661 if (atomic_read(&fcport->port_down_timer) == 0)
2662 continue;
2663
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002664 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002666
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002668 "%d remaining\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002669 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 t, atomic_read(&fcport->port_down_timer)));
2671 }
2672 t++;
2673 } /* End of for fcport */
2674
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675
2676 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002677 if (atomic_read(&vha->loop_down_timer) > 0 &&
2678 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
2679 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002681 if (atomic_read(&vha->loop_down_timer) ==
2682 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683
2684 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2685 "queues before time expire\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002686 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002688 if (!IS_QLA2100(ha) && vha->link_down_timeout)
2689 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690
2691 /* Schedule an ISP abort to return any tape commands. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002692 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002693 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002694 spin_lock_irqsave(&ha->hardware_lock,
2695 cpu_flags);
2696 for (index = 1;
2697 index < MAX_OUTSTANDING_COMMANDS;
2698 index++) {
2699 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05002700
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002701 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002702 if (!sp)
2703 continue;
2704 sfcp = sp->fcport;
2705 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2706 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002708 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002709 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002710 break;
2711 }
2712 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002713 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002715 set_bit(ABORT_QUEUES_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 start_dpc++;
2717 }
2718
2719 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002720 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2722 "restarting queues.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002723 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002725 set_bit(RESTART_QUEUES_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 start_dpc++;
2727
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002728 if (!(vha->device_flags & DFLG_NO_CABLE) &&
2729 !vha->vp_idx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 DEBUG(printk("scsi(%ld): Loop down - "
2731 "aborting ISP.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002732 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 qla_printk(KERN_WARNING, ha,
2734 "Loop down - aborting ISP.\n");
2735
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002736 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 }
2738 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002739 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002740 vha->host_no,
2741 atomic_read(&vha->loop_down_timer)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 }
2743
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002744 /* Check if beacon LED needs to be blinked */
2745 if (ha->beacon_blink_led == 1) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002746 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002747 start_dpc++;
2748 }
2749
Andrew Vasquez550bf572008-04-24 15:21:23 -07002750 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002751 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07002752 start_dpc++;
2753
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002755 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
2756 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
2757 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002759 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
2760 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
2761 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
2762 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
2763 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002765 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766}
2767
Andrew Vasquez54333832005-11-09 15:49:04 -08002768/* Firmware interface routines. */
2769
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002770#define FW_BLOBS 6
Andrew Vasquez54333832005-11-09 15:49:04 -08002771#define FW_ISP21XX 0
2772#define FW_ISP22XX 1
2773#define FW_ISP2300 2
2774#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002775#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002776#define FW_ISP25XX 5
Andrew Vasquez54333832005-11-09 15:49:04 -08002777
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002778#define FW_FILE_ISP21XX "ql2100_fw.bin"
2779#define FW_FILE_ISP22XX "ql2200_fw.bin"
2780#define FW_FILE_ISP2300 "ql2300_fw.bin"
2781#define FW_FILE_ISP2322 "ql2322_fw.bin"
2782#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002783#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002784
Daniel Walkere1e82b62008-05-12 22:21:10 -07002785static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002786
2787static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002788 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
2789 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
2790 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
2791 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
2792 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002793 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08002794};
2795
2796struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002797qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08002798{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002799 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08002800 struct fw_blob *blob;
2801
2802 blob = NULL;
2803 if (IS_QLA2100(ha)) {
2804 blob = &qla_fw_blobs[FW_ISP21XX];
2805 } else if (IS_QLA2200(ha)) {
2806 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002807 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002808 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002809 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002810 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002811 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002812 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002813 } else if (IS_QLA25XX(ha)) {
2814 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08002815 }
2816
Daniel Walkere1e82b62008-05-12 22:21:10 -07002817 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002818 if (blob->fw)
2819 goto out;
2820
2821 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
2822 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002823 "(%s).\n", vha->host_no, blob->name));
Andrew Vasquez54333832005-11-09 15:49:04 -08002824 blob->fw = NULL;
2825 blob = NULL;
2826 goto out;
2827 }
2828
2829out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07002830 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002831 return blob;
2832}
2833
2834static void
2835qla2x00_release_firmware(void)
2836{
2837 int idx;
2838
Daniel Walkere1e82b62008-05-12 22:21:10 -07002839 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002840 for (idx = 0; idx < FW_BLOBS; idx++)
2841 if (qla_fw_blobs[idx].fw)
2842 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07002843 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002844}
2845
Seokmann Ju14e660e2007-09-20 14:07:36 -07002846static pci_ers_result_t
2847qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
2848{
2849 switch (state) {
2850 case pci_channel_io_normal:
2851 return PCI_ERS_RESULT_CAN_RECOVER;
2852 case pci_channel_io_frozen:
2853 pci_disable_device(pdev);
2854 return PCI_ERS_RESULT_NEED_RESET;
2855 case pci_channel_io_perm_failure:
2856 qla2x00_remove_one(pdev);
2857 return PCI_ERS_RESULT_DISCONNECT;
2858 }
2859 return PCI_ERS_RESULT_NEED_RESET;
2860}
2861
2862static pci_ers_result_t
2863qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
2864{
2865 int risc_paused = 0;
2866 uint32_t stat;
2867 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002868 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
2869 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07002870 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2871 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
2872
2873 spin_lock_irqsave(&ha->hardware_lock, flags);
2874 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
2875 stat = RD_REG_DWORD(&reg->hccr);
2876 if (stat & HCCR_RISC_PAUSE)
2877 risc_paused = 1;
2878 } else if (IS_QLA23XX(ha)) {
2879 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
2880 if (stat & HSR_RISC_PAUSED)
2881 risc_paused = 1;
2882 } else if (IS_FWI2_CAPABLE(ha)) {
2883 stat = RD_REG_DWORD(&reg24->host_status);
2884 if (stat & HSRX_RISC_PAUSED)
2885 risc_paused = 1;
2886 }
2887 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2888
2889 if (risc_paused) {
2890 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
2891 "Dumping firmware!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002892 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002893
2894 return PCI_ERS_RESULT_NEED_RESET;
2895 } else
2896 return PCI_ERS_RESULT_RECOVERED;
2897}
2898
2899static pci_ers_result_t
2900qla2xxx_pci_slot_reset(struct pci_dev *pdev)
2901{
2902 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002903 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
2904 struct qla_hw_data *ha = base_vha->hw;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002905 int rc;
Seokmann Ju14e660e2007-09-20 14:07:36 -07002906
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002907 if (ha->mem_only)
2908 rc = pci_enable_device_mem(pdev);
2909 else
2910 rc = pci_enable_device(pdev);
2911
2912 if (rc) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07002913 qla_printk(KERN_WARNING, ha,
2914 "Can't re-enable PCI device after reset.\n");
2915
2916 return ret;
2917 }
2918 pci_set_master(pdev);
2919
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002920 if (ha->isp_ops->pci_config(base_vha))
Seokmann Ju14e660e2007-09-20 14:07:36 -07002921 return ret;
2922
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002923 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
2924 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07002925 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002926 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002927
2928 return ret;
2929}
2930
2931static void
2932qla2xxx_pci_resume(struct pci_dev *pdev)
2933{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002934 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
2935 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07002936 int ret;
2937
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002938 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002939 if (ret != QLA_SUCCESS) {
2940 qla_printk(KERN_ERR, ha,
2941 "the device failed to resume I/O "
2942 "from slot/link_reset");
2943 }
2944 pci_cleanup_aer_uncorrect_error_status(pdev);
2945}
2946
2947static struct pci_error_handlers qla2xxx_err_handler = {
2948 .error_detected = qla2xxx_pci_error_detected,
2949 .mmio_enabled = qla2xxx_pci_mmio_enabled,
2950 .slot_reset = qla2xxx_pci_slot_reset,
2951 .resume = qla2xxx_pci_resume,
2952};
2953
Andrew Vasquez54333832005-11-09 15:49:04 -08002954static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07002955 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
2956 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
2957 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
2958 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
2959 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
2960 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
2961 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
2962 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
2963 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002964 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07002965 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
2966 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002967 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez54333832005-11-09 15:49:04 -08002968 { 0 },
2969};
2970MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2971
Andrew Vasquezfca29702005-07-06 10:31:47 -07002972static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07002973 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06002974 .driver = {
2975 .owner = THIS_MODULE,
2976 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07002977 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002978 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08002979 .remove = qla2x00_remove_one,
Seokmann Ju14e660e2007-09-20 14:07:36 -07002980 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07002981};
2982
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983/**
2984 * qla2x00_module_init - Module initialization.
2985 **/
2986static int __init
2987qla2x00_module_init(void)
2988{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002989 int ret = 0;
2990
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002992 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09002993 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 if (srb_cachep == NULL) {
2995 printk(KERN_ERR
2996 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2997 return -ENOMEM;
2998 }
2999
3000 /* Derive version string. */
3001 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07003002 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07003003 strcat(qla2x00_version_str, "-debug");
3004
Andrew Vasquez1c97a122005-04-21 16:13:36 -04003005 qla2xxx_transport_template =
3006 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003007 if (!qla2xxx_transport_template) {
3008 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003010 }
3011 qla2xxx_transport_vport_template =
3012 fc_attach_transport(&qla2xxx_transport_vport_functions);
3013 if (!qla2xxx_transport_vport_template) {
3014 kmem_cache_destroy(srb_cachep);
3015 fc_release_transport(qla2xxx_transport_template);
3016 return -ENODEV;
3017 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07003019 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3020 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003021 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003022 if (ret) {
3023 kmem_cache_destroy(srb_cachep);
3024 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003025 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003026 }
3027 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028}
3029
3030/**
3031 * qla2x00_module_exit - Module cleanup.
3032 **/
3033static void __exit
3034qla2x00_module_exit(void)
3035{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003036 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08003037 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003038 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003040 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041}
3042
3043module_init(qla2x00_module_init);
3044module_exit(qla2x00_module_exit);
3045
3046MODULE_AUTHOR("QLogic Corporation");
3047MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3048MODULE_LICENSE("GPL");
3049MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003050MODULE_FIRMWARE(FW_FILE_ISP21XX);
3051MODULE_FIRMWARE(FW_FILE_ISP22XX);
3052MODULE_FIRMWARE(FW_FILE_ISP2300);
3053MODULE_FIRMWARE(FW_FILE_ISP2322);
3054MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08003055MODULE_FIRMWARE(FW_FILE_ISP25XX);