/* 3w-xxxx.c -- 3ware Storage Controller device driver for Linux.
Written By: Adam Radford <aradford@gmail.com> Modifications By: Joel Jacobson <linux@3ware.com> Arnaldo Carvalho de Melo <acme@conectiva.com.br> Brad Strand <linux@3ware.com>
Copyright (C) 1999-2010 3ware Inc.
Kernel compatibility By: Andre Hedrick <andre@suse.com> Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com>
Further tiny build fixes and trivial hoovering Alan Cox
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
NO WARRANTY THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement, including but not limited to the risks and costs of program errors, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
DISCLAIMER OF LIABILITY NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Bugs/Comments/Suggestions should be mailed to:
aradford@gmail.com
History ------- 0.1.000 - Initial release. 0.4.000 - Added support for Asynchronous Event Notification through ioctls for 3DM. 1.0.000 - Added DPO & FUA bit support for WRITE_10 & WRITE_6 cdb to disable drive write-cache before writes. 1.1.000 - Fixed performance bug with DPO & FUA not existing for WRITE_6. 1.2.000 - Added support for clean shutdown notification/feature table. 1.02.00.001 - Added support for full command packet posts through ioctls for 3DM. 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. 08/21/00 - 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. 1.02.00.005 - Allocate bounce buffers and custom queue depth for raid5 for 6000 and 5000 series controllers. Reduce polling mdelays causing problems on some systems. Fix use_sg = 1 calculation bug. Check for scsi_register returning NULL. Add aen count to /proc/scsi/3w-xxxx. Remove aen code unit masking in tw_aen_complete(). 1.02.00.006 - Remove unit from printk in tw_scsi_eh_abort(), causing possible oops. Fix possible null pointer dereference in tw_scsi_queue() if done function pointer was invalid. 1.02.00.007 - Fix possible null pointer dereferences in tw_ioctl(). Remove check for invalid done function pointer from tw_scsi_queue(). 1.02.00.008 - Set max sectors per io to TW_MAX_SECTORS in tw_findcards(). Add tw_decode_error() for printing readable error messages. Print some useful information on certain aen codes. Add tw_decode_bits() for interpreting status register output. Make scsi_set_pci_device() for kernels >= 2.4.4 Fix bug where aen's could be lost before a reset. Re-add spinlocks in tw_scsi_detect(). Fix possible null pointer dereference in tw_aen_drain_queue() during initialization. Clear pci parity errors during initialization and during io. 1.02.00.009 - Remove redundant increment in tw_state_request_start(). Add ioctl support for direct ATA command passthru. Add entire aen code string list. 1.02.00.010 - Cleanup queueing code, fix jbod thoughput. Fix get_param for specific units. 1.02.00.011 - Fix bug in tw_aen_complete() where aen's could be lost. Fix tw_aen_drain_queue() to display useful info at init. Set tw_host->max_id for 12 port cards. Add ioctl support for raw command packet post from userspace with sglist fragments (parameter and io). 1.02.00.012 - Fix read capacity to under report by 1 sector to fix get last sector ioctl. 1.02.00.013 - Fix bug where more AEN codes weren't coming out during driver initialization. Improved handling of PCI aborts. 1.02.00.014 - Fix bug in tw_findcards() where AEN code could be lost. Increase timeout in tw_aen_drain_queue() to 30 seconds. 1.02.00.015 - Re-write raw command post with data ioctl method. Remove raid5 bounce buffers for raid5 for 6XXX for kernel 2.5 Add tw_map/unmap_scsi_sg/single_data() for kernel 2.5 Replace io_request_lock with host_lock for kernel 2.5 Set max_cmd_len to 16 for 3dm for kernel 2.5 1.02.00.016 - Set host->max_sectors back up to 256. 1.02.00.017 - Modified pci parity error handling/clearing from config space during initialization. 1.02.00.018 - Better handling of request sense opcode and sense information for failed commands. Add tw_decode_sense(). Replace all mdelay()'s with scsi_sleep(). 1.02.00.019 - Revert mdelay's and scsi_sleep's, this caused problems on some SMP systems. 1.02.00.020 - Add pci_set_dma_mask(), rewrite kmalloc()/virt_to_bus() to pci_alloc/free_consistent(). Better alignment checking in tw_allocate_memory(). Cleanup tw_initialize_device_extension(). 1.02.00.021 - Bump cmd_per_lun in SHT to 255 for better jbod performance. Improve handling of errors in tw_interrupt(). Add handling/clearing of controller queue error. Empty stale responses before draining aen queue. Fix tw_scsi_eh_abort() to not reset on every io abort. Set can_queue in SHT to 255 to prevent hang from AEN. 1.02.00.022 - Fix possible null pointer dereference in tw_scsi_release(). 1.02.00.023 - Fix bug in tw_aen_drain_queue() where unit # was always zero. 1.02.00.024 - Add severity levels to AEN strings. 1.02.00.025 - Fix command interrupt spurious error messages. Fix bug in raw command post with data ioctl method. Fix bug where rollcall sometimes failed with cable errors. Print unit # on all command timeouts. 1.02.00.026 - Fix possible infinite retry bug with power glitch induced drive timeouts. Cleanup some AEN severity levels. 1.02.00.027 - Add drive not supported AEN code for SATA controllers. Remove spurious unknown ioctl error message. 1.02.00.028 - Fix bug where multiple controllers with no units were the same card number. Fix bug where cards were being shut down more than once. 1.02.00.029 - Add missing pci_free_consistent() in tw_allocate_memory(). Replace pci_map_single() with pci_map_page() for highmem. Check for tw_setfeature() failure. 1.02.00.030 - Make driver 64-bit clean. 1.02.00.031 - Cleanup polling timeouts/routines in several places. Add support for mode sense opcode. Add support for cache mode page. Add support for synchronize cache opcode. 1.02.00.032 - Fix small multicard rollcall bug. Make driver stay loaded with no units for hot add/swap. Add support for "twe" character device for ioctls. Clean up request_id queueing code. Fix tw_scsi_queue() spinlocks. 1.02.00.033 - Fix tw_aen_complete() to not queue 'queue empty' AEN's. Initialize queues correctly when loading with no valid units. 1.02.00.034 - Fix tw_decode_bits() to handle multiple errors. Add support for user configurable cmd_per_lun. Add support for sht->sdev_configure(). 1.02.00.035 - Improve tw_allocate_memory() memory allocation. Fix tw_chrdev_ioctl() to sleep correctly. 1.02.00.036 - Increase character ioctl timeout to 60 seconds. 1.02.00.037 - Fix tw_ioctl() to handle all non-data ATA passthru cmds for 'smartmontools' support. 1.26.00.038 - Roll driver minor version to 26 to denote kernel 2.6. Add support for cmds_per_lun module parameter. 1.26.00.039 - Fix bug in tw_chrdev_ioctl() polling code. Fix data_buffer_length usage in tw_chrdev_ioctl(). Update contact information. 1.26.02.000 - Convert driver to pci_driver format. 1.26.02.001 - Increase max ioctl buffer size to 512 sectors. Make tw_scsi_queue() return 0 for 'Unknown scsi opcode'. Fix tw_remove() to free irq handler/unregister_chrdev() before shutting down card. Change to new 'change_queue_depth' api. Fix 'handled=1' ISR usage, remove bogus IRQ check. 1.26.02.002 - Free irq handler in __tw_shutdown(). Turn on RCD bit for caching mode page. Serialize reset code. 1.26.02.003 - Force 60 second timeout default.
*/
/* Function prototypes */ staticint tw_reset_device_extension(TW_Device_Extension *tw_dev);
/* Functions */
/* This function will check the status register for unexpected bits */ staticint tw_check_bits(u32 status_reg_value)
{ if ((status_reg_value & TW_STATUS_EXPECTED_BITS) != TW_STATUS_EXPECTED_BITS) {
dprintk(KERN_WARNING "3w-xxxx: tw_check_bits(): No expected bits (0x%x).\n", status_reg_value); return 1;
} if ((status_reg_value & TW_STATUS_UNEXPECTED_BITS) != 0) {
dprintk(KERN_WARNING "3w-xxxx: tw_check_bits(): Found unexpected bits (0x%x).\n", status_reg_value); return 1;
}
return 0;
} /* End tw_check_bits() */
/* This function will print readable messages from status register errors */ staticint tw_decode_bits(TW_Device_Extension *tw_dev, u32 status_reg_value, int print_host)
{ char host[16];
/* This function will poll the status register for a flag */ staticint tw_poll_status(TW_Device_Extension *tw_dev, u32 flag, int seconds)
{
u32 status_reg_value; unsignedlong before; int retval = 1;
status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
before = jiffies;
if (tw_check_bits(status_reg_value))
tw_decode_bits(tw_dev, status_reg_value, 0);
while ((status_reg_value & flag) != flag) {
status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
if (tw_check_bits(status_reg_value))
tw_decode_bits(tw_dev, status_reg_value, 0);
if (time_after(jiffies, before + HZ * seconds)) goto out;
/* This function will poll the status register for disappearance of a flag */ staticint tw_poll_status_gone(TW_Device_Extension *tw_dev, u32 flag, int seconds)
{
u32 status_reg_value; unsignedlong before; int retval = 1;
status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
before = jiffies;
if (tw_check_bits(status_reg_value))
tw_decode_bits(tw_dev, status_reg_value, 0);
while ((status_reg_value & flag) != 0) {
status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
if (tw_check_bits(status_reg_value))
tw_decode_bits(tw_dev, status_reg_value, 0);
if (time_after(jiffies, before + HZ * seconds)) goto out;
/* This function will attempt to post a command packet to the board */ staticint tw_post_command_packet(TW_Device_Extension *tw_dev, int request_id)
{
u32 status_reg_value; unsignedlong command_que_value;
if ((status_reg_value & TW_STATUS_COMMAND_QUEUE_FULL) == 0) { /* We successfully posted the command packet */
outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
tw_dev->state[request_id] = TW_S_POSTED;
tw_dev->posted_request_count++; if (tw_dev->posted_request_count > tw_dev->max_posted_request_count) {
tw_dev->max_posted_request_count = tw_dev->posted_request_count;
}
} else { /* Couldn't post the command packet, so we do it in the isr */ if (tw_dev->state[request_id] != TW_S_PENDING) {
tw_dev->state[request_id] = TW_S_PENDING;
tw_dev->pending_request_count++; if (tw_dev->pending_request_count > tw_dev->max_pending_request_count) {
tw_dev->max_pending_request_count = tw_dev->pending_request_count;
}
tw_dev->pending_queue[tw_dev->pending_tail] = request_id; if (tw_dev->pending_tail == TW_Q_LENGTH-1) {
tw_dev->pending_tail = TW_Q_START;
} else {
tw_dev->pending_tail = tw_dev->pending_tail + 1;
}
}
TW_UNMASK_COMMAND_INTERRUPT(tw_dev); return 1;
} return 0;
} /* End tw_post_command_packet() */
/* This function will return valid sense buffer information for failed cmds */ staticint tw_decode_sense(TW_Device_Extension *tw_dev, int request_id, int fill_sense)
{ int i;
TW_Command *command;
printk(KERN_WARNING "3w-xxxx: scsi%d: Command failed: status = 0x%x, flags = 0x%x, unit #%d.\n", tw_dev->host->host_no, command->status, command->flags, TW_UNIT_OUT(command->unit__hostid));
/* Attempt to return intelligent sense information */ if (fill_sense) { if ((command->status == 0xc7) || (command->status == 0xcb)) { for (i = 0; i < ARRAY_SIZE(tw_sense_table); i++) { if (command->flags == tw_sense_table[i][0]) {
/* Valid bit and 'current errors' */
tw_dev->srb[request_id]->sense_buffer[0] = (0x1 << 7 | 0x70);
/* Sense key */
tw_dev->srb[request_id]->sense_buffer[2] = tw_sense_table[i][1];
/* Additional sense code */
tw_dev->srb[request_id]->sense_buffer[12] = tw_sense_table[i][2];
/* Additional sense code qualifier */
tw_dev->srb[request_id]->sense_buffer[13] = tw_sense_table[i][3];
tw_dev->srb[request_id]->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; return TW_ISR_DONT_RESULT; /* Special case for isr to not over-write result */
}
}
}
/* If no table match, error so we get a reset */ return 1;
}
return 0;
} /* End tw_decode_sense() */
/* This function will report controller error status */ staticint tw_check_errors(TW_Device_Extension *tw_dev)
{
u32 status_reg_value;
while ((status_reg_value & TW_STATUS_RESPONSE_QUEUE_EMPTY) == 0) {
inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
}
} /* End tw_empty_response_que() */
/* This function will free a request_id */ staticvoid tw_state_request_finish(TW_Device_Extension *tw_dev, int request_id)
{
tw_dev->free_queue[tw_dev->free_tail] = request_id;
tw_dev->state[request_id] = TW_S_FINISHED;
tw_dev->free_tail = (tw_dev->free_tail + 1) % TW_Q_LENGTH;
} /* End tw_state_request_finish() */
/* This function will assign an available request_id */ staticvoid tw_state_request_start(TW_Device_Extension *tw_dev, int *request_id)
{
*request_id = tw_dev->free_queue[tw_dev->free_head];
tw_dev->free_head = (tw_dev->free_head + 1) % TW_Q_LENGTH;
tw_dev->state[*request_id] = TW_S_STARTED;
} /* End tw_state_request_start() */
/* Show some statistics about the card */ static ssize_t tw_show_stats(struct device *dev, struct device_attribute *attr, char *buf)
{ struct Scsi_Host *host = class_to_shost(dev);
TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; unsignedlong flags = 0;
ssize_t len;
/* This function will read the aen queue from the isr */ staticint tw_aen_read_queue(TW_Device_Extension *tw_dev, int request_id)
{
TW_Command *command_packet;
TW_Param *param; unsignedlong command_que_value;
u32 status_reg_value; unsignedlong param_value = 0;
/* Now post the command packet */ if ((status_reg_value & TW_STATUS_COMMAND_QUEUE_FULL) == 0) {
dprintk(KERN_WARNING "3w-xxxx: tw_aen_read_queue(): Post succeeded.\n");
tw_dev->srb[request_id] = NULL; /* Flag internal command */
tw_dev->state[request_id] = TW_S_POSTED;
outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
} else {
printk(KERN_WARNING "3w-xxxx: tw_aen_read_queue(): Post failed, will retry.\n"); return 1;
}
return 0;
} /* End tw_aen_read_queue() */
/* This function will complete an aen request from the isr */ staticint tw_aen_complete(TW_Device_Extension *tw_dev, int request_id)
{
TW_Param *param; unsignedshort aen; int error = 0, table_max = 0;
/* This function will drain the aen queue after a soft reset */ staticint tw_aen_drain_queue(TW_Device_Extension *tw_dev)
{
TW_Command *command_packet;
TW_Param *param; int request_id = 0; unsignedlong command_que_value; unsignedlong param_value;
TW_Response_Queue response_queue; unsignedshort aen; unsignedshort aen_code; int finished = 0; int first_reset = 0; int queue = 0; int found = 0, table_max = 0;
/* Now setup the param */ if (tw_dev->alignment_virtual_address[request_id] == NULL) {
printk(KERN_WARNING "3w-xxxx: tw_aen_drain_queue(): Bad alignment virtual address.\n"); return 1;
}
param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
memset(param, 0, sizeof(TW_Sector));
param->table_id = 0x401; /* AEN table */
param->parameter_id = 2; /* Unit code */
param->parameter_size_bytes = 2;
param_value = tw_dev->alignment_physical_address[request_id]; if (param_value == 0) {
printk(KERN_WARNING "3w-xxxx: tw_aen_drain_queue(): Bad alignment physical address.\n"); return 1;
}
command_packet->byte8.param.sgl[0].address = param_value;
command_packet->byte8.param.sgl[0].length = sizeof(TW_Sector);
/* Now drain the controller's aen queue */ do { /* Post command packet */
outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
/* Now poll for completion */ if (tw_poll_status_gone(tw_dev, TW_STATUS_RESPONSE_QUEUE_EMPTY, 30) == 0) {
response_queue.value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
request_id = TW_RESID_OUT(response_queue.response_id);
if (request_id != 0) { /* Unexpected request id */
printk(KERN_WARNING "3w-xxxx: tw_aen_drain_queue(): Unexpected request id.\n"); return 1;
}
if (command_packet->status != 0) { if (command_packet->flags != TW_AEN_TABLE_UNDEFINED) { /* Bad response */
tw_decode_sense(tw_dev, request_id, 0); return 1;
} else { /* We know this is a 3w-1x00, and doesn't support aen's */ return 0;
}
}
/* Now put the aen on the aen_queue */ if (queue == 1) {
tw_dev->aen_queue[tw_dev->aen_tail] = aen; if (tw_dev->aen_tail == TW_Q_LENGTH - 1) {
tw_dev->aen_tail = TW_Q_START;
} else {
tw_dev->aen_tail = tw_dev->aen_tail + 1;
} if (tw_dev->aen_head == tw_dev->aen_tail) { if (tw_dev->aen_head == TW_Q_LENGTH - 1) {
tw_dev->aen_head = TW_Q_START;
} else {
tw_dev->aen_head = tw_dev->aen_head + 1;
}
}
}
found = 1;
} if (found == 0) {
printk(KERN_WARNING "3w-xxxx: tw_aen_drain_queue(): Response never received.\n"); return 1;
}
} while (finished == 0);
return 0;
} /* End tw_aen_drain_queue() */
/* This function will allocate memory */ staticint tw_allocate_memory(TW_Device_Extension *tw_dev, int size, int which)
{ int i;
dma_addr_t dma_handle; unsignedlong *cpu_addr = NULL;
mutex_lock(&tw_mutex); /* Only let one of these through at a time */ if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
mutex_unlock(&tw_mutex); return -EINTR;
}
/* First copy down the buffer length */ if (copy_from_user(&data_buffer_length, argp, sizeof(unsignedint))) goto out;
/* See which ioctl we are doing */ switch (cmd) { case TW_OP_NOP:
dprintk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl(): caught TW_OP_NOP.\n"); break; case TW_OP_AEN_LISTEN:
dprintk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl(): caught TW_AEN_LISTEN.\n");
memset(tw_ioctl->data_buffer, 0, data_buffer_length);
/* Now post the command packet to the controller */
tw_post_command_packet(tw_dev, request_id);
spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
timeout = TW_IOCTL_CHRDEV_TIMEOUT*HZ;
/* Now wait for the command to complete */
timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE, timeout);
/* We timed out, and didn't get an interrupt */ if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) { /* Now we need to reset the board */
printk(KERN_WARNING "3w-xxxx: scsi%d: Character ioctl (0x%x) timed out, resetting card.\n", tw_dev->host->host_no, cmd);
retval = -EIO; if (tw_reset_device_extension(tw_dev)) {
printk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl(): Reset failed for card %d.\n", tw_dev->host->host_no);
} goto out2;
}
/* Now copy in the command packet response */
memcpy(&(tw_ioctl->firmware_command), tw_dev->command_packet_virtual_address[request_id], sizeof(TW_Command));
/* Now copy the response to userspace */ if (copy_to_user(argp, tw_ioctl, sizeof(TW_New_Ioctl) + data_buffer_length)) goto out2;
retval = 0;
out2: /* Now free ioctl buf memory */
dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted + sizeof(TW_New_Ioctl), cpu_addr, dma_handle);
out:
mutex_unlock(&tw_dev->ioctl_lock);
mutex_unlock(&tw_mutex); return retval;
} /* End tw_chrdev_ioctl() */
/* This function handles open for the character device */ /* NOTE that this function races with remove. */ staticint tw_chrdev_open(struct inode *inode, struct file *file)
{ unsignedint minor_number;
/* This function will free up device extension resources */ staticvoid tw_free_device_extension(TW_Device_Extension *tw_dev)
{
dprintk(KERN_NOTICE "3w-xxxx: tw_free_device_extension()\n");
/* Free command packet and generic buffer memory */ if (tw_dev->command_packet_virtual_address[0])
dma_free_coherent(&tw_dev->tw_pci_dev->dev, sizeof(TW_Command) * TW_Q_LENGTH,
tw_dev->command_packet_virtual_address[0],
tw_dev->command_packet_physical_address[0]);
if (tw_dev->alignment_virtual_address[0])
dma_free_coherent(&tw_dev->tw_pci_dev->dev, sizeof(TW_Sector) * TW_Q_LENGTH,
tw_dev->alignment_virtual_address[0],
tw_dev->alignment_physical_address[0]);
} /* End tw_free_device_extension() */
/* This function will send an initconnection command to controller */ staticint tw_initconnection(TW_Device_Extension *tw_dev, int message_credits)
{ unsignedlong command_que_value;
TW_Command *command_packet;
TW_Response_Queue response_queue; int request_id = 0;
if (command_que_value == 0) {
printk(KERN_WARNING "3w-xxxx: tw_initconnection(): Bad command packet physical address.\n"); return 1;
}
/* Send command packet to the board */
outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
/* Poll for completion */ if (tw_poll_status_gone(tw_dev, TW_STATUS_RESPONSE_QUEUE_EMPTY, 30) == 0) {
response_queue.value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
request_id = TW_RESID_OUT(response_queue.response_id);
if (request_id != 0) { /* unexpected request id */
printk(KERN_WARNING "3w-xxxx: tw_initconnection(): Unexpected request id.\n"); return 1;
} if (command_packet->status != 0) { /* bad response */
tw_decode_sense(tw_dev, request_id, 0); return 1;
}
} return 0;
} /* End tw_initconnection() */
/* Set a value in the features table */ staticint tw_setfeature(TW_Device_Extension *tw_dev, int parm, int param_size, unsignedchar *val)
{
TW_Param *param;
TW_Command *command_packet;
TW_Response_Queue response_queue; int request_id = 0; unsignedlong command_que_value; unsignedlong param_value;
command_que_value = tw_dev->command_packet_physical_address[request_id]; if (command_que_value == 0) {
printk(KERN_WARNING "3w-xxxx: tw_setfeature(): Bad command packet physical address.\n"); return 1;
}
/* Send command packet to the board */
outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
/* Poll for completion */ if (tw_poll_status_gone(tw_dev, TW_STATUS_RESPONSE_QUEUE_EMPTY, 30) == 0) {
response_queue.value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
request_id = TW_RESID_OUT(response_queue.response_id);
if (request_id != 0) { /* unexpected request id */
printk(KERN_WARNING "3w-xxxx: tw_setfeature(): Unexpected request id.\n"); return 1;
} if (command_packet->status != 0) { /* bad response */
tw_decode_sense(tw_dev, request_id, 0); return 1;
}
}
return 0;
} /* End tw_setfeature() */
/* This function will reset a controller */ staticint tw_reset_sequence(TW_Device_Extension *tw_dev)
{ int error = 0; int tries = 0; unsignedchar c = 1;
/* Reset the board */ while (tries < TW_MAX_RESET_TRIES) {
TW_SOFT_RESET(tw_dev);
error = tw_setfeature(tw_dev, 2, 1, &c); if (error) {
printk(KERN_WARNING "3w-xxxx: Unable to set features for card, probable old firmware or card.\n");
}
return 0;
} /* End tw_reset_sequence() */
/* This function will initialize the fields of a device extension */ staticint tw_initialize_device_extension(TW_Device_Extension *tw_dev)
{ int i, error=0;
return 0;
} /* End tw_initialize_device_extension() */
/* This function will reset a device extension */ staticint tw_reset_device_extension(TW_Device_Extension *tw_dev)
{ int i = 0; struct scsi_cmnd *srb; unsignedlong flags = 0;
/* This funciton returns unit geometry in cylinders/heads/sectors */ staticint tw_scsi_biosparam(struct scsi_device *sdev, struct block_device *bdev,
sector_t capacity, int geom[])
{ int heads, sectors, cylinders;
/* This is the new scsi eh reset function */ staticint tw_scsi_eh_reset(struct scsi_cmnd *SCpnt)
{
TW_Device_Extension *tw_dev=NULL; int retval = FAILED;
/* Make sure we are not issuing an ioctl or resetting from ioctl */
mutex_lock(&tw_dev->ioctl_lock);
/* Now reset the card and some of the device extension data */ if (tw_reset_device_extension(tw_dev)) {
printk(KERN_WARNING "3w-xxxx: scsi%d: Reset failed.\n", tw_dev->host->host_no); goto out;
}
/* This function is called by the isr to complete an inquiry command */ staticint tw_scsiop_inquiry_complete(TW_Device_Extension *tw_dev, int request_id)
{ unsignedchar *is_unit_present; unsignedchar request_buffer[36];
TW_Param *param;
/* Now read firmware cache setting for this unit */
command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id]; if (command_packet == NULL) {
printk(KERN_WARNING "3w-xxxx: tw_scsiop_mode_sense(): Bad command packet virtual address.\n"); return 1;
}
/* Now try to post the command packet */
tw_post_command_packet(tw_dev, request_id);
return 0;
} /* End tw_scsiop_mode_sense() */
/* This function is called by the isr to complete a mode sense command */ staticint tw_scsiop_mode_sense_complete(TW_Device_Extension *tw_dev, int request_id)
{
TW_Param *param; unsignedchar *flags; unsignedchar request_buffer[8];
/* Now try to post the command to the board */
tw_post_command_packet(tw_dev, request_id);
return 0;
} /* End tw_scsiop_read_capacity() */
/* This function is called by the isr to complete a readcapacity command */ staticint tw_scsiop_read_capacity_complete(TW_Device_Extension *tw_dev, int request_id)
{ unsignedchar *param_data;
u32 capacity; char buff[8];
TW_Param *param;
command_que_value = tw_dev->command_packet_physical_address[request_id]; if (command_que_value == 0) {
dprintk(KERN_WARNING "3w-xxxx: tw_scsiop_read_write(): Bad command packet physical address.\n"); return 1;
}
/* Now try to post the command to the board */
tw_post_command_packet(tw_dev, request_id);
return 0;
} /* End tw_scsiop_read_write() */
/* This function will handle the request sense scsi command */ staticint tw_scsiop_request_sense(TW_Device_Extension *tw_dev, int request_id)
{ char request_buffer[18];
/* If we got a request_sense, we probably want a reset, return error */
tw_dev->srb[request_id]->result = (DID_ERROR << 16);
scsi_done(tw_dev->srb[request_id]);
return 0;
} /* End tw_scsiop_request_sense() */
/* This function will handle synchronize cache scsi command */ staticint tw_scsiop_synchronize_cache(TW_Device_Extension *tw_dev, int request_id)
{
TW_Command *command_packet; unsignedlong command_que_value;
/* Now try to post the command packet */
tw_post_command_packet(tw_dev, request_id);
return 0;
} /* End tw_scsiop_synchronize_cache() */
/* This function will handle test unit ready scsi command */ staticint tw_scsiop_test_unit_ready(TW_Device_Extension *tw_dev, int request_id)
{
TW_Param *param;
TW_Command *command_packet; unsignedlong command_que_value; unsignedlong param_value;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.