blob: 74a26a4a69b6ace6cca6b1bb276a250b4d5a8cbe [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>
11#include <linux/smp_lock.h>
12#include <linux/delay.h>
13
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 */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -040027static kmem_cache_t *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29/*
30 * Ioctl related information.
31 */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -040032static int num_hosts;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34int ql2xlogintimeout = 20;
35module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
36MODULE_PARM_DESC(ql2xlogintimeout,
37 "Login timeout value in seconds.");
38
8482e1182005-04-17 15:04:54 -050039int qlport_down_retry = 30;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
41MODULE_PARM_DESC(qlport_down_retry,
42 "Maximum number of command retries to a port that returns"
43 "a PORT-DOWN status.");
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045int ql2xplogiabsentdevice;
46module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
47MODULE_PARM_DESC(ql2xplogiabsentdevice,
48 "Option to enable PLOGI to devices that are not present after "
49 "a Fabric scan. This is needed for several broken switches."
50 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052int ql2xloginretrycount = 0;
53module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
54MODULE_PARM_DESC(ql2xloginretrycount,
55 "Specify an alternate value for the NVRAM login retry count.");
56
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -070057int ql2xfwloadbin=1;
Andrew Vasquezfca29702005-07-06 10:31:47 -070058module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
59MODULE_PARM_DESC(ql2xfwloadbin,
60 "Load ISP2xxx firmware image via hotplug.");
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062static void qla2x00_free_device(scsi_qla_host_t *);
63
64static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
65
Andrew Vasquezcca53352005-08-26 19:08:30 -070066int ql2xfdmienable;
67module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
68MODULE_PARM_DESC(ql2xfdmienable,
69 "Enables FDMI registratons "
70 "Default is 0 - no FDMI. 1 - perfom FDMI.");
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -070073 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 */
75static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -050076static int qla2xxx_slave_alloc(struct scsi_device *);
77static void qla2xxx_slave_destroy(struct scsi_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
79 void (*fn)(struct scsi_cmnd *));
Andrew Vasquezfca29702005-07-06 10:31:47 -070080static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
81 void (*fn)(struct scsi_cmnd *));
Linus Torvalds1da177e2005-04-16 15:20:36 -070082static int qla2xxx_eh_abort(struct scsi_cmnd *);
83static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
84static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
85static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
86static int qla2x00_loop_reset(scsi_qla_host_t *ha);
87static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
88
Andrew Vasquezce7e4af2005-08-26 19:09:30 -070089static int qla2x00_change_queue_depth(struct scsi_device *, int);
90static int qla2x00_change_queue_type(struct scsi_device *, int);
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092static struct scsi_host_template qla2x00_driver_template = {
93 .module = THIS_MODULE,
94 .name = "qla2xxx",
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 .queuecommand = qla2x00_queuecommand,
96
97 .eh_abort_handler = qla2xxx_eh_abort,
98 .eh_device_reset_handler = qla2xxx_eh_device_reset,
99 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
100 .eh_host_reset_handler = qla2xxx_eh_host_reset,
101
102 .slave_configure = qla2xxx_slave_configure,
103
f4f051e2005-04-17 15:02:26 -0500104 .slave_alloc = qla2xxx_slave_alloc,
105 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700106 .change_queue_depth = qla2x00_change_queue_depth,
107 .change_queue_type = qla2x00_change_queue_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 .this_id = -1,
109 .cmd_per_lun = 3,
110 .use_clustering = ENABLE_CLUSTERING,
111 .sg_tablesize = SG_ALL,
112
113 /*
114 * The RISC allows for each command to transfer (2^32-1) bytes of data,
115 * which equates to 0x800000 sectors.
116 */
117 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700118 .shost_attrs = qla2x00_host_attrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119};
120
Andrew Vasquezfca29702005-07-06 10:31:47 -0700121static struct scsi_host_template qla24xx_driver_template = {
122 .module = THIS_MODULE,
123 .name = "qla2xxx",
124 .queuecommand = qla24xx_queuecommand,
125
126 .eh_abort_handler = qla2xxx_eh_abort,
127 .eh_device_reset_handler = qla2xxx_eh_device_reset,
128 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
129 .eh_host_reset_handler = qla2xxx_eh_host_reset,
130
131 .slave_configure = qla2xxx_slave_configure,
132
133 .slave_alloc = qla2xxx_slave_alloc,
134 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700135 .change_queue_depth = qla2x00_change_queue_depth,
136 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700137 .this_id = -1,
138 .cmd_per_lun = 3,
139 .use_clustering = ENABLE_CLUSTERING,
140 .sg_tablesize = SG_ALL,
141
142 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700143 .shost_attrs = qla2x00_host_attrs,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700144};
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146static struct scsi_transport_template *qla2xxx_transport_template = NULL;
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148/* TODO Convert to inlines
149 *
150 * Timer routines
151 */
152#define WATCH_INTERVAL 1 /* number of seconds */
153
154static void qla2x00_timer(scsi_qla_host_t *);
155
156static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
157 void *, unsigned long);
158static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
159static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
160
161static inline void
162qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
163{
164 init_timer(&ha->timer);
165 ha->timer.expires = jiffies + interval * HZ;
166 ha->timer.data = (unsigned long)ha;
167 ha->timer.function = (void (*)(unsigned long))func;
168 add_timer(&ha->timer);
169 ha->timer_active = 1;
170}
171
172static inline void
173qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
174{
175 mod_timer(&ha->timer, jiffies + interval * HZ);
176}
177
178static __inline__ void
179qla2x00_stop_timer(scsi_qla_host_t *ha)
180{
181 del_timer_sync(&ha->timer);
182 ha->timer_active = 0;
183}
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185static int qla2x00_do_dpc(void *data);
186
187static void qla2x00_rst_aen(scsi_qla_host_t *);
188
189static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
190static void qla2x00_mem_free(scsi_qla_host_t *ha);
191static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
192static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
f4f051e2005-04-17 15:02:26 -0500193static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
194void qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196/* -------------------------------------------------------------------------- */
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198static char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700199qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
201 static char *pci_bus_modes[] = {
202 "33", "66", "100", "133",
203 };
204 uint16_t pci_bus;
205
206 strcpy(str, "PCI");
207 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
208 if (pci_bus) {
209 strcat(str, "-X (");
210 strcat(str, pci_bus_modes[pci_bus]);
211 } else {
212 pci_bus = (ha->pci_attr & BIT_8) >> 8;
213 strcat(str, " (");
214 strcat(str, pci_bus_modes[pci_bus]);
215 }
216 strcat(str, " MHz)");
217
218 return (str);
219}
220
Andrew Vasquezfca29702005-07-06 10:31:47 -0700221static char *
222qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
223{
224 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
225 uint32_t pci_bus;
226 int pcie_reg;
227
228 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
229 if (pcie_reg) {
230 char lwstr[6];
231 uint16_t pcie_lstat, lspeed, lwidth;
232
233 pcie_reg += 0x12;
234 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
235 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
236 lwidth = (pcie_lstat &
237 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
238
239 strcpy(str, "PCIe (");
240 if (lspeed == 1)
241 strcat(str, "2.5Gb/s ");
242 else
243 strcat(str, "<unknown> ");
244 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
245 strcat(str, lwstr);
246
247 return str;
248 }
249
250 strcpy(str, "PCI");
251 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
252 if (pci_bus == 0 || pci_bus == 8) {
253 strcat(str, " (");
254 strcat(str, pci_bus_modes[pci_bus >> 3]);
255 } else {
256 strcat(str, "-X ");
257 if (pci_bus & BIT_2)
258 strcat(str, "Mode 2");
259 else
260 strcat(str, "Mode 1");
261 strcat(str, " (");
262 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
263 }
264 strcat(str, " MHz)");
265
266 return str;
267}
268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269char *
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700270qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271{
272 char un_str[10];
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
275 ha->fw_minor_version,
276 ha->fw_subminor_version);
277
278 if (ha->fw_attributes & BIT_9) {
279 strcat(str, "FLX");
280 return (str);
281 }
282
283 switch (ha->fw_attributes & 0xFF) {
284 case 0x7:
285 strcat(str, "EF");
286 break;
287 case 0x17:
288 strcat(str, "TP");
289 break;
290 case 0x37:
291 strcat(str, "IP");
292 break;
293 case 0x77:
294 strcat(str, "VI");
295 break;
296 default:
297 sprintf(un_str, "(%x)", ha->fw_attributes);
298 strcat(str, un_str);
299 break;
300 }
301 if (ha->fw_attributes & 0x100)
302 strcat(str, "X");
303
304 return (str);
305}
306
Andrew Vasquezfca29702005-07-06 10:31:47 -0700307char *
308qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
309{
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700310 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
311 ha->fw_minor_version,
312 ha->fw_subminor_version);
313
Andrew Vasquezfca29702005-07-06 10:31:47 -0700314 if (ha->fw_attributes & BIT_0)
315 strcat(str, "[Class 2] ");
316 if (ha->fw_attributes & BIT_1)
317 strcat(str, "[IP] ");
318 if (ha->fw_attributes & BIT_2)
319 strcat(str, "[Multi-ID] ");
320 if (ha->fw_attributes & BIT_13)
321 strcat(str, "[Experimental]");
322 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700323}
324
325static inline srb_t *
326qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
327 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
328{
329 srb_t *sp;
330
331 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
332 if (!sp)
333 return sp;
334
335 atomic_set(&sp->ref_count, 1);
336 sp->ha = ha;
337 sp->fcport = fcport;
338 sp->cmd = cmd;
339 sp->flags = 0;
340 CMD_SP(cmd) = (void *)sp;
341 cmd->scsi_done = done;
342
343 return sp;
344}
345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346static int
f4f051e2005-04-17 15:02:26 -0500347qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
f4f051e2005-04-17 15:02:26 -0500349 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500350 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500351 srb_t *sp;
352 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
bdf79622005-04-17 15:06:53 -0500354 if (!fcport) {
f4f051e2005-04-17 15:02:26 -0500355 cmd->result = DID_NO_CONNECT << 16;
356 goto qc_fail_command;
357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
f4f051e2005-04-17 15:02:26 -0500359 if (atomic_read(&fcport->state) != FCS_ONLINE) {
360 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
361 atomic_read(&ha->loop_state) == LOOP_DEAD) {
362 cmd->result = DID_NO_CONNECT << 16;
363 goto qc_fail_command;
364 }
365 goto qc_host_busy;
366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 spin_unlock_irq(ha->host->host_lock);
369
Andrew Vasquezfca29702005-07-06 10:31:47 -0700370 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
371 if (!sp)
f4f051e2005-04-17 15:02:26 -0500372 goto qc_host_busy_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
f4f051e2005-04-17 15:02:26 -0500374 rval = qla2x00_start_scsi(sp);
375 if (rval != QLA_SUCCESS)
376 goto qc_host_busy_free_sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 spin_lock_irq(ha->host->host_lock);
379
f4f051e2005-04-17 15:02:26 -0500380 return 0;
381
382qc_host_busy_free_sp:
383 qla2x00_sp_free_dma(ha, sp);
f4f051e2005-04-17 15:02:26 -0500384 mempool_free(sp, ha->srb_mempool);
385
386qc_host_busy_lock:
387 spin_lock_irq(ha->host->host_lock);
388
389qc_host_busy:
390 return SCSI_MLQUEUE_HOST_BUSY;
391
392qc_fail_command:
393 done(cmd);
394
395 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396}
397
Andrew Vasquezfca29702005-07-06 10:31:47 -0700398
399static int
400qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
401{
402 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
403 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
404 srb_t *sp;
405 int rval;
406
407 if (!fcport) {
408 cmd->result = DID_NO_CONNECT << 16;
409 goto qc24_fail_command;
410 }
411
412 if (atomic_read(&fcport->state) != FCS_ONLINE) {
413 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
414 atomic_read(&ha->loop_state) == LOOP_DEAD) {
415 cmd->result = DID_NO_CONNECT << 16;
416 goto qc24_fail_command;
417 }
418 goto qc24_host_busy;
419 }
420
421 spin_unlock_irq(ha->host->host_lock);
422
423 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
424 if (!sp)
425 goto qc24_host_busy_lock;
426
427 rval = qla24xx_start_scsi(sp);
428 if (rval != QLA_SUCCESS)
429 goto qc24_host_busy_free_sp;
430
431 spin_lock_irq(ha->host->host_lock);
432
433 return 0;
434
435qc24_host_busy_free_sp:
436 qla2x00_sp_free_dma(ha, sp);
437 mempool_free(sp, ha->srb_mempool);
438
439qc24_host_busy_lock:
440 spin_lock_irq(ha->host->host_lock);
441
442qc24_host_busy:
443 return SCSI_MLQUEUE_HOST_BUSY;
444
445qc24_fail_command:
446 done(cmd);
447
448 return 0;
449}
450
451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452/*
453 * qla2x00_eh_wait_on_command
454 * Waits for the command to be returned by the Firmware for some
455 * max time.
456 *
457 * Input:
458 * ha = actual ha whose done queue will contain the command
459 * returned by firmware.
460 * cmd = Scsi Command to wait on.
461 * flag = Abort/Reset(Bus or Device Reset)
462 *
463 * Return:
464 * Not Found : 0
465 * Found : 1
466 */
467static int
468qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
469{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700470#define ABORT_POLLING_PERIOD 1000
471#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500472 unsigned long wait_iter = ABORT_WAIT_ITER;
473 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
f4f051e2005-04-17 15:02:26 -0500475 while (CMD_SP(cmd)) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700476 msleep(ABORT_POLLING_PERIOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
f4f051e2005-04-17 15:02:26 -0500478 if (--wait_iter)
479 break;
480 }
481 if (CMD_SP(cmd))
482 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
f4f051e2005-04-17 15:02:26 -0500484 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485}
486
487/*
488 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700489 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 * <= MAX_RETRIES_OF_ISP_ABORT or
491 * finally HBA is disabled ie marked offline
492 *
493 * Input:
494 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700495 *
496 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 * Does context switching-Release SPIN_LOCK
498 * (if any) before calling this routine.
499 *
500 * Return:
501 * Success (Adapter is online) : 0
502 * Failed (Adapter is offline/disabled) : 1
503 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700504static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
506{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700507 int return_status;
508 unsigned long wait_online;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700510 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
512 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
513 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
514 ha->dpc_active) && time_before(jiffies, wait_online)) {
515
516 msleep(1000);
517 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700518 if (ha->flags.online)
519 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 else
521 return_status = QLA_FUNCTION_FAILED;
522
523 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
524
525 return (return_status);
526}
527
528/*
529 * qla2x00_wait_for_loop_ready
530 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700531 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 * Input:
533 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700534 *
535 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 * Does context switching-Release SPIN_LOCK
537 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700538 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 *
540 * Return:
541 * Success (LOOP_READY) : 0
542 * Failed (LOOP_NOT_READY) : 1
543 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700544static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
546{
547 int return_status = QLA_SUCCESS;
548 unsigned long loop_timeout ;
549
550 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700551 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 while ((!atomic_read(&ha->loop_down_timer) &&
554 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 atomic_read(&ha->loop_state) != LOOP_READY) {
556 msleep(1000);
557 if (time_after_eq(jiffies, loop_timeout)) {
558 return_status = QLA_FUNCTION_FAILED;
559 break;
560 }
561 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700562 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563}
564
565/**************************************************************************
566* qla2xxx_eh_abort
567*
568* Description:
569* The abort function will abort the specified command.
570*
571* Input:
572* cmd = Linux SCSI command packet to be aborted.
573*
574* Returns:
575* Either SUCCESS or FAILED.
576*
577* Note:
578**************************************************************************/
579int
580qla2xxx_eh_abort(struct scsi_cmnd *cmd)
581{
f4f051e2005-04-17 15:02:26 -0500582 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
583 srb_t *sp;
584 int ret, i;
585 unsigned int id, lun;
586 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700587 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
f4f051e2005-04-17 15:02:26 -0500589 if (!CMD_SP(cmd))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
f4f051e2005-04-17 15:02:26 -0500592 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
f4f051e2005-04-17 15:02:26 -0500594 id = cmd->device->id;
595 lun = cmd->device->lun;
596 serial = cmd->serial_number;
597
598 /* Check active list for command command. */
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700599 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500600 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
601 sp = ha->outstanding_cmds[i];
602
603 if (sp == NULL)
604 continue;
605
606 if (sp->cmd != cmd)
607 continue;
608
609 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
610 "sp->state=%x\n", __func__, ha->host_no, sp, serial,
611 sp->state));
612 DEBUG3(qla2x00_print_scsi_cmd(cmd);)
613
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700614 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700615 if (ha->isp_ops.abort_command(ha, sp)) {
f4f051e2005-04-17 15:02:26 -0500616 DEBUG2(printk("%s(%ld): abort_command "
617 "mbx failed.\n", __func__, ha->host_no));
618 } else {
619 DEBUG3(printk("%s(%ld): abort_command "
620 "mbx success.\n", __func__, ha->host_no));
621 ret = SUCCESS;
622 }
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700623 spin_lock_irqsave(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500624
625 break;
626 }
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700627 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500628
629 /* Wait for the command to be returned. */
630 if (ret == SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500631 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700632 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500633 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
634 "%x.\n", ha->host_no, id, lun, serial, ret);
635 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700638 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500639 "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no,
640 id, lun, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
f4f051e2005-04-17 15:02:26 -0500642 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643}
644
645/**************************************************************************
646* qla2x00_eh_wait_for_pending_target_commands
647*
648* Description:
649* Waits for all the commands to come back from the specified target.
650*
651* Input:
652* ha - pointer to scsi_qla_host structure.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700653* t - target
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654* Returns:
655* Either SUCCESS or FAILED.
656*
657* Note:
658**************************************************************************/
659static int
660qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
661{
662 int cnt;
663 int status;
664 srb_t *sp;
665 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700666 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
668 status = 0;
669
670 /*
671 * Waiting for all commands for the designated target in the active
672 * array
673 */
674 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700675 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 sp = ha->outstanding_cmds[cnt];
677 if (sp) {
678 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700679 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 if (cmd->device->id == t) {
681 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
682 status = 1;
683 break;
684 }
685 }
f4f051e2005-04-17 15:02:26 -0500686 } else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700687 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 }
689 }
690 return (status);
691}
692
693
694/**************************************************************************
695* qla2xxx_eh_device_reset
696*
697* Description:
698* The device reset function will reset the target and abort any
699* executing commands.
700*
701* NOTE: The use of SP is undefined within this context. Do *NOT*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700702* attempt to use this value, even if you determine it is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703* non-null.
704*
705* Input:
706* cmd = Linux SCSI command packet of the command that cause the
707* bus device reset.
708*
709* Returns:
710* SUCCESS/FAILURE (defined as macro in scsi.h).
711*
712**************************************************************************/
713int
714qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
715{
f4f051e2005-04-17 15:02:26 -0500716 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500717 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500718 srb_t *sp;
719 int ret;
720 unsigned int id, lun;
721 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
f4f051e2005-04-17 15:02:26 -0500723 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
f4f051e2005-04-17 15:02:26 -0500725 id = cmd->device->id;
726 lun = cmd->device->lun;
727 serial = cmd->serial_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
f4f051e2005-04-17 15:02:26 -0500729 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500730 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500731 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500734 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -0400736 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 goto eh_dev_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500740 if (qla2x00_device_reset(ha, fcport) == 0)
741 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
743#if defined(LOGOUT_AFTER_DEVICE_RESET)
f4f051e2005-04-17 15:02:26 -0500744 if (ret == SUCCESS) {
745 if (fcport->flags & FC_FABRIC_DEVICE) {
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700746 ha->isp_ops.fabric_logout(ha, fcport->loop_id);
f4f051e2005-04-17 15:02:26 -0500747 qla2x00_mark_device_lost(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 }
749 }
750#endif
751 } else {
752 DEBUG2(printk(KERN_INFO
753 "%s failed: loop not ready\n",__func__);)
754 }
755
f4f051e2005-04-17 15:02:26 -0500756 if (ret == FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 DEBUG3(printk("%s(%ld): device reset failed\n",
758 __func__, ha->host_no));
759 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
760 __func__);
761
762 goto eh_dev_reset_done;
763 }
764
765 /*
766 * If we are coming down the EH path, wait for all commands to
767 * complete for the device.
768 */
769 if (cmd->device->host->eh_active) {
f4f051e2005-04-17 15:02:26 -0500770 if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
771 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
f4f051e2005-04-17 15:02:26 -0500773 if (ret == FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 DEBUG3(printk("%s(%ld): failed while waiting for "
775 "commands\n", __func__, ha->host_no));
776 qla_printk(KERN_INFO, ha,
777 "%s: failed while waiting for commands\n",
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700778 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
780 goto eh_dev_reset_done;
781 }
782 }
783
784 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500785 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787eh_dev_reset_done:
f4f051e2005-04-17 15:02:26 -0500788 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789}
790
791/**************************************************************************
792* qla2x00_eh_wait_for_pending_commands
793*
794* Description:
795* Waits for all the commands to come back from the specified host.
796*
797* Input:
798* ha - pointer to scsi_qla_host structure.
799*
800* Returns:
801* 1 : SUCCESS
802* 0 : FAILED
803*
804* Note:
805**************************************************************************/
806static int
807qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
808{
809 int cnt;
810 int status;
811 srb_t *sp;
812 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700813 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 status = 1;
816
817 /*
818 * Waiting for all commands for the designated target in the active
819 * array
820 */
821 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700822 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 sp = ha->outstanding_cmds[cnt];
824 if (sp) {
825 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700826 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 status = qla2x00_eh_wait_on_command(ha, cmd);
828 if (status == 0)
829 break;
830 }
831 else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700832 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 }
834 }
835 return (status);
836}
837
838
839/**************************************************************************
840* qla2xxx_eh_bus_reset
841*
842* Description:
843* The bus reset function will reset the bus and abort any executing
844* commands.
845*
846* Input:
847* cmd = Linux SCSI command packet of the command that cause the
848* bus reset.
849*
850* Returns:
851* SUCCESS/FAILURE (defined as macro in scsi.h).
852*
853**************************************************************************/
854int
855qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
856{
f4f051e2005-04-17 15:02:26 -0500857 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500858 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 srb_t *sp;
f4f051e2005-04-17 15:02:26 -0500860 int ret;
861 unsigned int id, lun;
862 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
f4f051e2005-04-17 15:02:26 -0500864 ret = FAILED;
865
866 id = cmd->device->id;
867 lun = cmd->device->lun;
868 serial = cmd->serial_number;
869
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500871 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500872 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
874 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500875 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
878 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500879 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 }
881
882 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500883 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
884 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 }
f4f051e2005-04-17 15:02:26 -0500886 if (ret == FAILED)
887 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
889 /* Waiting for our command in done_queue to be returned to OS.*/
890 if (cmd->device->host->eh_active)
891 if (!qla2x00_eh_wait_for_pending_commands(ha))
f4f051e2005-04-17 15:02:26 -0500892 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
f4f051e2005-04-17 15:02:26 -0500894eh_bus_reset_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500896 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
f4f051e2005-04-17 15:02:26 -0500898 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899}
900
901/**************************************************************************
902* qla2xxx_eh_host_reset
903*
904* Description:
905* The reset function will reset the Adapter.
906*
907* Input:
908* cmd = Linux SCSI command packet of the command that cause the
909* adapter reset.
910*
911* Returns:
912* Either SUCCESS or FAILED.
913*
914* Note:
915**************************************************************************/
916int
917qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
918{
f4f051e2005-04-17 15:02:26 -0500919 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500920 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500921 srb_t *sp;
922 int ret;
923 unsigned int id, lun;
924 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
f4f051e2005-04-17 15:02:26 -0500926 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
f4f051e2005-04-17 15:02:26 -0500928 id = cmd->device->id;
929 lun = cmd->device->lun;
930 serial = cmd->serial_number;
931
932 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500933 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500934 return ret;
935
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500937 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500940 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942 /*
943 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700944 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 * be completed and then issue big hammer.Otherwise
946 * it may cause I/O failure as big hammer marks the
947 * devices as lost kicking of the port_down_timer
948 * while dpc is stuck for the mailbox to complete.
949 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 qla2x00_wait_for_loop_ready(ha);
951 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
952 if (qla2x00_abort_isp(ha)) {
953 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
954 /* failed. schedule dpc to try */
955 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
956
957 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500958 goto eh_host_reset_lock;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 /* Waiting for our command in done_queue to be returned to OS.*/
f4f051e2005-04-17 15:02:26 -0500963 if (qla2x00_eh_wait_for_pending_commands(ha))
964 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
f4f051e2005-04-17 15:02:26 -0500966eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -0500967 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
968 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
f4f051e2005-04-17 15:02:26 -0500970 return ret;
971}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973/*
974* qla2x00_loop_reset
975* Issue loop reset.
976*
977* Input:
978* ha = adapter block pointer.
979*
980* Returns:
981* 0 = success
982*/
983static int
984qla2x00_loop_reset(scsi_qla_host_t *ha)
985{
986 int status = QLA_SUCCESS;
bdf79622005-04-17 15:06:53 -0500987 struct fc_port *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
989 if (ha->flags.enable_lip_reset) {
990 status = qla2x00_lip_reset(ha);
991 }
992
993 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
bdf79622005-04-17 15:06:53 -0500994 list_for_each_entry(fcport, &ha->fcports, list) {
995 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 continue;
997
Andrew Vasquezc00c72a2005-08-26 19:08:50 -0700998 status = qla2x00_device_reset(ha, fcport);
bdf79622005-04-17 15:06:53 -0500999 if (status != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 }
1002 }
1003
1004 if (status == QLA_SUCCESS &&
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001005 ((!ha->flags.enable_target_reset &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 !ha->flags.enable_lip_reset) ||
1007 ha->flags.enable_lip_full_login)) {
1008
1009 status = qla2x00_full_login_lip(ha);
1010 }
1011
1012 /* Issue marker command only when we are going to start the I/O */
1013 ha->marker_needed = 1;
1014
1015 if (status) {
1016 /* Empty */
1017 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1018 __func__,
1019 ha->host_no);)
1020 } else {
1021 /* Empty */
1022 DEBUG3(printk("%s(%ld): exiting normally.\n",
1023 __func__,
1024 ha->host_no);)
1025 }
1026
1027 return(status);
1028}
1029
1030/*
1031 * qla2x00_device_reset
1032 * Issue bus device reset message to the target.
1033 *
1034 * Input:
1035 * ha = adapter block pointer.
1036 * t = SCSI ID.
1037 * TARGET_QUEUE_LOCK must be released.
1038 * ADAPTER_STATE_LOCK must be released.
1039 *
1040 * Context:
1041 * Kernel context.
1042 */
1043static int
1044qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1045{
1046 /* Abort Target command will clear Reservation */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001047 return ha->isp_ops.abort_target(reset_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048}
1049
f4f051e2005-04-17 15:02:26 -05001050static int
1051qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052{
bdf79622005-04-17 15:06:53 -05001053 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
bdf79622005-04-17 15:06:53 -05001055 if (!rport)
f4f051e2005-04-17 15:02:26 -05001056 return -ENXIO;
1057
Andrew Vasquez77d74142005-07-08 18:00:36 -07001058 sdev->hostdata = rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001059
1060 return 0;
1061}
1062
1063static int
1064qla2xxx_slave_configure(struct scsi_device *sdev)
1065{
8482e1182005-04-17 15:04:54 -05001066 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1067 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1068
f4f051e2005-04-17 15:02:26 -05001069 if (sdev->tagged_supported)
1070 scsi_activate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 else
f4f051e2005-04-17 15:02:26 -05001072 scsi_deactivate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
8482e1182005-04-17 15:04:54 -05001074 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
1075
f4f051e2005-04-17 15:02:26 -05001076 return 0;
1077}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
f4f051e2005-04-17 15:02:26 -05001079static void
1080qla2xxx_slave_destroy(struct scsi_device *sdev)
1081{
1082 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083}
1084
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001085static int
1086qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1087{
1088 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1089 return sdev->queue_depth;
1090}
1091
1092static int
1093qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1094{
1095 if (sdev->tagged_supported) {
1096 scsi_set_tag_type(sdev, tag_type);
1097 if (tag_type)
1098 scsi_activate_tcq(sdev, sdev->queue_depth);
1099 else
1100 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1101 } else
1102 tag_type = 0;
1103
1104 return tag_type;
1105}
1106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107/**
1108 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1109 * @ha: HA context
1110 *
1111 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1112 * supported addressing method.
1113 */
1114static void
1115qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1116{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001117 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001120 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1121 /* Any upper-dword bits set? */
1122 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1123 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1124 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001126 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_64;
1127 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001128 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001131
1132 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1133 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134}
1135
1136static int
1137qla2x00_iospace_config(scsi_qla_host_t *ha)
1138{
1139 unsigned long pio, pio_len, pio_flags;
1140 unsigned long mmio, mmio_len, mmio_flags;
1141
1142 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1143 pio = pci_resource_start(ha->pdev, 0);
1144 pio_len = pci_resource_len(ha->pdev, 0);
1145 pio_flags = pci_resource_flags(ha->pdev, 0);
1146 if (pio_flags & IORESOURCE_IO) {
1147 if (pio_len < MIN_IOBASE_LEN) {
1148 qla_printk(KERN_WARNING, ha,
1149 "Invalid PCI I/O region size (%s)...\n",
1150 pci_name(ha->pdev));
1151 pio = 0;
1152 }
1153 } else {
1154 qla_printk(KERN_WARNING, ha,
1155 "region #0 not a PIO resource (%s)...\n",
1156 pci_name(ha->pdev));
1157 pio = 0;
1158 }
1159
1160 /* Use MMIO operations for all accesses. */
1161 mmio = pci_resource_start(ha->pdev, 1);
1162 mmio_len = pci_resource_len(ha->pdev, 1);
1163 mmio_flags = pci_resource_flags(ha->pdev, 1);
1164
1165 if (!(mmio_flags & IORESOURCE_MEM)) {
1166 qla_printk(KERN_ERR, ha,
1167 "region #0 not an MMIO resource (%s), aborting\n",
1168 pci_name(ha->pdev));
1169 goto iospace_error_exit;
1170 }
1171 if (mmio_len < MIN_IOBASE_LEN) {
1172 qla_printk(KERN_ERR, ha,
1173 "Invalid PCI mem region size (%s), aborting\n",
1174 pci_name(ha->pdev));
1175 goto iospace_error_exit;
1176 }
1177
1178 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1179 qla_printk(KERN_WARNING, ha,
1180 "Failed to reserve PIO/MMIO regions (%s)\n",
1181 pci_name(ha->pdev));
1182
1183 goto iospace_error_exit;
1184 }
1185
1186 ha->pio_address = pio;
1187 ha->pio_length = pio_len;
1188 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1189 if (!ha->iobase) {
1190 qla_printk(KERN_ERR, ha,
1191 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1192
1193 goto iospace_error_exit;
1194 }
1195
1196 return (0);
1197
1198iospace_error_exit:
1199 return (-ENOMEM);
1200}
1201
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001202static void
1203qla2x00_enable_intrs(scsi_qla_host_t *ha)
1204{
1205 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001206 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001207
1208 spin_lock_irqsave(&ha->hardware_lock, flags);
1209 ha->interrupts_on = 1;
1210 /* enable risc and host interrupts */
1211 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1212 RD_REG_WORD(&reg->ictrl);
1213 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1214
1215}
1216
1217static void
1218qla2x00_disable_intrs(scsi_qla_host_t *ha)
1219{
1220 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001221 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001222
1223 spin_lock_irqsave(&ha->hardware_lock, flags);
1224 ha->interrupts_on = 0;
1225 /* disable risc and host interrupts */
1226 WRT_REG_WORD(&reg->ictrl, 0);
1227 RD_REG_WORD(&reg->ictrl);
1228 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1229}
1230
Andrew Vasquezfca29702005-07-06 10:31:47 -07001231static void
1232qla24xx_enable_intrs(scsi_qla_host_t *ha)
1233{
1234 unsigned long flags = 0;
1235 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1236
1237 spin_lock_irqsave(&ha->hardware_lock, flags);
1238 ha->interrupts_on = 1;
1239 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1240 RD_REG_DWORD(&reg->ictrl);
1241 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1242}
1243
1244static void
1245qla24xx_disable_intrs(scsi_qla_host_t *ha)
1246{
1247 unsigned long flags = 0;
1248 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1249
1250 spin_lock_irqsave(&ha->hardware_lock, flags);
1251 ha->interrupts_on = 0;
1252 WRT_REG_DWORD(&reg->ictrl, 0);
1253 RD_REG_DWORD(&reg->ictrl);
1254 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1255}
1256
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257/*
1258 * PCI driver interface
1259 */
1260int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1261{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001262 int ret = -ENODEV;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001263 device_reg_t __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 struct Scsi_Host *host;
1265 scsi_qla_host_t *ha;
1266 unsigned long flags = 0;
1267 unsigned long wait_switch = 0;
1268 char pci_info[20];
1269 char fw_str[30];
8482e1182005-04-17 15:04:54 -05001270 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
1272 if (pci_enable_device(pdev))
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001273 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
Andrew Vasquezfca29702005-07-06 10:31:47 -07001275 host = scsi_host_alloc(brd_info->sht ? brd_info->sht:
1276 &qla2x00_driver_template, sizeof(scsi_qla_host_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 if (host == NULL) {
1278 printk(KERN_WARNING
1279 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1280 goto probe_disable_device;
1281 }
1282
1283 /* Clear our data area */
1284 ha = (scsi_qla_host_t *)host->hostdata;
1285 memset(ha, 0, sizeof(scsi_qla_host_t));
1286
1287 ha->pdev = pdev;
1288 ha->host = host;
1289 ha->host_no = host->host_no;
1290 ha->brd_info = brd_info;
1291 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1292
Andrew Morton444d1d92005-10-25 11:00:56 -07001293 ha->dpc_pid = -1;
1294
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 /* Configure PCI I/O space */
1296 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001297 if (ret)
1298 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 qla_printk(KERN_INFO, ha,
1301 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
Andrew Vasquezfca29702005-07-06 10:31:47 -07001302 pdev->irq, ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
1304 spin_lock_init(&ha->hardware_lock);
1305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 ha->prev_topology = 0;
1307 ha->ports = MAX_BUSES;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001308 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001309 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001311 /* Assign ISP specific operations. */
1312 ha->isp_ops.pci_config = qla2100_pci_config;
1313 ha->isp_ops.reset_chip = qla2x00_reset_chip;
1314 ha->isp_ops.chip_diag = qla2x00_chip_diag;
1315 ha->isp_ops.config_rings = qla2x00_config_rings;
1316 ha->isp_ops.reset_adapter = qla2x00_reset_adapter;
1317 ha->isp_ops.nvram_config = qla2x00_nvram_config;
1318 ha->isp_ops.update_fw_options = qla2x00_update_fw_options;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001319 ha->isp_ops.load_risc = qla2x00_load_risc;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001320 ha->isp_ops.pci_info_str = qla2x00_pci_info_str;
1321 ha->isp_ops.fw_version_str = qla2x00_fw_version_str;
1322 ha->isp_ops.intr_handler = qla2100_intr_handler;
1323 ha->isp_ops.enable_intrs = qla2x00_enable_intrs;
1324 ha->isp_ops.disable_intrs = qla2x00_disable_intrs;
1325 ha->isp_ops.abort_command = qla2x00_abort_command;
1326 ha->isp_ops.abort_target = qla2x00_abort_target;
1327 ha->isp_ops.fabric_login = qla2x00_login_fabric;
1328 ha->isp_ops.fabric_logout = qla2x00_fabric_logout;
1329 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_32;
1330 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_32;
1331 ha->isp_ops.prep_ms_iocb = qla2x00_prep_ms_iocb;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001332 ha->isp_ops.prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb;
Andrew Vasquez459c5372005-07-06 10:31:07 -07001333 ha->isp_ops.read_nvram = qla2x00_read_nvram_data;
1334 ha->isp_ops.write_nvram = qla2x00_write_nvram_data;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001335 ha->isp_ops.fw_dump = qla2100_fw_dump;
1336 ha->isp_ops.ascii_fw_dump = qla2100_ascii_fw_dump;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 if (IS_QLA2100(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001338 host->max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1340 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1341 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1342 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1343 host->sg_tablesize = 32;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001344 ha->gid_list_info_size = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 } else if (IS_QLA2200(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001346 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1348 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1349 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1350 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001351 ha->gid_list_info_size = 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001352 } else if (IS_QLA23XX(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001353 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1355 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1356 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1357 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001358 ha->isp_ops.pci_config = qla2300_pci_config;
1359 ha->isp_ops.intr_handler = qla2300_intr_handler;
1360 ha->isp_ops.fw_dump = qla2300_fw_dump;
1361 ha->isp_ops.ascii_fw_dump = qla2300_ascii_fw_dump;
1362 ha->gid_list_info_size = 6;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001363 } else if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1364 host->max_id = MAX_TARGETS_2200;
1365 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1366 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1367 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1368 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1369 ha->init_cb_size = sizeof(struct init_cb_24xx);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001370 ha->mgmt_svr_loop_id = 10;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001371 ha->isp_ops.pci_config = qla24xx_pci_config;
1372 ha->isp_ops.reset_chip = qla24xx_reset_chip;
1373 ha->isp_ops.chip_diag = qla24xx_chip_diag;
1374 ha->isp_ops.config_rings = qla24xx_config_rings;
1375 ha->isp_ops.reset_adapter = qla24xx_reset_adapter;
1376 ha->isp_ops.nvram_config = qla24xx_nvram_config;
1377 ha->isp_ops.update_fw_options = qla24xx_update_fw_options;
1378 ha->isp_ops.load_risc = qla24xx_load_risc_flash;
1379 if (ql2xfwloadbin)
1380 ha->isp_ops.load_risc = qla24xx_load_risc_hotplug;
1381 ha->isp_ops.pci_info_str = qla24xx_pci_info_str;
1382 ha->isp_ops.fw_version_str = qla24xx_fw_version_str;
1383 ha->isp_ops.intr_handler = qla24xx_intr_handler;
1384 ha->isp_ops.enable_intrs = qla24xx_enable_intrs;
1385 ha->isp_ops.disable_intrs = qla24xx_disable_intrs;
1386 ha->isp_ops.abort_command = qla24xx_abort_command;
1387 ha->isp_ops.abort_target = qla24xx_abort_target;
1388 ha->isp_ops.fabric_login = qla24xx_login_fabric;
1389 ha->isp_ops.fabric_logout = qla24xx_fabric_logout;
1390 ha->isp_ops.prep_ms_iocb = qla24xx_prep_ms_iocb;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001391 ha->isp_ops.prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001392 ha->isp_ops.read_nvram = qla24xx_read_nvram_data;
1393 ha->isp_ops.write_nvram = qla24xx_write_nvram_data;
1394 ha->isp_ops.fw_dump = qla24xx_fw_dump;
1395 ha->isp_ops.ascii_fw_dump = qla24xx_ascii_fw_dump;
1396 ha->gid_list_info_size = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 }
1398 host->can_queue = ha->request_q_length + 128;
1399
1400 /* load the F/W, read paramaters, and init the H/W */
1401 ha->instance = num_hosts;
1402
1403 init_MUTEX(&ha->mbx_cmd_sem);
1404 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1405
1406 INIT_LIST_HEAD(&ha->list);
1407 INIT_LIST_HEAD(&ha->fcports);
1408 INIT_LIST_HEAD(&ha->rscn_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
1410 /*
1411 * These locks are used to prevent more than one CPU
1412 * from modifying the queue at the same time. The
1413 * higher level "host_lock" will reduce most
1414 * contention for these locks.
1415 */
1416 spin_lock_init(&ha->mbx_reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 init_completion(&ha->dpc_inited);
1419 init_completion(&ha->dpc_exited);
1420
1421 qla2x00_config_dma_addressing(ha);
1422 if (qla2x00_mem_alloc(ha)) {
1423 qla_printk(KERN_WARNING, ha,
1424 "[ERROR] Failed to allocate memory for adapter\n");
1425
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001426 ret = -ENOMEM;
1427 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 }
1429
1430 if (qla2x00_initialize_adapter(ha) &&
1431 !(ha->device_flags & DFLG_NO_CABLE)) {
1432
1433 qla_printk(KERN_WARNING, ha,
1434 "Failed to initialize adapter\n");
1435
1436 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1437 "Adapter flags %x.\n",
1438 ha->host_no, ha->device_flags));
1439
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001440 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 goto probe_failed;
1442 }
1443
1444 /*
1445 * Startup the kernel thread for this host adapter
1446 */
1447 ha->dpc_should_die = 0;
1448 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
1449 if (ha->dpc_pid < 0) {
1450 qla_printk(KERN_WARNING, ha,
1451 "Unable to start DPC thread!\n");
1452
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001453 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 goto probe_failed;
1455 }
1456 wait_for_completion(&ha->dpc_inited);
1457
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001458 host->this_id = 255;
1459 host->cmd_per_lun = 3;
1460 host->unique_id = ha->instance;
1461 host->max_cmd_len = MAX_CMDSZ;
1462 host->max_channel = ha->ports - 1;
1463 host->max_lun = MAX_LUNS;
1464 host->transportt = qla2xxx_transport_template;
1465
Andrew Vasquezfca29702005-07-06 10:31:47 -07001466 ret = request_irq(pdev->irq, ha->isp_ops.intr_handler,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001467 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001468 if (ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 qla_printk(KERN_WARNING, ha,
1470 "Failed to reserve interrupt %d already in use.\n",
Andrew Vasquezfca29702005-07-06 10:31:47 -07001471 pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 goto probe_failed;
1473 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001474 host->irq = pdev->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
1476 /* Initialized the timer */
1477 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1478
1479 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1480 ha->host_no, ha));
1481
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001482 ha->isp_ops.disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001485 reg = ha->iobase;
1486 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1487 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1488 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1489 } else {
1490 WRT_REG_WORD(&reg->isp.semaphore, 0);
1491 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1492 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
Andrew Vasquezfca29702005-07-06 10:31:47 -07001494 /* Enable proper parity */
1495 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1496 if (IS_QLA2300(ha))
1497 /* SRAM parity */
1498 WRT_REG_WORD(&reg->isp.hccr,
1499 (HCCR_ENABLE_PARITY + 0x1));
1500 else
1501 /* SRAM, Instruction RAM and GP RAM parity */
1502 WRT_REG_WORD(&reg->isp.hccr,
1503 (HCCR_ENABLE_PARITY + 0x7));
1504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 }
1506 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1507
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001508 ha->isp_ops.enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
1510 /* v2.19.5b6 */
1511 /*
1512 * Wait around max loop_reset_delay secs for the devices to come
1513 * on-line. We don't want Linux scanning before we are ready.
1514 *
1515 */
1516 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
1517 time_before(jiffies,wait_switch) &&
1518 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
1519 && (ha->device_flags & SWITCH_FOUND) ;) {
1520
1521 qla2x00_check_fabric_devices(ha);
1522
1523 msleep(10);
1524 }
1525
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001526 pci_set_drvdata(pdev, ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 ha->flags.init_done = 1;
1528 num_hosts++;
1529
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001530 ret = scsi_add_host(host, &pdev->dev);
1531 if (ret)
1532 goto probe_failed;
1533
1534 qla2x00_alloc_sysfs_attr(ha);
1535
1536 qla2x00_init_host_attr(ha);
1537
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 qla_printk(KERN_INFO, ha, "\n"
1539 " QLogic Fibre Channel HBA Driver: %s\n"
1540 " QLogic %s - %s\n"
1541 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
1542 ha->model_number, ha->model_desc ? ha->model_desc: "",
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001543 ha->brd_info->isp_name, ha->isp_ops.pci_info_str(ha, pci_info),
Andrew Vasquezfca29702005-07-06 10:31:47 -07001544 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+': '-',
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001545 ha->host_no, ha->isp_ops.fw_version_str(ha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
8482e1182005-04-17 15:04:54 -05001547 /* Go with fc_rport registration. */
1548 list_for_each_entry(fcport, &ha->fcports, list)
1549 qla2x00_reg_remote_port(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
1551 return 0;
1552
1553probe_failed:
1554 qla2x00_free_device(ha);
1555
1556 scsi_host_put(host);
1557
1558probe_disable_device:
1559 pci_disable_device(pdev);
1560
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001561probe_out:
1562 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563}
1564EXPORT_SYMBOL_GPL(qla2x00_probe_one);
1565
1566void qla2x00_remove_one(struct pci_dev *pdev)
1567{
1568 scsi_qla_host_t *ha;
1569
1570 ha = pci_get_drvdata(pdev);
1571
8482e1182005-04-17 15:04:54 -05001572 qla2x00_free_sysfs_attr(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
bdf79622005-04-17 15:06:53 -05001574 fc_remove_host(ha->host);
1575
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 scsi_remove_host(ha->host);
1577
1578 qla2x00_free_device(ha);
1579
1580 scsi_host_put(ha->host);
1581
1582 pci_set_drvdata(pdev, NULL);
1583}
1584EXPORT_SYMBOL_GPL(qla2x00_remove_one);
1585
1586static void
1587qla2x00_free_device(scsi_qla_host_t *ha)
1588{
1589 int ret;
1590
1591 /* Abort any outstanding IO descriptors. */
1592 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1593 qla2x00_cancel_io_descriptors(ha);
1594
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 /* Disable timer */
1596 if (ha->timer_active)
1597 qla2x00_stop_timer(ha);
1598
1599 /* Kill the kernel thread for this host */
1600 if (ha->dpc_pid >= 0) {
1601 ha->dpc_should_die = 1;
1602 wmb();
1603 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
1604 if (ret) {
1605 qla_printk(KERN_ERR, ha,
1606 "Unable to signal DPC thread -- (%d)\n", ret);
1607
1608 /* TODO: SOMETHING MORE??? */
1609 } else {
1610 wait_for_completion(&ha->dpc_exited);
1611 }
1612 }
1613
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001614 /* Stop currently executing firmware. */
1615 qla2x00_stop_firmware(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001617 /* turn-off interrupts on the card */
1618 if (ha->interrupts_on)
1619 ha->isp_ops.disable_intrs(ha);
1620
1621 qla2x00_mem_free(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
1623 ha->flags.online = 0;
1624
1625 /* Detach interrupts */
1626 if (ha->pdev->irq)
1627 free_irq(ha->pdev->irq, ha);
1628
1629 /* release io space registers */
1630 if (ha->iobase)
1631 iounmap(ha->iobase);
1632 pci_release_regions(ha->pdev);
1633
1634 pci_disable_device(ha->pdev);
1635}
1636
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1639 *
1640 * Input: ha = adapter block pointer. fcport = port structure pointer.
1641 *
1642 * Return: None.
1643 *
1644 * Context:
1645 */
1646void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1647 int do_login)
1648{
8482e1182005-04-17 15:04:54 -05001649 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1650 fc_remote_port_block(fcport->rport);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001651 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 * We may need to retry the login, so don't change the state of the
1653 * port but do the retries.
1654 */
1655 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1656 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1657
1658 if (!do_login)
1659 return;
1660
1661 if (fcport->login_retry == 0) {
1662 fcport->login_retry = ha->login_retry_count;
1663 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1664
1665 DEBUG(printk("scsi(%ld): Port login retry: "
1666 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1667 "id = 0x%04x retry cnt=%d\n",
1668 ha->host_no,
1669 fcport->port_name[0],
1670 fcport->port_name[1],
1671 fcport->port_name[2],
1672 fcport->port_name[3],
1673 fcport->port_name[4],
1674 fcport->port_name[5],
1675 fcport->port_name[6],
1676 fcport->port_name[7],
1677 fcport->loop_id,
1678 fcport->login_retry));
1679 }
1680}
1681
1682/*
1683 * qla2x00_mark_all_devices_lost
1684 * Updates fcport state when device goes offline.
1685 *
1686 * Input:
1687 * ha = adapter block pointer.
1688 * fcport = port structure pointer.
1689 *
1690 * Return:
1691 * None.
1692 *
1693 * Context:
1694 */
1695void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001696qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697{
1698 fc_port_t *fcport;
1699
1700 list_for_each_entry(fcport, &ha->fcports, list) {
1701 if (fcport->port_type != FCT_TARGET)
1702 continue;
1703
1704 /*
1705 * No point in marking the device as lost, if the device is
1706 * already DEAD.
1707 */
1708 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1709 continue;
8482e1182005-04-17 15:04:54 -05001710 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1711 fc_remote_port_block(fcport->rport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1713 }
1714}
1715
1716/*
1717* qla2x00_mem_alloc
1718* Allocates adapter memory.
1719*
1720* Returns:
1721* 0 = success.
1722* 1 = failure.
1723*/
1724static uint8_t
1725qla2x00_mem_alloc(scsi_qla_host_t *ha)
1726{
1727 char name[16];
1728 uint8_t status = 1;
1729 int retry= 10;
1730
1731 do {
1732 /*
1733 * This will loop only once if everything goes well, else some
1734 * number of retries will be performed to get around a kernel
1735 * bug where available mem is not allocated until after a
1736 * little delay and a retry.
1737 */
1738 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
1739 (ha->request_q_length + 1) * sizeof(request_t),
1740 &ha->request_dma, GFP_KERNEL);
1741 if (ha->request_ring == NULL) {
1742 qla_printk(KERN_WARNING, ha,
1743 "Memory Allocation failed - request_ring\n");
1744
1745 qla2x00_mem_free(ha);
1746 msleep(100);
1747
1748 continue;
1749 }
1750
1751 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1752 (ha->response_q_length + 1) * sizeof(response_t),
1753 &ha->response_dma, GFP_KERNEL);
1754 if (ha->response_ring == NULL) {
1755 qla_printk(KERN_WARNING, ha,
1756 "Memory Allocation failed - response_ring\n");
1757
1758 qla2x00_mem_free(ha);
1759 msleep(100);
1760
1761 continue;
1762 }
1763
1764 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1765 &ha->gid_list_dma, GFP_KERNEL);
1766 if (ha->gid_list == NULL) {
1767 qla_printk(KERN_WARNING, ha,
1768 "Memory Allocation failed - gid_list\n");
1769
1770 qla2x00_mem_free(ha);
1771 msleep(100);
1772
1773 continue;
1774 }
1775
1776 ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
1777 sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
1778 if (ha->rlc_rsp == NULL) {
1779 qla_printk(KERN_WARNING, ha,
1780 "Memory Allocation failed - rlc");
1781
1782 qla2x00_mem_free(ha);
1783 msleep(100);
1784
1785 continue;
1786 }
1787
1788 snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
1789 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
1790 DMA_POOL_SIZE, 8, 0);
1791 if (ha->s_dma_pool == NULL) {
1792 qla_printk(KERN_WARNING, ha,
1793 "Memory Allocation failed - s_dma_pool\n");
1794
1795 qla2x00_mem_free(ha);
1796 msleep(100);
1797
1798 continue;
1799 }
1800
1801 /* get consistent memory allocated for init control block */
1802 ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1803 &ha->init_cb_dma);
1804 if (ha->init_cb == NULL) {
1805 qla_printk(KERN_WARNING, ha,
1806 "Memory Allocation failed - init_cb\n");
1807
1808 qla2x00_mem_free(ha);
1809 msleep(100);
1810
1811 continue;
1812 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001813 memset(ha->init_cb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
1815 /* Get consistent memory allocated for Get Port Database cmd */
1816 ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1817 &ha->iodesc_pd_dma);
1818 if (ha->iodesc_pd == NULL) {
1819 /* error */
1820 qla_printk(KERN_WARNING, ha,
1821 "Memory Allocation failed - iodesc_pd\n");
1822
1823 qla2x00_mem_free(ha);
1824 msleep(100);
1825
1826 continue;
1827 }
1828 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
1829
1830 /* Allocate ioctl related memory. */
1831 if (qla2x00_alloc_ioctl_mem(ha)) {
1832 qla_printk(KERN_WARNING, ha,
1833 "Memory Allocation failed - ioctl_mem\n");
1834
1835 qla2x00_mem_free(ha);
1836 msleep(100);
1837
1838 continue;
1839 }
1840
1841 if (qla2x00_allocate_sp_pool(ha)) {
1842 qla_printk(KERN_WARNING, ha,
1843 "Memory Allocation failed - "
1844 "qla2x00_allocate_sp_pool()\n");
1845
1846 qla2x00_mem_free(ha);
1847 msleep(100);
1848
1849 continue;
1850 }
1851
1852 /* Allocate memory for SNS commands */
1853 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1854 /* Get consistent memory allocated for SNS commands */
1855 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
1856 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
1857 GFP_KERNEL);
1858 if (ha->sns_cmd == NULL) {
1859 /* error */
1860 qla_printk(KERN_WARNING, ha,
1861 "Memory Allocation failed - sns_cmd\n");
1862
1863 qla2x00_mem_free(ha);
1864 msleep(100);
1865
1866 continue;
1867 }
1868 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
1869 } else {
1870 /* Get consistent memory allocated for MS IOCB */
1871 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1872 &ha->ms_iocb_dma);
1873 if (ha->ms_iocb == NULL) {
1874 /* error */
1875 qla_printk(KERN_WARNING, ha,
1876 "Memory Allocation failed - ms_iocb\n");
1877
1878 qla2x00_mem_free(ha);
1879 msleep(100);
1880
1881 continue;
1882 }
1883 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
1884
1885 /*
1886 * Get consistent memory allocated for CT SNS
1887 * commands
1888 */
1889 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
1890 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
1891 GFP_KERNEL);
1892 if (ha->ct_sns == NULL) {
1893 /* error */
1894 qla_printk(KERN_WARNING, ha,
1895 "Memory Allocation failed - ct_sns\n");
1896
1897 qla2x00_mem_free(ha);
1898 msleep(100);
1899
1900 continue;
1901 }
1902 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
1903 }
1904
1905 /* Done all allocations without any error. */
1906 status = 0;
1907
1908 } while (retry-- && status != 0);
1909
1910 if (status) {
1911 printk(KERN_WARNING
1912 "%s(): **** FAILED ****\n", __func__);
1913 }
1914
1915 return(status);
1916}
1917
1918/*
1919* qla2x00_mem_free
1920* Frees all adapter allocated memory.
1921*
1922* Input:
1923* ha = adapter block pointer.
1924*/
1925static void
1926qla2x00_mem_free(scsi_qla_host_t *ha)
1927{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 struct list_head *fcpl, *fcptemp;
1929 fc_port_t *fcport;
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001930 unsigned int wtime;/* max wait time if mbx cmd is busy. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931
1932 if (ha == NULL) {
1933 /* error */
1934 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
1935 return;
1936 }
1937
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 /* Make sure all other threads are stopped. */
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001939 wtime = 60 * 1000;
1940 while (ha->dpc_wait && wtime)
1941 wtime = msleep_interruptible(wtime);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
1943 /* free ioctl memory */
1944 qla2x00_free_ioctl_mem(ha);
1945
1946 /* free sp pool */
1947 qla2x00_free_sp_pool(ha);
1948
1949 if (ha->sns_cmd)
1950 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
1951 ha->sns_cmd, ha->sns_cmd_dma);
1952
1953 if (ha->ct_sns)
1954 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
1955 ha->ct_sns, ha->ct_sns_dma);
1956
1957 if (ha->ms_iocb)
1958 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
1959
1960 if (ha->iodesc_pd)
1961 dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
1962
1963 if (ha->init_cb)
1964 dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
1965
1966 if (ha->s_dma_pool)
1967 dma_pool_destroy(ha->s_dma_pool);
1968
1969 if (ha->rlc_rsp)
1970 dma_free_coherent(&ha->pdev->dev,
1971 sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
1972 ha->rlc_rsp_dma);
1973
1974 if (ha->gid_list)
1975 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
1976 ha->gid_list_dma);
1977
1978 if (ha->response_ring)
1979 dma_free_coherent(&ha->pdev->dev,
1980 (ha->response_q_length + 1) * sizeof(response_t),
1981 ha->response_ring, ha->response_dma);
1982
1983 if (ha->request_ring)
1984 dma_free_coherent(&ha->pdev->dev,
1985 (ha->request_q_length + 1) * sizeof(request_t),
1986 ha->request_ring, ha->request_dma);
1987
1988 ha->sns_cmd = NULL;
1989 ha->sns_cmd_dma = 0;
1990 ha->ct_sns = NULL;
1991 ha->ct_sns_dma = 0;
1992 ha->ms_iocb = NULL;
1993 ha->ms_iocb_dma = 0;
1994 ha->iodesc_pd = NULL;
1995 ha->iodesc_pd_dma = 0;
1996 ha->init_cb = NULL;
1997 ha->init_cb_dma = 0;
1998
1999 ha->s_dma_pool = NULL;
2000
2001 ha->rlc_rsp = NULL;
2002 ha->rlc_rsp_dma = 0;
2003 ha->gid_list = NULL;
2004 ha->gid_list_dma = 0;
2005
2006 ha->response_ring = NULL;
2007 ha->response_dma = 0;
2008 ha->request_ring = NULL;
2009 ha->request_dma = 0;
2010
2011 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2012 fcport = list_entry(fcpl, fc_port_t, list);
2013
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 /* fc ports */
2015 list_del_init(&fcport->list);
2016 kfree(fcport);
2017 }
2018 INIT_LIST_HEAD(&ha->fcports);
2019
2020 if (ha->fw_dump)
2021 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
2022
Andrew Vasquezfca29702005-07-06 10:31:47 -07002023 vfree(ha->fw_dump24);
2024
2025 vfree(ha->fw_dump_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
2027 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002028 ha->fw_dump24 = NULL;
2029 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 ha->fw_dump_reading = 0;
2031 ha->fw_dump_buffer = NULL;
2032}
2033
2034/*
2035 * qla2x00_allocate_sp_pool
2036 * This routine is called during initialization to allocate
2037 * memory for local srb_t.
2038 *
2039 * Input:
2040 * ha = adapter block pointer.
2041 *
2042 * Context:
2043 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002044 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 * Note: Sets the ref_count for non Null sp to one.
2046 */
2047static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002048qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049{
2050 int rval;
2051
2052 rval = QLA_SUCCESS;
2053 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
2054 mempool_free_slab, srb_cachep);
2055 if (ha->srb_mempool == NULL) {
2056 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
2057 rval = QLA_FUNCTION_FAILED;
2058 }
2059 return (rval);
2060}
2061
2062/*
2063 * This routine frees all adapter allocated memory.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002064 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 */
2066static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002067qla2x00_free_sp_pool( scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068{
2069 if (ha->srb_mempool) {
2070 mempool_destroy(ha->srb_mempool);
2071 ha->srb_mempool = NULL;
2072 }
2073}
2074
2075/**************************************************************************
2076* qla2x00_do_dpc
2077* This kernel thread is a task that is schedule by the interrupt handler
2078* to perform the background processing for interrupts.
2079*
2080* Notes:
2081* This task always run in the context of a kernel thread. It
2082* is kick-off by the driver's detect code and starts up
2083* up one per adapter. It immediately goes to sleep and waits for
2084* some fibre event. When either the interrupt handler or
2085* the timer routine detects a event it will one of the task
2086* bits then wake us up.
2087**************************************************************************/
2088static int
2089qla2x00_do_dpc(void *data)
2090{
2091 DECLARE_MUTEX_LOCKED(sem);
2092 scsi_qla_host_t *ha;
2093 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 uint8_t status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 uint16_t next_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096
2097 ha = (scsi_qla_host_t *)data;
2098
2099 lock_kernel();
2100
2101 daemonize("%s_dpc", ha->host_str);
2102 allow_signal(SIGHUP);
2103
2104 ha->dpc_wait = &sem;
2105
2106 set_user_nice(current, -20);
2107
2108 unlock_kernel();
2109
2110 complete(&ha->dpc_inited);
2111
2112 while (1) {
2113 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2114
2115 if (down_interruptible(&sem))
2116 break;
2117
2118 if (ha->dpc_should_die)
2119 break;
2120
2121 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2122
2123 /* Initialization not yet finished. Don't do anything yet. */
2124 if (!ha->flags.init_done || ha->dpc_active)
2125 continue;
2126
2127 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2128
2129 ha->dpc_active = 1;
2130
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 ha->dpc_active = 0;
2133 continue;
2134 }
2135
2136 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2137
2138 DEBUG(printk("scsi(%ld): dpc: sched "
2139 "qla2x00_abort_isp ha = %p\n",
2140 ha->host_no, ha));
2141 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2142 &ha->dpc_flags))) {
2143
2144 if (qla2x00_abort_isp(ha)) {
2145 /* failed. retry later */
2146 set_bit(ISP_ABORT_NEEDED,
2147 &ha->dpc_flags);
2148 }
2149 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2150 }
2151 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2152 ha->host_no));
2153 }
2154
2155 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2156 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2157
2158 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2159 ha->host_no));
2160
2161 qla2x00_rst_aen(ha);
2162 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2163 }
2164
2165 /* Retry each device up to login retry count */
2166 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2167 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2168 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2169
2170 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2171 ha->host_no));
2172
2173 next_loopid = 0;
2174 list_for_each_entry(fcport, &ha->fcports, list) {
2175 if (fcport->port_type != FCT_TARGET)
2176 continue;
2177
2178 /*
2179 * If the port is not ONLINE then try to login
2180 * to it if we haven't run out of retries.
2181 */
2182 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2183 fcport->login_retry) {
2184
2185 fcport->login_retry--;
2186 if (fcport->flags & FCF_FABRIC_DEVICE) {
2187 if (fcport->flags &
2188 FCF_TAPE_PRESENT)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002189 ha->isp_ops.fabric_logout(
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002190 ha, fcport->loop_id,
2191 fcport->d_id.b.domain,
2192 fcport->d_id.b.area,
2193 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 status = qla2x00_fabric_login(
2195 ha, fcport, &next_loopid);
2196 } else
2197 status =
2198 qla2x00_local_device_login(
2199 ha, fcport->loop_id);
2200
2201 if (status == QLA_SUCCESS) {
2202 fcport->old_loop_id = fcport->loop_id;
2203
2204 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2205 ha->host_no, fcport->loop_id));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002206
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 fcport->port_login_retry_count =
2208 ha->port_down_retry_count * PORT_RETRY_TIME;
2209 atomic_set(&fcport->state, FCS_ONLINE);
2210 atomic_set(&fcport->port_down_timer,
2211 ha->port_down_retry_count * PORT_RETRY_TIME);
2212
2213 fcport->login_retry = 0;
2214 } else if (status == 1) {
2215 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2216 /* retry the login again */
2217 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2218 ha->host_no,
2219 fcport->login_retry, fcport->loop_id));
2220 } else {
2221 fcport->login_retry = 0;
2222 }
2223 }
2224 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2225 break;
2226 }
2227 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2228 ha->host_no));
2229 }
2230
2231 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
2232 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2233
2234 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
2235 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2236 ha->host_no));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002237
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2239
2240 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2241 ha->host_no));
2242 }
2243
2244 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2245
2246 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2247 ha->host_no));
2248
2249 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2250 &ha->dpc_flags))) {
2251
2252 qla2x00_loop_resync(ha);
2253
2254 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2255 }
2256
2257 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2258 ha->host_no));
2259 }
2260
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
2262
2263 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2264 ha->host_no));
2265
2266 qla2x00_rescan_fcports(ha);
2267
2268 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2269 "end.\n",
2270 ha->host_no));
2271 }
2272
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 if (!ha->interrupts_on)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002274 ha->isp_ops.enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 ha->dpc_active = 0;
2277 } /* End of while(1) */
2278
2279 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2280
2281 /*
2282 * Make sure that nobody tries to wake us up again.
2283 */
2284 ha->dpc_wait = NULL;
2285 ha->dpc_active = 0;
2286
2287 complete_and_exit(&ha->dpc_exited, 0);
2288}
2289
2290/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291* qla2x00_rst_aen
2292* Processes asynchronous reset.
2293*
2294* Input:
2295* ha = adapter block pointer.
2296*/
2297static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002298qla2x00_rst_aen(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299{
2300 if (ha->flags.online && !ha->flags.reset_active &&
2301 !atomic_read(&ha->loop_down_timer) &&
2302 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2303 do {
2304 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2305
2306 /*
2307 * Issue marker command only when we are going to start
2308 * the I/O.
2309 */
2310 ha->marker_needed = 1;
2311 } while (!atomic_read(&ha->loop_down_timer) &&
2312 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2313 }
2314}
2315
f4f051e2005-04-17 15:02:26 -05002316static void
2317qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2318{
2319 struct scsi_cmnd *cmd = sp->cmd;
2320
2321 if (sp->flags & SRB_DMA_VALID) {
2322 if (cmd->use_sg) {
2323 dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
2324 cmd->use_sg, cmd->sc_data_direction);
2325 } else if (cmd->request_bufflen) {
2326 dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
2327 cmd->request_bufflen, cmd->sc_data_direction);
2328 }
2329 sp->flags &= ~SRB_DMA_VALID;
2330 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002331 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002332}
2333
2334void
2335qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2336{
2337 struct scsi_cmnd *cmd = sp->cmd;
2338
2339 qla2x00_sp_free_dma(ha, sp);
2340
f4f051e2005-04-17 15:02:26 -05002341 mempool_free(sp, ha->srb_mempool);
2342
2343 cmd->scsi_done(cmd);
2344}
bdf79622005-04-17 15:06:53 -05002345
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346/**************************************************************************
2347* qla2x00_timer
2348*
2349* Description:
2350* One second timer
2351*
2352* Context: Interrupt
2353***************************************************************************/
2354static void
2355qla2x00_timer(scsi_qla_host_t *ha)
2356{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 unsigned long cpu_flags = 0;
2358 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 int start_dpc = 0;
2360 int index;
2361 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002362 int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363
2364 /*
2365 * Ports - Port down timer.
2366 *
2367 * Whenever, a port is in the LOST state we start decrementing its port
2368 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002369 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 */
2371 t = 0;
2372 list_for_each_entry(fcport, &ha->fcports, list) {
2373 if (fcport->port_type != FCT_TARGET)
2374 continue;
2375
2376 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2377
2378 if (atomic_read(&fcport->port_down_timer) == 0)
2379 continue;
2380
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002381 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002383
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002385 "%d remaining\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 ha->host_no,
2387 t, atomic_read(&fcport->port_down_timer)));
2388 }
2389 t++;
2390 } /* End of for fcport */
2391
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
2393 /* Loop down handler. */
2394 if (atomic_read(&ha->loop_down_timer) > 0 &&
2395 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2396
2397 if (atomic_read(&ha->loop_down_timer) ==
2398 ha->loop_down_abort_time) {
2399
2400 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2401 "queues before time expire\n",
2402 ha->host_no));
2403
2404 if (!IS_QLA2100(ha) && ha->link_down_timeout)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002405 atomic_set(&ha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
2407 /* Schedule an ISP abort to return any tape commands. */
2408 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
2409 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
2410 index++) {
bdf79622005-04-17 15:06:53 -05002411 fc_port_t *sfcp;
2412
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 sp = ha->outstanding_cmds[index];
2414 if (!sp)
2415 continue;
bdf79622005-04-17 15:06:53 -05002416 sfcp = sp->fcport;
2417 if (!(sfcp->flags & FCF_TAPE_PRESENT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 continue;
2419
2420 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2421 break;
2422 }
2423 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
2424
2425 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2426 start_dpc++;
2427 }
2428
2429 /* if the loop has been down for 4 minutes, reinit adapter */
2430 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2431 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2432 "restarting queues.\n",
2433 ha->host_no));
2434
2435 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2436 start_dpc++;
2437
2438 if (!(ha->device_flags & DFLG_NO_CABLE)) {
2439 DEBUG(printk("scsi(%ld): Loop down - "
2440 "aborting ISP.\n",
2441 ha->host_no));
2442 qla_printk(KERN_WARNING, ha,
2443 "Loop down - aborting ISP.\n");
2444
2445 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2446 }
2447 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002448 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 ha->host_no,
2450 atomic_read(&ha->loop_down_timer)));
2451 }
2452
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 /* Schedule the DPC routine if needed */
2454 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2455 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
2456 start_dpc ||
2457 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
f4f051e2005-04-17 15:02:26 -05002458 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2460 ha->dpc_wait && !ha->dpc_active) {
2461
2462 up(ha->dpc_wait);
2463 }
2464
2465 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2466}
2467
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468/* XXX(hch): crude hack to emulate a down_timeout() */
2469int
2470qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
2471{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07002472 const unsigned int step = 100; /* msecs */
2473 unsigned int iterations = jiffies_to_msecs(timeout)/100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
2475 do {
2476 if (!down_trylock(sema))
2477 return 0;
Andrew Vasquezfe74c712005-08-26 19:10:10 -07002478 if (msleep_interruptible(step))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 break;
Andrew Vasquezfe74c712005-08-26 19:10:10 -07002480 } while (--iterations >= 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481
2482 return -ETIMEDOUT;
2483}
2484
Andrew Vasquezfca29702005-07-06 10:31:47 -07002485static struct qla_board_info qla_board_tbl[] = {
2486 {
2487 .drv_name = "qla2400",
2488 .isp_name = "ISP2422",
2489 .fw_fname = "ql2400_fw.bin",
2490 .sht = &qla24xx_driver_template,
2491 },
2492 {
2493 .drv_name = "qla2400",
2494 .isp_name = "ISP2432",
2495 .fw_fname = "ql2400_fw.bin",
2496 .sht = &qla24xx_driver_template,
2497 },
2498};
2499
2500static struct pci_device_id qla2xxx_pci_tbl[] = {
2501 {
2502 .vendor = PCI_VENDOR_ID_QLOGIC,
2503 .device = PCI_DEVICE_ID_QLOGIC_ISP2422,
2504 .subvendor = PCI_ANY_ID,
2505 .subdevice = PCI_ANY_ID,
2506 .driver_data = (unsigned long)&qla_board_tbl[0],
2507 },
2508 {
2509 .vendor = PCI_VENDOR_ID_QLOGIC,
2510 .device = PCI_DEVICE_ID_QLOGIC_ISP2432,
2511 .subvendor = PCI_ANY_ID,
2512 .subdevice = PCI_ANY_ID,
2513 .driver_data = (unsigned long)&qla_board_tbl[1],
2514 },
2515 {0, 0},
2516};
2517MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2518
2519static int __devinit
2520qla2xxx_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2521{
2522 return qla2x00_probe_one(pdev,
2523 (struct qla_board_info *)id->driver_data);
2524}
2525
2526static void __devexit
2527qla2xxx_remove_one(struct pci_dev *pdev)
2528{
2529 qla2x00_remove_one(pdev);
2530}
2531
2532static struct pci_driver qla2xxx_pci_driver = {
2533 .name = "qla2xxx",
2534 .id_table = qla2xxx_pci_tbl,
2535 .probe = qla2xxx_probe_one,
2536 .remove = __devexit_p(qla2xxx_remove_one),
2537};
2538
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539/**
2540 * qla2x00_module_init - Module initialization.
2541 **/
2542static int __init
2543qla2x00_module_init(void)
2544{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002545 int ret = 0;
2546
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002548 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 SLAB_HWCACHE_ALIGN, NULL, NULL);
2550 if (srb_cachep == NULL) {
2551 printk(KERN_ERR
2552 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2553 return -ENOMEM;
2554 }
2555
2556 /* Derive version string. */
2557 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
2558#if DEBUG_QLA2100
2559 strcat(qla2x00_version_str, "-debug");
2560#endif
Andrew Vasquez1c97a122005-04-21 16:13:36 -04002561 qla2xxx_transport_template =
2562 fc_attach_transport(&qla2xxx_transport_functions);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 if (!qla2xxx_transport_template)
2564 return -ENODEV;
2565
2566 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
Andrew Vasquezfca29702005-07-06 10:31:47 -07002567 ret = pci_module_init(&qla2xxx_pci_driver);
2568 if (ret) {
2569 kmem_cache_destroy(srb_cachep);
2570 fc_release_transport(qla2xxx_transport_template);
2571 }
2572 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573}
2574
2575/**
2576 * qla2x00_module_exit - Module cleanup.
2577 **/
2578static void __exit
2579qla2x00_module_exit(void)
2580{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002581 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002582 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 fc_release_transport(qla2xxx_transport_template);
2584}
2585
2586module_init(qla2x00_module_init);
2587module_exit(qla2x00_module_exit);
2588
2589MODULE_AUTHOR("QLogic Corporation");
2590MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2591MODULE_LICENSE("GPL");
2592MODULE_VERSION(QLA2XXX_VERSION);