blob: 2a03400b6f7241a731707b8e5bc9ce0e49d34446 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include <scsi/scsi_tcq.h>
15#include <scsi/scsicam.h>
16#include <scsi/scsi_transport.h>
17#include <scsi/scsi_transport_fc.h>
18
19/*
20 * Driver version
21 */
22char qla2x00_version_str[40];
23
24/*
25 * SRB allocation cache
26 */
Christoph Lametere18b8902006-12-06 20:33:20 -080027static struct kmem_cache *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29/*
30 * Ioctl related information.
31 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070032int num_hosts;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033int ql2xlogintimeout = 20;
34module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
35MODULE_PARM_DESC(ql2xlogintimeout,
36 "Login timeout value in seconds.");
37
Andrew Vasqueza7b61842007-05-07 07:42:59 -070038int qlport_down_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
40MODULE_PARM_DESC(qlport_down_retry,
Jesper Juhl900d9f92006-06-30 02:33:07 -070041 "Maximum number of command retries to a port that returns "
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 "a PORT-DOWN status.");
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044int ql2xplogiabsentdevice;
45module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
46MODULE_PARM_DESC(ql2xplogiabsentdevice,
47 "Option to enable PLOGI to devices that are not present after "
Jesper Juhl900d9f92006-06-30 02:33:07 -070048 "a Fabric scan. This is needed for several broken switches. "
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051int ql2xloginretrycount = 0;
52module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
53MODULE_PARM_DESC(ql2xloginretrycount,
54 "Specify an alternate value for the NVRAM login retry count.");
55
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070056int ql2xallocfwdump = 1;
57module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
58MODULE_PARM_DESC(ql2xallocfwdump,
59 "Option to enable allocation of memory for a firmware dump "
60 "during HBA initialization. Memory allocation requirements "
61 "vary by ISP type. Default is 1 - allocate memory.");
62
Andrew Vasquez11010fe2006-10-06 09:54:59 -070063int ql2xextended_error_logging;
Andrew Vasquez27d94032007-03-12 10:41:30 -070064module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070065MODULE_PARM_DESC(ql2xextended_error_logging,
Andrew Vasquez01819442006-06-23 16:11:10 -070066 "Option to enable extended error logging, "
67 "Default is 0 - no logging. 1 - log errors.");
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static void qla2x00_free_device(scsi_qla_host_t *);
70
71static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
72
Andrew Vasquezcca53352005-08-26 19:08:30 -070073int ql2xfdmienable;
74module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
75MODULE_PARM_DESC(ql2xfdmienable,
76 "Enables FDMI registratons "
77 "Default is 0 - no FDMI. 1 - perfom FDMI.");
78
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070079#define MAX_Q_DEPTH 32
80static int ql2xmaxqdepth = MAX_Q_DEPTH;
81module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
82MODULE_PARM_DESC(ql2xmaxqdepth,
83 "Maximum queue depth to report for target devices.");
84
85int ql2xqfullrampup = 120;
86module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR);
87MODULE_PARM_DESC(ql2xqfullrampup,
88 "Number of seconds to wait to begin to ramp-up the queue "
89 "depth for a device after a queue-full condition has been "
90 "detected. Default is 120 seconds.");
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -070093 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 */
95static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -050096static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -080097static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
98static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -050099static void qla2xxx_slave_destroy(struct scsi_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
101 void (*fn)(struct scsi_cmnd *));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700102static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
103 void (*fn)(struct scsi_cmnd *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104static int qla2xxx_eh_abort(struct scsi_cmnd *);
105static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
106static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
107static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
108static int qla2x00_loop_reset(scsi_qla_host_t *ha);
109static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
110
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700111static int qla2x00_change_queue_depth(struct scsi_device *, int);
112static int qla2x00_change_queue_type(struct scsi_device *, int);
113
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700114struct scsi_host_template qla2x00_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700116 .name = QLA2XXX_DRIVER_NAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 .queuecommand = qla2x00_queuecommand,
118
119 .eh_abort_handler = qla2xxx_eh_abort,
120 .eh_device_reset_handler = qla2xxx_eh_device_reset,
121 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
122 .eh_host_reset_handler = qla2xxx_eh_host_reset,
123
124 .slave_configure = qla2xxx_slave_configure,
125
f4f051e2005-04-17 15:02:26 -0500126 .slave_alloc = qla2xxx_slave_alloc,
127 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800128 .scan_finished = qla2xxx_scan_finished,
129 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700130 .change_queue_depth = qla2x00_change_queue_depth,
131 .change_queue_type = qla2x00_change_queue_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 .this_id = -1,
133 .cmd_per_lun = 3,
134 .use_clustering = ENABLE_CLUSTERING,
135 .sg_tablesize = SG_ALL,
136
137 /*
138 * The RISC allows for each command to transfer (2^32-1) bytes of data,
139 * which equates to 0x800000 sectors.
140 */
141 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700142 .shost_attrs = qla2x00_host_attrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143};
144
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700145struct scsi_host_template qla24xx_driver_template = {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700146 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700147 .name = QLA2XXX_DRIVER_NAME,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700148 .queuecommand = qla24xx_queuecommand,
149
150 .eh_abort_handler = qla2xxx_eh_abort,
151 .eh_device_reset_handler = qla2xxx_eh_device_reset,
152 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
153 .eh_host_reset_handler = qla2xxx_eh_host_reset,
154
155 .slave_configure = qla2xxx_slave_configure,
156
157 .slave_alloc = qla2xxx_slave_alloc,
158 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700159 .scan_finished = qla2xxx_scan_finished,
160 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700161 .change_queue_depth = qla2x00_change_queue_depth,
162 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700163 .this_id = -1,
164 .cmd_per_lun = 3,
165 .use_clustering = ENABLE_CLUSTERING,
166 .sg_tablesize = SG_ALL,
167
168 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700169 .shost_attrs = qla2x00_host_attrs,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700170};
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700173struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175/* TODO Convert to inlines
176 *
177 * Timer routines
178 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700180void qla2x00_timer(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700182__inline__ void qla2x00_start_timer(scsi_qla_host_t *,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 void *, unsigned long);
184static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700185__inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700187__inline__ void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
189{
190 init_timer(&ha->timer);
191 ha->timer.expires = jiffies + interval * HZ;
192 ha->timer.data = (unsigned long)ha;
193 ha->timer.function = (void (*)(unsigned long))func;
194 add_timer(&ha->timer);
195 ha->timer_active = 1;
196}
197
198static inline void
199qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
200{
201 mod_timer(&ha->timer, jiffies + interval * HZ);
202}
203
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700204__inline__ void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205qla2x00_stop_timer(scsi_qla_host_t *ha)
206{
207 del_timer_sync(&ha->timer);
208 ha->timer_active = 0;
209}
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211static int qla2x00_do_dpc(void *data);
212
213static void qla2x00_rst_aen(scsi_qla_host_t *);
214
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700215uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
216void qla2x00_mem_free(scsi_qla_host_t *ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
218static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
f4f051e2005-04-17 15:02:26 -0500219static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
220void qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222/* -------------------------------------------------------------------------- */
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224static char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700225qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
227 static char *pci_bus_modes[] = {
228 "33", "66", "100", "133",
229 };
230 uint16_t pci_bus;
231
232 strcpy(str, "PCI");
233 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
234 if (pci_bus) {
235 strcat(str, "-X (");
236 strcat(str, pci_bus_modes[pci_bus]);
237 } else {
238 pci_bus = (ha->pci_attr & BIT_8) >> 8;
239 strcat(str, " (");
240 strcat(str, pci_bus_modes[pci_bus]);
241 }
242 strcat(str, " MHz)");
243
244 return (str);
245}
246
Andrew Vasquezfca29702005-07-06 10:31:47 -0700247static char *
248qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
249{
250 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
251 uint32_t pci_bus;
252 int pcie_reg;
253
254 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
255 if (pcie_reg) {
256 char lwstr[6];
257 uint16_t pcie_lstat, lspeed, lwidth;
258
259 pcie_reg += 0x12;
260 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
261 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
262 lwidth = (pcie_lstat &
263 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
264
265 strcpy(str, "PCIe (");
266 if (lspeed == 1)
267 strcat(str, "2.5Gb/s ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700268 else if (lspeed == 2)
269 strcat(str, "5.0Gb/s ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700270 else
271 strcat(str, "<unknown> ");
272 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
273 strcat(str, lwstr);
274
275 return str;
276 }
277
278 strcpy(str, "PCI");
279 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
280 if (pci_bus == 0 || pci_bus == 8) {
281 strcat(str, " (");
282 strcat(str, pci_bus_modes[pci_bus >> 3]);
283 } else {
284 strcat(str, "-X ");
285 if (pci_bus & BIT_2)
286 strcat(str, "Mode 2");
287 else
288 strcat(str, "Mode 1");
289 strcat(str, " (");
290 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
291 }
292 strcat(str, " MHz)");
293
294 return str;
295}
296
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800297static char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700298qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
300 char un_str[10];
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700301
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
303 ha->fw_minor_version,
304 ha->fw_subminor_version);
305
306 if (ha->fw_attributes & BIT_9) {
307 strcat(str, "FLX");
308 return (str);
309 }
310
311 switch (ha->fw_attributes & 0xFF) {
312 case 0x7:
313 strcat(str, "EF");
314 break;
315 case 0x17:
316 strcat(str, "TP");
317 break;
318 case 0x37:
319 strcat(str, "IP");
320 break;
321 case 0x77:
322 strcat(str, "VI");
323 break;
324 default:
325 sprintf(un_str, "(%x)", ha->fw_attributes);
326 strcat(str, un_str);
327 break;
328 }
329 if (ha->fw_attributes & 0x100)
330 strcat(str, "X");
331
332 return (str);
333}
334
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800335static char *
Andrew Vasquezfca29702005-07-06 10:31:47 -0700336qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
337{
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700338 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
339 ha->fw_minor_version,
340 ha->fw_subminor_version);
341
Andrew Vasquezfca29702005-07-06 10:31:47 -0700342 if (ha->fw_attributes & BIT_0)
343 strcat(str, "[Class 2] ");
344 if (ha->fw_attributes & BIT_1)
345 strcat(str, "[IP] ");
346 if (ha->fw_attributes & BIT_2)
347 strcat(str, "[Multi-ID] ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700348 if (ha->fw_attributes & BIT_3)
349 strcat(str, "[SB-2] ");
350 if (ha->fw_attributes & BIT_4)
351 strcat(str, "[T10 CRC] ");
352 if (ha->fw_attributes & BIT_5)
353 strcat(str, "[VI] ");
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 *
360qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
361 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
362{
363 srb_t *sp;
364
365 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
366 if (!sp)
367 return sp;
368
Andrew Vasquezfca29702005-07-06 10:31:47 -0700369 sp->ha = ha;
370 sp->fcport = fcport;
371 sp->cmd = cmd;
372 sp->flags = 0;
373 CMD_SP(cmd) = (void *)sp;
374 cmd->scsi_done = done;
375
376 return sp;
377}
378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379static int
f4f051e2005-04-17 15:02:26 -0500380qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
f4f051e2005-04-17 15:02:26 -0500382 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500383 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400384 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
f4f051e2005-04-17 15:02:26 -0500385 srb_t *sp;
386 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400388 rval = fc_remote_port_chkready(rport);
389 if (rval) {
390 cmd->result = rval;
f4f051e2005-04-17 15:02:26 -0500391 goto qc_fail_command;
392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800394 /* Close window on fcport/rport state-transitioning. */
395 if (!*(fc_port_t **)rport->dd_data) {
396 cmd->result = DID_IMM_RETRY << 16;
397 goto qc_fail_command;
398 }
399
f4f051e2005-04-17 15:02:26 -0500400 if (atomic_read(&fcport->state) != FCS_ONLINE) {
401 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
402 atomic_read(&ha->loop_state) == LOOP_DEAD) {
403 cmd->result = DID_NO_CONNECT << 16;
404 goto qc_fail_command;
405 }
406 goto qc_host_busy;
407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 spin_unlock_irq(ha->host->host_lock);
410
Andrew Vasquezfca29702005-07-06 10:31:47 -0700411 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
412 if (!sp)
f4f051e2005-04-17 15:02:26 -0500413 goto qc_host_busy_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
f4f051e2005-04-17 15:02:26 -0500415 rval = qla2x00_start_scsi(sp);
416 if (rval != QLA_SUCCESS)
417 goto qc_host_busy_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 spin_lock_irq(ha->host->host_lock);
420
f4f051e2005-04-17 15:02:26 -0500421 return 0;
422
423qc_host_busy_free_sp:
424 qla2x00_sp_free_dma(ha, sp);
f4f051e2005-04-17 15:02:26 -0500425 mempool_free(sp, ha->srb_mempool);
426
427qc_host_busy_lock:
428 spin_lock_irq(ha->host->host_lock);
429
430qc_host_busy:
431 return SCSI_MLQUEUE_HOST_BUSY;
432
433qc_fail_command:
434 done(cmd);
435
436 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437}
438
Andrew Vasquezfca29702005-07-06 10:31:47 -0700439
440static int
441qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
442{
443 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
444 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400445 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700446 srb_t *sp;
447 int rval;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700448 scsi_qla_host_t *pha = to_qla_parent(ha);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700449
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400450 rval = fc_remote_port_chkready(rport);
451 if (rval) {
452 cmd->result = rval;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700453 goto qc24_fail_command;
454 }
455
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800456 /* Close window on fcport/rport state-transitioning. */
457 if (!*(fc_port_t **)rport->dd_data) {
458 cmd->result = DID_IMM_RETRY << 16;
459 goto qc24_fail_command;
460 }
461
Andrew Vasquezfca29702005-07-06 10:31:47 -0700462 if (atomic_read(&fcport->state) != FCS_ONLINE) {
463 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700464 atomic_read(&pha->loop_state) == LOOP_DEAD) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700465 cmd->result = DID_NO_CONNECT << 16;
466 goto qc24_fail_command;
467 }
468 goto qc24_host_busy;
469 }
470
471 spin_unlock_irq(ha->host->host_lock);
472
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700473 sp = qla2x00_get_new_sp(pha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700474 if (!sp)
475 goto qc24_host_busy_lock;
476
477 rval = qla24xx_start_scsi(sp);
478 if (rval != QLA_SUCCESS)
479 goto qc24_host_busy_free_sp;
480
481 spin_lock_irq(ha->host->host_lock);
482
483 return 0;
484
485qc24_host_busy_free_sp:
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700486 qla2x00_sp_free_dma(pha, sp);
487 mempool_free(sp, pha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700488
489qc24_host_busy_lock:
490 spin_lock_irq(ha->host->host_lock);
491
492qc24_host_busy:
493 return SCSI_MLQUEUE_HOST_BUSY;
494
495qc24_fail_command:
496 done(cmd);
497
498 return 0;
499}
500
501
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502/*
503 * qla2x00_eh_wait_on_command
504 * Waits for the command to be returned by the Firmware for some
505 * max time.
506 *
507 * Input:
508 * ha = actual ha whose done queue will contain the command
509 * returned by firmware.
510 * cmd = Scsi Command to wait on.
511 * flag = Abort/Reset(Bus or Device Reset)
512 *
513 * Return:
514 * Not Found : 0
515 * Found : 1
516 */
517static int
518qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
519{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700520#define ABORT_POLLING_PERIOD 1000
521#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500522 unsigned long wait_iter = ABORT_WAIT_ITER;
523 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
f4f051e2005-04-17 15:02:26 -0500525 while (CMD_SP(cmd)) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700526 msleep(ABORT_POLLING_PERIOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
f4f051e2005-04-17 15:02:26 -0500528 if (--wait_iter)
529 break;
530 }
531 if (CMD_SP(cmd))
532 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
f4f051e2005-04-17 15:02:26 -0500534 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535}
536
537/*
538 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700539 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 * <= MAX_RETRIES_OF_ISP_ABORT or
541 * finally HBA is disabled ie marked offline
542 *
543 * Input:
544 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700545 *
546 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 * Does context switching-Release SPIN_LOCK
548 * (if any) before calling this routine.
549 *
550 * Return:
551 * Success (Adapter is online) : 0
552 * Failed (Adapter is offline/disabled) : 1
553 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800554int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
556{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700557 int return_status;
558 unsigned long wait_online;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700559 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700561 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700562 while (((test_bit(ISP_ABORT_NEEDED, &pha->dpc_flags)) ||
563 test_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags) ||
564 test_bit(ISP_ABORT_RETRY, &pha->dpc_flags) ||
565 pha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
567 msleep(1000);
568 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700569 if (pha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700570 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 else
572 return_status = QLA_FUNCTION_FAILED;
573
574 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
575
576 return (return_status);
577}
578
579/*
580 * qla2x00_wait_for_loop_ready
581 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700582 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 * Input:
584 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700585 *
586 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 * Does context switching-Release SPIN_LOCK
588 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700589 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 *
591 * Return:
592 * Success (LOOP_READY) : 0
593 * Failed (LOOP_NOT_READY) : 1
594 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700595static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
597{
598 int return_status = QLA_SUCCESS;
599 unsigned long loop_timeout ;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700600 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
602 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700603 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700605 while ((!atomic_read(&pha->loop_down_timer) &&
606 atomic_read(&pha->loop_state) == LOOP_DOWN) ||
607 atomic_read(&pha->loop_state) != LOOP_READY) {
608 if (atomic_read(&pha->loop_state) == LOOP_DEAD) {
Ravi Anand57680082006-05-17 15:08:44 -0700609 return_status = QLA_FUNCTION_FAILED;
610 break;
611 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 msleep(1000);
613 if (time_after_eq(jiffies, loop_timeout)) {
614 return_status = QLA_FUNCTION_FAILED;
615 break;
616 }
617 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700618 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619}
620
Andrew Vasquez07db5182006-10-02 12:00:49 -0700621static void
622qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
623{
624 struct Scsi_Host *shost = cmnd->device->host;
625 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
626 unsigned long flags;
627
628 spin_lock_irqsave(shost->host_lock, flags);
629 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
630 spin_unlock_irqrestore(shost->host_lock, flags);
631 msleep(1000);
632 spin_lock_irqsave(shost->host_lock, flags);
633 }
634 spin_unlock_irqrestore(shost->host_lock, flags);
635 return;
636}
637
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638/**************************************************************************
639* qla2xxx_eh_abort
640*
641* Description:
642* The abort function will abort the specified command.
643*
644* Input:
645* cmd = Linux SCSI command packet to be aborted.
646*
647* Returns:
648* Either SUCCESS or FAILED.
649*
650* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700651* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800653static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654qla2xxx_eh_abort(struct scsi_cmnd *cmd)
655{
f4f051e2005-04-17 15:02:26 -0500656 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
657 srb_t *sp;
658 int ret, i;
659 unsigned int id, lun;
660 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700661 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700662 int wait = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700663 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Andrew Vasquez07db5182006-10-02 12:00:49 -0700665 qla2x00_block_error_handler(cmd);
666
f4f051e2005-04-17 15:02:26 -0500667 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700668 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Michael Reed2ea00202006-04-27 16:25:30 -0700670 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
f4f051e2005-04-17 15:02:26 -0500672 id = cmd->device->id;
673 lun = cmd->device->lun;
674 serial = cmd->serial_number;
675
676 /* Check active list for command command. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700677 spin_lock_irqsave(&pha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500678 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700679 sp = pha->outstanding_cmds[i];
f4f051e2005-04-17 15:02:26 -0500680
681 if (sp == NULL)
682 continue;
683
684 if (sp->cmd != cmd)
685 continue;
686
Andrew Vasquez75bc4192006-05-17 15:09:22 -0700687 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld.\n",
688 __func__, ha->host_no, sp, serial));
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700689 DEBUG3(qla2x00_print_scsi_cmd(cmd));
f4f051e2005-04-17 15:02:26 -0500690
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700691 spin_unlock_irqrestore(&pha->hardware_lock, flags);
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700692 if (ha->isp_ops->abort_command(ha, sp)) {
f4f051e2005-04-17 15:02:26 -0500693 DEBUG2(printk("%s(%ld): abort_command "
694 "mbx failed.\n", __func__, ha->host_no));
695 } else {
696 DEBUG3(printk("%s(%ld): abort_command "
697 "mbx success.\n", __func__, ha->host_no));
Michael Reed2ea00202006-04-27 16:25:30 -0700698 wait = 1;
f4f051e2005-04-17 15:02:26 -0500699 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700700 spin_lock_irqsave(&pha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500701
702 break;
703 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700704 spin_unlock_irqrestore(&pha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500705
706 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700707 if (wait) {
f4f051e2005-04-17 15:02:26 -0500708 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700709 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500710 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
711 "%x.\n", ha->host_no, id, lun, serial, ret);
Michael Reed2ea00202006-04-27 16:25:30 -0700712 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500713 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700716 qla_printk(KERN_INFO, ha,
Michael Reed2ea00202006-04-27 16:25:30 -0700717 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
718 ha->host_no, id, lun, wait, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
f4f051e2005-04-17 15:02:26 -0500720 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721}
722
723/**************************************************************************
724* qla2x00_eh_wait_for_pending_target_commands
725*
726* Description:
727* Waits for all the commands to come back from the specified target.
728*
729* Input:
730* ha - pointer to scsi_qla_host structure.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700731* t - target
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732* Returns:
733* Either SUCCESS or FAILED.
734*
735* Note:
736**************************************************************************/
737static int
738qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
739{
740 int cnt;
741 int status;
742 srb_t *sp;
743 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700744 unsigned long flags;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700745 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 status = 0;
748
749 /*
750 * Waiting for all commands for the designated target in the active
751 * array
752 */
753 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700754 spin_lock_irqsave(&pha->hardware_lock, flags);
755 sp = pha->outstanding_cmds[cnt];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 if (sp) {
757 cmd = sp->cmd;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700758 spin_unlock_irqrestore(&pha->hardware_lock, flags);
759 if (cmd->device->id == t &&
760 ha->vp_idx == sp->ha->vp_idx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
762 status = 1;
763 break;
764 }
765 }
f4f051e2005-04-17 15:02:26 -0500766 } else {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700767 spin_unlock_irqrestore(&pha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 }
769 }
770 return (status);
771}
772
773
774/**************************************************************************
775* qla2xxx_eh_device_reset
776*
777* Description:
778* The device reset function will reset the target and abort any
779* executing commands.
780*
781* NOTE: The use of SP is undefined within this context. Do *NOT*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700782* attempt to use this value, even if you determine it is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783* non-null.
784*
785* Input:
786* cmd = Linux SCSI command packet of the command that cause the
787* bus device reset.
788*
789* Returns:
790* SUCCESS/FAILURE (defined as macro in scsi.h).
791*
792**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800793static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
795{
f4f051e2005-04-17 15:02:26 -0500796 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500797 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700798 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500799 unsigned int id, lun;
800 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Andrew Vasquez07db5182006-10-02 12:00:49 -0700802 qla2x00_block_error_handler(cmd);
803
f4f051e2005-04-17 15:02:26 -0500804 id = cmd->device->id;
805 lun = cmd->device->lun;
806 serial = cmd->serial_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700808 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500809 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
811 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500812 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -0400814 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 goto eh_dev_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
817 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500818 if (qla2x00_device_reset(ha, fcport) == 0)
819 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
821#if defined(LOGOUT_AFTER_DEVICE_RESET)
f4f051e2005-04-17 15:02:26 -0500822 if (ret == SUCCESS) {
823 if (fcport->flags & FC_FABRIC_DEVICE) {
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700824 ha->isp_ops->fabric_logout(ha, fcport->loop_id);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -0800825 qla2x00_mark_device_lost(ha, fcport, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 }
827 }
828#endif
829 } else {
830 DEBUG2(printk(KERN_INFO
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700831 "%s failed: loop not ready\n",__func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 }
833
f4f051e2005-04-17 15:02:26 -0500834 if (ret == FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 DEBUG3(printk("%s(%ld): device reset failed\n",
836 __func__, ha->host_no));
837 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
838 __func__);
839
840 goto eh_dev_reset_done;
841 }
842
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700843 /* Flush outstanding commands. */
844 if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
845 ret = FAILED;
846 if (ret == FAILED) {
847 DEBUG3(printk("%s(%ld): failed while waiting for commands\n",
848 __func__, ha->host_no));
849 qla_printk(KERN_INFO, ha,
850 "%s: failed while waiting for commands\n", __func__);
851 } else
852 qla_printk(KERN_INFO, ha,
853 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no,
854 id, lun);
James Bottomley28f22b02005-10-28 17:22:18 -0500855 eh_dev_reset_done:
f4f051e2005-04-17 15:02:26 -0500856 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857}
858
859/**************************************************************************
860* qla2x00_eh_wait_for_pending_commands
861*
862* Description:
863* Waits for all the commands to come back from the specified host.
864*
865* Input:
866* ha - pointer to scsi_qla_host structure.
867*
868* Returns:
869* 1 : SUCCESS
870* 0 : FAILED
871*
872* Note:
873**************************************************************************/
874static int
875qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
876{
877 int cnt;
878 int status;
879 srb_t *sp;
880 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700881 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883 status = 1;
884
885 /*
886 * Waiting for all commands for the designated target in the active
887 * array
888 */
889 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700890 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 sp = ha->outstanding_cmds[cnt];
892 if (sp) {
893 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700894 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 status = qla2x00_eh_wait_on_command(ha, cmd);
896 if (status == 0)
897 break;
898 }
899 else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700900 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 }
902 }
903 return (status);
904}
905
906
907/**************************************************************************
908* qla2xxx_eh_bus_reset
909*
910* Description:
911* The bus reset function will reset the bus and abort any executing
912* commands.
913*
914* Input:
915* cmd = Linux SCSI command packet of the command that cause the
916* bus reset.
917*
918* Returns:
919* SUCCESS/FAILURE (defined as macro in scsi.h).
920*
921**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800922static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
924{
f4f051e2005-04-17 15:02:26 -0500925 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700926 scsi_qla_host_t *pha = to_qla_parent(ha);
bdf79622005-04-17 15:06:53 -0500927 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700928 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500929 unsigned int id, lun;
930 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
Andrew Vasquez07db5182006-10-02 12:00:49 -0700932 qla2x00_block_error_handler(cmd);
933
f4f051e2005-04-17 15:02:26 -0500934 id = cmd->device->id;
935 lun = cmd->device->lun;
936 serial = cmd->serial_number;
937
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700938 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500939 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500942 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
945 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500946 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 }
948
949 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500950 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
951 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 }
f4f051e2005-04-17 15:02:26 -0500953 if (ret == FAILED)
954 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700956 /* Flush outstanding commands. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700957 if (!qla2x00_eh_wait_for_pending_commands(pha))
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700958 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
f4f051e2005-04-17 15:02:26 -0500960eh_bus_reset_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500962 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
f4f051e2005-04-17 15:02:26 -0500964 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965}
966
967/**************************************************************************
968* qla2xxx_eh_host_reset
969*
970* Description:
971* The reset function will reset the Adapter.
972*
973* Input:
974* cmd = Linux SCSI command packet of the command that cause the
975* adapter reset.
976*
977* Returns:
978* Either SUCCESS or FAILED.
979*
980* Note:
981**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800982static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
984{
f4f051e2005-04-17 15:02:26 -0500985 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500986 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700987 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500988 unsigned int id, lun;
989 unsigned long serial;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700990 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
Andrew Vasquez07db5182006-10-02 12:00:49 -0700992 qla2x00_block_error_handler(cmd);
993
f4f051e2005-04-17 15:02:26 -0500994 id = cmd->device->id;
995 lun = cmd->device->lun;
996 serial = cmd->serial_number;
997
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700998 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500999 return ret;
1000
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -05001002 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001005 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
1007 /*
1008 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001009 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 * be completed and then issue big hammer.Otherwise
1011 * it may cause I/O failure as big hammer marks the
1012 * devices as lost kicking of the port_down_timer
1013 * while dpc is stuck for the mailbox to complete.
1014 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 qla2x00_wait_for_loop_ready(ha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001016 set_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
1017 if (qla2x00_abort_isp(pha)) {
1018 clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 /* failed. schedule dpc to try */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001020 set_bit(ISP_ABORT_NEEDED, &pha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
1022 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001023 goto eh_host_reset_lock;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001024 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001025 clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 /* Waiting for our command in done_queue to be returned to OS.*/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001028 if (qla2x00_eh_wait_for_pending_commands(pha))
f4f051e2005-04-17 15:02:26 -05001029 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001031 if (ha->parent)
1032 qla2x00_vp_abort_isp(ha);
1033
f4f051e2005-04-17 15:02:26 -05001034eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001035 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1036 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037
f4f051e2005-04-17 15:02:26 -05001038 return ret;
1039}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
1041/*
1042* qla2x00_loop_reset
1043* Issue loop reset.
1044*
1045* Input:
1046* ha = adapter block pointer.
1047*
1048* Returns:
1049* 0 = success
1050*/
1051static int
1052qla2x00_loop_reset(scsi_qla_host_t *ha)
1053{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001054 int ret;
bdf79622005-04-17 15:06:53 -05001055 struct fc_port *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001057 if (ha->flags.enable_lip_full_login) {
1058 ret = qla2x00_full_login_lip(ha);
1059 if (ret != QLA_SUCCESS) {
1060 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1061 "full_login_lip=%d.\n", __func__, ha->host_no,
1062 ret));
1063 }
1064 atomic_set(&ha->loop_state, LOOP_DOWN);
1065 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
1066 qla2x00_mark_all_devices_lost(ha, 0);
1067 qla2x00_wait_for_loop_ready(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
1069
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001070 if (ha->flags.enable_lip_reset) {
1071 ret = qla2x00_lip_reset(ha);
1072 if (ret != QLA_SUCCESS) {
1073 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1074 "lip_reset=%d.\n", __func__, ha->host_no, ret));
1075 }
1076 qla2x00_wait_for_loop_ready(ha);
1077 }
1078
1079 if (ha->flags.enable_target_reset) {
bdf79622005-04-17 15:06:53 -05001080 list_for_each_entry(fcport, &ha->fcports, list) {
1081 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 continue;
1083
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001084 ret = qla2x00_device_reset(ha, fcport);
1085 if (ret != QLA_SUCCESS) {
1086 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1087 "target_reset=%d d_id=%x.\n", __func__,
1088 ha->host_no, ret, fcport->d_id.b24));
1089 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 }
1091 }
1092
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 /* Issue marker command only when we are going to start the I/O */
1094 ha->marker_needed = 1;
1095
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001096 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097}
1098
1099/*
1100 * qla2x00_device_reset
1101 * Issue bus device reset message to the target.
1102 *
1103 * Input:
1104 * ha = adapter block pointer.
1105 * t = SCSI ID.
1106 * TARGET_QUEUE_LOCK must be released.
1107 * ADAPTER_STATE_LOCK must be released.
1108 *
1109 * Context:
1110 * Kernel context.
1111 */
1112static int
1113qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1114{
1115 /* Abort Target command will clear Reservation */
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001116 return ha->isp_ops->abort_target(reset_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117}
1118
f4f051e2005-04-17 15:02:26 -05001119static int
1120qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121{
bdf79622005-04-17 15:06:53 -05001122 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001124 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001125 return -ENXIO;
1126
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001127 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001128
1129 return 0;
1130}
1131
1132static int
1133qla2xxx_slave_configure(struct scsi_device *sdev)
1134{
8482e1182005-04-17 15:04:54 -05001135 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1136 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1137
f4f051e2005-04-17 15:02:26 -05001138 if (sdev->tagged_supported)
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001139 scsi_activate_tcq(sdev, ha->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 else
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001141 scsi_deactivate_tcq(sdev, ha->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
8482e1182005-04-17 15:04:54 -05001143 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
1144
f4f051e2005-04-17 15:02:26 -05001145 return 0;
1146}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
f4f051e2005-04-17 15:02:26 -05001148static void
1149qla2xxx_slave_destroy(struct scsi_device *sdev)
1150{
1151 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152}
1153
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001154static int
1155qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1156{
1157 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1158 return sdev->queue_depth;
1159}
1160
1161static int
1162qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1163{
1164 if (sdev->tagged_supported) {
1165 scsi_set_tag_type(sdev, tag_type);
1166 if (tag_type)
1167 scsi_activate_tcq(sdev, sdev->queue_depth);
1168 else
1169 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1170 } else
1171 tag_type = 0;
1172
1173 return tag_type;
1174}
1175
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176/**
1177 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1178 * @ha: HA context
1179 *
1180 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1181 * supported addressing method.
1182 */
1183static void
1184qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1185{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001186 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001189 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1190 /* Any upper-dword bits set? */
1191 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1192 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1193 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001195 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1196 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001197 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001200
1201 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1202 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203}
1204
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001205static void
1206qla2x00_enable_intrs(scsi_qla_host_t *ha)
1207{
1208 unsigned long flags = 0;
1209 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1210
1211 spin_lock_irqsave(&ha->hardware_lock, flags);
1212 ha->interrupts_on = 1;
1213 /* enable risc and host interrupts */
1214 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1215 RD_REG_WORD(&reg->ictrl);
1216 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1217
1218}
1219
1220static void
1221qla2x00_disable_intrs(scsi_qla_host_t *ha)
1222{
1223 unsigned long flags = 0;
1224 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1225
1226 spin_lock_irqsave(&ha->hardware_lock, flags);
1227 ha->interrupts_on = 0;
1228 /* disable risc and host interrupts */
1229 WRT_REG_WORD(&reg->ictrl, 0);
1230 RD_REG_WORD(&reg->ictrl);
1231 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1232}
1233
1234static void
1235qla24xx_enable_intrs(scsi_qla_host_t *ha)
1236{
1237 unsigned long flags = 0;
1238 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1239
1240 spin_lock_irqsave(&ha->hardware_lock, flags);
1241 ha->interrupts_on = 1;
1242 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1243 RD_REG_DWORD(&reg->ictrl);
1244 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1245}
1246
1247static void
1248qla24xx_disable_intrs(scsi_qla_host_t *ha)
1249{
1250 unsigned long flags = 0;
1251 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1252
1253 spin_lock_irqsave(&ha->hardware_lock, flags);
1254 ha->interrupts_on = 0;
1255 WRT_REG_DWORD(&reg->ictrl, 0);
1256 RD_REG_DWORD(&reg->ictrl);
1257 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1258}
1259
1260static struct isp_operations qla2100_isp_ops = {
1261 .pci_config = qla2100_pci_config,
1262 .reset_chip = qla2x00_reset_chip,
1263 .chip_diag = qla2x00_chip_diag,
1264 .config_rings = qla2x00_config_rings,
1265 .reset_adapter = qla2x00_reset_adapter,
1266 .nvram_config = qla2x00_nvram_config,
1267 .update_fw_options = qla2x00_update_fw_options,
1268 .load_risc = qla2x00_load_risc,
1269 .pci_info_str = qla2x00_pci_info_str,
1270 .fw_version_str = qla2x00_fw_version_str,
1271 .intr_handler = qla2100_intr_handler,
1272 .enable_intrs = qla2x00_enable_intrs,
1273 .disable_intrs = qla2x00_disable_intrs,
1274 .abort_command = qla2x00_abort_command,
1275 .abort_target = qla2x00_abort_target,
1276 .fabric_login = qla2x00_login_fabric,
1277 .fabric_logout = qla2x00_fabric_logout,
1278 .calc_req_entries = qla2x00_calc_iocbs_32,
1279 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1280 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1281 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1282 .read_nvram = qla2x00_read_nvram_data,
1283 .write_nvram = qla2x00_write_nvram_data,
1284 .fw_dump = qla2100_fw_dump,
1285 .beacon_on = NULL,
1286 .beacon_off = NULL,
1287 .beacon_blink = NULL,
1288 .read_optrom = qla2x00_read_optrom_data,
1289 .write_optrom = qla2x00_write_optrom_data,
1290 .get_flash_version = qla2x00_get_flash_version,
1291};
1292
1293static struct isp_operations qla2300_isp_ops = {
1294 .pci_config = qla2300_pci_config,
1295 .reset_chip = qla2x00_reset_chip,
1296 .chip_diag = qla2x00_chip_diag,
1297 .config_rings = qla2x00_config_rings,
1298 .reset_adapter = qla2x00_reset_adapter,
1299 .nvram_config = qla2x00_nvram_config,
1300 .update_fw_options = qla2x00_update_fw_options,
1301 .load_risc = qla2x00_load_risc,
1302 .pci_info_str = qla2x00_pci_info_str,
1303 .fw_version_str = qla2x00_fw_version_str,
1304 .intr_handler = qla2300_intr_handler,
1305 .enable_intrs = qla2x00_enable_intrs,
1306 .disable_intrs = qla2x00_disable_intrs,
1307 .abort_command = qla2x00_abort_command,
1308 .abort_target = qla2x00_abort_target,
1309 .fabric_login = qla2x00_login_fabric,
1310 .fabric_logout = qla2x00_fabric_logout,
1311 .calc_req_entries = qla2x00_calc_iocbs_32,
1312 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1313 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1314 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1315 .read_nvram = qla2x00_read_nvram_data,
1316 .write_nvram = qla2x00_write_nvram_data,
1317 .fw_dump = qla2300_fw_dump,
1318 .beacon_on = qla2x00_beacon_on,
1319 .beacon_off = qla2x00_beacon_off,
1320 .beacon_blink = qla2x00_beacon_blink,
1321 .read_optrom = qla2x00_read_optrom_data,
1322 .write_optrom = qla2x00_write_optrom_data,
1323 .get_flash_version = qla2x00_get_flash_version,
1324};
1325
1326static struct isp_operations qla24xx_isp_ops = {
1327 .pci_config = qla24xx_pci_config,
1328 .reset_chip = qla24xx_reset_chip,
1329 .chip_diag = qla24xx_chip_diag,
1330 .config_rings = qla24xx_config_rings,
1331 .reset_adapter = qla24xx_reset_adapter,
1332 .nvram_config = qla24xx_nvram_config,
1333 .update_fw_options = qla24xx_update_fw_options,
1334 .load_risc = qla24xx_load_risc,
1335 .pci_info_str = qla24xx_pci_info_str,
1336 .fw_version_str = qla24xx_fw_version_str,
1337 .intr_handler = qla24xx_intr_handler,
1338 .enable_intrs = qla24xx_enable_intrs,
1339 .disable_intrs = qla24xx_disable_intrs,
1340 .abort_command = qla24xx_abort_command,
1341 .abort_target = qla24xx_abort_target,
1342 .fabric_login = qla24xx_login_fabric,
1343 .fabric_logout = qla24xx_fabric_logout,
1344 .calc_req_entries = NULL,
1345 .build_iocbs = NULL,
1346 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1347 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1348 .read_nvram = qla24xx_read_nvram_data,
1349 .write_nvram = qla24xx_write_nvram_data,
1350 .fw_dump = qla24xx_fw_dump,
1351 .beacon_on = qla24xx_beacon_on,
1352 .beacon_off = qla24xx_beacon_off,
1353 .beacon_blink = qla24xx_beacon_blink,
1354 .read_optrom = qla24xx_read_optrom_data,
1355 .write_optrom = qla24xx_write_optrom_data,
1356 .get_flash_version = qla24xx_get_flash_version,
1357};
1358
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001359static struct isp_operations qla25xx_isp_ops = {
1360 .pci_config = qla25xx_pci_config,
1361 .reset_chip = qla24xx_reset_chip,
1362 .chip_diag = qla24xx_chip_diag,
1363 .config_rings = qla24xx_config_rings,
1364 .reset_adapter = qla24xx_reset_adapter,
1365 .nvram_config = qla24xx_nvram_config,
1366 .update_fw_options = qla24xx_update_fw_options,
1367 .load_risc = qla24xx_load_risc,
1368 .pci_info_str = qla24xx_pci_info_str,
1369 .fw_version_str = qla24xx_fw_version_str,
1370 .intr_handler = qla24xx_intr_handler,
1371 .enable_intrs = qla24xx_enable_intrs,
1372 .disable_intrs = qla24xx_disable_intrs,
1373 .abort_command = qla24xx_abort_command,
1374 .abort_target = qla24xx_abort_target,
1375 .fabric_login = qla24xx_login_fabric,
1376 .fabric_logout = qla24xx_fabric_logout,
1377 .calc_req_entries = NULL,
1378 .build_iocbs = NULL,
1379 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1380 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1381 .read_nvram = qla25xx_read_nvram_data,
1382 .write_nvram = qla25xx_write_nvram_data,
1383 .fw_dump = qla25xx_fw_dump,
1384 .beacon_on = qla24xx_beacon_on,
1385 .beacon_off = qla24xx_beacon_off,
1386 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001387 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001388 .write_optrom = qla24xx_write_optrom_data,
1389 .get_flash_version = qla24xx_get_flash_version,
1390};
1391
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001392static inline void
1393qla2x00_set_isp_flags(scsi_qla_host_t *ha)
1394{
1395 ha->device_type = DT_EXTENDED_IDS;
1396 switch (ha->pdev->device) {
1397 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1398 ha->device_type |= DT_ISP2100;
1399 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001400 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001401 break;
1402 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1403 ha->device_type |= DT_ISP2200;
1404 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001405 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001406 break;
1407 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1408 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001409 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001410 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001411 break;
1412 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1413 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001414 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001415 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001416 break;
1417 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1418 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001419 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001420 if (ha->pdev->subsystem_vendor == 0x1028 &&
1421 ha->pdev->subsystem_device == 0x0170)
1422 ha->device_type |= DT_OEM_001;
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_ISP6312:
1426 ha->device_type |= DT_ISP6312;
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_ISP6322:
1430 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001431 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001432 break;
1433 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1434 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001435 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001436 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001437 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001438 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001439 break;
1440 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1441 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001442 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001443 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001444 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001445 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001446 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001447 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1448 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001449 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001450 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001451 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001452 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1453 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001454 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001455 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001456 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001457 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1458 ha->device_type |= DT_ISP2532;
1459 ha->device_type |= DT_ZIO_SUPPORTED;
1460 ha->device_type |= DT_FWI2;
1461 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001462 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1463 break;
1464 }
1465}
1466
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467static int
1468qla2x00_iospace_config(scsi_qla_host_t *ha)
1469{
1470 unsigned long pio, pio_len, pio_flags;
1471 unsigned long mmio, mmio_len, mmio_flags;
1472
1473 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1474 pio = pci_resource_start(ha->pdev, 0);
1475 pio_len = pci_resource_len(ha->pdev, 0);
1476 pio_flags = pci_resource_flags(ha->pdev, 0);
1477 if (pio_flags & IORESOURCE_IO) {
1478 if (pio_len < MIN_IOBASE_LEN) {
1479 qla_printk(KERN_WARNING, ha,
1480 "Invalid PCI I/O region size (%s)...\n",
1481 pci_name(ha->pdev));
1482 pio = 0;
1483 }
1484 } else {
1485 qla_printk(KERN_WARNING, ha,
1486 "region #0 not a PIO resource (%s)...\n",
1487 pci_name(ha->pdev));
1488 pio = 0;
1489 }
1490
1491 /* Use MMIO operations for all accesses. */
1492 mmio = pci_resource_start(ha->pdev, 1);
1493 mmio_len = pci_resource_len(ha->pdev, 1);
1494 mmio_flags = pci_resource_flags(ha->pdev, 1);
1495
1496 if (!(mmio_flags & IORESOURCE_MEM)) {
1497 qla_printk(KERN_ERR, ha,
1498 "region #0 not an MMIO resource (%s), aborting\n",
1499 pci_name(ha->pdev));
1500 goto iospace_error_exit;
1501 }
1502 if (mmio_len < MIN_IOBASE_LEN) {
1503 qla_printk(KERN_ERR, ha,
1504 "Invalid PCI mem region size (%s), aborting\n",
1505 pci_name(ha->pdev));
1506 goto iospace_error_exit;
1507 }
1508
Andrew Vasquezcb630672006-05-17 15:09:45 -07001509 if (pci_request_regions(ha->pdev, QLA2XXX_DRIVER_NAME)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 qla_printk(KERN_WARNING, ha,
1511 "Failed to reserve PIO/MMIO regions (%s)\n",
1512 pci_name(ha->pdev));
1513
1514 goto iospace_error_exit;
1515 }
1516
1517 ha->pio_address = pio;
1518 ha->pio_length = pio_len;
1519 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1520 if (!ha->iobase) {
1521 qla_printk(KERN_ERR, ha,
1522 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1523
1524 goto iospace_error_exit;
1525 }
1526
1527 return (0);
1528
1529iospace_error_exit:
1530 return (-ENOMEM);
1531}
1532
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001533static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001534qla2xxx_scan_start(struct Scsi_Host *shost)
1535{
1536 scsi_qla_host_t *ha = (scsi_qla_host_t *)shost->hostdata;
1537
1538 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1539 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1540 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1541}
1542
1543static int
1544qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1545{
1546 scsi_qla_host_t *ha = (scsi_qla_host_t *)shost->hostdata;
1547
1548 if (!ha->host)
1549 return 1;
1550 if (time > ha->loop_reset_delay * HZ)
1551 return 1;
1552
1553 return atomic_read(&ha->loop_state) == LOOP_READY;
1554}
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;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001563 device_reg_t __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 struct Scsi_Host *host;
1565 scsi_qla_host_t *ha;
1566 unsigned long flags = 0;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001567 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001569 struct scsi_host_template *sht;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
1571 if (pci_enable_device(pdev))
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001572 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
Andrew Vasquez54333832005-11-09 15:49:04 -08001574 sht = &qla2x00_driver_template;
1575 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
Andrew Vasquez8bc69e72006-12-13 19:20:29 -08001576 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
1577 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001578 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1579 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532)
Andrew Vasquez54333832005-11-09 15:49:04 -08001580 sht = &qla24xx_driver_template;
1581 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 if (host == NULL) {
1583 printk(KERN_WARNING
1584 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1585 goto probe_disable_device;
1586 }
1587
1588 /* Clear our data area */
1589 ha = (scsi_qla_host_t *)host->hostdata;
1590 memset(ha, 0, sizeof(scsi_qla_host_t));
1591
1592 ha->pdev = pdev;
1593 ha->host = host;
1594 ha->host_no = host->host_no;
Andrew Vasquezcb630672006-05-17 15:09:45 -07001595 sprintf(ha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, ha->host_no);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001596 ha->parent = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001598 /* Set ISP-type information. */
1599 qla2x00_set_isp_flags(ha);
1600
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 /* Configure PCI I/O space */
1602 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001603 if (ret)
1604 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08001607 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1608 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
1610 spin_lock_init(&ha->hardware_lock);
1611
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001613 ha->init_cb_size = sizeof(init_cb_t);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001614 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER + ha->vp_idx;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001615 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001616 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
Andrew Vasquezdf7baa52006-10-13 09:33:39 -07001618 ha->max_q_depth = MAX_Q_DEPTH;
1619 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1620 ha->max_q_depth = ql2xmaxqdepth;
1621
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001622 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 if (IS_QLA2100(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001624 host->max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1626 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1627 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1628 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1629 host->sg_tablesize = 32;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001630 ha->gid_list_info_size = 4;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001631 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 } else if (IS_QLA2200(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001633 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1635 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1636 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1637 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001638 ha->gid_list_info_size = 4;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001639 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001640 } else if (IS_QLA23XX(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001641 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1643 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1644 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1645 ha->last_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;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001650 } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07001651 host->max_id = MAX_TARGETS_2200;
1652 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1653 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1654 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1655 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001656 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1657 ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001658 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001659 ha->optrom_size = OPTROM_SIZE_24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001660 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001661 } else if (IS_QLA25XX(ha)) {
1662 host->max_id = MAX_TARGETS_2200;
1663 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1664 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1665 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1666 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1667 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1668 ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
1669 ha->gid_list_info_size = 8;
1670 ha->optrom_size = OPTROM_SIZE_25XX;
1671 ha->isp_ops = &qla25xx_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 }
1673 host->can_queue = ha->request_q_length + 128;
1674
1675 /* load the F/W, read paramaters, and init the H/W */
1676 ha->instance = num_hosts;
1677
1678 init_MUTEX(&ha->mbx_cmd_sem);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001679 init_MUTEX(&ha->vport_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1681
1682 INIT_LIST_HEAD(&ha->list);
1683 INIT_LIST_HEAD(&ha->fcports);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001684 INIT_LIST_HEAD(&ha->vp_list);
1685
1686 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 qla2x00_config_dma_addressing(ha);
1689 if (qla2x00_mem_alloc(ha)) {
1690 qla_printk(KERN_WARNING, ha,
1691 "[ERROR] Failed to allocate memory for adapter\n");
1692
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001693 ret = -ENOMEM;
1694 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 }
1696
Andrew Vasquez765140b2007-05-07 07:42:58 -07001697 if (qla2x00_initialize_adapter(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 qla_printk(KERN_WARNING, ha,
1699 "Failed to initialize adapter\n");
1700
1701 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1702 "Adapter flags %x.\n",
1703 ha->host_no, ha->device_flags));
1704
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001705 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 goto probe_failed;
1707 }
1708
1709 /*
1710 * Startup the kernel thread for this host adapter
1711 */
Christoph Hellwig39a11242006-02-14 18:46:22 +01001712 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1713 "%s_dpc", ha->host_str);
1714 if (IS_ERR(ha->dpc_thread)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 qla_printk(KERN_WARNING, ha,
1716 "Unable to start DPC thread!\n");
Christoph Hellwig39a11242006-02-14 18:46:22 +01001717 ret = PTR_ERR(ha->dpc_thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 goto probe_failed;
1719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001721 host->this_id = 255;
1722 host->cmd_per_lun = 3;
1723 host->unique_id = ha->instance;
1724 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001725 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001726 host->max_lun = MAX_LUNS;
1727 host->transportt = qla2xxx_transport_template;
1728
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001729 ret = qla2x00_request_irqs(ha);
1730 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
1733 /* Initialized the timer */
1734 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1735
1736 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1737 ha->host_no, ha));
1738
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001739 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001742 reg = ha->iobase;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001743 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07001744 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1745 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1746 } else {
1747 WRT_REG_WORD(&reg->isp.semaphore, 0);
1748 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1749 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
Andrew Vasquezfca29702005-07-06 10:31:47 -07001751 /* Enable proper parity */
1752 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1753 if (IS_QLA2300(ha))
1754 /* SRAM parity */
1755 WRT_REG_WORD(&reg->isp.hccr,
1756 (HCCR_ENABLE_PARITY + 0x1));
1757 else
1758 /* SRAM, Instruction RAM and GP RAM parity */
1759 WRT_REG_WORD(&reg->isp.hccr,
1760 (HCCR_ENABLE_PARITY + 0x7));
1761 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 }
1763 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1764
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001765 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001767 pci_set_drvdata(pdev, ha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001768
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 ha->flags.init_done = 1;
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001770 ha->flags.online = 1;
1771
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 num_hosts++;
1773
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001774 ret = scsi_add_host(host, &pdev->dev);
1775 if (ret)
1776 goto probe_failed;
1777
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001778 scsi_scan_host(host);
1779
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001780 qla2x00_alloc_sysfs_attr(ha);
1781
1782 qla2x00_init_host_attr(ha);
1783
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 qla_printk(KERN_INFO, ha, "\n"
1785 " QLogic Fibre Channel HBA Driver: %s\n"
1786 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08001787 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1788 qla2x00_version_str, ha->model_number,
1789 ha->model_desc ? ha->model_desc: "", pdev->device,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001790 ha->isp_ops->pci_info_str(ha, pci_info), pci_name(pdev),
Andrew Vasquez54333832005-11-09 15:49:04 -08001791 ha->flags.enable_64bit_addressing ? '+': '-', ha->host_no,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001792 ha->isp_ops->fw_version_str(ha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 return 0;
1795
1796probe_failed:
1797 qla2x00_free_device(ha);
1798
1799 scsi_host_put(host);
1800
1801probe_disable_device:
1802 pci_disable_device(pdev);
1803
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001804probe_out:
1805 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001808static void __devexit
1809qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810{
1811 scsi_qla_host_t *ha;
1812
1813 ha = pci_get_drvdata(pdev);
1814
8482e1182005-04-17 15:04:54 -05001815 qla2x00_free_sysfs_attr(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
bdf79622005-04-17 15:06:53 -05001817 fc_remove_host(ha->host);
1818
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 scsi_remove_host(ha->host);
1820
1821 qla2x00_free_device(ha);
1822
1823 scsi_host_put(ha->host);
1824
Bernhard Walle665db932007-03-28 00:49:49 +02001825 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 pci_set_drvdata(pdev, NULL);
1827}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
1829static void
1830qla2x00_free_device(scsi_qla_host_t *ha)
1831{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 /* Disable timer */
1833 if (ha->timer_active)
1834 qla2x00_stop_timer(ha);
1835
1836 /* Kill the kernel thread for this host */
Christoph Hellwig39a11242006-02-14 18:46:22 +01001837 if (ha->dpc_thread) {
1838 struct task_struct *t = ha->dpc_thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
Christoph Hellwig39a11242006-02-14 18:46:22 +01001840 /*
1841 * qla2xxx_wake_dpc checks for ->dpc_thread
1842 * so we need to zero it out.
1843 */
1844 ha->dpc_thread = NULL;
1845 kthread_stop(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 }
1847
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001848 if (ha->eft)
1849 qla2x00_trace_control(ha, TC_DISABLE, 0, 0);
1850
Andrew Vasquez18c6c122006-10-13 09:33:38 -07001851 ha->flags.online = 0;
1852
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001853 /* Stop currently executing firmware. */
Andrew Vasquez18c6c122006-10-13 09:33:38 -07001854 qla2x00_try_to_stop_firmware(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001856 /* turn-off interrupts on the card */
1857 if (ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001858 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001859
1860 qla2x00_mem_free(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001862 qla2x00_free_irqs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
1864 /* release io space registers */
1865 if (ha->iobase)
1866 iounmap(ha->iobase);
1867 pci_release_regions(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868}
1869
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001870static inline void
1871qla2x00_schedule_rport_del(struct scsi_qla_host *ha, fc_port_t *fcport,
1872 int defer)
1873{
1874 unsigned long flags;
1875 struct fc_rport *rport;
1876
1877 if (!fcport->rport)
1878 return;
1879
1880 rport = fcport->rport;
1881 if (defer) {
1882 spin_lock_irqsave(&fcport->rport_lock, flags);
1883 fcport->drport = rport;
1884 fcport->rport = NULL;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -08001885 *(fc_port_t **)rport->dd_data = NULL;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001886 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1887 set_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags);
1888 } else {
1889 spin_lock_irqsave(&fcport->rport_lock, flags);
1890 fcport->rport = NULL;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -08001891 *(fc_port_t **)rport->dd_data = NULL;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001892 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1893 fc_remote_port_delete(rport);
1894 }
1895}
1896
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1899 *
1900 * Input: ha = adapter block pointer. fcport = port structure pointer.
1901 *
1902 * Return: None.
1903 *
1904 * Context:
1905 */
1906void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001907 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001909 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1910 ha->vp_idx == fcport->vp_idx)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001911 qla2x00_schedule_rport_del(ha, fcport, defer);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001912
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001913 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 * We may need to retry the login, so don't change the state of the
1915 * port but do the retries.
1916 */
1917 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1918 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1919
1920 if (!do_login)
1921 return;
1922
1923 if (fcport->login_retry == 0) {
1924 fcport->login_retry = ha->login_retry_count;
1925 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1926
1927 DEBUG(printk("scsi(%ld): Port login retry: "
1928 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1929 "id = 0x%04x retry cnt=%d\n",
1930 ha->host_no,
1931 fcport->port_name[0],
1932 fcport->port_name[1],
1933 fcport->port_name[2],
1934 fcport->port_name[3],
1935 fcport->port_name[4],
1936 fcport->port_name[5],
1937 fcport->port_name[6],
1938 fcport->port_name[7],
1939 fcport->loop_id,
1940 fcport->login_retry));
1941 }
1942}
1943
1944/*
1945 * qla2x00_mark_all_devices_lost
1946 * Updates fcport state when device goes offline.
1947 *
1948 * Input:
1949 * ha = adapter block pointer.
1950 * fcport = port structure pointer.
1951 *
1952 * Return:
1953 * None.
1954 *
1955 * Context:
1956 */
1957void
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001958qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959{
1960 fc_port_t *fcport;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001961 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001963 list_for_each_entry(fcport, &pha->fcports, list) {
1964 if (ha->vp_idx != 0 && ha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 /*
1967 * No point in marking the device as lost, if the device is
1968 * already DEAD.
1969 */
1970 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1971 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001972 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1973 if (defer)
1974 qla2x00_schedule_rport_del(ha, fcport, defer);
1975 else if (ha->vp_idx == fcport->vp_idx)
1976 qla2x00_schedule_rport_del(ha, fcport, defer);
1977 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1979 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001980
Christoph Hellwig39a11242006-02-14 18:46:22 +01001981 if (defer)
1982 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983}
1984
1985/*
1986* qla2x00_mem_alloc
1987* Allocates adapter memory.
1988*
1989* Returns:
1990* 0 = success.
1991* 1 = failure.
1992*/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001993uint8_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994qla2x00_mem_alloc(scsi_qla_host_t *ha)
1995{
1996 char name[16];
1997 uint8_t status = 1;
1998 int retry= 10;
1999
2000 do {
2001 /*
2002 * This will loop only once if everything goes well, else some
2003 * number of retries will be performed to get around a kernel
2004 * bug where available mem is not allocated until after a
2005 * little delay and a retry.
2006 */
2007 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
2008 (ha->request_q_length + 1) * sizeof(request_t),
2009 &ha->request_dma, GFP_KERNEL);
2010 if (ha->request_ring == NULL) {
2011 qla_printk(KERN_WARNING, ha,
2012 "Memory Allocation failed - request_ring\n");
2013
2014 qla2x00_mem_free(ha);
2015 msleep(100);
2016
2017 continue;
2018 }
2019
2020 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
2021 (ha->response_q_length + 1) * sizeof(response_t),
2022 &ha->response_dma, GFP_KERNEL);
2023 if (ha->response_ring == NULL) {
2024 qla_printk(KERN_WARNING, ha,
2025 "Memory Allocation failed - response_ring\n");
2026
2027 qla2x00_mem_free(ha);
2028 msleep(100);
2029
2030 continue;
2031 }
2032
2033 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2034 &ha->gid_list_dma, GFP_KERNEL);
2035 if (ha->gid_list == NULL) {
2036 qla_printk(KERN_WARNING, ha,
2037 "Memory Allocation failed - gid_list\n");
2038
2039 qla2x00_mem_free(ha);
2040 msleep(100);
2041
2042 continue;
2043 }
2044
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002045 /* get consistent memory allocated for init control block */
2046 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev,
2047 ha->init_cb_size, &ha->init_cb_dma, GFP_KERNEL);
2048 if (ha->init_cb == NULL) {
2049 qla_printk(KERN_WARNING, ha,
2050 "Memory Allocation failed - init_cb\n");
2051
2052 qla2x00_mem_free(ha);
2053 msleep(100);
2054
2055 continue;
2056 }
2057 memset(ha->init_cb, 0, ha->init_cb_size);
2058
Andrew Vasquezcb630672006-05-17 15:09:45 -07002059 snprintf(name, sizeof(name), "%s_%ld", QLA2XXX_DRIVER_NAME,
2060 ha->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2062 DMA_POOL_SIZE, 8, 0);
2063 if (ha->s_dma_pool == NULL) {
2064 qla_printk(KERN_WARNING, ha,
2065 "Memory Allocation failed - s_dma_pool\n");
2066
2067 qla2x00_mem_free(ha);
2068 msleep(100);
2069
2070 continue;
2071 }
2072
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 if (qla2x00_allocate_sp_pool(ha)) {
2074 qla_printk(KERN_WARNING, ha,
2075 "Memory Allocation failed - "
2076 "qla2x00_allocate_sp_pool()\n");
2077
2078 qla2x00_mem_free(ha);
2079 msleep(100);
2080
2081 continue;
2082 }
2083
2084 /* Allocate memory for SNS commands */
2085 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2086 /* Get consistent memory allocated for SNS commands */
2087 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2088 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
2089 GFP_KERNEL);
2090 if (ha->sns_cmd == NULL) {
2091 /* error */
2092 qla_printk(KERN_WARNING, ha,
2093 "Memory Allocation failed - sns_cmd\n");
2094
2095 qla2x00_mem_free(ha);
2096 msleep(100);
2097
2098 continue;
2099 }
2100 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
2101 } else {
2102 /* Get consistent memory allocated for MS IOCB */
2103 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2104 &ha->ms_iocb_dma);
2105 if (ha->ms_iocb == NULL) {
2106 /* error */
2107 qla_printk(KERN_WARNING, ha,
2108 "Memory Allocation failed - ms_iocb\n");
2109
2110 qla2x00_mem_free(ha);
2111 msleep(100);
2112
2113 continue;
2114 }
2115 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
2116
2117 /*
2118 * Get consistent memory allocated for CT SNS
2119 * commands
2120 */
2121 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2122 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
2123 GFP_KERNEL);
2124 if (ha->ct_sns == NULL) {
2125 /* error */
2126 qla_printk(KERN_WARNING, ha,
2127 "Memory Allocation failed - ct_sns\n");
2128
2129 qla2x00_mem_free(ha);
2130 msleep(100);
2131
2132 continue;
2133 }
2134 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
Andrew Vasquez88729e52006-06-23 16:10:50 -07002135
Andrew Vasqueze4289242007-07-19 15:05:56 -07002136 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez88729e52006-06-23 16:10:50 -07002137 /*
2138 * Get consistent memory allocated for SFP
2139 * block.
2140 */
2141 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool,
2142 GFP_KERNEL, &ha->sfp_data_dma);
2143 if (ha->sfp_data == NULL) {
2144 qla_printk(KERN_WARNING, ha,
2145 "Memory Allocation failed - "
2146 "sfp_data\n");
2147
2148 qla2x00_mem_free(ha);
2149 msleep(100);
2150
2151 continue;
2152 }
2153 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
2154 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 }
2156
Seokmann Ju53772a22007-07-30 11:01:07 -07002157 /* Get memory for cached NVRAM */
2158 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2159 if (ha->nvram == NULL) {
2160 /* error */
2161 qla_printk(KERN_WARNING, ha,
2162 "Memory Allocation failed - nvram cache\n");
2163
2164 qla2x00_mem_free(ha);
2165 msleep(100);
2166
2167 continue;
2168 }
2169
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 /* Done all allocations without any error. */
2171 status = 0;
2172
2173 } while (retry-- && status != 0);
2174
2175 if (status) {
2176 printk(KERN_WARNING
2177 "%s(): **** FAILED ****\n", __func__);
2178 }
2179
2180 return(status);
2181}
2182
2183/*
2184* qla2x00_mem_free
2185* Frees all adapter allocated memory.
2186*
2187* Input:
2188* ha = adapter block pointer.
2189*/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002190void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191qla2x00_mem_free(scsi_qla_host_t *ha)
2192{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 struct list_head *fcpl, *fcptemp;
2194 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
2196 if (ha == NULL) {
2197 /* error */
2198 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
2199 return;
2200 }
2201
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 /* free sp pool */
2203 qla2x00_free_sp_pool(ha);
2204
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002205 if (ha->fw_dump) {
2206 if (ha->eft)
2207 dma_free_coherent(&ha->pdev->dev,
2208 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2209 vfree(ha->fw_dump);
2210 }
2211
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 if (ha->sns_cmd)
2213 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2214 ha->sns_cmd, ha->sns_cmd_dma);
2215
2216 if (ha->ct_sns)
2217 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2218 ha->ct_sns, ha->ct_sns_dma);
2219
Andrew Vasquez88729e52006-06-23 16:10:50 -07002220 if (ha->sfp_data)
2221 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2222
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 if (ha->ms_iocb)
2224 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2225
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 if (ha->s_dma_pool)
2227 dma_pool_destroy(ha->s_dma_pool);
2228
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002229 if (ha->init_cb)
2230 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2231 ha->init_cb, ha->init_cb_dma);
2232
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 if (ha->gid_list)
2234 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2235 ha->gid_list_dma);
2236
2237 if (ha->response_ring)
2238 dma_free_coherent(&ha->pdev->dev,
2239 (ha->response_q_length + 1) * sizeof(response_t),
2240 ha->response_ring, ha->response_dma);
2241
2242 if (ha->request_ring)
2243 dma_free_coherent(&ha->pdev->dev,
2244 (ha->request_q_length + 1) * sizeof(request_t),
2245 ha->request_ring, ha->request_dma);
2246
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002247 ha->eft = NULL;
2248 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 ha->sns_cmd = NULL;
2250 ha->sns_cmd_dma = 0;
2251 ha->ct_sns = NULL;
2252 ha->ct_sns_dma = 0;
2253 ha->ms_iocb = NULL;
2254 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 ha->init_cb = NULL;
2256 ha->init_cb_dma = 0;
2257
2258 ha->s_dma_pool = NULL;
2259
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 ha->gid_list = NULL;
2261 ha->gid_list_dma = 0;
2262
2263 ha->response_ring = NULL;
2264 ha->response_dma = 0;
2265 ha->request_ring = NULL;
2266 ha->request_dma = 0;
2267
2268 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2269 fcport = list_entry(fcpl, fc_port_t, list);
2270
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 /* fc ports */
2272 list_del_init(&fcport->list);
2273 kfree(fcport);
2274 }
2275 INIT_LIST_HEAD(&ha->fcports);
2276
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002278 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 ha->fw_dump_reading = 0;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002280
2281 vfree(ha->optrom_buffer);
Seokmann Ju53772a22007-07-30 11:01:07 -07002282 kfree(ha->nvram);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283}
2284
2285/*
2286 * qla2x00_allocate_sp_pool
2287 * This routine is called during initialization to allocate
2288 * memory for local srb_t.
2289 *
2290 * Input:
2291 * ha = adapter block pointer.
2292 *
2293 * Context:
2294 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 */
2296static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002297qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298{
2299 int rval;
2300
2301 rval = QLA_SUCCESS;
Matthew Dobson93d23412006-03-26 01:37:50 -08002302 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 if (ha->srb_mempool == NULL) {
2304 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
2305 rval = QLA_FUNCTION_FAILED;
2306 }
2307 return (rval);
2308}
2309
2310/*
2311 * This routine frees all adapter allocated memory.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002312 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 */
2314static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002315qla2x00_free_sp_pool( scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316{
2317 if (ha->srb_mempool) {
2318 mempool_destroy(ha->srb_mempool);
2319 ha->srb_mempool = NULL;
2320 }
2321}
2322
2323/**************************************************************************
2324* qla2x00_do_dpc
2325* This kernel thread is a task that is schedule by the interrupt handler
2326* to perform the background processing for interrupts.
2327*
2328* Notes:
2329* This task always run in the context of a kernel thread. It
2330* is kick-off by the driver's detect code and starts up
2331* up one per adapter. It immediately goes to sleep and waits for
2332* some fibre event. When either the interrupt handler or
2333* the timer routine detects a event it will one of the task
2334* bits then wake us up.
2335**************************************************************************/
2336static int
2337qla2x00_do_dpc(void *data)
2338{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002339 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 scsi_qla_host_t *ha;
2341 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 uint8_t status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 uint16_t next_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344
2345 ha = (scsi_qla_host_t *)data;
2346
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 set_user_nice(current, -20);
2348
Christoph Hellwig39a11242006-02-14 18:46:22 +01002349 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2351
Christoph Hellwig39a11242006-02-14 18:46:22 +01002352 set_current_state(TASK_INTERRUPTIBLE);
2353 schedule();
2354 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
2356 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2357
2358 /* Initialization not yet finished. Don't do anything yet. */
Christoph Hellwig39a11242006-02-14 18:46:22 +01002359 if (!ha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 continue;
2361
2362 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2363
2364 ha->dpc_active = 1;
2365
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 ha->dpc_active = 0;
2368 continue;
2369 }
2370
2371 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2372
2373 DEBUG(printk("scsi(%ld): dpc: sched "
2374 "qla2x00_abort_isp ha = %p\n",
2375 ha->host_no, ha));
2376 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2377 &ha->dpc_flags))) {
2378
2379 if (qla2x00_abort_isp(ha)) {
2380 /* failed. retry later */
2381 set_bit(ISP_ABORT_NEEDED,
2382 &ha->dpc_flags);
2383 }
2384 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2385 }
2386 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2387 ha->host_no));
2388 }
2389
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002390 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags))
2391 qla2x00_update_fcports(ha);
2392
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07002393 if (test_and_clear_bit(LOOP_RESET_NEEDED, &ha->dpc_flags)) {
2394 DEBUG(printk("scsi(%ld): dpc: sched loop_reset()\n",
2395 ha->host_no));
2396 qla2x00_loop_reset(ha);
2397 }
2398
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2400 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2401
2402 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2403 ha->host_no));
2404
2405 qla2x00_rst_aen(ha);
2406 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2407 }
2408
2409 /* Retry each device up to login retry count */
2410 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2411 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2412 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2413
2414 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2415 ha->host_no));
2416
2417 next_loopid = 0;
2418 list_for_each_entry(fcport, &ha->fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 /*
2420 * If the port is not ONLINE then try to login
2421 * to it if we haven't run out of retries.
2422 */
2423 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2424 fcport->login_retry) {
2425
2426 fcport->login_retry--;
2427 if (fcport->flags & FCF_FABRIC_DEVICE) {
2428 if (fcport->flags &
2429 FCF_TAPE_PRESENT)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002430 ha->isp_ops->fabric_logout(
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002431 ha, fcport->loop_id,
2432 fcport->d_id.b.domain,
2433 fcport->d_id.b.area,
2434 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 status = qla2x00_fabric_login(
2436 ha, fcport, &next_loopid);
2437 } else
2438 status =
2439 qla2x00_local_device_login(
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08002440 ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
2442 if (status == QLA_SUCCESS) {
2443 fcport->old_loop_id = fcport->loop_id;
2444
2445 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2446 ha->host_no, fcport->loop_id));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002447
andrew.vasquez@qlogic.com052c40c2006-01-20 14:53:19 -08002448 qla2x00_update_fcport(ha,
2449 fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 } else if (status == 1) {
2451 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2452 /* retry the login again */
2453 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2454 ha->host_no,
2455 fcport->login_retry, fcport->loop_id));
2456 } else {
2457 fcport->login_retry = 0;
2458 }
2459 }
2460 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2461 break;
2462 }
2463 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2464 ha->host_no));
2465 }
2466
2467 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
2468 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2469
2470 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
2471 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2472 ha->host_no));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002473
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2475
2476 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2477 ha->host_no));
2478 }
2479
2480 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2481
2482 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2483 ha->host_no));
2484
2485 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2486 &ha->dpc_flags))) {
2487
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002488 rval = qla2x00_loop_resync(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
2490 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2491 }
2492
2493 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2494 ha->host_no));
2495 }
2496
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
2498
2499 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2500 ha->host_no));
2501
2502 qla2x00_rescan_fcports(ha);
2503
2504 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2505 "end.\n",
2506 ha->host_no));
2507 }
2508
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002510 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002512 if (test_and_clear_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags))
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002513 ha->isp_ops->beacon_blink(ha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002514
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002515 qla2x00_do_dpc_all_vps(ha);
2516
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 ha->dpc_active = 0;
2518 } /* End of while(1) */
2519
2520 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2521
2522 /*
2523 * Make sure that nobody tries to wake us up again.
2524 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 ha->dpc_active = 0;
2526
Christoph Hellwig39a11242006-02-14 18:46:22 +01002527 return 0;
2528}
2529
2530void
2531qla2xxx_wake_dpc(scsi_qla_host_t *ha)
2532{
2533 if (ha->dpc_thread)
2534 wake_up_process(ha->dpc_thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535}
2536
2537/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538* qla2x00_rst_aen
2539* Processes asynchronous reset.
2540*
2541* Input:
2542* ha = adapter block pointer.
2543*/
2544static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002545qla2x00_rst_aen(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546{
2547 if (ha->flags.online && !ha->flags.reset_active &&
2548 !atomic_read(&ha->loop_down_timer) &&
2549 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2550 do {
2551 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2552
2553 /*
2554 * Issue marker command only when we are going to start
2555 * the I/O.
2556 */
2557 ha->marker_needed = 1;
2558 } while (!atomic_read(&ha->loop_down_timer) &&
2559 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2560 }
2561}
2562
f4f051e2005-04-17 15:02:26 -05002563static void
2564qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2565{
2566 struct scsi_cmnd *cmd = sp->cmd;
2567
2568 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002569 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05002570 sp->flags &= ~SRB_DMA_VALID;
2571 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002572 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002573}
2574
2575void
2576qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2577{
2578 struct scsi_cmnd *cmd = sp->cmd;
2579
2580 qla2x00_sp_free_dma(ha, sp);
2581
f4f051e2005-04-17 15:02:26 -05002582 mempool_free(sp, ha->srb_mempool);
2583
2584 cmd->scsi_done(cmd);
2585}
bdf79622005-04-17 15:06:53 -05002586
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587/**************************************************************************
2588* qla2x00_timer
2589*
2590* Description:
2591* One second timer
2592*
2593* Context: Interrupt
2594***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002595void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596qla2x00_timer(scsi_qla_host_t *ha)
2597{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 unsigned long cpu_flags = 0;
2599 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 int start_dpc = 0;
2601 int index;
2602 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002603 int t;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002604 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605
2606 /*
2607 * Ports - Port down timer.
2608 *
2609 * Whenever, a port is in the LOST state we start decrementing its port
2610 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002611 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 */
2613 t = 0;
2614 list_for_each_entry(fcport, &ha->fcports, list) {
2615 if (fcport->port_type != FCT_TARGET)
2616 continue;
2617
2618 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2619
2620 if (atomic_read(&fcport->port_down_timer) == 0)
2621 continue;
2622
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002623 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002625
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002627 "%d remaining\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 ha->host_no,
2629 t, atomic_read(&fcport->port_down_timer)));
2630 }
2631 t++;
2632 } /* End of for fcport */
2633
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634
2635 /* Loop down handler. */
2636 if (atomic_read(&ha->loop_down_timer) > 0 &&
2637 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2638
2639 if (atomic_read(&ha->loop_down_timer) ==
2640 ha->loop_down_abort_time) {
2641
2642 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2643 "queues before time expire\n",
2644 ha->host_no));
2645
2646 if (!IS_QLA2100(ha) && ha->link_down_timeout)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002647 atomic_set(&ha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648
2649 /* Schedule an ISP abort to return any tape commands. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002650 /* NPIV - scan physical port only */
2651 if (!ha->parent) {
2652 spin_lock_irqsave(&ha->hardware_lock,
2653 cpu_flags);
2654 for (index = 1;
2655 index < MAX_OUTSTANDING_COMMANDS;
2656 index++) {
2657 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05002658
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002659 sp = ha->outstanding_cmds[index];
2660 if (!sp)
2661 continue;
2662 sfcp = sp->fcport;
2663 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2664 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002666 set_bit(ISP_ABORT_NEEDED,
2667 &ha->dpc_flags);
2668 break;
2669 }
2670 spin_unlock_irqrestore(&ha->hardware_lock,
2671 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2674 start_dpc++;
2675 }
2676
2677 /* if the loop has been down for 4 minutes, reinit adapter */
2678 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2679 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2680 "restarting queues.\n",
2681 ha->host_no));
2682
2683 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2684 start_dpc++;
2685
2686 if (!(ha->device_flags & DFLG_NO_CABLE)) {
2687 DEBUG(printk("scsi(%ld): Loop down - "
2688 "aborting ISP.\n",
2689 ha->host_no));
2690 qla_printk(KERN_WARNING, ha,
2691 "Loop down - aborting ISP.\n");
2692
2693 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2694 }
2695 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002696 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 ha->host_no,
2698 atomic_read(&ha->loop_down_timer)));
2699 }
2700
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002701 /* Check if beacon LED needs to be blinked */
2702 if (ha->beacon_blink_led == 1) {
2703 set_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags);
2704 start_dpc++;
2705 }
2706
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 /* Schedule the DPC routine if needed */
2708 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2709 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07002710 test_bit(LOOP_RESET_NEEDED, &ha->dpc_flags) ||
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002711 test_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 start_dpc ||
2713 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
f4f051e2005-04-17 15:02:26 -05002714 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002715 test_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags) ||
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002716 test_bit(VP_DPC_NEEDED, &ha->dpc_flags) ||
Christoph Hellwig39a11242006-02-14 18:46:22 +01002717 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002718 qla2xxx_wake_dpc(pha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719
2720 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2721}
2722
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723/* XXX(hch): crude hack to emulate a down_timeout() */
2724int
2725qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
2726{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07002727 const unsigned int step = 100; /* msecs */
2728 unsigned int iterations = jiffies_to_msecs(timeout)/100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729
2730 do {
2731 if (!down_trylock(sema))
2732 return 0;
Andrew Vasquezfe74c712005-08-26 19:10:10 -07002733 if (msleep_interruptible(step))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 break;
Bill Nottingham88f57742007-05-30 04:16:43 -04002735 } while (--iterations > 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736
2737 return -ETIMEDOUT;
2738}
2739
Andrew Vasquez54333832005-11-09 15:49:04 -08002740/* Firmware interface routines. */
2741
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002742#define FW_BLOBS 6
Andrew Vasquez54333832005-11-09 15:49:04 -08002743#define FW_ISP21XX 0
2744#define FW_ISP22XX 1
2745#define FW_ISP2300 2
2746#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002747#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002748#define FW_ISP25XX 5
Andrew Vasquez54333832005-11-09 15:49:04 -08002749
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002750#define FW_FILE_ISP21XX "ql2100_fw.bin"
2751#define FW_FILE_ISP22XX "ql2200_fw.bin"
2752#define FW_FILE_ISP2300 "ql2300_fw.bin"
2753#define FW_FILE_ISP2322 "ql2322_fw.bin"
2754#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002755#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002756
Andrew Vasquez54333832005-11-09 15:49:04 -08002757static DECLARE_MUTEX(qla_fw_lock);
2758
2759static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002760 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
2761 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
2762 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
2763 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
2764 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002765 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08002766};
2767
2768struct fw_blob *
2769qla2x00_request_firmware(scsi_qla_host_t *ha)
2770{
2771 struct fw_blob *blob;
2772
2773 blob = NULL;
2774 if (IS_QLA2100(ha)) {
2775 blob = &qla_fw_blobs[FW_ISP21XX];
2776 } else if (IS_QLA2200(ha)) {
2777 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002778 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002779 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002780 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002781 blob = &qla_fw_blobs[FW_ISP2322];
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002782 } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002783 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002784 } else if (IS_QLA25XX(ha)) {
2785 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08002786 }
2787
2788 down(&qla_fw_lock);
2789 if (blob->fw)
2790 goto out;
2791
2792 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
2793 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
2794 "(%s).\n", ha->host_no, blob->name));
2795 blob->fw = NULL;
2796 blob = NULL;
2797 goto out;
2798 }
2799
2800out:
2801 up(&qla_fw_lock);
2802 return blob;
2803}
2804
2805static void
2806qla2x00_release_firmware(void)
2807{
2808 int idx;
2809
2810 down(&qla_fw_lock);
2811 for (idx = 0; idx < FW_BLOBS; idx++)
2812 if (qla_fw_blobs[idx].fw)
2813 release_firmware(qla_fw_blobs[idx].fw);
2814 up(&qla_fw_lock);
2815}
2816
Andrew Vasquez54333832005-11-09 15:49:04 -08002817static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07002818 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
2819 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
2820 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
2821 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
2822 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
2823 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
2824 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
2825 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
2826 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
2827 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
2828 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002829 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez54333832005-11-09 15:49:04 -08002830 { 0 },
2831};
2832MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2833
Andrew Vasquezfca29702005-07-06 10:31:47 -07002834static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07002835 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06002836 .driver = {
2837 .owner = THIS_MODULE,
2838 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07002839 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002840 .probe = qla2x00_probe_one,
2841 .remove = __devexit_p(qla2x00_remove_one),
Andrew Vasquezfca29702005-07-06 10:31:47 -07002842};
2843
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844/**
2845 * qla2x00_module_init - Module initialization.
2846 **/
2847static int __init
2848qla2x00_module_init(void)
2849{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002850 int ret = 0;
2851
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002853 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09002854 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 if (srb_cachep == NULL) {
2856 printk(KERN_ERR
2857 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2858 return -ENOMEM;
2859 }
2860
2861 /* Derive version string. */
2862 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002863 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07002864 strcat(qla2x00_version_str, "-debug");
2865
Andrew Vasquez1c97a122005-04-21 16:13:36 -04002866 qla2xxx_transport_template =
2867 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002868 if (!qla2xxx_transport_template) {
2869 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002871 }
2872 qla2xxx_transport_vport_template =
2873 fc_attach_transport(&qla2xxx_transport_vport_functions);
2874 if (!qla2xxx_transport_vport_template) {
2875 kmem_cache_destroy(srb_cachep);
2876 fc_release_transport(qla2xxx_transport_template);
2877 return -ENODEV;
2878 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879
2880 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002881 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002882 if (ret) {
2883 kmem_cache_destroy(srb_cachep);
2884 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002885 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002886 }
2887 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888}
2889
2890/**
2891 * qla2x00_module_exit - Module cleanup.
2892 **/
2893static void __exit
2894qla2x00_module_exit(void)
2895{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002896 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08002897 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002898 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002900 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901}
2902
2903module_init(qla2x00_module_init);
2904module_exit(qla2x00_module_exit);
2905
2906MODULE_AUTHOR("QLogic Corporation");
2907MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2908MODULE_LICENSE("GPL");
2909MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002910MODULE_FIRMWARE(FW_FILE_ISP21XX);
2911MODULE_FIRMWARE(FW_FILE_ISP22XX);
2912MODULE_FIRMWARE(FW_FILE_ISP2300);
2913MODULE_FIRMWARE(FW_FILE_ISP2322);
2914MODULE_FIRMWARE(FW_FILE_ISP24XX);