blob: 92976c235ee2aa7960a8077726de14393bcdf530 [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
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700765 /* Flush outstanding commands. */
766 if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
767 ret = FAILED;
768 if (ret == FAILED) {
769 DEBUG3(printk("%s(%ld): failed while waiting for commands\n",
770 __func__, ha->host_no));
771 qla_printk(KERN_INFO, ha,
772 "%s: failed while waiting for commands\n", __func__);
773 } else
774 qla_printk(KERN_INFO, ha,
775 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no,
776 id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
f4f051e2005-04-17 15:02:26 -0500778 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779}
780
781/**************************************************************************
782* qla2x00_eh_wait_for_pending_commands
783*
784* Description:
785* Waits for all the commands to come back from the specified host.
786*
787* Input:
788* ha - pointer to scsi_qla_host structure.
789*
790* Returns:
791* 1 : SUCCESS
792* 0 : FAILED
793*
794* Note:
795**************************************************************************/
796static int
797qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
798{
799 int cnt;
800 int status;
801 srb_t *sp;
802 struct scsi_cmnd *cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700803 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 status = 1;
806
807 /*
808 * Waiting for all commands for the designated target in the active
809 * array
810 */
811 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700812 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 sp = ha->outstanding_cmds[cnt];
814 if (sp) {
815 cmd = sp->cmd;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700816 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 status = qla2x00_eh_wait_on_command(ha, cmd);
818 if (status == 0)
819 break;
820 }
821 else {
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700822 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 }
824 }
825 return (status);
826}
827
828
829/**************************************************************************
830* qla2xxx_eh_bus_reset
831*
832* Description:
833* The bus reset function will reset the bus and abort any executing
834* commands.
835*
836* Input:
837* cmd = Linux SCSI command packet of the command that cause the
838* bus reset.
839*
840* Returns:
841* SUCCESS/FAILURE (defined as macro in scsi.h).
842*
843**************************************************************************/
844int
845qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
846{
f4f051e2005-04-17 15:02:26 -0500847 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500848 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 srb_t *sp;
f4f051e2005-04-17 15:02:26 -0500850 int ret;
851 unsigned int id, lun;
852 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
f4f051e2005-04-17 15:02:26 -0500854 ret = FAILED;
855
856 id = cmd->device->id;
857 lun = cmd->device->lun;
858 serial = cmd->serial_number;
859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500861 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500862 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
864 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500865 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
868 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500869 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 }
871
872 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
f4f051e2005-04-17 15:02:26 -0500873 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
874 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 }
f4f051e2005-04-17 15:02:26 -0500876 if (ret == FAILED)
877 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700879 /* Flush outstanding commands. */
880 if (!qla2x00_eh_wait_for_pending_commands(ha))
881 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
f4f051e2005-04-17 15:02:26 -0500883eh_bus_reset_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500885 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
f4f051e2005-04-17 15:02:26 -0500887 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888}
889
890/**************************************************************************
891* qla2xxx_eh_host_reset
892*
893* Description:
894* The reset function will reset the Adapter.
895*
896* Input:
897* cmd = Linux SCSI command packet of the command that cause the
898* adapter reset.
899*
900* Returns:
901* Either SUCCESS or FAILED.
902*
903* Note:
904**************************************************************************/
905int
906qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
907{
f4f051e2005-04-17 15:02:26 -0500908 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500909 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
f4f051e2005-04-17 15:02:26 -0500910 srb_t *sp;
911 int ret;
912 unsigned int id, lun;
913 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
f4f051e2005-04-17 15:02:26 -0500915 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
f4f051e2005-04-17 15:02:26 -0500917 id = cmd->device->id;
918 lun = cmd->device->lun;
919 serial = cmd->serial_number;
920
921 sp = (srb_t *) CMD_SP(cmd);
bdf79622005-04-17 15:06:53 -0500922 if (!sp || !fcport)
f4f051e2005-04-17 15:02:26 -0500923 return ret;
924
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 qla_printk(KERN_INFO, ha,
f4f051e2005-04-17 15:02:26 -0500926 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500929 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
931 /*
932 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700933 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 * be completed and then issue big hammer.Otherwise
935 * it may cause I/O failure as big hammer marks the
936 * devices as lost kicking of the port_down_timer
937 * while dpc is stuck for the mailbox to complete.
938 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 qla2x00_wait_for_loop_ready(ha);
940 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
941 if (qla2x00_abort_isp(ha)) {
942 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
943 /* failed. schedule dpc to try */
944 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
945
946 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500947 goto eh_host_reset_lock;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 /* Waiting for our command in done_queue to be returned to OS.*/
f4f051e2005-04-17 15:02:26 -0500952 if (qla2x00_eh_wait_for_pending_commands(ha))
953 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
f4f051e2005-04-17 15:02:26 -0500955eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -0500956 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
957 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
f4f051e2005-04-17 15:02:26 -0500959 return ret;
960}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
962/*
963* qla2x00_loop_reset
964* Issue loop reset.
965*
966* Input:
967* ha = adapter block pointer.
968*
969* Returns:
970* 0 = success
971*/
972static int
973qla2x00_loop_reset(scsi_qla_host_t *ha)
974{
975 int status = QLA_SUCCESS;
bdf79622005-04-17 15:06:53 -0500976 struct fc_port *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
978 if (ha->flags.enable_lip_reset) {
979 status = qla2x00_lip_reset(ha);
980 }
981
982 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
bdf79622005-04-17 15:06:53 -0500983 list_for_each_entry(fcport, &ha->fcports, list) {
984 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 continue;
986
Andrew Vasquezc00c72a2005-08-26 19:08:50 -0700987 status = qla2x00_device_reset(ha, fcport);
bdf79622005-04-17 15:06:53 -0500988 if (status != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 }
991 }
992
993 if (status == QLA_SUCCESS &&
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700994 ((!ha->flags.enable_target_reset &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 !ha->flags.enable_lip_reset) ||
996 ha->flags.enable_lip_full_login)) {
997
998 status = qla2x00_full_login_lip(ha);
999 }
1000
1001 /* Issue marker command only when we are going to start the I/O */
1002 ha->marker_needed = 1;
1003
1004 if (status) {
1005 /* Empty */
1006 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1007 __func__,
1008 ha->host_no);)
1009 } else {
1010 /* Empty */
1011 DEBUG3(printk("%s(%ld): exiting normally.\n",
1012 __func__,
1013 ha->host_no);)
1014 }
1015
1016 return(status);
1017}
1018
1019/*
1020 * qla2x00_device_reset
1021 * Issue bus device reset message to the target.
1022 *
1023 * Input:
1024 * ha = adapter block pointer.
1025 * t = SCSI ID.
1026 * TARGET_QUEUE_LOCK must be released.
1027 * ADAPTER_STATE_LOCK must be released.
1028 *
1029 * Context:
1030 * Kernel context.
1031 */
1032static int
1033qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1034{
1035 /* Abort Target command will clear Reservation */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001036 return ha->isp_ops.abort_target(reset_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037}
1038
f4f051e2005-04-17 15:02:26 -05001039static int
1040qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
bdf79622005-04-17 15:06:53 -05001042 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
bdf79622005-04-17 15:06:53 -05001044 if (!rport)
f4f051e2005-04-17 15:02:26 -05001045 return -ENXIO;
1046
Andrew Vasquez77d74142005-07-08 18:00:36 -07001047 sdev->hostdata = rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001048
1049 return 0;
1050}
1051
1052static int
1053qla2xxx_slave_configure(struct scsi_device *sdev)
1054{
8482e1182005-04-17 15:04:54 -05001055 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1056 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1057
f4f051e2005-04-17 15:02:26 -05001058 if (sdev->tagged_supported)
1059 scsi_activate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 else
f4f051e2005-04-17 15:02:26 -05001061 scsi_deactivate_tcq(sdev, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
8482e1182005-04-17 15:04:54 -05001063 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
1064
f4f051e2005-04-17 15:02:26 -05001065 return 0;
1066}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
f4f051e2005-04-17 15:02:26 -05001068static void
1069qla2xxx_slave_destroy(struct scsi_device *sdev)
1070{
1071 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072}
1073
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001074static int
1075qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1076{
1077 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1078 return sdev->queue_depth;
1079}
1080
1081static int
1082qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1083{
1084 if (sdev->tagged_supported) {
1085 scsi_set_tag_type(sdev, tag_type);
1086 if (tag_type)
1087 scsi_activate_tcq(sdev, sdev->queue_depth);
1088 else
1089 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1090 } else
1091 tag_type = 0;
1092
1093 return tag_type;
1094}
1095
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096/**
1097 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1098 * @ha: HA context
1099 *
1100 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1101 * supported addressing method.
1102 */
1103static void
1104qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1105{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001106 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001109 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1110 /* Any upper-dword bits set? */
1111 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1112 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1113 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001115 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_64;
1116 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001117 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001120
1121 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1122 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123}
1124
1125static int
1126qla2x00_iospace_config(scsi_qla_host_t *ha)
1127{
1128 unsigned long pio, pio_len, pio_flags;
1129 unsigned long mmio, mmio_len, mmio_flags;
1130
1131 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1132 pio = pci_resource_start(ha->pdev, 0);
1133 pio_len = pci_resource_len(ha->pdev, 0);
1134 pio_flags = pci_resource_flags(ha->pdev, 0);
1135 if (pio_flags & IORESOURCE_IO) {
1136 if (pio_len < MIN_IOBASE_LEN) {
1137 qla_printk(KERN_WARNING, ha,
1138 "Invalid PCI I/O region size (%s)...\n",
1139 pci_name(ha->pdev));
1140 pio = 0;
1141 }
1142 } else {
1143 qla_printk(KERN_WARNING, ha,
1144 "region #0 not a PIO resource (%s)...\n",
1145 pci_name(ha->pdev));
1146 pio = 0;
1147 }
1148
1149 /* Use MMIO operations for all accesses. */
1150 mmio = pci_resource_start(ha->pdev, 1);
1151 mmio_len = pci_resource_len(ha->pdev, 1);
1152 mmio_flags = pci_resource_flags(ha->pdev, 1);
1153
1154 if (!(mmio_flags & IORESOURCE_MEM)) {
1155 qla_printk(KERN_ERR, ha,
1156 "region #0 not an MMIO resource (%s), aborting\n",
1157 pci_name(ha->pdev));
1158 goto iospace_error_exit;
1159 }
1160 if (mmio_len < MIN_IOBASE_LEN) {
1161 qla_printk(KERN_ERR, ha,
1162 "Invalid PCI mem region size (%s), aborting\n",
1163 pci_name(ha->pdev));
1164 goto iospace_error_exit;
1165 }
1166
1167 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1168 qla_printk(KERN_WARNING, ha,
1169 "Failed to reserve PIO/MMIO regions (%s)\n",
1170 pci_name(ha->pdev));
1171
1172 goto iospace_error_exit;
1173 }
1174
1175 ha->pio_address = pio;
1176 ha->pio_length = pio_len;
1177 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1178 if (!ha->iobase) {
1179 qla_printk(KERN_ERR, ha,
1180 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1181
1182 goto iospace_error_exit;
1183 }
1184
1185 return (0);
1186
1187iospace_error_exit:
1188 return (-ENOMEM);
1189}
1190
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001191static void
1192qla2x00_enable_intrs(scsi_qla_host_t *ha)
1193{
1194 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001195 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001196
1197 spin_lock_irqsave(&ha->hardware_lock, flags);
1198 ha->interrupts_on = 1;
1199 /* enable risc and host interrupts */
1200 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1201 RD_REG_WORD(&reg->ictrl);
1202 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1203
1204}
1205
1206static void
1207qla2x00_disable_intrs(scsi_qla_host_t *ha)
1208{
1209 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001210 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001211
1212 spin_lock_irqsave(&ha->hardware_lock, flags);
1213 ha->interrupts_on = 0;
1214 /* disable risc and host interrupts */
1215 WRT_REG_WORD(&reg->ictrl, 0);
1216 RD_REG_WORD(&reg->ictrl);
1217 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1218}
1219
Andrew Vasquezfca29702005-07-06 10:31:47 -07001220static void
1221qla24xx_enable_intrs(scsi_qla_host_t *ha)
1222{
1223 unsigned long flags = 0;
1224 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1225
1226 spin_lock_irqsave(&ha->hardware_lock, flags);
1227 ha->interrupts_on = 1;
1228 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1229 RD_REG_DWORD(&reg->ictrl);
1230 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1231}
1232
1233static void
1234qla24xx_disable_intrs(scsi_qla_host_t *ha)
1235{
1236 unsigned long flags = 0;
1237 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1238
1239 spin_lock_irqsave(&ha->hardware_lock, flags);
1240 ha->interrupts_on = 0;
1241 WRT_REG_DWORD(&reg->ictrl, 0);
1242 RD_REG_DWORD(&reg->ictrl);
1243 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1244}
1245
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246/*
1247 * PCI driver interface
1248 */
1249int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1250{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001251 int ret = -ENODEV;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001252 device_reg_t __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 struct Scsi_Host *host;
1254 scsi_qla_host_t *ha;
1255 unsigned long flags = 0;
1256 unsigned long wait_switch = 0;
1257 char pci_info[20];
1258 char fw_str[30];
8482e1182005-04-17 15:04:54 -05001259 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
1261 if (pci_enable_device(pdev))
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001262 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
Andrew Vasquezfca29702005-07-06 10:31:47 -07001264 host = scsi_host_alloc(brd_info->sht ? brd_info->sht:
1265 &qla2x00_driver_template, sizeof(scsi_qla_host_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 if (host == NULL) {
1267 printk(KERN_WARNING
1268 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1269 goto probe_disable_device;
1270 }
1271
1272 /* Clear our data area */
1273 ha = (scsi_qla_host_t *)host->hostdata;
1274 memset(ha, 0, sizeof(scsi_qla_host_t));
1275
1276 ha->pdev = pdev;
1277 ha->host = host;
1278 ha->host_no = host->host_no;
1279 ha->brd_info = brd_info;
1280 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1281
Andrew Morton444d1d92005-10-25 11:00:56 -07001282 ha->dpc_pid = -1;
1283
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 /* Configure PCI I/O space */
1285 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001286 if (ret)
1287 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 qla_printk(KERN_INFO, ha,
1290 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
Andrew Vasquezfca29702005-07-06 10:31:47 -07001291 pdev->irq, ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
1293 spin_lock_init(&ha->hardware_lock);
1294
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 ha->prev_topology = 0;
1296 ha->ports = MAX_BUSES;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001297 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001298 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001300 /* Assign ISP specific operations. */
1301 ha->isp_ops.pci_config = qla2100_pci_config;
1302 ha->isp_ops.reset_chip = qla2x00_reset_chip;
1303 ha->isp_ops.chip_diag = qla2x00_chip_diag;
1304 ha->isp_ops.config_rings = qla2x00_config_rings;
1305 ha->isp_ops.reset_adapter = qla2x00_reset_adapter;
1306 ha->isp_ops.nvram_config = qla2x00_nvram_config;
1307 ha->isp_ops.update_fw_options = qla2x00_update_fw_options;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001308 ha->isp_ops.load_risc = qla2x00_load_risc;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001309 ha->isp_ops.pci_info_str = qla2x00_pci_info_str;
1310 ha->isp_ops.fw_version_str = qla2x00_fw_version_str;
1311 ha->isp_ops.intr_handler = qla2100_intr_handler;
1312 ha->isp_ops.enable_intrs = qla2x00_enable_intrs;
1313 ha->isp_ops.disable_intrs = qla2x00_disable_intrs;
1314 ha->isp_ops.abort_command = qla2x00_abort_command;
1315 ha->isp_ops.abort_target = qla2x00_abort_target;
1316 ha->isp_ops.fabric_login = qla2x00_login_fabric;
1317 ha->isp_ops.fabric_logout = qla2x00_fabric_logout;
1318 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_32;
1319 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_32;
1320 ha->isp_ops.prep_ms_iocb = qla2x00_prep_ms_iocb;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001321 ha->isp_ops.prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb;
Andrew Vasquez459c5372005-07-06 10:31:07 -07001322 ha->isp_ops.read_nvram = qla2x00_read_nvram_data;
1323 ha->isp_ops.write_nvram = qla2x00_write_nvram_data;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001324 ha->isp_ops.fw_dump = qla2100_fw_dump;
1325 ha->isp_ops.ascii_fw_dump = qla2100_ascii_fw_dump;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 if (IS_QLA2100(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001327 host->max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1329 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1330 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1331 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1332 host->sg_tablesize = 32;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001333 ha->gid_list_info_size = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 } else if (IS_QLA2200(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001335 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1337 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1338 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1339 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001340 ha->gid_list_info_size = 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001341 } else if (IS_QLA23XX(ha)) {
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001342 host->max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1344 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1345 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1346 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001347 ha->isp_ops.pci_config = qla2300_pci_config;
1348 ha->isp_ops.intr_handler = qla2300_intr_handler;
1349 ha->isp_ops.fw_dump = qla2300_fw_dump;
1350 ha->isp_ops.ascii_fw_dump = qla2300_ascii_fw_dump;
1351 ha->gid_list_info_size = 6;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001352 } else if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1353 host->max_id = MAX_TARGETS_2200;
1354 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1355 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1356 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1357 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1358 ha->init_cb_size = sizeof(struct init_cb_24xx);
Andrew Vasquezcca53352005-08-26 19:08:30 -07001359 ha->mgmt_svr_loop_id = 10;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001360 ha->isp_ops.pci_config = qla24xx_pci_config;
1361 ha->isp_ops.reset_chip = qla24xx_reset_chip;
1362 ha->isp_ops.chip_diag = qla24xx_chip_diag;
1363 ha->isp_ops.config_rings = qla24xx_config_rings;
1364 ha->isp_ops.reset_adapter = qla24xx_reset_adapter;
1365 ha->isp_ops.nvram_config = qla24xx_nvram_config;
1366 ha->isp_ops.update_fw_options = qla24xx_update_fw_options;
1367 ha->isp_ops.load_risc = qla24xx_load_risc_flash;
1368 if (ql2xfwloadbin)
1369 ha->isp_ops.load_risc = qla24xx_load_risc_hotplug;
1370 ha->isp_ops.pci_info_str = qla24xx_pci_info_str;
1371 ha->isp_ops.fw_version_str = qla24xx_fw_version_str;
1372 ha->isp_ops.intr_handler = qla24xx_intr_handler;
1373 ha->isp_ops.enable_intrs = qla24xx_enable_intrs;
1374 ha->isp_ops.disable_intrs = qla24xx_disable_intrs;
1375 ha->isp_ops.abort_command = qla24xx_abort_command;
1376 ha->isp_ops.abort_target = qla24xx_abort_target;
1377 ha->isp_ops.fabric_login = qla24xx_login_fabric;
1378 ha->isp_ops.fabric_logout = qla24xx_fabric_logout;
1379 ha->isp_ops.prep_ms_iocb = qla24xx_prep_ms_iocb;
Andrew Vasquezcca53352005-08-26 19:08:30 -07001380 ha->isp_ops.prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001381 ha->isp_ops.read_nvram = qla24xx_read_nvram_data;
1382 ha->isp_ops.write_nvram = qla24xx_write_nvram_data;
1383 ha->isp_ops.fw_dump = qla24xx_fw_dump;
1384 ha->isp_ops.ascii_fw_dump = qla24xx_ascii_fw_dump;
1385 ha->gid_list_info_size = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 }
1387 host->can_queue = ha->request_q_length + 128;
1388
1389 /* load the F/W, read paramaters, and init the H/W */
1390 ha->instance = num_hosts;
1391
1392 init_MUTEX(&ha->mbx_cmd_sem);
1393 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1394
1395 INIT_LIST_HEAD(&ha->list);
1396 INIT_LIST_HEAD(&ha->fcports);
1397 INIT_LIST_HEAD(&ha->rscn_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
1399 /*
1400 * These locks are used to prevent more than one CPU
1401 * from modifying the queue at the same time. The
1402 * higher level "host_lock" will reduce most
1403 * contention for these locks.
1404 */
1405 spin_lock_init(&ha->mbx_reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 init_completion(&ha->dpc_inited);
1408 init_completion(&ha->dpc_exited);
1409
1410 qla2x00_config_dma_addressing(ha);
1411 if (qla2x00_mem_alloc(ha)) {
1412 qla_printk(KERN_WARNING, ha,
1413 "[ERROR] Failed to allocate memory for adapter\n");
1414
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001415 ret = -ENOMEM;
1416 goto probe_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 }
1418
1419 if (qla2x00_initialize_adapter(ha) &&
1420 !(ha->device_flags & DFLG_NO_CABLE)) {
1421
1422 qla_printk(KERN_WARNING, ha,
1423 "Failed to initialize adapter\n");
1424
1425 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1426 "Adapter flags %x.\n",
1427 ha->host_no, ha->device_flags));
1428
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001429 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 goto probe_failed;
1431 }
1432
1433 /*
1434 * Startup the kernel thread for this host adapter
1435 */
1436 ha->dpc_should_die = 0;
1437 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
1438 if (ha->dpc_pid < 0) {
1439 qla_printk(KERN_WARNING, ha,
1440 "Unable to start DPC thread!\n");
1441
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001442 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 goto probe_failed;
1444 }
1445 wait_for_completion(&ha->dpc_inited);
1446
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001447 host->this_id = 255;
1448 host->cmd_per_lun = 3;
1449 host->unique_id = ha->instance;
1450 host->max_cmd_len = MAX_CMDSZ;
1451 host->max_channel = ha->ports - 1;
1452 host->max_lun = MAX_LUNS;
1453 host->transportt = qla2xxx_transport_template;
1454
Andrew Vasquezfca29702005-07-06 10:31:47 -07001455 ret = request_irq(pdev->irq, ha->isp_ops.intr_handler,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001456 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001457 if (ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 qla_printk(KERN_WARNING, ha,
1459 "Failed to reserve interrupt %d already in use.\n",
Andrew Vasquezfca29702005-07-06 10:31:47 -07001460 pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 goto probe_failed;
1462 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001463 host->irq = pdev->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
1465 /* Initialized the timer */
1466 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1467
1468 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1469 ha->host_no, ha));
1470
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001471 ha->isp_ops.disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001474 reg = ha->iobase;
1475 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1476 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1477 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1478 } else {
1479 WRT_REG_WORD(&reg->isp.semaphore, 0);
1480 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1481 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Andrew Vasquezfca29702005-07-06 10:31:47 -07001483 /* Enable proper parity */
1484 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1485 if (IS_QLA2300(ha))
1486 /* SRAM parity */
1487 WRT_REG_WORD(&reg->isp.hccr,
1488 (HCCR_ENABLE_PARITY + 0x1));
1489 else
1490 /* SRAM, Instruction RAM and GP RAM parity */
1491 WRT_REG_WORD(&reg->isp.hccr,
1492 (HCCR_ENABLE_PARITY + 0x7));
1493 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 }
1495 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1496
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001497 ha->isp_ops.enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
1499 /* v2.19.5b6 */
1500 /*
1501 * Wait around max loop_reset_delay secs for the devices to come
1502 * on-line. We don't want Linux scanning before we are ready.
1503 *
1504 */
1505 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
1506 time_before(jiffies,wait_switch) &&
1507 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
1508 && (ha->device_flags & SWITCH_FOUND) ;) {
1509
1510 qla2x00_check_fabric_devices(ha);
1511
1512 msleep(10);
1513 }
1514
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001515 pci_set_drvdata(pdev, ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 ha->flags.init_done = 1;
1517 num_hosts++;
1518
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001519 ret = scsi_add_host(host, &pdev->dev);
1520 if (ret)
1521 goto probe_failed;
1522
1523 qla2x00_alloc_sysfs_attr(ha);
1524
1525 qla2x00_init_host_attr(ha);
1526
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 qla_printk(KERN_INFO, ha, "\n"
1528 " QLogic Fibre Channel HBA Driver: %s\n"
1529 " QLogic %s - %s\n"
1530 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
1531 ha->model_number, ha->model_desc ? ha->model_desc: "",
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001532 ha->brd_info->isp_name, ha->isp_ops.pci_info_str(ha, pci_info),
Andrew Vasquezfca29702005-07-06 10:31:47 -07001533 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+': '-',
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001534 ha->host_no, ha->isp_ops.fw_version_str(ha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
8482e1182005-04-17 15:04:54 -05001536 /* Go with fc_rport registration. */
1537 list_for_each_entry(fcport, &ha->fcports, list)
1538 qla2x00_reg_remote_port(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
1540 return 0;
1541
1542probe_failed:
1543 qla2x00_free_device(ha);
1544
1545 scsi_host_put(host);
1546
1547probe_disable_device:
1548 pci_disable_device(pdev);
1549
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001550probe_out:
1551 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552}
1553EXPORT_SYMBOL_GPL(qla2x00_probe_one);
1554
1555void qla2x00_remove_one(struct pci_dev *pdev)
1556{
1557 scsi_qla_host_t *ha;
1558
1559 ha = pci_get_drvdata(pdev);
1560
8482e1182005-04-17 15:04:54 -05001561 qla2x00_free_sysfs_attr(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
bdf79622005-04-17 15:06:53 -05001563 fc_remove_host(ha->host);
1564
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 scsi_remove_host(ha->host);
1566
1567 qla2x00_free_device(ha);
1568
1569 scsi_host_put(ha->host);
1570
1571 pci_set_drvdata(pdev, NULL);
1572}
1573EXPORT_SYMBOL_GPL(qla2x00_remove_one);
1574
1575static void
1576qla2x00_free_device(scsi_qla_host_t *ha)
1577{
1578 int ret;
1579
1580 /* Abort any outstanding IO descriptors. */
1581 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1582 qla2x00_cancel_io_descriptors(ha);
1583
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 /* Disable timer */
1585 if (ha->timer_active)
1586 qla2x00_stop_timer(ha);
1587
1588 /* Kill the kernel thread for this host */
1589 if (ha->dpc_pid >= 0) {
1590 ha->dpc_should_die = 1;
1591 wmb();
1592 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
1593 if (ret) {
1594 qla_printk(KERN_ERR, ha,
1595 "Unable to signal DPC thread -- (%d)\n", ret);
1596
1597 /* TODO: SOMETHING MORE??? */
1598 } else {
1599 wait_for_completion(&ha->dpc_exited);
1600 }
1601 }
1602
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001603 /* Stop currently executing firmware. */
1604 qla2x00_stop_firmware(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07001606 /* turn-off interrupts on the card */
1607 if (ha->interrupts_on)
1608 ha->isp_ops.disable_intrs(ha);
1609
1610 qla2x00_mem_free(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 ha->flags.online = 0;
1613
1614 /* Detach interrupts */
1615 if (ha->pdev->irq)
1616 free_irq(ha->pdev->irq, ha);
1617
1618 /* release io space registers */
1619 if (ha->iobase)
1620 iounmap(ha->iobase);
1621 pci_release_regions(ha->pdev);
1622
1623 pci_disable_device(ha->pdev);
1624}
1625
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1628 *
1629 * Input: ha = adapter block pointer. fcport = port structure pointer.
1630 *
1631 * Return: None.
1632 *
1633 * Context:
1634 */
1635void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1636 int do_login)
1637{
8482e1182005-04-17 15:04:54 -05001638 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1639 fc_remote_port_block(fcport->rport);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001640 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 * We may need to retry the login, so don't change the state of the
1642 * port but do the retries.
1643 */
1644 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1645 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1646
1647 if (!do_login)
1648 return;
1649
1650 if (fcport->login_retry == 0) {
1651 fcport->login_retry = ha->login_retry_count;
1652 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1653
1654 DEBUG(printk("scsi(%ld): Port login retry: "
1655 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1656 "id = 0x%04x retry cnt=%d\n",
1657 ha->host_no,
1658 fcport->port_name[0],
1659 fcport->port_name[1],
1660 fcport->port_name[2],
1661 fcport->port_name[3],
1662 fcport->port_name[4],
1663 fcport->port_name[5],
1664 fcport->port_name[6],
1665 fcport->port_name[7],
1666 fcport->loop_id,
1667 fcport->login_retry));
1668 }
1669}
1670
1671/*
1672 * qla2x00_mark_all_devices_lost
1673 * Updates fcport state when device goes offline.
1674 *
1675 * Input:
1676 * ha = adapter block pointer.
1677 * fcport = port structure pointer.
1678 *
1679 * Return:
1680 * None.
1681 *
1682 * Context:
1683 */
1684void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001685qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686{
1687 fc_port_t *fcport;
1688
1689 list_for_each_entry(fcport, &ha->fcports, list) {
1690 if (fcport->port_type != FCT_TARGET)
1691 continue;
1692
1693 /*
1694 * No point in marking the device as lost, if the device is
1695 * already DEAD.
1696 */
1697 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1698 continue;
8482e1182005-04-17 15:04:54 -05001699 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1700 fc_remote_port_block(fcport->rport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1702 }
1703}
1704
1705/*
1706* qla2x00_mem_alloc
1707* Allocates adapter memory.
1708*
1709* Returns:
1710* 0 = success.
1711* 1 = failure.
1712*/
1713static uint8_t
1714qla2x00_mem_alloc(scsi_qla_host_t *ha)
1715{
1716 char name[16];
1717 uint8_t status = 1;
1718 int retry= 10;
1719
1720 do {
1721 /*
1722 * This will loop only once if everything goes well, else some
1723 * number of retries will be performed to get around a kernel
1724 * bug where available mem is not allocated until after a
1725 * little delay and a retry.
1726 */
1727 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
1728 (ha->request_q_length + 1) * sizeof(request_t),
1729 &ha->request_dma, GFP_KERNEL);
1730 if (ha->request_ring == NULL) {
1731 qla_printk(KERN_WARNING, ha,
1732 "Memory Allocation failed - request_ring\n");
1733
1734 qla2x00_mem_free(ha);
1735 msleep(100);
1736
1737 continue;
1738 }
1739
1740 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1741 (ha->response_q_length + 1) * sizeof(response_t),
1742 &ha->response_dma, GFP_KERNEL);
1743 if (ha->response_ring == NULL) {
1744 qla_printk(KERN_WARNING, ha,
1745 "Memory Allocation failed - response_ring\n");
1746
1747 qla2x00_mem_free(ha);
1748 msleep(100);
1749
1750 continue;
1751 }
1752
1753 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1754 &ha->gid_list_dma, GFP_KERNEL);
1755 if (ha->gid_list == NULL) {
1756 qla_printk(KERN_WARNING, ha,
1757 "Memory Allocation failed - gid_list\n");
1758
1759 qla2x00_mem_free(ha);
1760 msleep(100);
1761
1762 continue;
1763 }
1764
1765 ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
1766 sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
1767 if (ha->rlc_rsp == NULL) {
1768 qla_printk(KERN_WARNING, ha,
1769 "Memory Allocation failed - rlc");
1770
1771 qla2x00_mem_free(ha);
1772 msleep(100);
1773
1774 continue;
1775 }
1776
1777 snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
1778 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
1779 DMA_POOL_SIZE, 8, 0);
1780 if (ha->s_dma_pool == NULL) {
1781 qla_printk(KERN_WARNING, ha,
1782 "Memory Allocation failed - s_dma_pool\n");
1783
1784 qla2x00_mem_free(ha);
1785 msleep(100);
1786
1787 continue;
1788 }
1789
1790 /* get consistent memory allocated for init control block */
1791 ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1792 &ha->init_cb_dma);
1793 if (ha->init_cb == NULL) {
1794 qla_printk(KERN_WARNING, ha,
1795 "Memory Allocation failed - init_cb\n");
1796
1797 qla2x00_mem_free(ha);
1798 msleep(100);
1799
1800 continue;
1801 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001802 memset(ha->init_cb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
1804 /* Get consistent memory allocated for Get Port Database cmd */
1805 ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1806 &ha->iodesc_pd_dma);
1807 if (ha->iodesc_pd == NULL) {
1808 /* error */
1809 qla_printk(KERN_WARNING, ha,
1810 "Memory Allocation failed - iodesc_pd\n");
1811
1812 qla2x00_mem_free(ha);
1813 msleep(100);
1814
1815 continue;
1816 }
1817 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
1818
1819 /* Allocate ioctl related memory. */
1820 if (qla2x00_alloc_ioctl_mem(ha)) {
1821 qla_printk(KERN_WARNING, ha,
1822 "Memory Allocation failed - ioctl_mem\n");
1823
1824 qla2x00_mem_free(ha);
1825 msleep(100);
1826
1827 continue;
1828 }
1829
1830 if (qla2x00_allocate_sp_pool(ha)) {
1831 qla_printk(KERN_WARNING, ha,
1832 "Memory Allocation failed - "
1833 "qla2x00_allocate_sp_pool()\n");
1834
1835 qla2x00_mem_free(ha);
1836 msleep(100);
1837
1838 continue;
1839 }
1840
1841 /* Allocate memory for SNS commands */
1842 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1843 /* Get consistent memory allocated for SNS commands */
1844 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
1845 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
1846 GFP_KERNEL);
1847 if (ha->sns_cmd == NULL) {
1848 /* error */
1849 qla_printk(KERN_WARNING, ha,
1850 "Memory Allocation failed - sns_cmd\n");
1851
1852 qla2x00_mem_free(ha);
1853 msleep(100);
1854
1855 continue;
1856 }
1857 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
1858 } else {
1859 /* Get consistent memory allocated for MS IOCB */
1860 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1861 &ha->ms_iocb_dma);
1862 if (ha->ms_iocb == NULL) {
1863 /* error */
1864 qla_printk(KERN_WARNING, ha,
1865 "Memory Allocation failed - ms_iocb\n");
1866
1867 qla2x00_mem_free(ha);
1868 msleep(100);
1869
1870 continue;
1871 }
1872 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
1873
1874 /*
1875 * Get consistent memory allocated for CT SNS
1876 * commands
1877 */
1878 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
1879 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
1880 GFP_KERNEL);
1881 if (ha->ct_sns == NULL) {
1882 /* error */
1883 qla_printk(KERN_WARNING, ha,
1884 "Memory Allocation failed - ct_sns\n");
1885
1886 qla2x00_mem_free(ha);
1887 msleep(100);
1888
1889 continue;
1890 }
1891 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
1892 }
1893
1894 /* Done all allocations without any error. */
1895 status = 0;
1896
1897 } while (retry-- && status != 0);
1898
1899 if (status) {
1900 printk(KERN_WARNING
1901 "%s(): **** FAILED ****\n", __func__);
1902 }
1903
1904 return(status);
1905}
1906
1907/*
1908* qla2x00_mem_free
1909* Frees all adapter allocated memory.
1910*
1911* Input:
1912* ha = adapter block pointer.
1913*/
1914static void
1915qla2x00_mem_free(scsi_qla_host_t *ha)
1916{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 struct list_head *fcpl, *fcptemp;
1918 fc_port_t *fcport;
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001919 unsigned int wtime;/* max wait time if mbx cmd is busy. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
1921 if (ha == NULL) {
1922 /* error */
1923 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
1924 return;
1925 }
1926
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 /* Make sure all other threads are stopped. */
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001928 wtime = 60 * 1000;
1929 while (ha->dpc_wait && wtime)
1930 wtime = msleep_interruptible(wtime);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931
1932 /* free ioctl memory */
1933 qla2x00_free_ioctl_mem(ha);
1934
1935 /* free sp pool */
1936 qla2x00_free_sp_pool(ha);
1937
1938 if (ha->sns_cmd)
1939 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
1940 ha->sns_cmd, ha->sns_cmd_dma);
1941
1942 if (ha->ct_sns)
1943 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
1944 ha->ct_sns, ha->ct_sns_dma);
1945
1946 if (ha->ms_iocb)
1947 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
1948
1949 if (ha->iodesc_pd)
1950 dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
1951
1952 if (ha->init_cb)
1953 dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
1954
1955 if (ha->s_dma_pool)
1956 dma_pool_destroy(ha->s_dma_pool);
1957
1958 if (ha->rlc_rsp)
1959 dma_free_coherent(&ha->pdev->dev,
1960 sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
1961 ha->rlc_rsp_dma);
1962
1963 if (ha->gid_list)
1964 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
1965 ha->gid_list_dma);
1966
1967 if (ha->response_ring)
1968 dma_free_coherent(&ha->pdev->dev,
1969 (ha->response_q_length + 1) * sizeof(response_t),
1970 ha->response_ring, ha->response_dma);
1971
1972 if (ha->request_ring)
1973 dma_free_coherent(&ha->pdev->dev,
1974 (ha->request_q_length + 1) * sizeof(request_t),
1975 ha->request_ring, ha->request_dma);
1976
1977 ha->sns_cmd = NULL;
1978 ha->sns_cmd_dma = 0;
1979 ha->ct_sns = NULL;
1980 ha->ct_sns_dma = 0;
1981 ha->ms_iocb = NULL;
1982 ha->ms_iocb_dma = 0;
1983 ha->iodesc_pd = NULL;
1984 ha->iodesc_pd_dma = 0;
1985 ha->init_cb = NULL;
1986 ha->init_cb_dma = 0;
1987
1988 ha->s_dma_pool = NULL;
1989
1990 ha->rlc_rsp = NULL;
1991 ha->rlc_rsp_dma = 0;
1992 ha->gid_list = NULL;
1993 ha->gid_list_dma = 0;
1994
1995 ha->response_ring = NULL;
1996 ha->response_dma = 0;
1997 ha->request_ring = NULL;
1998 ha->request_dma = 0;
1999
2000 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2001 fcport = list_entry(fcpl, fc_port_t, list);
2002
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 /* fc ports */
2004 list_del_init(&fcport->list);
2005 kfree(fcport);
2006 }
2007 INIT_LIST_HEAD(&ha->fcports);
2008
2009 if (ha->fw_dump)
2010 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
2011
Andrew Vasquezfca29702005-07-06 10:31:47 -07002012 vfree(ha->fw_dump24);
2013
2014 vfree(ha->fw_dump_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015
2016 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002017 ha->fw_dump24 = NULL;
2018 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 ha->fw_dump_reading = 0;
2020 ha->fw_dump_buffer = NULL;
2021}
2022
2023/*
2024 * qla2x00_allocate_sp_pool
2025 * This routine is called during initialization to allocate
2026 * memory for local srb_t.
2027 *
2028 * Input:
2029 * ha = adapter block pointer.
2030 *
2031 * Context:
2032 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002033 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 * Note: Sets the ref_count for non Null sp to one.
2035 */
2036static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002037qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038{
2039 int rval;
2040
2041 rval = QLA_SUCCESS;
2042 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
2043 mempool_free_slab, srb_cachep);
2044 if (ha->srb_mempool == NULL) {
2045 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
2046 rval = QLA_FUNCTION_FAILED;
2047 }
2048 return (rval);
2049}
2050
2051/*
2052 * This routine frees all adapter allocated memory.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002053 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 */
2055static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002056qla2x00_free_sp_pool( scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057{
2058 if (ha->srb_mempool) {
2059 mempool_destroy(ha->srb_mempool);
2060 ha->srb_mempool = NULL;
2061 }
2062}
2063
2064/**************************************************************************
2065* qla2x00_do_dpc
2066* This kernel thread is a task that is schedule by the interrupt handler
2067* to perform the background processing for interrupts.
2068*
2069* Notes:
2070* This task always run in the context of a kernel thread. It
2071* is kick-off by the driver's detect code and starts up
2072* up one per adapter. It immediately goes to sleep and waits for
2073* some fibre event. When either the interrupt handler or
2074* the timer routine detects a event it will one of the task
2075* bits then wake us up.
2076**************************************************************************/
2077static int
2078qla2x00_do_dpc(void *data)
2079{
2080 DECLARE_MUTEX_LOCKED(sem);
2081 scsi_qla_host_t *ha;
2082 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 uint8_t status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 uint16_t next_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
2086 ha = (scsi_qla_host_t *)data;
2087
2088 lock_kernel();
2089
2090 daemonize("%s_dpc", ha->host_str);
2091 allow_signal(SIGHUP);
2092
2093 ha->dpc_wait = &sem;
2094
2095 set_user_nice(current, -20);
2096
2097 unlock_kernel();
2098
2099 complete(&ha->dpc_inited);
2100
2101 while (1) {
2102 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2103
2104 if (down_interruptible(&sem))
2105 break;
2106
2107 if (ha->dpc_should_die)
2108 break;
2109
2110 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2111
2112 /* Initialization not yet finished. Don't do anything yet. */
2113 if (!ha->flags.init_done || ha->dpc_active)
2114 continue;
2115
2116 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2117
2118 ha->dpc_active = 1;
2119
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 ha->dpc_active = 0;
2122 continue;
2123 }
2124
2125 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2126
2127 DEBUG(printk("scsi(%ld): dpc: sched "
2128 "qla2x00_abort_isp ha = %p\n",
2129 ha->host_no, ha));
2130 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2131 &ha->dpc_flags))) {
2132
2133 if (qla2x00_abort_isp(ha)) {
2134 /* failed. retry later */
2135 set_bit(ISP_ABORT_NEEDED,
2136 &ha->dpc_flags);
2137 }
2138 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2139 }
2140 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2141 ha->host_no));
2142 }
2143
2144 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2145 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2146
2147 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2148 ha->host_no));
2149
2150 qla2x00_rst_aen(ha);
2151 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2152 }
2153
2154 /* Retry each device up to login retry count */
2155 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2156 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2157 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2158
2159 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2160 ha->host_no));
2161
2162 next_loopid = 0;
2163 list_for_each_entry(fcport, &ha->fcports, list) {
2164 if (fcport->port_type != FCT_TARGET)
2165 continue;
2166
2167 /*
2168 * If the port is not ONLINE then try to login
2169 * to it if we haven't run out of retries.
2170 */
2171 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2172 fcport->login_retry) {
2173
2174 fcport->login_retry--;
2175 if (fcport->flags & FCF_FABRIC_DEVICE) {
2176 if (fcport->flags &
2177 FCF_TAPE_PRESENT)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002178 ha->isp_ops.fabric_logout(
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002179 ha, fcport->loop_id,
2180 fcport->d_id.b.domain,
2181 fcport->d_id.b.area,
2182 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 status = qla2x00_fabric_login(
2184 ha, fcport, &next_loopid);
2185 } else
2186 status =
2187 qla2x00_local_device_login(
2188 ha, fcport->loop_id);
2189
2190 if (status == QLA_SUCCESS) {
2191 fcport->old_loop_id = fcport->loop_id;
2192
2193 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2194 ha->host_no, fcport->loop_id));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002195
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 fcport->port_login_retry_count =
2197 ha->port_down_retry_count * PORT_RETRY_TIME;
2198 atomic_set(&fcport->state, FCS_ONLINE);
2199 atomic_set(&fcport->port_down_timer,
2200 ha->port_down_retry_count * PORT_RETRY_TIME);
2201
2202 fcport->login_retry = 0;
2203 } else if (status == 1) {
2204 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2205 /* retry the login again */
2206 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2207 ha->host_no,
2208 fcport->login_retry, fcport->loop_id));
2209 } else {
2210 fcport->login_retry = 0;
2211 }
2212 }
2213 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2214 break;
2215 }
2216 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2217 ha->host_no));
2218 }
2219
2220 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
2221 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2222
2223 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
2224 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2225 ha->host_no));
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002226
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2228
2229 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2230 ha->host_no));
2231 }
2232
2233 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2234
2235 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2236 ha->host_no));
2237
2238 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2239 &ha->dpc_flags))) {
2240
2241 qla2x00_loop_resync(ha);
2242
2243 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2244 }
2245
2246 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2247 ha->host_no));
2248 }
2249
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
2251
2252 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2253 ha->host_no));
2254
2255 qla2x00_rescan_fcports(ha);
2256
2257 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2258 "end.\n",
2259 ha->host_no));
2260 }
2261
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 if (!ha->interrupts_on)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002263 ha->isp_ops.enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 ha->dpc_active = 0;
2266 } /* End of while(1) */
2267
2268 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2269
2270 /*
2271 * Make sure that nobody tries to wake us up again.
2272 */
2273 ha->dpc_wait = NULL;
2274 ha->dpc_active = 0;
2275
2276 complete_and_exit(&ha->dpc_exited, 0);
2277}
2278
2279/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280* qla2x00_rst_aen
2281* Processes asynchronous reset.
2282*
2283* Input:
2284* ha = adapter block pointer.
2285*/
2286static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002287qla2x00_rst_aen(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288{
2289 if (ha->flags.online && !ha->flags.reset_active &&
2290 !atomic_read(&ha->loop_down_timer) &&
2291 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2292 do {
2293 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2294
2295 /*
2296 * Issue marker command only when we are going to start
2297 * the I/O.
2298 */
2299 ha->marker_needed = 1;
2300 } while (!atomic_read(&ha->loop_down_timer) &&
2301 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2302 }
2303}
2304
f4f051e2005-04-17 15:02:26 -05002305static void
2306qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2307{
2308 struct scsi_cmnd *cmd = sp->cmd;
2309
2310 if (sp->flags & SRB_DMA_VALID) {
2311 if (cmd->use_sg) {
2312 dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
2313 cmd->use_sg, cmd->sc_data_direction);
2314 } else if (cmd->request_bufflen) {
2315 dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
2316 cmd->request_bufflen, cmd->sc_data_direction);
2317 }
2318 sp->flags &= ~SRB_DMA_VALID;
2319 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002320 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002321}
2322
2323void
2324qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2325{
2326 struct scsi_cmnd *cmd = sp->cmd;
2327
2328 qla2x00_sp_free_dma(ha, sp);
2329
f4f051e2005-04-17 15:02:26 -05002330 mempool_free(sp, ha->srb_mempool);
2331
2332 cmd->scsi_done(cmd);
2333}
bdf79622005-04-17 15:06:53 -05002334
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335/**************************************************************************
2336* qla2x00_timer
2337*
2338* Description:
2339* One second timer
2340*
2341* Context: Interrupt
2342***************************************************************************/
2343static void
2344qla2x00_timer(scsi_qla_host_t *ha)
2345{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 unsigned long cpu_flags = 0;
2347 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 int start_dpc = 0;
2349 int index;
2350 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002351 int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352
2353 /*
2354 * Ports - Port down timer.
2355 *
2356 * Whenever, a port is in the LOST state we start decrementing its port
2357 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002358 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 */
2360 t = 0;
2361 list_for_each_entry(fcport, &ha->fcports, list) {
2362 if (fcport->port_type != FCT_TARGET)
2363 continue;
2364
2365 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2366
2367 if (atomic_read(&fcport->port_down_timer) == 0)
2368 continue;
2369
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002370 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002372
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002374 "%d remaining\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 ha->host_no,
2376 t, atomic_read(&fcport->port_down_timer)));
2377 }
2378 t++;
2379 } /* End of for fcport */
2380
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
2382 /* Loop down handler. */
2383 if (atomic_read(&ha->loop_down_timer) > 0 &&
2384 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2385
2386 if (atomic_read(&ha->loop_down_timer) ==
2387 ha->loop_down_abort_time) {
2388
2389 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2390 "queues before time expire\n",
2391 ha->host_no));
2392
2393 if (!IS_QLA2100(ha) && ha->link_down_timeout)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002394 atomic_set(&ha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395
2396 /* Schedule an ISP abort to return any tape commands. */
2397 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
2398 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
2399 index++) {
bdf79622005-04-17 15:06:53 -05002400 fc_port_t *sfcp;
2401
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 sp = ha->outstanding_cmds[index];
2403 if (!sp)
2404 continue;
bdf79622005-04-17 15:06:53 -05002405 sfcp = sp->fcport;
2406 if (!(sfcp->flags & FCF_TAPE_PRESENT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 continue;
2408
2409 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2410 break;
2411 }
2412 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
2413
2414 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2415 start_dpc++;
2416 }
2417
2418 /* if the loop has been down for 4 minutes, reinit adapter */
2419 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2420 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2421 "restarting queues.\n",
2422 ha->host_no));
2423
2424 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2425 start_dpc++;
2426
2427 if (!(ha->device_flags & DFLG_NO_CABLE)) {
2428 DEBUG(printk("scsi(%ld): Loop down - "
2429 "aborting ISP.\n",
2430 ha->host_no));
2431 qla_printk(KERN_WARNING, ha,
2432 "Loop down - aborting ISP.\n");
2433
2434 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2435 }
2436 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002437 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 ha->host_no,
2439 atomic_read(&ha->loop_down_timer)));
2440 }
2441
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 /* Schedule the DPC routine if needed */
2443 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2444 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
2445 start_dpc ||
2446 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
f4f051e2005-04-17 15:02:26 -05002447 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2449 ha->dpc_wait && !ha->dpc_active) {
2450
2451 up(ha->dpc_wait);
2452 }
2453
2454 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2455}
2456
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457/* XXX(hch): crude hack to emulate a down_timeout() */
2458int
2459qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
2460{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07002461 const unsigned int step = 100; /* msecs */
2462 unsigned int iterations = jiffies_to_msecs(timeout)/100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463
2464 do {
2465 if (!down_trylock(sema))
2466 return 0;
Andrew Vasquezfe74c712005-08-26 19:10:10 -07002467 if (msleep_interruptible(step))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 break;
Andrew Vasquezfe74c712005-08-26 19:10:10 -07002469 } while (--iterations >= 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470
2471 return -ETIMEDOUT;
2472}
2473
Andrew Vasquezfca29702005-07-06 10:31:47 -07002474static struct qla_board_info qla_board_tbl[] = {
2475 {
2476 .drv_name = "qla2400",
2477 .isp_name = "ISP2422",
2478 .fw_fname = "ql2400_fw.bin",
2479 .sht = &qla24xx_driver_template,
2480 },
2481 {
2482 .drv_name = "qla2400",
2483 .isp_name = "ISP2432",
2484 .fw_fname = "ql2400_fw.bin",
2485 .sht = &qla24xx_driver_template,
2486 },
2487};
2488
2489static struct pci_device_id qla2xxx_pci_tbl[] = {
2490 {
2491 .vendor = PCI_VENDOR_ID_QLOGIC,
2492 .device = PCI_DEVICE_ID_QLOGIC_ISP2422,
2493 .subvendor = PCI_ANY_ID,
2494 .subdevice = PCI_ANY_ID,
2495 .driver_data = (unsigned long)&qla_board_tbl[0],
2496 },
2497 {
2498 .vendor = PCI_VENDOR_ID_QLOGIC,
2499 .device = PCI_DEVICE_ID_QLOGIC_ISP2432,
2500 .subvendor = PCI_ANY_ID,
2501 .subdevice = PCI_ANY_ID,
2502 .driver_data = (unsigned long)&qla_board_tbl[1],
2503 },
2504 {0, 0},
2505};
2506MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2507
2508static int __devinit
2509qla2xxx_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2510{
2511 return qla2x00_probe_one(pdev,
2512 (struct qla_board_info *)id->driver_data);
2513}
2514
2515static void __devexit
2516qla2xxx_remove_one(struct pci_dev *pdev)
2517{
2518 qla2x00_remove_one(pdev);
2519}
2520
2521static struct pci_driver qla2xxx_pci_driver = {
2522 .name = "qla2xxx",
2523 .id_table = qla2xxx_pci_tbl,
2524 .probe = qla2xxx_probe_one,
2525 .remove = __devexit_p(qla2xxx_remove_one),
2526};
2527
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528/**
2529 * qla2x00_module_init - Module initialization.
2530 **/
2531static int __init
2532qla2x00_module_init(void)
2533{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002534 int ret = 0;
2535
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002537 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 SLAB_HWCACHE_ALIGN, NULL, NULL);
2539 if (srb_cachep == NULL) {
2540 printk(KERN_ERR
2541 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2542 return -ENOMEM;
2543 }
2544
2545 /* Derive version string. */
2546 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
2547#if DEBUG_QLA2100
2548 strcat(qla2x00_version_str, "-debug");
2549#endif
Andrew Vasquez1c97a122005-04-21 16:13:36 -04002550 qla2xxx_transport_template =
2551 fc_attach_transport(&qla2xxx_transport_functions);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 if (!qla2xxx_transport_template)
2553 return -ENODEV;
2554
2555 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
Andrew Vasquezfca29702005-07-06 10:31:47 -07002556 ret = pci_module_init(&qla2xxx_pci_driver);
2557 if (ret) {
2558 kmem_cache_destroy(srb_cachep);
2559 fc_release_transport(qla2xxx_transport_template);
2560 }
2561 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562}
2563
2564/**
2565 * qla2x00_module_exit - Module cleanup.
2566 **/
2567static void __exit
2568qla2x00_module_exit(void)
2569{
Andrew Vasquezfca29702005-07-06 10:31:47 -07002570 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002571 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 fc_release_transport(qla2xxx_transport_template);
2573}
2574
2575module_init(qla2x00_module_init);
2576module_exit(qla2x00_module_exit);
2577
2578MODULE_AUTHOR("QLogic Corporation");
2579MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2580MODULE_LICENSE("GPL");
2581MODULE_VERSION(QLA2XXX_VERSION);