patch-2.2.19 linux/drivers/scsi/3w-xxxx.c
Next file: linux/drivers/scsi/3w-xxxx.h
Previous file: linux/drivers/sbus/char/zs.c
Back to the patch index
Back to the overall index
- Lines: 514
- Date:
Sun Mar 25 11:37:35 2001
- Orig file:
v2.2.18/drivers/scsi/3w-xxxx.c
- Orig date:
Sun Mar 25 11:13:04 2001
diff -u --new-file --recursive --exclude-from /usr/src/exclude v2.2.18/drivers/scsi/3w-xxxx.c linux/drivers/scsi/3w-xxxx.c
@@ -3,8 +3,10 @@
Written By: Adam Radford <linux@3ware.com>
Modifications By: Joel Jacobson <linux@3ware.com>
+ Arnaldo Carvalho de Melo <acme@conectiva.com.br>
- Copyright (C) 1999-2000 3ware Inc.
+
+ Copyright (C) 1999-2001 3ware Inc.
Kernel compatablity By: Andre Hedrick <andre@suse.com>
Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com>
@@ -64,6 +66,17 @@
Bug fix so hot spare drives don't show up.
1.02.00.002 - Fix bug with tw_setfeature() call that caused oops on some
systems.
+ 12/09/2000 - release previously allocated resources on failure at
+ tw_allocate_memory (acme)
+ 1.02.00.003 - Fix tw_interrupt() to report error to scsi layer when
+ controller status is non-zero.
+ Added handling of request_sense opcode.
+ Fix possible null pointer dereference in
+ tw_reset_device_extension()
+ 1.02.00.004 - Add support for device id of 3ware 7000 series controllers.
+ Make tw_setfeature() call with interrupts disabled.
+ Register interrupt handler before enabling interrupts.
+ Clear attention interrupt before draining aen queue.
*/
#include <linux/module.h>
@@ -115,7 +128,7 @@
};
/* Globals */
-char *tw_driver_version="1.02.00.002";
+char *tw_driver_version="1.02.00.004";
TW_Device_Extension *tw_device_extension_list[TW_MAX_SLOT];
int tw_device_extension_count = 0;
@@ -416,37 +429,29 @@
/* This function will allocate memory and check if it is 16 d-word aligned */
int tw_allocate_memory(TW_Device_Extension *tw_dev, int request_id, int size, int which)
{
- u32 *virt_addr;
+ u32 *virt_addr = kmalloc(size, GFP_ATOMIC);
dprintk(KERN_NOTICE "3w-xxxx: tw_allocate_memory()\n");
+ if (!virt_addr) {
+ printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): kmalloc() failed.\n");
+ return 1;
+ }
+
+ if ((u32)virt_addr % TW_ALIGNMENT) {
+ kfree(virt_addr);
+ printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): Found unaligned address.\n");
+ return 1;
+ }
+
if (which == 0) {
- /* Allocate command packet memory */
- virt_addr = kmalloc(size, GFP_ATOMIC);
- if (virt_addr == NULL) {
- printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): kmalloc() failed.\n");
- return 1;
- }
- if ((u32)virt_addr % TW_ALIGNMENT) {
- printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): Found unaligned address.\n");
- return 1;
- }
tw_dev->command_packet_virtual_address[request_id] = virt_addr;
tw_dev->command_packet_physical_address[request_id] =
- virt_to_bus(virt_addr);
+ virt_to_bus(virt_addr);
} else {
- /* Allocate generic buffer */
- virt_addr = kmalloc(size, GFP_ATOMIC);
- if (virt_addr == NULL) {
- printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): kmalloc() failed.\n");
- return 1;
- }
- if ((u32)virt_addr % TW_ALIGNMENT) {
- printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): Found unaligned address.\n");
- return 1;
- }
tw_dev->alignment_virtual_address[request_id] = virt_addr;
- tw_dev->alignment_physical_address[request_id] = virt_to_bus(virt_addr);
+ tw_dev->alignment_physical_address[request_id] =
+ virt_to_bus(virt_addr);
}
return 0;
} /* End tw_allocate_memory() */
@@ -593,173 +598,178 @@
struct pci_dev *tw_pci_dev = pci_devices;
u32 status_reg_value;
unsigned char c = 1;
+ int i;
+ u16 device[TW_NUMDEVICES] = { TW_DEVICE_ID, TW_DEVICE_ID2 };
dprintk(KERN_NOTICE "3w-xxxx: tw_findcards()\n");
- while ((tw_pci_dev = pci_find_device(TW_VENDOR_ID, TW_DEVICE_ID, tw_pci_dev))) {
- /* Prepare temporary device extension */
- tw_dev=(TW_Device_Extension *)kmalloc(sizeof(TW_Device_Extension), GFP_ATOMIC);
- if (tw_dev == NULL) {
- printk(KERN_WARNING "3w-xxxx: tw_findcards(): kmalloc() failed for card %d.\n", numcards);
- continue;
- }
- memset(tw_dev, 0, sizeof(TW_Device_Extension));
-
- error = tw_initialize_device_extension(tw_dev);
- if (error) {
- printk(KERN_WARNING "3w-xxxx: tw_findcards(): Couldn't initialize device extension for card %d.\n", numcards);
- tw_free_device_extension(tw_dev);
- kfree(tw_dev);
- continue;
- }
-
- /* Calculate the cards register addresses */
- tw_dev->registers.base_addr = tw_pci_dev->base_address[0];
- tw_dev->registers.control_reg_addr = (tw_pci_dev->base_address[0] & ~15);
- tw_dev->registers.status_reg_addr = ((tw_pci_dev->base_address[0] & ~15) + 0x4);
- tw_dev->registers.command_que_addr = ((tw_pci_dev->base_address[0] & ~15) + 0x8);
- tw_dev->registers.response_que_addr = ((tw_pci_dev->base_address[0] & ~15) + 0xC);
- /* Save pci_dev struct to device extension */
- tw_dev->tw_pci_dev = tw_pci_dev;
-
- /* Poll status register for 60 secs for 'Controller Ready' flag */
- if (tw_poll_status(tw_dev, TW_STATUS_MICROCONTROLLER_READY, 60)) {
- printk(KERN_WARNING "3w-xxxx: tw_findcards(): Microcontroller not ready for card %d.\n", numcards);
- tw_free_device_extension(tw_dev);
- kfree(tw_dev);
- continue;
- }
-
- /* Disable interrupts on the card */
- tw_disable_interrupts(tw_dev);
-
- while (tries < TW_MAX_RESET_TRIES) {
- /* Do soft reset */
- tw_soft_reset(tw_dev);
-
- error = tw_aen_drain_queue(tw_dev);
+
+ for (i=0;i<TW_NUMDEVICES;i++) {
+ while ((tw_pci_dev = pci_find_device(TW_VENDOR_ID, device[i], tw_pci_dev))) {
+ /* Prepare temporary device extension */
+ tw_dev=(TW_Device_Extension *)kmalloc(sizeof(TW_Device_Extension), GFP_ATOMIC);
+ if (tw_dev == NULL) {
+ printk(KERN_WARNING "3w-xxxx: tw_findcards(): kmalloc() failed for card %d.\n", numcards);
+ continue;
+ }
+ memset(tw_dev, 0, sizeof(TW_Device_Extension));
+
+ error = tw_initialize_device_extension(tw_dev);
if (error) {
- printk(KERN_WARNING "3w-xxxx: tw_findcards(): No attention interrupt for card %d.\n", numcards);
- tries++;
+ printk(KERN_WARNING "3w-xxxx: tw_findcards(): Couldn't initialize device extension for card %d.\n", numcards);
+ tw_free_device_extension(tw_dev);
+ kfree(tw_dev);
continue;
}
-
- /* Check for controller errors */
- if (tw_check_errors(tw_dev)) {
- printk(KERN_WARNING "3w-xxxx: tw_findcards(): Controller errors found, soft resetting card %d.\n", numcards);
- tries++;
+
+ /* Calculate the cards register addresses */
+ tw_dev->registers.base_addr = tw_pci_dev->base_address[0];
+ tw_dev->registers.control_reg_addr = (tw_pci_dev->base_address[0] & ~15);
+ tw_dev->registers.status_reg_addr = ((tw_pci_dev->base_address[0] & ~15) + 0x4);
+ tw_dev->registers.command_que_addr = ((tw_pci_dev->base_address[0] & ~15) + 0x8);
+ tw_dev->registers.response_que_addr = ((tw_pci_dev->base_address[0] & ~15) + 0xC);
+ /* Save pci_dev struct to device extension */
+ tw_dev->tw_pci_dev = tw_pci_dev;
+
+ /* Poll status register for 60 secs for 'Controller Ready' flag */
+ if (tw_poll_status(tw_dev, TW_STATUS_MICROCONTROLLER_READY, 60)) {
+ printk(KERN_WARNING "3w-xxxx: tw_findcards(): Microcontroller not ready for card %d.\n", numcards);
+ tw_free_device_extension(tw_dev);
+ kfree(tw_dev);
continue;
}
-
- /* Empty the response queue */
- error = tw_empty_response_que(tw_dev);
+
+ /* Disable interrupts on the card */
+ tw_disable_interrupts(tw_dev);
+
+ while (tries < TW_MAX_RESET_TRIES) {
+ /* Do soft reset */
+ tw_soft_reset(tw_dev);
+
+ error = tw_aen_drain_queue(tw_dev);
+ if (error) {
+ printk(KERN_WARNING "3w-xxxx: tw_findcards(): No attention interrupt for card %d.\n", numcards);
+ tries++;
+ continue;
+ }
+
+ /* Check for controller errors */
+ if (tw_check_errors(tw_dev)) {
+ printk(KERN_WARNING "3w-xxxx: tw_findcards(): Controller errors found, soft resetting card %d.\n", numcards);
+ tries++;
+ continue;
+ }
+
+ /* Empty the response queue */
+ error = tw_empty_response_que(tw_dev);
+ if (error) {
+ printk(KERN_WARNING "3w-xxxx: tw_findcards(): Couldn't empty response queue for card %d.\n", numcards);
+ tries++;
+ continue;
+ }
+
+ /* Now the controller is in a good state */
+ break;
+ }
+
+ if (tries >= TW_MAX_RESET_TRIES) {
+ printk(KERN_WARNING "3w-xxxx: tw_findcards(): Controller error or no attention interrupt: giving up for card %d.\n", numcards);
+ tw_free_device_extension(tw_dev);
+ kfree(tw_dev);
+ continue;
+ }
+
+ /* Make sure that io region isn't already taken */
+ if (check_region((tw_dev->tw_pci_dev->base_address[0]), TW_IO_ADDRESS_RANGE)) {
+ printk(KERN_WARNING "3w-xxxx: tw_findcards(): Couldn't get io range 0x%lx-0x%lx for card %d.\n",
+ (tw_dev->tw_pci_dev->base_address[0]),
+ (tw_dev->tw_pci_dev->base_address[0]) +
+ TW_IO_ADDRESS_RANGE, numcards);
+ tw_free_device_extension(tw_dev);
+ kfree(tw_dev);
+ continue;
+ }
+
+ /* Reserve the io address space */
+ request_region((tw_dev->tw_pci_dev->base_address[0]), TW_IO_ADDRESS_RANGE, TW_DEVICE_NAME);
+ error = tw_initialize_units(tw_dev);
if (error) {
- printk(KERN_WARNING "3w-xxxx: tw_findcards(): Couldn't empty response queue for card %d.\n", numcards);
- tries++;
+ printk(KERN_WARNING "3w-xxxx: tw_findcards(): Couldn't initialize units for card %d.\n", numcards);
+ release_region((tw_dev->tw_pci_dev->base_address[0]), TW_IO_ADDRESS_RANGE);
+ tw_free_device_extension(tw_dev);
+ kfree(tw_dev);
continue;
}
-
- /* Now the controller is in a good state */
- break;
- }
-
- if (tries >= TW_MAX_RESET_TRIES) {
- printk(KERN_WARNING "3w-xxxx: tw_findcards(): Controller error or no attention interrupt: giving up for card %d.\n", numcards);
- tw_free_device_extension(tw_dev);
- kfree(tw_dev);
- continue;
- }
-
- /* Make sure that io region isn't already taken */
- if (check_region((tw_dev->tw_pci_dev->base_address[0]), TW_IO_ADDRESS_RANGE)) {
- printk(KERN_WARNING "3w-xxxx: tw_findcards(): Couldn't get io range 0x%lx-0x%lx for card %d.\n",
- (tw_dev->tw_pci_dev->base_address[0]),
- (tw_dev->tw_pci_dev->base_address[0]) +
- TW_IO_ADDRESS_RANGE, numcards);
- tw_free_device_extension(tw_dev);
- kfree(tw_dev);
- continue;
- }
-
- /* Reserve the io address space */
- request_region((tw_dev->tw_pci_dev->base_address[0]), TW_IO_ADDRESS_RANGE, TW_DEVICE_NAME);
- error = tw_initialize_units(tw_dev);
- if (error) {
- printk(KERN_WARNING "3w-xxxx: tw_findcards(): Couldn't initialize units for card %d.\n", numcards);
- release_region((tw_dev->tw_pci_dev->base_address[0]), TW_IO_ADDRESS_RANGE);
- tw_free_device_extension(tw_dev);
- kfree(tw_dev);
- continue;
- }
-
- error = tw_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS);
- if (error) {
- printk(KERN_WARNING "3w-xxxx: tw_findcards(): Couldn't initconnection for card %d.\n", numcards);
- release_region((tw_dev->tw_pci_dev->base_address[0]), TW_IO_ADDRESS_RANGE);
- tw_free_device_extension(tw_dev);
- kfree(tw_dev);
- continue;
- }
-
- /* Calculate max cmds per lun */
- if (tw_dev->num_units > 0)
- tw_host->cmd_per_lun = (TW_Q_LENGTH-2)/tw_dev->num_units;
-
- /* Register the card with the kernel SCSI layer */
- host = scsi_register(tw_host, sizeof(TW_Device_Extension));
-
- /* FIXME - check for NULL */
-
- status_reg_value = inl(tw_dev->registers.status_reg_addr);
-
- dprintk(KERN_NOTICE "scsi%d : Found a 3ware Storage Controller at 0x%x, IRQ: %d P-chip: %d.%d\n", host->host_no,
+
+ error = tw_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS);
+ if (error) {
+ printk(KERN_WARNING "3w-xxxx: tw_findcards(): Couldn't initconnection for card %d.\n", numcards);
+ release_region((tw_dev->tw_pci_dev->base_address[0]), TW_IO_ADDRESS_RANGE);
+ tw_free_device_extension(tw_dev);
+ kfree(tw_dev);
+ continue;
+ }
+
+ /* Calculate max cmds per lun */
+ if (tw_dev->num_units > 0)
+ tw_host->cmd_per_lun = (TW_Q_LENGTH-2)/tw_dev->num_units;
+
+ /* Register the card with the kernel SCSI layer */
+ host = scsi_register(tw_host, sizeof(TW_Device_Extension));
+
+ /* FIXME - check for NULL */
+
+ status_reg_value = inl(tw_dev->registers.status_reg_addr);
+
+ dprintk(KERN_NOTICE "scsi%d : Found a 3ware Storage Controller at 0x%x, IRQ: %d P-chip: %d.%d\n", host->host_no,
(u32)(tw_pci_dev->base_address[0]), tw_pci_dev->irq,
(status_reg_value & TW_STATUS_MAJOR_VERSION_MASK) >> 28,
(status_reg_value & TW_STATUS_MINOR_VERSION_MASK) >> 24);
+
+ if (host->hostdata) {
+ tw_dev2 = (TW_Device_Extension *)host->hostdata;
+ memcpy(tw_dev2, tw_dev, sizeof(TW_Device_Extension));
+ tw_device_extension_list[tw_device_extension_count] = tw_dev2;
+ numcards++;
+ tw_device_extension_count = numcards;
+ tw_dev2->host = host;
+ } else {
+ printk(KERN_WARNING "3w-xxxx: tw_findcards(): Bad scsi host data for card %d.\n", numcards-1);
+ scsi_unregister(host);
+ release_region((tw_dev->tw_pci_dev->base_address[0]), TW_IO_ADDRESS_RANGE);
+ tw_free_device_extension(tw_dev);
+ kfree(tw_dev);
+ continue;
+ }
+
+ /* Tell the firmware we support shutdown notification*/
+ tw_setfeature(tw_dev2, 2, 1, &c);
+
+ /* Now setup the interrupt handler */
+ error = tw_setup_irq(tw_dev2);
+ if (error) {
+ printk(KERN_WARNING "3w-xxxx: tw_findcards(): Error requesting irq for card %d.\n", numcards-1);
+ scsi_unregister(host);
+ release_region((tw_dev->tw_pci_dev->base_address[0]), TW_IO_ADDRESS_RANGE);
+
+ tw_free_device_extension(tw_dev);
+ kfree(tw_dev);
+ numcards--;
+ continue;
+ }
- if (host->hostdata) {
- tw_dev2 = (TW_Device_Extension *)host->hostdata;
- memcpy(tw_dev2, tw_dev, sizeof(TW_Device_Extension));
- tw_device_extension_list[tw_device_extension_count] = tw_dev2;
- numcards++;
- tw_device_extension_count = numcards;
- tw_dev2->host = host;
- } else {
- printk(KERN_WARNING "3w-xxxx: tw_findcards(): Bad scsi host data for card %d.\n", numcards-1);
- scsi_unregister(host);
- release_region((tw_dev->tw_pci_dev->base_address[0]), TW_IO_ADDRESS_RANGE);
- tw_free_device_extension(tw_dev);
- kfree(tw_dev);
- continue;
- }
-
- /* Re-enable interrupts on the card */
- tw_enable_interrupts(tw_dev2);
-
- /* Now setup the interrupt handler */
- error = tw_setup_irq(tw_dev2);
- if (error) {
- printk(KERN_WARNING "3w-xxxx: tw_findcards(): Error requesting irq for card %d.\n", numcards-1);
- scsi_unregister(host);
- release_region((tw_dev->tw_pci_dev->base_address[0]), TW_IO_ADDRESS_RANGE);
-
- tw_free_device_extension(tw_dev);
- kfree(tw_dev);
- numcards--;
- continue;
+ /* Re-enable interrupts on the card */
+ tw_enable_interrupts(tw_dev2);
+
+ /* Free the temporary device extension */
+ if (tw_dev)
+ kfree(tw_dev);
}
-
- /* Free the temporary device extension */
- if (tw_dev)
- kfree(tw_dev);
- /* Tell the firmware we support shutdown notification*/
- tw_setfeature(tw_dev2, 2, 1, &c);
}
-
if (numcards == 0)
printk(KERN_WARNING "3w-xxxx: tw_findcards(): No cards found.\n");
else
- register_reboot_notifier(&tw_notifier);
-
+ register_reboot_notifier(&tw_notifier);
+
return numcards;
} /* End tw_findcards() */
@@ -1090,15 +1100,14 @@
/* Handle attention interrupt */
if (do_attention_interrupt) {
dprintk(KERN_NOTICE "3w-xxxx: tw_interrupt(): Received attention interrupt.\n");
+ dprintk(KERN_WARNING "3w-xxxx: tw_interrupt(): Clearing attention interrupt.\n");
+ tw_clear_attention_interrupt(tw_dev);
tw_state_request_start(tw_dev, &request_id);
error = tw_aen_read_queue(tw_dev, request_id);
if (error) {
printk(KERN_WARNING "3w-xxxx: tw_interrupt(): Error reading aen queue.\n");
tw_dev->state[request_id] = TW_S_COMPLETED;
tw_state_request_finish(tw_dev, request_id);
- } else {
- dprintk(KERN_WARNING "3w-xxxx: tw_interrupt(): Clearing attention interrupt.\n");
- tw_clear_attention_interrupt(tw_dev);
}
}
@@ -1134,13 +1143,15 @@
response_que.value = inl(response_que_addr);
request_id = response_que.u.response_id;
command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
+ error = 0;
if (command_packet->status != 0) {
- printk(KERN_WARNING "3w-xxxx: tw_interrupt(): Bad response, status = 0x%x, flags = 0x%x.\n", command_packet->status, command_packet->flags);
+ printk(KERN_WARNING "3w-xxxx: tw_interrupt(): Bad response, status = 0x%x, flags = 0x%x, unit = 0x%x.\n", command_packet->status, command_packet->flags, command_packet->byte3.unit);
+ error = 1;
}
if (tw_dev->state[request_id] != TW_S_POSTED) {
printk(KERN_WARNING "3w-xxxx: tw_interrupt(): Received a request id (%d) (opcode = 0x%x) that wasn't posted.\n", request_id, command_packet->byte0.opcode);
+ error = 1;
}
- error = 0;
dprintk(KERN_NOTICE "3w-xxxx: tw_interrupt(): Response queue request id: %d.\n", request_id);
/* Check for internal command */
if (tw_dev->srb[request_id] == 0) {
@@ -1184,8 +1195,8 @@
}
if (error) {
/* Tell scsi layer there was an error */
- printk(KERN_WARNING "3w-xxxx: tw_interrupt(): Scsi Error.\n");
- tw_dev->srb[request_id]->result = (DID_ERROR << 16);
+ dprintk(KERN_WARNING "3w-xxxx: tw_interrupt(): Scsi Error.\n");
+ tw_dev->srb[request_id]->result = (DID_RESET << 16);
} else {
/* Tell scsi layer command was a success */
tw_dev->srb[request_id]->result = (DID_OK << 16);
@@ -1467,8 +1478,10 @@
(tw_dev->state[i] != TW_S_INITIAL) &&
(tw_dev->state[i] != TW_S_COMPLETED)) {
srb = tw_dev->srb[i];
- srb->result = (DID_RESET << 16);
- tw_dev->srb[i]->scsi_done(tw_dev->srb[i]);
+ if (srb != NULL) {
+ srb->result = (DID_RESET << 16);
+ tw_dev->srb[i]->scsi_done(tw_dev->srb[i]);
+ }
}
}
@@ -1813,6 +1826,10 @@
dprintk(KERN_NOTICE "3w-xxxx: tw_scsi_queue(): caught READ_CAPACITY.\n");
error = tw_scsiop_read_capacity(tw_dev, request_id);
break;
+ case REQUEST_SENSE:
+ dprintk(KERN_NOTICE "3w-xxxx: tw_scsi_queue(): caught REQUEST_SENSE.\n");
+ error = tw_scsiop_request_sense(tw_dev, request_id);
+ break;
case TW_IOCTL:
dprintk(KERN_NOTICE "3w-xxxx: tw_scsi_queue(): caught TW_SCSI_IOCTL.\n");
error = tw_ioctl(tw_dev, request_id);
@@ -2168,6 +2185,23 @@
return 0;
} /* End tw_scsiop_read_write() */
+
+/* This function will handle the request sense scsi command */
+int tw_scsiop_request_sense(TW_Device_Extension *tw_dev, int request_id)
+{
+ dprintk(KERN_NOTICE "3w-xxxx: tw_scsiop_request_sense()\n");
+
+ /* For now we just zero the sense buffer */
+ memset(tw_dev->srb[request_id]->request_buffer, 0, tw_dev->srb[request_id]->request_bufflen);
+ tw_dev->state[request_id] = TW_S_COMPLETED;
+ tw_state_request_finish(tw_dev, request_id);
+
+ /* If we got a request_sense, we probably want a reset, return error */
+ tw_dev->srb[request_id]->result = (DID_ERROR << 16);
+ tw_dev->srb[request_id]->scsi_done(tw_dev->srb[request_id]);
+
+ return 0;
+} /* End tw_scsiop_request_sense() */
/* This function will handle test unit ready scsi command */
int tw_scsiop_test_unit_ready(TW_Device_Extension *tw_dev, int request_id)
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)