blob: 10a233e65bc9f885e846607127d3b99a224c62b7 [file] [log] [blame]
David Somayajuluafaf5a22006-09-19 10:28:00 -07001/*
2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2006 QLogic Corporation
4 *
5 * See LICENSE.qla4xxx for copyright and licensing details.
6 */
7#include <linux/moduleparam.h>
8
9#include <scsi/scsi_tcq.h>
10#include <scsi/scsicam.h>
11
12#include "ql4_def.h"
David C Somayajulubee4fe82007-05-23 18:03:32 -070013#include "ql4_version.h"
14#include "ql4_glbl.h"
15#include "ql4_dbg.h"
16#include "ql4_inline.h"
David Somayajuluafaf5a22006-09-19 10:28:00 -070017
18/*
19 * Driver version
20 */
Adrian Bunk47975472007-04-26 00:35:16 -070021static char qla4xxx_version_str[40];
David Somayajuluafaf5a22006-09-19 10:28:00 -070022
23/*
24 * SRB allocation cache
25 */
Christoph Lametere18b8902006-12-06 20:33:20 -080026static struct kmem_cache *srb_cachep;
David Somayajuluafaf5a22006-09-19 10:28:00 -070027
28/*
29 * Module parameter information and variables
30 */
31int ql4xdiscoverywait = 60;
32module_param(ql4xdiscoverywait, int, S_IRUGO | S_IRUSR);
33MODULE_PARM_DESC(ql4xdiscoverywait, "Discovery wait time");
34int ql4xdontresethba = 0;
35module_param(ql4xdontresethba, int, S_IRUGO | S_IRUSR);
36MODULE_PARM_DESC(ql4xdontresethba,
37 "Dont reset the HBA when the driver gets 0x8002 AEN "
38 " default it will reset hba :0"
39 " set to 1 to avoid resetting HBA");
40
Andrew Vasquez11010fe2006-10-06 09:54:59 -070041int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */
42module_param(ql4xextended_error_logging, int, S_IRUGO | S_IRUSR);
43MODULE_PARM_DESC(ql4xextended_error_logging,
David Somayajuluafaf5a22006-09-19 10:28:00 -070044 "Option to enable extended error logging, "
45 "Default is 0 - no logging, 1 - debug logging");
46
David C Somayajulu477ffb92007-01-22 12:26:11 -080047int ql4_mod_unload = 0;
48
David Somayajuluafaf5a22006-09-19 10:28:00 -070049/*
50 * SCSI host template entry points
51 */
Adrian Bunk47975472007-04-26 00:35:16 -070052static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -070053
54/*
55 * iSCSI template entry points
56 */
Mike Christie2174a042007-05-30 12:57:10 -050057static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
58 enum iscsi_tgt_dscvr type, uint32_t enable,
59 struct sockaddr *dst_addr);
David Somayajuluafaf5a22006-09-19 10:28:00 -070060static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
61 enum iscsi_param param, char *buf);
62static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
63 enum iscsi_param param, char *buf);
Mike Christieaa1e93a2007-05-30 12:57:09 -050064static int qla4xxx_host_get_param(struct Scsi_Host *shost,
65 enum iscsi_host_param param, char *buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -070066static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session);
67
68/*
69 * SCSI host template entry points
70 */
71static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
72 void (*done) (struct scsi_cmnd *));
73static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
74static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
75static int qla4xxx_slave_alloc(struct scsi_device *device);
76static int qla4xxx_slave_configure(struct scsi_device *device);
77static void qla4xxx_slave_destroy(struct scsi_device *sdev);
78
79static struct scsi_host_template qla4xxx_driver_template = {
80 .module = THIS_MODULE,
81 .name = DRIVER_NAME,
82 .proc_name = DRIVER_NAME,
83 .queuecommand = qla4xxx_queuecommand,
84
85 .eh_device_reset_handler = qla4xxx_eh_device_reset,
86 .eh_host_reset_handler = qla4xxx_eh_host_reset,
87
88 .slave_configure = qla4xxx_slave_configure,
89 .slave_alloc = qla4xxx_slave_alloc,
90 .slave_destroy = qla4xxx_slave_destroy,
91
Mike Christie921601b2008-01-31 13:36:49 -060092 .scan_finished = iscsi_scan_finished,
93
David Somayajuluafaf5a22006-09-19 10:28:00 -070094 .this_id = -1,
95 .cmd_per_lun = 3,
96 .use_clustering = ENABLE_CLUSTERING,
97 .sg_tablesize = SG_ALL,
98
99 .max_sectors = 0xFFFF,
100};
101
102static struct iscsi_transport qla4xxx_iscsi_transport = {
103 .owner = THIS_MODULE,
104 .name = DRIVER_NAME,
Mike Christied8196ed2007-05-30 12:57:25 -0500105 .caps = CAP_FW_DB | CAP_SENDTARGETS_OFFLOAD |
106 CAP_DATA_PATH_OFFLOAD,
Mike Christieaa1e93a2007-05-30 12:57:09 -0500107 .param_mask = ISCSI_CONN_PORT | ISCSI_CONN_ADDRESS |
108 ISCSI_TARGET_NAME | ISCSI_TPGT,
Mike Christie8ad57812007-05-30 12:57:13 -0500109 .host_param_mask = ISCSI_HOST_HWADDRESS |
Mike Christie22236962007-05-30 12:57:24 -0500110 ISCSI_HOST_IPADDRESS |
Mike Christie8ad57812007-05-30 12:57:13 -0500111 ISCSI_HOST_INITIATOR_NAME,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700112 .sessiondata_size = sizeof(struct ddb_entry),
113 .host_template = &qla4xxx_driver_template,
114
115 .tgt_dscvr = qla4xxx_tgt_dscvr,
116 .get_conn_param = qla4xxx_conn_get_param,
117 .get_session_param = qla4xxx_sess_get_param,
Mike Christieaa1e93a2007-05-30 12:57:09 -0500118 .get_host_param = qla4xxx_host_get_param,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700119 .session_recovery_timedout = qla4xxx_recovery_timedout,
120};
121
122static struct scsi_transport_template *qla4xxx_scsi_transport;
123
124static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
125{
126 struct ddb_entry *ddb_entry = session->dd_data;
127 struct scsi_qla_host *ha = ddb_entry->ha;
128
Mike Christie568d3032008-01-31 13:36:47 -0600129 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
130 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700131
Mike Christie568d3032008-01-31 13:36:47 -0600132 DEBUG2(printk("scsi%ld: %s: index [%d] port down retry count "
133 "of (%d) secs exhausted, marking device DEAD.\n",
134 ha->host_no, __func__, ddb_entry->fw_ddb_index,
135 ha->port_down_retry_count));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700136
Mike Christie568d3032008-01-31 13:36:47 -0600137 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine - dpc "
138 "flags = 0x%lx\n",
139 ha->host_no, __func__, ha->dpc_flags));
140 queue_work(ha->dpc_thread, &ha->dpc_work);
141 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700142}
143
Mike Christieaa1e93a2007-05-30 12:57:09 -0500144static int qla4xxx_host_get_param(struct Scsi_Host *shost,
145 enum iscsi_host_param param, char *buf)
146{
147 struct scsi_qla_host *ha = to_qla_host(shost);
148 int len;
149
150 switch (param) {
151 case ISCSI_HOST_PARAM_HWADDRESS:
Michael Chan7ffc49a2007-12-24 21:28:09 -0800152 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
Mike Christieaa1e93a2007-05-30 12:57:09 -0500153 break;
Mike Christie22236962007-05-30 12:57:24 -0500154 case ISCSI_HOST_PARAM_IPADDRESS:
155 len = sprintf(buf, "%d.%d.%d.%d\n", ha->ip_address[0],
156 ha->ip_address[1], ha->ip_address[2],
157 ha->ip_address[3]);
158 break;
Mike Christie8ad57812007-05-30 12:57:13 -0500159 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Mike Christie22236962007-05-30 12:57:24 -0500160 len = sprintf(buf, "%s\n", ha->name_string);
Mike Christie8ad57812007-05-30 12:57:13 -0500161 break;
Mike Christieaa1e93a2007-05-30 12:57:09 -0500162 default:
163 return -ENOSYS;
164 }
165
166 return len;
167}
168
David Somayajuluafaf5a22006-09-19 10:28:00 -0700169static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
170 enum iscsi_param param, char *buf)
171{
172 struct ddb_entry *ddb_entry = sess->dd_data;
173 int len;
174
175 switch (param) {
176 case ISCSI_PARAM_TARGET_NAME:
177 len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
178 ddb_entry->iscsi_name);
179 break;
180 case ISCSI_PARAM_TPGT:
181 len = sprintf(buf, "%u\n", ddb_entry->tpgt);
182 break;
183 default:
184 return -ENOSYS;
185 }
186
187 return len;
188}
189
190static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
191 enum iscsi_param param, char *buf)
192{
193 struct iscsi_cls_session *session;
194 struct ddb_entry *ddb_entry;
195 int len;
196
197 session = iscsi_dev_to_session(conn->dev.parent);
198 ddb_entry = session->dd_data;
199
200 switch (param) {
201 case ISCSI_PARAM_CONN_PORT:
202 len = sprintf(buf, "%hu\n", ddb_entry->port);
203 break;
204 case ISCSI_PARAM_CONN_ADDRESS:
205 /* TODO: what are the ipv6 bits */
206 len = sprintf(buf, "%u.%u.%u.%u\n",
207 NIPQUAD(ddb_entry->ip_addr));
208 break;
209 default:
210 return -ENOSYS;
211 }
212
213 return len;
214}
215
Mike Christie2174a042007-05-30 12:57:10 -0500216static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
217 enum iscsi_tgt_dscvr type, uint32_t enable,
218 struct sockaddr *dst_addr)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700219{
220 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700221 struct sockaddr_in *addr;
222 struct sockaddr_in6 *addr6;
223 int ret = 0;
224
David Somayajuluafaf5a22006-09-19 10:28:00 -0700225 ha = (struct scsi_qla_host *) shost->hostdata;
226
227 switch (type) {
228 case ISCSI_TGT_DSCVR_SEND_TARGETS:
229 if (dst_addr->sa_family == AF_INET) {
230 addr = (struct sockaddr_in *)dst_addr;
231 if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr,
232 addr->sin_port) != QLA_SUCCESS)
233 ret = -EIO;
234 } else if (dst_addr->sa_family == AF_INET6) {
235 /*
236 * TODO: fix qla4xxx_send_tgts
237 */
238 addr6 = (struct sockaddr_in6 *)dst_addr;
239 if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr,
240 addr6->sin6_port) != QLA_SUCCESS)
241 ret = -EIO;
242 } else
243 ret = -ENOSYS;
244 break;
245 default:
246 ret = -ENOSYS;
247 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700248 return ret;
249}
250
251void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry)
252{
253 if (!ddb_entry->sess)
254 return;
255
256 if (ddb_entry->conn) {
Mike Christie26974782007-12-13 12:43:29 -0600257 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700258 iscsi_remove_session(ddb_entry->sess);
259 }
260 iscsi_free_session(ddb_entry->sess);
261}
262
263int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
264{
265 int err;
266
Mike Christie26974782007-12-13 12:43:29 -0600267 ddb_entry->sess->recovery_tmo = ddb_entry->ha->port_down_retry_count;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700268 err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
269 if (err) {
270 DEBUG2(printk(KERN_ERR "Could not add session.\n"));
271 return err;
272 }
273
274 ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0);
275 if (!ddb_entry->conn) {
276 iscsi_remove_session(ddb_entry->sess);
277 DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
278 return -ENOMEM;
279 }
Mike Christieb6359302008-01-31 13:36:44 -0600280
281 /* finally ready to go */
282 iscsi_unblock_session(ddb_entry->sess);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700283 return 0;
284}
285
286struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha)
287{
288 struct ddb_entry *ddb_entry;
289 struct iscsi_cls_session *sess;
290
291 sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport);
292 if (!sess)
293 return NULL;
294
295 ddb_entry = sess->dd_data;
296 memset(ddb_entry, 0, sizeof(*ddb_entry));
297 ddb_entry->ha = ha;
298 ddb_entry->sess = sess;
299 return ddb_entry;
300}
301
302/*
303 * Timer routines
304 */
305
306static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
307 unsigned long interval)
308{
309 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
310 __func__, ha->host->host_no));
311 init_timer(&ha->timer);
312 ha->timer.expires = jiffies + interval * HZ;
313 ha->timer.data = (unsigned long)ha;
314 ha->timer.function = (void (*)(unsigned long))func;
315 add_timer(&ha->timer);
316 ha->timer_active = 1;
317}
318
319static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
320{
321 del_timer_sync(&ha->timer);
322 ha->timer_active = 0;
323}
324
325/***
326 * qla4xxx_mark_device_missing - mark a device as missing.
327 * @ha: Pointer to host adapter structure.
328 * @ddb_entry: Pointer to device database entry
329 *
330 * This routine marks a device missing and resets the relogin retry count.
331 **/
332void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
333 struct ddb_entry *ddb_entry)
334{
335 atomic_set(&ddb_entry->state, DDB_STATE_MISSING);
336 DEBUG3(printk("scsi%d:%d:%d: index [%d] marked MISSING\n",
337 ha->host_no, ddb_entry->bus, ddb_entry->target,
338 ddb_entry->fw_ddb_index));
Mike Christieb6359302008-01-31 13:36:44 -0600339 iscsi_block_session(ddb_entry->sess);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700340 iscsi_conn_error(ddb_entry->conn, ISCSI_ERR_CONN_FAILED);
341}
342
343static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
344 struct ddb_entry *ddb_entry,
345 struct scsi_cmnd *cmd,
346 void (*done)(struct scsi_cmnd *))
347{
348 struct srb *srb;
349
350 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
351 if (!srb)
352 return srb;
353
354 atomic_set(&srb->ref_count, 1);
355 srb->ha = ha;
356 srb->ddb = ddb_entry;
357 srb->cmd = cmd;
358 srb->flags = 0;
359 cmd->SCp.ptr = (void *)srb;
360 cmd->scsi_done = done;
361
362 return srb;
363}
364
365static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
366{
367 struct scsi_cmnd *cmd = srb->cmd;
368
369 if (srb->flags & SRB_DMA_VALID) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900370 scsi_dma_unmap(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700371 srb->flags &= ~SRB_DMA_VALID;
372 }
373 cmd->SCp.ptr = NULL;
374}
375
376void qla4xxx_srb_compl(struct scsi_qla_host *ha, struct srb *srb)
377{
378 struct scsi_cmnd *cmd = srb->cmd;
379
380 qla4xxx_srb_free_dma(ha, srb);
381
382 mempool_free(srb, ha->srb_mempool);
383
384 cmd->scsi_done(cmd);
385}
386
387/**
388 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
389 * @cmd: Pointer to Linux's SCSI command structure
390 * @done_fn: Function that the driver calls to notify the SCSI mid-layer
391 * that the command has been processed.
392 *
393 * Remarks:
394 * This routine is invoked by Linux to send a SCSI command to the driver.
395 * The mid-level driver tries to ensure that queuecommand never gets
396 * invoked concurrently with itself or the interrupt handler (although
397 * the interrupt handler may call this routine as part of request-
398 * completion handling). Unfortunely, it sometimes calls the scheduler
399 * in interrupt context which is a big NO! NO!.
400 **/
401static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
402 void (*done)(struct scsi_cmnd *))
403{
404 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
405 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christie7fb19212008-01-31 13:36:45 -0600406 struct iscsi_cls_session *sess = ddb_entry->sess;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700407 struct srb *srb;
408 int rval;
409
Mike Christie7fb19212008-01-31 13:36:45 -0600410 if (!sess) {
411 cmd->result = DID_IMM_RETRY << 16;
412 goto qc_fail_command;
413 }
414
415 rval = iscsi_session_chkready(sess);
416 if (rval) {
417 cmd->result = rval;
418 goto qc_fail_command;
419 }
420
David Somayajuluafaf5a22006-09-19 10:28:00 -0700421 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
422 if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) {
423 cmd->result = DID_NO_CONNECT << 16;
424 goto qc_fail_command;
425 }
426 goto qc_host_busy;
427 }
428
David C Somayajulu477ffb92007-01-22 12:26:11 -0800429 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags))
430 goto qc_host_busy;
431
David Somayajuluafaf5a22006-09-19 10:28:00 -0700432 spin_unlock_irq(ha->host->host_lock);
433
434 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd, done);
435 if (!srb)
436 goto qc_host_busy_lock;
437
438 rval = qla4xxx_send_command_to_isp(ha, srb);
439 if (rval != QLA_SUCCESS)
440 goto qc_host_busy_free_sp;
441
442 spin_lock_irq(ha->host->host_lock);
443 return 0;
444
445qc_host_busy_free_sp:
446 qla4xxx_srb_free_dma(ha, srb);
447 mempool_free(srb, ha->srb_mempool);
448
449qc_host_busy_lock:
450 spin_lock_irq(ha->host->host_lock);
451
452qc_host_busy:
453 return SCSI_MLQUEUE_HOST_BUSY;
454
455qc_fail_command:
456 done(cmd);
457
458 return 0;
459}
460
461/**
462 * qla4xxx_mem_free - frees memory allocated to adapter
463 * @ha: Pointer to host adapter structure.
464 *
465 * Frees memory previously allocated by qla4xxx_mem_alloc
466 **/
467static void qla4xxx_mem_free(struct scsi_qla_host *ha)
468{
469 if (ha->queues)
470 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
471 ha->queues_dma);
472
473 ha->queues_len = 0;
474 ha->queues = NULL;
475 ha->queues_dma = 0;
476 ha->request_ring = NULL;
477 ha->request_dma = 0;
478 ha->response_ring = NULL;
479 ha->response_dma = 0;
480 ha->shadow_regs = NULL;
481 ha->shadow_regs_dma = 0;
482
483 /* Free srb pool. */
484 if (ha->srb_mempool)
485 mempool_destroy(ha->srb_mempool);
486
487 ha->srb_mempool = NULL;
488
489 /* release io space registers */
490 if (ha->reg)
491 iounmap(ha->reg);
492 pci_release_regions(ha->pdev);
493}
494
495/**
496 * qla4xxx_mem_alloc - allocates memory for use by adapter.
497 * @ha: Pointer to host adapter structure
498 *
499 * Allocates DMA memory for request and response queues. Also allocates memory
500 * for srbs.
501 **/
502static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
503{
504 unsigned long align;
505
506 /* Allocate contiguous block of DMA memory for queues. */
507 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
508 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
509 sizeof(struct shadow_regs) +
510 MEM_ALIGN_VALUE +
511 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
512 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
513 &ha->queues_dma, GFP_KERNEL);
514 if (ha->queues == NULL) {
515 dev_warn(&ha->pdev->dev,
516 "Memory Allocation failed - queues.\n");
517
518 goto mem_alloc_error_exit;
519 }
520 memset(ha->queues, 0, ha->queues_len);
521
522 /*
523 * As per RISC alignment requirements -- the bus-address must be a
524 * multiple of the request-ring size (in bytes).
525 */
526 align = 0;
527 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
528 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
529 (MEM_ALIGN_VALUE - 1));
530
531 /* Update request and response queue pointers. */
532 ha->request_dma = ha->queues_dma + align;
533 ha->request_ring = (struct queue_entry *) (ha->queues + align);
534 ha->response_dma = ha->queues_dma + align +
535 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
536 ha->response_ring = (struct queue_entry *) (ha->queues + align +
537 (REQUEST_QUEUE_DEPTH *
538 QUEUE_SIZE));
539 ha->shadow_regs_dma = ha->queues_dma + align +
540 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
541 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
542 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
543 (REQUEST_QUEUE_DEPTH *
544 QUEUE_SIZE) +
545 (RESPONSE_QUEUE_DEPTH *
546 QUEUE_SIZE));
547
548 /* Allocate memory for srb pool. */
549 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
550 mempool_free_slab, srb_cachep);
551 if (ha->srb_mempool == NULL) {
552 dev_warn(&ha->pdev->dev,
553 "Memory Allocation failed - SRB Pool.\n");
554
555 goto mem_alloc_error_exit;
556 }
557
558 return QLA_SUCCESS;
559
560mem_alloc_error_exit:
561 qla4xxx_mem_free(ha);
562 return QLA_ERROR;
563}
564
565/**
566 * qla4xxx_timer - checks every second for work to do.
567 * @ha: Pointer to host adapter structure.
568 **/
569static void qla4xxx_timer(struct scsi_qla_host *ha)
570{
571 struct ddb_entry *ddb_entry, *dtemp;
572 int start_dpc = 0;
573
574 /* Search for relogin's to time-out and port down retry. */
575 list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
576 /* Count down time between sending relogins */
577 if (adapter_up(ha) &&
578 !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
579 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
580 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
581 INVALID_ENTRY) {
582 if (atomic_read(&ddb_entry->retry_relogin_timer)
583 == 0) {
584 atomic_set(&ddb_entry->
585 retry_relogin_timer,
586 INVALID_ENTRY);
587 set_bit(DPC_RELOGIN_DEVICE,
588 &ha->dpc_flags);
589 set_bit(DF_RELOGIN, &ddb_entry->flags);
590 DEBUG2(printk("scsi%ld: %s: index [%d]"
591 " login device\n",
592 ha->host_no, __func__,
593 ddb_entry->fw_ddb_index));
594 } else
595 atomic_dec(&ddb_entry->
596 retry_relogin_timer);
597 }
598 }
599
600 /* Wait for relogin to timeout */
601 if (atomic_read(&ddb_entry->relogin_timer) &&
602 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
603 /*
604 * If the relogin times out and the device is
605 * still NOT ONLINE then try and relogin again.
606 */
607 if (atomic_read(&ddb_entry->state) !=
608 DDB_STATE_ONLINE &&
609 ddb_entry->fw_ddb_device_state ==
610 DDB_DS_SESSION_FAILED) {
611 /* Reset retry relogin timer */
612 atomic_inc(&ddb_entry->relogin_retry_count);
613 DEBUG2(printk("scsi%ld: index[%d] relogin"
614 " timed out-retrying"
615 " relogin (%d)\n",
616 ha->host_no,
617 ddb_entry->fw_ddb_index,
618 atomic_read(&ddb_entry->
619 relogin_retry_count))
620 );
621 start_dpc++;
622 DEBUG(printk("scsi%ld:%d:%d: index [%d] "
623 "initate relogin after"
624 " %d seconds\n",
625 ha->host_no, ddb_entry->bus,
626 ddb_entry->target,
627 ddb_entry->fw_ddb_index,
628 ddb_entry->default_time2wait + 4)
629 );
630
631 atomic_set(&ddb_entry->retry_relogin_timer,
632 ddb_entry->default_time2wait + 4);
633 }
634 }
635 }
636
637 /* Check for heartbeat interval. */
638 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
639 ha->heartbeat_interval != 0) {
640 ha->seconds_since_last_heartbeat++;
641 if (ha->seconds_since_last_heartbeat >
642 ha->heartbeat_interval + 2)
643 set_bit(DPC_RESET_HA, &ha->dpc_flags);
644 }
645
646
647 /* Wakeup the dpc routine for this adapter, if needed. */
648 if ((start_dpc ||
649 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
650 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
651 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
652 test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags) ||
653 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
654 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
655 test_bit(DPC_AEN, &ha->dpc_flags)) &&
656 ha->dpc_thread) {
657 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
658 " - dpc flags = 0x%lx\n",
659 ha->host_no, __func__, ha->dpc_flags));
660 queue_work(ha->dpc_thread, &ha->dpc_work);
661 }
662
663 /* Reschedule timer thread to call us back in one second */
664 mod_timer(&ha->timer, jiffies + HZ);
665
666 DEBUG2(ha->seconds_since_last_intr++);
667}
668
669/**
670 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
671 * @ha: Pointer to host adapter structure.
672 *
673 * This routine stalls the driver until all outstanding commands are returned.
674 * Caller must release the Hardware Lock prior to calling this routine.
675 **/
676static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
677{
678 uint32_t index = 0;
679 int stat = QLA_SUCCESS;
680 unsigned long flags;
681 struct scsi_cmnd *cmd;
682 int wait_cnt = WAIT_CMD_TOV; /*
683 * Initialized for 30 seconds as we
684 * expect all commands to retuned
685 * ASAP.
686 */
687
688 while (wait_cnt) {
689 spin_lock_irqsave(&ha->hardware_lock, flags);
690 /* Find a command that hasn't completed. */
691 for (index = 0; index < ha->host->can_queue; index++) {
692 cmd = scsi_host_find_tag(ha->host, index);
693 if (cmd != NULL)
694 break;
695 }
696 spin_unlock_irqrestore(&ha->hardware_lock, flags);
697
698 /* If No Commands are pending, wait is complete */
699 if (index == ha->host->can_queue) {
700 break;
701 }
702
703 /* If we timed out on waiting for commands to come back
704 * return ERROR.
705 */
706 wait_cnt--;
707 if (wait_cnt == 0)
708 stat = QLA_ERROR;
709 else {
710 msleep(1000);
711 }
712 } /* End of While (wait_cnt) */
713
714 return stat;
715}
716
David C Somayajulubee4fe82007-05-23 18:03:32 -0700717void qla4xxx_hw_reset(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700718{
David Somayajuluafaf5a22006-09-19 10:28:00 -0700719 uint32_t ctrl_status;
David C Somayajulu477ffb92007-01-22 12:26:11 -0800720 unsigned long flags = 0;
721
722 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700723
724 spin_lock_irqsave(&ha->hardware_lock, flags);
725
726 /*
727 * If the SCSI Reset Interrupt bit is set, clear it.
728 * Otherwise, the Soft Reset won't work.
729 */
730 ctrl_status = readw(&ha->reg->ctrl_status);
731 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
732 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
733
734 /* Issue Soft Reset */
735 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
736 readl(&ha->reg->ctrl_status);
737
738 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David C Somayajulu477ffb92007-01-22 12:26:11 -0800739}
740
741/**
742 * qla4xxx_soft_reset - performs soft reset.
743 * @ha: Pointer to host adapter structure.
744 **/
745int qla4xxx_soft_reset(struct scsi_qla_host *ha)
746{
747 uint32_t max_wait_time;
748 unsigned long flags = 0;
749 int status = QLA_ERROR;
750 uint32_t ctrl_status;
751
752 qla4xxx_hw_reset(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700753
754 /* Wait until the Network Reset Intr bit is cleared */
755 max_wait_time = RESET_INTR_TOV;
756 do {
757 spin_lock_irqsave(&ha->hardware_lock, flags);
758 ctrl_status = readw(&ha->reg->ctrl_status);
759 spin_unlock_irqrestore(&ha->hardware_lock, flags);
760
761 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
762 break;
763
764 msleep(1000);
765 } while ((--max_wait_time));
766
767 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
768 DEBUG2(printk(KERN_WARNING
769 "scsi%ld: Network Reset Intr not cleared by "
770 "Network function, clearing it now!\n",
771 ha->host_no));
772 spin_lock_irqsave(&ha->hardware_lock, flags);
773 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
774 readl(&ha->reg->ctrl_status);
775 spin_unlock_irqrestore(&ha->hardware_lock, flags);
776 }
777
778 /* Wait until the firmware tells us the Soft Reset is done */
779 max_wait_time = SOFT_RESET_TOV;
780 do {
781 spin_lock_irqsave(&ha->hardware_lock, flags);
782 ctrl_status = readw(&ha->reg->ctrl_status);
783 spin_unlock_irqrestore(&ha->hardware_lock, flags);
784
785 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
786 status = QLA_SUCCESS;
787 break;
788 }
789
790 msleep(1000);
791 } while ((--max_wait_time));
792
793 /*
794 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
795 * after the soft reset has taken place.
796 */
797 spin_lock_irqsave(&ha->hardware_lock, flags);
798 ctrl_status = readw(&ha->reg->ctrl_status);
799 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
800 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
801 readl(&ha->reg->ctrl_status);
802 }
803 spin_unlock_irqrestore(&ha->hardware_lock, flags);
804
805 /* If soft reset fails then most probably the bios on other
806 * function is also enabled.
807 * Since the initialization is sequential the other fn
808 * wont be able to acknowledge the soft reset.
809 * Issue a force soft reset to workaround this scenario.
810 */
811 if (max_wait_time == 0) {
812 /* Issue Force Soft Reset */
813 spin_lock_irqsave(&ha->hardware_lock, flags);
814 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
815 readl(&ha->reg->ctrl_status);
816 spin_unlock_irqrestore(&ha->hardware_lock, flags);
817 /* Wait until the firmware tells us the Soft Reset is done */
818 max_wait_time = SOFT_RESET_TOV;
819 do {
820 spin_lock_irqsave(&ha->hardware_lock, flags);
821 ctrl_status = readw(&ha->reg->ctrl_status);
822 spin_unlock_irqrestore(&ha->hardware_lock, flags);
823
824 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
825 status = QLA_SUCCESS;
826 break;
827 }
828
829 msleep(1000);
830 } while ((--max_wait_time));
831 }
832
833 return status;
834}
835
836/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700837 * qla4xxx_flush_active_srbs - returns all outstanding i/o requests to O.S.
838 * @ha: Pointer to host adapter structure.
839 *
840 * This routine is called just prior to a HARD RESET to return all
841 * outstanding commands back to the Operating System.
842 * Caller should make sure that the following locks are released
843 * before this calling routine: Hardware lock, and io_request_lock.
844 **/
845static void qla4xxx_flush_active_srbs(struct scsi_qla_host *ha)
846{
847 struct srb *srb;
848 int i;
849 unsigned long flags;
850
851 spin_lock_irqsave(&ha->hardware_lock, flags);
852 for (i = 0; i < ha->host->can_queue; i++) {
853 srb = qla4xxx_del_from_active_array(ha, i);
854 if (srb != NULL) {
855 srb->cmd->result = DID_RESET << 16;
856 qla4xxx_srb_compl(ha, srb);
857 }
858 }
859 spin_unlock_irqrestore(&ha->hardware_lock, flags);
860
861}
862
863/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700864 * qla4xxx_recover_adapter - recovers adapter after a fatal error
865 * @ha: Pointer to host adapter structure.
866 * @renew_ddb_list: Indicates what to do with the adapter's ddb list
Mike Christie50a29ae2008-03-04 13:26:53 -0600867 *
868 * renew_ddb_list value can be 0=preserve ddb list, 1=destroy and rebuild
869 * ddb list.
David Somayajuluafaf5a22006-09-19 10:28:00 -0700870 **/
871static int qla4xxx_recover_adapter(struct scsi_qla_host *ha,
872 uint8_t renew_ddb_list)
873{
874 int status;
875
876 /* Stall incoming I/O until we are done */
877 clear_bit(AF_ONLINE, &ha->flags);
Mike Christie50a29ae2008-03-04 13:26:53 -0600878
David Somayajuluafaf5a22006-09-19 10:28:00 -0700879 DEBUG2(printk("scsi%ld: %s calling qla4xxx_cmd_wait\n", ha->host_no,
880 __func__));
881
882 /* Wait for outstanding commands to complete.
883 * Stalls the driver for max 30 secs
884 */
885 status = qla4xxx_cmd_wait(ha);
886
887 qla4xxx_disable_intrs(ha);
888
889 /* Flush any pending ddb changed AENs */
890 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
891
892 /* Reset the firmware. If successful, function
893 * returns with ISP interrupts enabled.
894 */
895 if (status == QLA_SUCCESS) {
896 DEBUG2(printk("scsi%ld: %s - Performing soft reset..\n",
897 ha->host_no, __func__));
David C Somayajuluf26b9042006-11-15 16:41:09 -0800898 qla4xxx_flush_active_srbs(ha);
899 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS)
900 status = qla4xxx_soft_reset(ha);
901 else
902 status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700903 }
904
905 /* Flush any pending ddb changed AENs */
906 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
907
908 /* Re-initialize firmware. If successful, function returns
909 * with ISP interrupts enabled */
910 if (status == QLA_SUCCESS) {
911 DEBUG2(printk("scsi%ld: %s - Initializing adapter..\n",
912 ha->host_no, __func__));
913
914 /* If successful, AF_ONLINE flag set in
915 * qla4xxx_initialize_adapter */
916 status = qla4xxx_initialize_adapter(ha, renew_ddb_list);
917 }
918
919 /* Failed adapter initialization?
920 * Retry reset_ha only if invoked via DPC (DPC_RESET_HA) */
921 if ((test_bit(AF_ONLINE, &ha->flags) == 0) &&
922 (test_bit(DPC_RESET_HA, &ha->dpc_flags))) {
923 /* Adapter initialization failed, see if we can retry
924 * resetting the ha */
925 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
926 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
927 DEBUG2(printk("scsi%ld: recover adapter - retrying "
928 "(%d) more times\n", ha->host_no,
929 ha->retry_reset_ha_cnt));
930 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
931 status = QLA_ERROR;
932 } else {
933 if (ha->retry_reset_ha_cnt > 0) {
934 /* Schedule another Reset HA--DPC will retry */
935 ha->retry_reset_ha_cnt--;
936 DEBUG2(printk("scsi%ld: recover adapter - "
937 "retry remaining %d\n",
938 ha->host_no,
939 ha->retry_reset_ha_cnt));
940 status = QLA_ERROR;
941 }
942
943 if (ha->retry_reset_ha_cnt == 0) {
944 /* Recover adapter retries have been exhausted.
945 * Adapter DEAD */
946 DEBUG2(printk("scsi%ld: recover adapter "
947 "failed - board disabled\n",
948 ha->host_no));
949 qla4xxx_flush_active_srbs(ha);
950 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
951 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
952 clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST,
953 &ha->dpc_flags);
954 status = QLA_ERROR;
955 }
956 }
957 } else {
958 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
959 clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags);
960 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
961 }
962
963 ha->adapter_error_count++;
964
965 if (status == QLA_SUCCESS)
966 qla4xxx_enable_intrs(ha);
967
968 DEBUG2(printk("scsi%ld: recover adapter .. DONE\n", ha->host_no));
969 return status;
970}
971
972/**
973 * qla4xxx_do_dpc - dpc routine
974 * @data: in our case pointer to adapter structure
975 *
976 * This routine is a task that is schedule by the interrupt handler
977 * to perform the background processing for interrupts. We put it
978 * on a task queue that is consumed whenever the scheduler runs; that's
979 * so you can do anything (i.e. put the process to sleep etc). In fact,
980 * the mid-level tries to sleep when it reaches the driver threshold
981 * "host->can_queue". This can cause a panic if we were in our interrupt code.
982 **/
David Howellsc4028952006-11-22 14:57:56 +0000983static void qla4xxx_do_dpc(struct work_struct *work)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700984{
David Howellsc4028952006-11-22 14:57:56 +0000985 struct scsi_qla_host *ha =
986 container_of(work, struct scsi_qla_host, dpc_work);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700987 struct ddb_entry *ddb_entry, *dtemp;
David C Somayajulu477ffb92007-01-22 12:26:11 -0800988 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700989
David C Somayajuluf26b9042006-11-15 16:41:09 -0800990 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
David C Somayajulu477ffb92007-01-22 12:26:11 -0800991 "flags = 0x%08lx, dpc_flags = 0x%08lx ctrl_stat = 0x%08x\n",
992 ha->host_no, __func__, ha->flags, ha->dpc_flags,
993 readw(&ha->reg->ctrl_status)));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700994
995 /* Initialization not yet finished. Don't do anything yet. */
996 if (!test_bit(AF_INIT_DONE, &ha->flags))
997 return;
998
999 if (adapter_up(ha) ||
1000 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1001 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1002 test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags)) {
David C Somayajuluf26b9042006-11-15 16:41:09 -08001003 if (test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags) ||
1004 test_bit(DPC_RESET_HA, &ha->dpc_flags))
David Somayajuluafaf5a22006-09-19 10:28:00 -07001005 qla4xxx_recover_adapter(ha, PRESERVE_DDB_LIST);
1006
David C Somayajulu477ffb92007-01-22 12:26:11 -08001007 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001008 uint8_t wait_time = RESET_INTR_TOV;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001009
David Somayajuluafaf5a22006-09-19 10:28:00 -07001010 while ((readw(&ha->reg->ctrl_status) &
1011 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
1012 if (--wait_time == 0)
1013 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001014 msleep(1000);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001015 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001016 if (wait_time == 0)
1017 DEBUG2(printk("scsi%ld: %s: SR|FSR "
1018 "bit not cleared-- resetting\n",
1019 ha->host_no, __func__));
David C Somayajulu477ffb92007-01-22 12:26:11 -08001020 qla4xxx_flush_active_srbs(ha);
1021 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
1022 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1023 status = qla4xxx_initialize_adapter(ha,
1024 PRESERVE_DDB_LIST);
1025 }
1026 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1027 if (status == QLA_SUCCESS)
1028 qla4xxx_enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001029 }
1030 }
1031
1032 /* ---- process AEN? --- */
1033 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
1034 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
1035
1036 /* ---- Get DHCP IP Address? --- */
1037 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
1038 qla4xxx_get_dhcp_ip_address(ha);
1039
1040 /* ---- relogin device? --- */
1041 if (adapter_up(ha) &&
1042 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
1043 list_for_each_entry_safe(ddb_entry, dtemp,
1044 &ha->ddb_list, list) {
1045 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
1046 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
1047 qla4xxx_relogin_device(ha, ddb_entry);
1048
1049 /*
1050 * If mbx cmd times out there is no point
1051 * in continuing further.
1052 * With large no of targets this can hang
1053 * the system.
1054 */
1055 if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
1056 printk(KERN_WARNING "scsi%ld: %s: "
1057 "need to reset hba\n",
1058 ha->host_no, __func__);
1059 break;
1060 }
1061 }
1062 }
1063}
1064
1065/**
1066 * qla4xxx_free_adapter - release the adapter
1067 * @ha: pointer to adapter structure
1068 **/
1069static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
1070{
1071
1072 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
1073 /* Turn-off interrupts on the card. */
1074 qla4xxx_disable_intrs(ha);
1075 }
1076
1077 /* Kill the kernel thread for this host */
1078 if (ha->dpc_thread)
1079 destroy_workqueue(ha->dpc_thread);
1080
1081 /* Issue Soft Reset to put firmware in unknown state */
David C Somayajuluf26b9042006-11-15 16:41:09 -08001082 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS)
David C Somayajulu477ffb92007-01-22 12:26:11 -08001083 qla4xxx_hw_reset(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001084
1085 /* Remove timer thread, if present */
1086 if (ha->timer_active)
1087 qla4xxx_stop_timer(ha);
1088
David Somayajuluafaf5a22006-09-19 10:28:00 -07001089 /* Detach interrupts */
1090 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
1091 free_irq(ha->pdev->irq, ha);
1092
David C Somayajulubee4fe82007-05-23 18:03:32 -07001093 /* free extra memory */
1094 qla4xxx_mem_free(ha);
1095
David Somayajuluafaf5a22006-09-19 10:28:00 -07001096 pci_disable_device(ha->pdev);
1097
1098}
1099
1100/***
1101 * qla4xxx_iospace_config - maps registers
1102 * @ha: pointer to adapter structure
1103 *
1104 * This routines maps HBA's registers from the pci address space
1105 * into the kernel virtual address space for memory mapped i/o.
1106 **/
1107static int qla4xxx_iospace_config(struct scsi_qla_host *ha)
1108{
1109 unsigned long pio, pio_len, pio_flags;
1110 unsigned long mmio, mmio_len, mmio_flags;
1111
1112 pio = pci_resource_start(ha->pdev, 0);
1113 pio_len = pci_resource_len(ha->pdev, 0);
1114 pio_flags = pci_resource_flags(ha->pdev, 0);
1115 if (pio_flags & IORESOURCE_IO) {
1116 if (pio_len < MIN_IOBASE_LEN) {
1117 dev_warn(&ha->pdev->dev,
1118 "Invalid PCI I/O region size\n");
1119 pio = 0;
1120 }
1121 } else {
1122 dev_warn(&ha->pdev->dev, "region #0 not a PIO resource\n");
1123 pio = 0;
1124 }
1125
1126 /* Use MMIO operations for all accesses. */
1127 mmio = pci_resource_start(ha->pdev, 1);
1128 mmio_len = pci_resource_len(ha->pdev, 1);
1129 mmio_flags = pci_resource_flags(ha->pdev, 1);
1130
1131 if (!(mmio_flags & IORESOURCE_MEM)) {
1132 dev_err(&ha->pdev->dev,
1133 "region #0 not an MMIO resource, aborting\n");
1134
1135 goto iospace_error_exit;
1136 }
1137 if (mmio_len < MIN_IOBASE_LEN) {
1138 dev_err(&ha->pdev->dev,
1139 "Invalid PCI mem region size, aborting\n");
1140 goto iospace_error_exit;
1141 }
1142
1143 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
1144 dev_warn(&ha->pdev->dev,
1145 "Failed to reserve PIO/MMIO regions\n");
1146
1147 goto iospace_error_exit;
1148 }
1149
1150 ha->pio_address = pio;
1151 ha->pio_length = pio_len;
1152 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
1153 if (!ha->reg) {
1154 dev_err(&ha->pdev->dev,
1155 "cannot remap MMIO, aborting\n");
1156
1157 goto iospace_error_exit;
1158 }
1159
1160 return 0;
1161
1162iospace_error_exit:
1163 return -ENOMEM;
1164}
1165
1166/**
1167 * qla4xxx_probe_adapter - callback function to probe HBA
1168 * @pdev: pointer to pci_dev structure
1169 * @pci_device_id: pointer to pci_device entry
1170 *
1171 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
1172 * It returns zero if successful. It also initializes all data necessary for
1173 * the driver.
1174 **/
1175static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
1176 const struct pci_device_id *ent)
1177{
1178 int ret = -ENODEV, status;
1179 struct Scsi_Host *host;
1180 struct scsi_qla_host *ha;
1181 struct ddb_entry *ddb_entry, *ddbtemp;
1182 uint8_t init_retry_count = 0;
1183 char buf[34];
1184
1185 if (pci_enable_device(pdev))
1186 return -1;
1187
1188 host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha));
1189 if (host == NULL) {
1190 printk(KERN_WARNING
1191 "qla4xxx: Couldn't allocate host from scsi layer!\n");
1192 goto probe_disable_device;
1193 }
1194
1195 /* Clear our data area */
1196 ha = (struct scsi_qla_host *) host->hostdata;
1197 memset(ha, 0, sizeof(*ha));
1198
1199 /* Save the information from PCI BIOS. */
1200 ha->pdev = pdev;
1201 ha->host = host;
1202 ha->host_no = host->host_no;
1203
1204 /* Configure PCI I/O space. */
1205 ret = qla4xxx_iospace_config(ha);
1206 if (ret)
1207 goto probe_failed;
1208
1209 dev_info(&ha->pdev->dev, "Found an ISP%04x, irq %d, iobase 0x%p\n",
1210 pdev->device, pdev->irq, ha->reg);
1211
1212 qla4xxx_config_dma_addressing(ha);
1213
1214 /* Initialize lists and spinlocks. */
1215 INIT_LIST_HEAD(&ha->ddb_list);
1216 INIT_LIST_HEAD(&ha->free_srb_q);
1217
1218 mutex_init(&ha->mbox_sem);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001219
1220 spin_lock_init(&ha->hardware_lock);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001221
1222 /* Allocate dma buffers */
1223 if (qla4xxx_mem_alloc(ha)) {
1224 dev_warn(&ha->pdev->dev,
1225 "[ERROR] Failed to allocate memory for adapter\n");
1226
1227 ret = -ENOMEM;
1228 goto probe_failed;
1229 }
1230
1231 /*
1232 * Initialize the Host adapter request/response queues and
1233 * firmware
1234 * NOTE: interrupts enabled upon successful completion
1235 */
1236 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
1237 while (status == QLA_ERROR && init_retry_count++ < MAX_INIT_RETRIES) {
1238 DEBUG2(printk("scsi: %s: retrying adapter initialization "
1239 "(%d)\n", __func__, init_retry_count));
1240 qla4xxx_soft_reset(ha);
1241 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
1242 }
1243 if (status == QLA_ERROR) {
1244 dev_warn(&ha->pdev->dev, "Failed to initialize adapter\n");
1245
1246 ret = -ENODEV;
1247 goto probe_failed;
1248 }
1249
1250 host->cmd_per_lun = 3;
1251 host->max_channel = 0;
1252 host->max_lun = MAX_LUNS - 1;
1253 host->max_id = MAX_TARGETS;
1254 host->max_cmd_len = IOCB_MAX_CDB_LEN;
1255 host->can_queue = MAX_SRBS ;
1256 host->transportt = qla4xxx_scsi_transport;
1257
1258 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
1259 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07001260 dev_warn(&ha->pdev->dev, "scsi_init_shared_tag_map failed\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001261 goto probe_failed;
1262 }
1263
1264 /* Startup the kernel thread for this host adapter. */
1265 DEBUG2(printk("scsi: %s: Starting kernel thread for "
1266 "qla4xxx_dpc\n", __func__));
1267 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
1268 ha->dpc_thread = create_singlethread_workqueue(buf);
1269 if (!ha->dpc_thread) {
1270 dev_warn(&ha->pdev->dev, "Unable to start DPC thread!\n");
1271 ret = -ENODEV;
1272 goto probe_failed;
1273 }
David Howellsc4028952006-11-22 14:57:56 +00001274 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001275
1276 ret = request_irq(pdev->irq, qla4xxx_intr_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001277 IRQF_DISABLED | IRQF_SHARED, "qla4xxx", ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001278 if (ret) {
1279 dev_warn(&ha->pdev->dev, "Failed to reserve interrupt %d"
1280 " already in use.\n", pdev->irq);
1281 goto probe_failed;
1282 }
1283 set_bit(AF_IRQ_ATTACHED, &ha->flags);
1284 host->irq = pdev->irq;
1285 DEBUG(printk("scsi%d: irq %d attached\n", ha->host_no, ha->pdev->irq));
1286
1287 qla4xxx_enable_intrs(ha);
1288
1289 /* Start timer thread. */
1290 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
1291
1292 set_bit(AF_INIT_DONE, &ha->flags);
1293
1294 pci_set_drvdata(pdev, ha);
1295
1296 ret = scsi_add_host(host, &pdev->dev);
1297 if (ret)
1298 goto probe_failed;
1299
1300 /* Update transport device information for all devices. */
1301 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
1302 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE)
1303 if (qla4xxx_add_sess(ddb_entry))
1304 goto remove_host;
1305 }
1306
1307 printk(KERN_INFO
1308 " QLogic iSCSI HBA Driver version: %s\n"
1309 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
1310 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
1311 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
1312 ha->patch_number, ha->build_number);
Mike Christie921601b2008-01-31 13:36:49 -06001313 scsi_scan_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001314 return 0;
1315
1316remove_host:
1317 qla4xxx_free_ddb_list(ha);
1318 scsi_remove_host(host);
1319
1320probe_failed:
1321 qla4xxx_free_adapter(ha);
1322 scsi_host_put(ha->host);
1323
1324probe_disable_device:
1325 pci_disable_device(pdev);
1326
1327 return ret;
1328}
1329
1330/**
1331 * qla4xxx_remove_adapter - calback function to remove adapter.
1332 * @pci_dev: PCI device pointer
1333 **/
1334static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
1335{
1336 struct scsi_qla_host *ha;
1337
1338 ha = pci_get_drvdata(pdev);
1339
David C Somayajulubee4fe82007-05-23 18:03:32 -07001340 qla4xxx_disable_intrs(ha);
1341
1342 while (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags))
1343 ssleep(1);
1344
David Somayajuluafaf5a22006-09-19 10:28:00 -07001345 /* remove devs from iscsi_sessions to scsi_devices */
1346 qla4xxx_free_ddb_list(ha);
1347
1348 scsi_remove_host(ha->host);
1349
1350 qla4xxx_free_adapter(ha);
1351
1352 scsi_host_put(ha->host);
1353
1354 pci_set_drvdata(pdev, NULL);
1355}
1356
1357/**
1358 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
1359 * @ha: HA context
1360 *
1361 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1362 * supported addressing method.
1363 */
Adrian Bunk47975472007-04-26 00:35:16 -07001364static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001365{
1366 int retval;
1367
1368 /* Update our PCI device dma_mask for full 64 bit mask */
1369 if (pci_set_dma_mask(ha->pdev, DMA_64BIT_MASK) == 0) {
1370 if (pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1371 dev_dbg(&ha->pdev->dev,
1372 "Failed to set 64 bit PCI consistent mask; "
1373 "using 32 bit.\n");
1374 retval = pci_set_consistent_dma_mask(ha->pdev,
1375 DMA_32BIT_MASK);
1376 }
1377 } else
1378 retval = pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1379}
1380
1381static int qla4xxx_slave_alloc(struct scsi_device *sdev)
1382{
1383 struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target);
1384 struct ddb_entry *ddb = sess->dd_data;
1385
1386 sdev->hostdata = ddb;
1387 sdev->tagged_supported = 1;
1388 scsi_activate_tcq(sdev, sdev->host->can_queue);
1389 return 0;
1390}
1391
1392static int qla4xxx_slave_configure(struct scsi_device *sdev)
1393{
1394 sdev->tagged_supported = 1;
1395 return 0;
1396}
1397
1398static void qla4xxx_slave_destroy(struct scsi_device *sdev)
1399{
1400 scsi_deactivate_tcq(sdev, 1);
1401}
1402
1403/**
1404 * qla4xxx_del_from_active_array - returns an active srb
1405 * @ha: Pointer to host adapter structure.
1406 * @index: index into to the active_array
1407 *
1408 * This routine removes and returns the srb at the specified index
1409 **/
1410struct srb * qla4xxx_del_from_active_array(struct scsi_qla_host *ha, uint32_t index)
1411{
1412 struct srb *srb = NULL;
1413 struct scsi_cmnd *cmd;
1414
1415 if (!(cmd = scsi_host_find_tag(ha->host, index)))
1416 return srb;
1417
1418 if (!(srb = (struct srb *)cmd->host_scribble))
1419 return srb;
1420
1421 /* update counters */
1422 if (srb->flags & SRB_DMA_VALID) {
1423 ha->req_q_count += srb->iocb_cnt;
1424 ha->iocb_cnt -= srb->iocb_cnt;
1425 if (srb->cmd)
1426 srb->cmd->host_scribble = NULL;
1427 }
1428 return srb;
1429}
1430
1431/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001432 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
1433 * @ha: actual ha whose done queue will contain the comd returned by firmware.
1434 * @cmd: Scsi Command to wait on.
1435 *
1436 * This routine waits for the command to be returned by the Firmware
1437 * for some max time.
1438 **/
1439static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
1440 struct scsi_cmnd *cmd)
1441{
1442 int done = 0;
1443 struct srb *rp;
1444 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
1445
1446 do {
1447 /* Checking to see if its returned to OS */
1448 rp = (struct srb *) cmd->SCp.ptr;
1449 if (rp == NULL) {
1450 done++;
1451 break;
1452 }
1453
1454 msleep(2000);
1455 } while (max_wait_time--);
1456
1457 return done;
1458}
1459
1460/**
1461 * qla4xxx_wait_for_hba_online - waits for HBA to come online
1462 * @ha: Pointer to host adapter structure
1463 **/
1464static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
1465{
1466 unsigned long wait_online;
1467
1468 wait_online = jiffies + (30 * HZ);
1469 while (time_before(jiffies, wait_online)) {
1470
1471 if (adapter_up(ha))
1472 return QLA_SUCCESS;
1473 else if (ha->retry_reset_ha_cnt == 0)
1474 return QLA_ERROR;
1475
1476 msleep(2000);
1477 }
1478
1479 return QLA_ERROR;
1480}
1481
1482/**
1483 * qla4xxx_eh_wait_for_active_target_commands - wait for active cmds to finish.
1484 * @ha: pointer to to HBA
1485 * @t: target id
1486 * @l: lun id
1487 *
1488 * This function waits for all outstanding commands to a lun to complete. It
1489 * returns 0 if all pending commands are returned and 1 otherwise.
1490 **/
1491static int qla4xxx_eh_wait_for_active_target_commands(struct scsi_qla_host *ha,
1492 int t, int l)
1493{
1494 int cnt;
1495 int status = 0;
1496 struct scsi_cmnd *cmd;
1497
1498 /*
1499 * Waiting for all commands for the designated target in the active
1500 * array
1501 */
1502 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
1503 cmd = scsi_host_find_tag(ha->host, cnt);
1504 if (cmd && cmd->device->id == t && cmd->device->lun == l) {
1505 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
1506 status++;
1507 break;
1508 }
1509 }
1510 }
1511 return status;
1512}
1513
1514/**
1515 * qla4xxx_eh_device_reset - callback for target reset.
1516 * @cmd: Pointer to Linux's SCSI command structure
1517 *
1518 * This routine is called by the Linux OS to reset all luns on the
1519 * specified target.
1520 **/
1521static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
1522{
1523 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
1524 struct ddb_entry *ddb_entry = cmd->device->hostdata;
1525 struct srb *sp;
1526 int ret = FAILED, stat;
1527
1528 sp = (struct srb *) cmd->SCp.ptr;
1529 if (!sp || !ddb_entry)
1530 return ret;
1531
1532 dev_info(&ha->pdev->dev,
1533 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
1534 cmd->device->channel, cmd->device->id, cmd->device->lun);
1535
1536 DEBUG2(printk(KERN_INFO
1537 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
1538 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
1539 cmd, jiffies, cmd->timeout_per_command / HZ,
1540 ha->dpc_flags, cmd->result, cmd->allowed));
1541
1542 /* FIXME: wait for hba to go online */
1543 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
1544 if (stat != QLA_SUCCESS) {
1545 dev_info(&ha->pdev->dev, "DEVICE RESET FAILED. %d\n", stat);
1546 goto eh_dev_reset_done;
1547 }
1548
1549 /* Send marker. */
1550 ha->marker_needed = 1;
1551
1552 /*
1553 * If we are coming down the EH path, wait for all commands to complete
1554 * for the device.
1555 */
1556 if (cmd->device->host->shost_state == SHOST_RECOVERY) {
1557 if (qla4xxx_eh_wait_for_active_target_commands(ha,
1558 cmd->device->id,
1559 cmd->device->lun)){
1560 dev_info(&ha->pdev->dev,
1561 "DEVICE RESET FAILED - waiting for "
1562 "commands.\n");
1563 goto eh_dev_reset_done;
1564 }
1565 }
1566
1567 dev_info(&ha->pdev->dev,
1568 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
1569 ha->host_no, cmd->device->channel, cmd->device->id,
1570 cmd->device->lun);
1571
1572 ret = SUCCESS;
1573
1574eh_dev_reset_done:
1575
1576 return ret;
1577}
1578
1579/**
1580 * qla4xxx_eh_host_reset - kernel callback
1581 * @cmd: Pointer to Linux's SCSI command structure
1582 *
1583 * This routine is invoked by the Linux kernel to perform fatal error
1584 * recovery on the specified adapter.
1585 **/
1586static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
1587{
1588 int return_status = FAILED;
1589 struct scsi_qla_host *ha;
1590
1591 ha = (struct scsi_qla_host *) cmd->device->host->hostdata;
1592
1593 dev_info(&ha->pdev->dev,
1594 "scsi(%ld:%d:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no,
1595 cmd->device->channel, cmd->device->id, cmd->device->lun);
1596
1597 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
1598 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
1599 "DEAD.\n", ha->host_no, cmd->device->channel,
1600 __func__));
1601
1602 return FAILED;
1603 }
1604
Mike Christie50a29ae2008-03-04 13:26:53 -06001605 /* make sure the dpc thread is stopped while we reset the hba */
1606 clear_bit(AF_ONLINE, &ha->flags);
1607 flush_workqueue(ha->dpc_thread);
1608
1609 if (qla4xxx_recover_adapter(ha, PRESERVE_DDB_LIST) == QLA_SUCCESS)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001610 return_status = SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001611
1612 dev_info(&ha->pdev->dev, "HOST RESET %s.\n",
1613 return_status == FAILED ? "FAILED" : "SUCCEDED");
1614
1615 return return_status;
1616}
1617
1618
1619static struct pci_device_id qla4xxx_pci_tbl[] = {
1620 {
1621 .vendor = PCI_VENDOR_ID_QLOGIC,
1622 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
1623 .subvendor = PCI_ANY_ID,
1624 .subdevice = PCI_ANY_ID,
1625 },
1626 {
1627 .vendor = PCI_VENDOR_ID_QLOGIC,
1628 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
1629 .subvendor = PCI_ANY_ID,
1630 .subdevice = PCI_ANY_ID,
1631 },
David C Somayajulud9150582006-11-15 17:38:40 -08001632 {
1633 .vendor = PCI_VENDOR_ID_QLOGIC,
1634 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
1635 .subvendor = PCI_ANY_ID,
1636 .subdevice = PCI_ANY_ID,
1637 },
David Somayajuluafaf5a22006-09-19 10:28:00 -07001638 {0, 0},
1639};
1640MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
1641
Adrian Bunk47975472007-04-26 00:35:16 -07001642static struct pci_driver qla4xxx_pci_driver = {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001643 .name = DRIVER_NAME,
1644 .id_table = qla4xxx_pci_tbl,
1645 .probe = qla4xxx_probe_adapter,
1646 .remove = qla4xxx_remove_adapter,
1647};
1648
1649static int __init qla4xxx_module_init(void)
1650{
1651 int ret;
1652
1653 /* Allocate cache for SRBs. */
1654 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09001655 SLAB_HWCACHE_ALIGN, NULL);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001656 if (srb_cachep == NULL) {
1657 printk(KERN_ERR
1658 "%s: Unable to allocate SRB cache..."
1659 "Failing load!\n", DRIVER_NAME);
1660 ret = -ENOMEM;
1661 goto no_srp_cache;
1662 }
1663
1664 /* Derive version string. */
1665 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001666 if (ql4xextended_error_logging)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001667 strcat(qla4xxx_version_str, "-debug");
1668
1669 qla4xxx_scsi_transport =
1670 iscsi_register_transport(&qla4xxx_iscsi_transport);
1671 if (!qla4xxx_scsi_transport){
1672 ret = -ENODEV;
1673 goto release_srb_cache;
1674 }
1675
David Somayajuluafaf5a22006-09-19 10:28:00 -07001676 ret = pci_register_driver(&qla4xxx_pci_driver);
1677 if (ret)
1678 goto unregister_transport;
1679
1680 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
1681 return 0;
Doug Maxey5ae16db2006-10-05 23:50:07 -05001682
David Somayajuluafaf5a22006-09-19 10:28:00 -07001683unregister_transport:
1684 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
1685release_srb_cache:
1686 kmem_cache_destroy(srb_cachep);
1687no_srp_cache:
1688 return ret;
1689}
1690
1691static void __exit qla4xxx_module_exit(void)
1692{
David C Somayajulu477ffb92007-01-22 12:26:11 -08001693 ql4_mod_unload = 1;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001694 pci_unregister_driver(&qla4xxx_pci_driver);
1695 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
1696 kmem_cache_destroy(srb_cachep);
1697}
1698
1699module_init(qla4xxx_module_init);
1700module_exit(qla4xxx_module_exit);
1701
1702MODULE_AUTHOR("QLogic Corporation");
1703MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
1704MODULE_LICENSE("GPL");
1705MODULE_VERSION(QLA4XXX_DRIVER_VERSION);