2 3w-9xxx.c -- 3ware 9000 Storage Controller device driver for Linux.
4 Written By: Adam Radford <linuxraid@amcc.com>
5 Modifications By: Tom Couch <linuxraid@amcc.com>
7 Copyright (C) 2004-2007 Applied Micro Circuits Corporation.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
19 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 solely responsible for determining the appropriateness of using and
24 distributing the Program and assumes all risks associated with its
25 exercise of rights under this Agreement, including but not limited to
26 the risks and costs of program errors, damage to or loss of data,
27 programs or equipment, and unavailability or interruption of operations.
29 DISCLAIMER OF LIABILITY
30 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 You should have received a copy of the GNU General Public License
39 along with this program; if not, write to the Free Software
40 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
42 Bugs/Comments/Suggestions should be mailed to:
45 For more information, goto:
48 Note: This version of the driver does not contain a bundled firmware
53 2.26.02.000 - Driver cleanup for kernel submission.
54 2.26.02.001 - Replace schedule_timeout() calls with msleep().
55 2.26.02.002 - Add support for PAE mode.
57 Fix twa_remove() to free irq handler/unregister_chrdev()
58 before shutting down card.
59 Change to new 'change_queue_depth' api.
60 Fix 'handled=1' ISR usage, remove bogus IRQ check.
61 Remove un-needed eh_abort handler.
62 Add support for embedded firmware error strings.
63 2.26.02.003 - Correctly handle single sgl's with use_sg=1.
64 2.26.02.004 - Add support for 9550SX controllers.
65 2.26.02.005 - Fix use_sg == 0 mapping on systems with 4GB or higher.
66 2.26.02.006 - Fix 9550SX pchip reset timeout.
67 Add big endian support.
68 2.26.02.007 - Disable local interrupts during kmap/unmap_atomic().
69 2.26.02.008 - Free irq handler in __twa_shutdown().
71 Add support for 9650SE controllers.
72 2.26.02.009 - Fix dma mask setting to fallback to 32-bit if 64-bit fails.
75 #include <linux/module.h>
76 #include <linux/reboot.h>
77 #include <linux/spinlock.h>
78 #include <linux/interrupt.h>
79 #include <linux/moduleparam.h>
80 #include <linux/errno.h>
81 #include <linux/types.h>
82 #include <linux/delay.h>
83 #include <linux/pci.h>
84 #include <linux/time.h>
85 #include <linux/mutex.h>
88 #include <asm/uaccess.h>
89 #include <scsi/scsi.h>
90 #include <scsi/scsi_host.h>
91 #include <scsi/scsi_tcq.h>
92 #include <scsi/scsi_cmnd.h>
96 #define TW_DRIVER_VERSION "2.26.02.009"
97 static TW_Device_Extension
*twa_device_extension_list
[TW_MAX_SLOT
];
98 static unsigned int twa_device_extension_count
;
99 static int twa_major
= -1;
100 extern struct timezone sys_tz
;
102 /* Module parameters */
103 MODULE_AUTHOR ("AMCC");
104 MODULE_DESCRIPTION ("3ware 9000 Storage Controller Linux Driver");
105 MODULE_LICENSE("GPL");
106 MODULE_VERSION(TW_DRIVER_VERSION
);
108 /* Function prototypes */
109 static void twa_aen_queue_event(TW_Device_Extension
*tw_dev
, TW_Command_Apache_Header
*header
);
110 static int twa_aen_read_queue(TW_Device_Extension
*tw_dev
, int request_id
);
111 static char *twa_aen_severity_lookup(unsigned char severity_code
);
112 static void twa_aen_sync_time(TW_Device_Extension
*tw_dev
, int request_id
);
113 static int twa_chrdev_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
);
114 static int twa_chrdev_open(struct inode
*inode
, struct file
*file
);
115 static int twa_fill_sense(TW_Device_Extension
*tw_dev
, int request_id
, int copy_sense
, int print_host
);
116 static void twa_free_request_id(TW_Device_Extension
*tw_dev
,int request_id
);
117 static void twa_get_request_id(TW_Device_Extension
*tw_dev
, int *request_id
);
118 static int twa_initconnection(TW_Device_Extension
*tw_dev
, int message_credits
,
119 u32 set_features
, unsigned short current_fw_srl
,
120 unsigned short current_fw_arch_id
,
121 unsigned short current_fw_branch
,
122 unsigned short current_fw_build
,
123 unsigned short *fw_on_ctlr_srl
,
124 unsigned short *fw_on_ctlr_arch_id
,
125 unsigned short *fw_on_ctlr_branch
,
126 unsigned short *fw_on_ctlr_build
,
127 u32
*init_connect_result
);
128 static void twa_load_sgl(TW_Command_Full
*full_command_packet
, int request_id
, dma_addr_t dma_handle
, int length
);
129 static int twa_poll_response(TW_Device_Extension
*tw_dev
, int request_id
, int seconds
);
130 static int twa_poll_status_gone(TW_Device_Extension
*tw_dev
, u32 flag
, int seconds
);
131 static int twa_post_command_packet(TW_Device_Extension
*tw_dev
, int request_id
, char internal
);
132 static int twa_reset_device_extension(TW_Device_Extension
*tw_dev
, int ioctl_reset
);
133 static int twa_reset_sequence(TW_Device_Extension
*tw_dev
, int soft_reset
);
134 static int twa_scsiop_execute_scsi(TW_Device_Extension
*tw_dev
, int request_id
, char *cdb
, int use_sg
, TW_SG_Entry
*sglistarg
);
135 static void twa_scsiop_execute_scsi_complete(TW_Device_Extension
*tw_dev
, int request_id
);
136 static char *twa_string_lookup(twa_message_type
*table
, unsigned int aen_code
);
137 static void twa_unmap_scsi_data(TW_Device_Extension
*tw_dev
, int request_id
);
141 /* Show some statistics about the card */
142 static ssize_t
twa_show_stats(struct class_device
*class_dev
, char *buf
)
144 struct Scsi_Host
*host
= class_to_shost(class_dev
);
145 TW_Device_Extension
*tw_dev
= (TW_Device_Extension
*)host
->hostdata
;
146 unsigned long flags
= 0;
149 spin_lock_irqsave(tw_dev
->host
->host_lock
, flags
);
150 len
= snprintf(buf
, PAGE_SIZE
, "3w-9xxx Driver version: %s\n"
151 "Current commands posted: %4d\n"
152 "Max commands posted: %4d\n"
153 "Current pending commands: %4d\n"
154 "Max pending commands: %4d\n"
155 "Last sgl length: %4d\n"
156 "Max sgl length: %4d\n"
157 "Last sector count: %4d\n"
158 "Max sector count: %4d\n"
159 "SCSI Host Resets: %4d\n"
162 tw_dev
->posted_request_count
,
163 tw_dev
->max_posted_request_count
,
164 tw_dev
->pending_request_count
,
165 tw_dev
->max_pending_request_count
,
167 tw_dev
->max_sgl_entries
,
168 tw_dev
->sector_count
,
169 tw_dev
->max_sector_count
,
172 spin_unlock_irqrestore(tw_dev
->host
->host_lock
, flags
);
174 } /* End twa_show_stats() */
176 /* This function will set a devices queue depth */
177 static int twa_change_queue_depth(struct scsi_device
*sdev
, int queue_depth
)
179 if (queue_depth
> TW_Q_LENGTH
-2)
180 queue_depth
= TW_Q_LENGTH
-2;
181 scsi_adjust_queue_depth(sdev
, MSG_ORDERED_TAG
, queue_depth
);
183 } /* End twa_change_queue_depth() */
185 /* Create sysfs 'stats' entry */
186 static struct class_device_attribute twa_host_stats_attr
= {
191 .show
= twa_show_stats
194 /* Host attributes initializer */
195 static struct class_device_attribute
*twa_host_attrs
[] = {
196 &twa_host_stats_attr
,
200 /* File operations struct for character device */
201 static const struct file_operations twa_fops
= {
202 .owner
= THIS_MODULE
,
203 .ioctl
= twa_chrdev_ioctl
,
204 .open
= twa_chrdev_open
,
208 /* This function will complete an aen request from the isr */
209 static int twa_aen_complete(TW_Device_Extension
*tw_dev
, int request_id
)
211 TW_Command_Full
*full_command_packet
;
212 TW_Command
*command_packet
;
213 TW_Command_Apache_Header
*header
;
217 header
= (TW_Command_Apache_Header
*)tw_dev
->generic_buffer_virt
[request_id
];
218 tw_dev
->posted_request_count
--;
219 aen
= le16_to_cpu(header
->status_block
.error
);
220 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
221 command_packet
= &full_command_packet
->command
.oldcommand
;
223 /* First check for internal completion of set param for time sync */
224 if (TW_OP_OUT(command_packet
->opcode__sgloffset
) == TW_OP_SET_PARAM
) {
225 /* Keep reading the queue in case there are more aen's */
226 if (twa_aen_read_queue(tw_dev
, request_id
))
235 case TW_AEN_QUEUE_EMPTY
:
236 /* Quit reading the queue if this is the last one */
238 case TW_AEN_SYNC_TIME_WITH_HOST
:
239 twa_aen_sync_time(tw_dev
, request_id
);
243 twa_aen_queue_event(tw_dev
, header
);
245 /* If there are more aen's, keep reading the queue */
246 if (twa_aen_read_queue(tw_dev
, request_id
))
255 tw_dev
->state
[request_id
] = TW_S_COMPLETED
;
256 twa_free_request_id(tw_dev
, request_id
);
257 clear_bit(TW_IN_ATTENTION_LOOP
, &tw_dev
->flags
);
260 } /* End twa_aen_complete() */
262 /* This function will drain aen queue */
263 static int twa_aen_drain_queue(TW_Device_Extension
*tw_dev
, int no_check_reset
)
266 char cdb
[TW_MAX_CDB_LEN
];
267 TW_SG_Entry sglist
[1];
268 int finished
= 0, count
= 0;
269 TW_Command_Full
*full_command_packet
;
270 TW_Command_Apache_Header
*header
;
272 int first_reset
= 0, queue
= 0, retval
= 1;
279 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
280 memset(full_command_packet
, 0, sizeof(TW_Command_Full
));
283 memset(&cdb
, 0, TW_MAX_CDB_LEN
);
284 cdb
[0] = REQUEST_SENSE
; /* opcode */
285 cdb
[4] = TW_ALLOCATION_LENGTH
; /* allocation length */
287 /* Initialize sglist */
288 memset(&sglist
, 0, sizeof(TW_SG_Entry
));
289 sglist
[0].length
= TW_SECTOR_SIZE
;
290 sglist
[0].address
= tw_dev
->generic_buffer_phys
[request_id
];
292 if (sglist
[0].address
& TW_ALIGNMENT_9000_SGL
) {
293 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x1, "Found unaligned address during AEN drain");
297 /* Mark internal command */
298 tw_dev
->srb
[request_id
] = NULL
;
301 /* Send command to the board */
302 if (twa_scsiop_execute_scsi(tw_dev
, request_id
, cdb
, 1, sglist
)) {
303 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x2, "Error posting request sense");
307 /* Now poll for completion */
308 if (twa_poll_response(tw_dev
, request_id
, 30)) {
309 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x3, "No valid response while draining AEN queue");
310 tw_dev
->posted_request_count
--;
314 tw_dev
->posted_request_count
--;
315 header
= (TW_Command_Apache_Header
*)tw_dev
->generic_buffer_virt
[request_id
];
316 aen
= le16_to_cpu(header
->status_block
.error
);
321 case TW_AEN_QUEUE_EMPTY
:
322 if (first_reset
!= 1)
327 case TW_AEN_SOFT_RESET
:
328 if (first_reset
== 0)
333 case TW_AEN_SYNC_TIME_WITH_HOST
:
339 /* Now queue an event info */
341 twa_aen_queue_event(tw_dev
, header
);
342 } while ((finished
== 0) && (count
< TW_MAX_AEN_DRAIN
));
344 if (count
== TW_MAX_AEN_DRAIN
)
349 tw_dev
->state
[request_id
] = TW_S_INITIAL
;
351 } /* End twa_aen_drain_queue() */
353 /* This function will queue an event */
354 static void twa_aen_queue_event(TW_Device_Extension
*tw_dev
, TW_Command_Apache_Header
*header
)
365 /* Fill out event info */
366 event
= tw_dev
->event_queue
[tw_dev
->error_index
];
368 /* Check for clobber */
371 sprintf(host
, " scsi%d:", tw_dev
->host
->host_no
);
372 if (event
->retrieved
== TW_AEN_NOT_RETRIEVED
)
373 tw_dev
->aen_clobber
= 1;
376 aen
= le16_to_cpu(header
->status_block
.error
);
377 memset(event
, 0, sizeof(TW_Event
));
379 event
->severity
= TW_SEV_OUT(header
->status_block
.severity__reserved
);
380 do_gettimeofday(&time
);
381 local_time
= (u32
)(time
.tv_sec
- (sys_tz
.tz_minuteswest
* 60));
382 event
->time_stamp_sec
= local_time
;
383 event
->aen_code
= aen
;
384 event
->retrieved
= TW_AEN_NOT_RETRIEVED
;
385 event
->sequence_id
= tw_dev
->error_sequence_id
;
386 tw_dev
->error_sequence_id
++;
388 /* Check for embedded error string */
389 error_str
= &(header
->err_specific_desc
[strlen(header
->err_specific_desc
)+1]);
391 header
->err_specific_desc
[sizeof(header
->err_specific_desc
) - 1] = '\0';
392 event
->parameter_len
= strlen(header
->err_specific_desc
);
393 memcpy(event
->parameter_data
, header
->err_specific_desc
, event
->parameter_len
+ (error_str
[0] == '\0' ? 0 : (1 + strlen(error_str
))));
394 if (event
->severity
!= TW_AEN_SEVERITY_DEBUG
)
395 printk(KERN_WARNING
"3w-9xxx:%s AEN: %s (0x%02X:0x%04X): %s:%s.\n",
397 twa_aen_severity_lookup(TW_SEV_OUT(header
->status_block
.severity__reserved
)),
398 TW_MESSAGE_SOURCE_CONTROLLER_EVENT
, aen
,
399 error_str
[0] == '\0' ? twa_string_lookup(twa_aen_table
, aen
) : error_str
,
400 header
->err_specific_desc
);
404 if ((tw_dev
->error_index
+ 1) == TW_Q_LENGTH
)
405 tw_dev
->event_queue_wrapped
= 1;
406 tw_dev
->error_index
= (tw_dev
->error_index
+ 1 ) % TW_Q_LENGTH
;
407 } /* End twa_aen_queue_event() */
409 /* This function will read the aen queue from the isr */
410 static int twa_aen_read_queue(TW_Device_Extension
*tw_dev
, int request_id
)
412 char cdb
[TW_MAX_CDB_LEN
];
413 TW_SG_Entry sglist
[1];
414 TW_Command_Full
*full_command_packet
;
417 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
418 memset(full_command_packet
, 0, sizeof(TW_Command_Full
));
421 memset(&cdb
, 0, TW_MAX_CDB_LEN
);
422 cdb
[0] = REQUEST_SENSE
; /* opcode */
423 cdb
[4] = TW_ALLOCATION_LENGTH
; /* allocation length */
425 /* Initialize sglist */
426 memset(&sglist
, 0, sizeof(TW_SG_Entry
));
427 sglist
[0].length
= TW_SECTOR_SIZE
;
428 sglist
[0].address
= tw_dev
->generic_buffer_phys
[request_id
];
430 /* Mark internal command */
431 tw_dev
->srb
[request_id
] = NULL
;
433 /* Now post the command packet */
434 if (twa_scsiop_execute_scsi(tw_dev
, request_id
, cdb
, 1, sglist
)) {
435 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x4, "Post failed while reading AEN queue");
441 } /* End twa_aen_read_queue() */
443 /* This function will look up an AEN severity string */
444 static char *twa_aen_severity_lookup(unsigned char severity_code
)
448 if ((severity_code
< (unsigned char) TW_AEN_SEVERITY_ERROR
) ||
449 (severity_code
> (unsigned char) TW_AEN_SEVERITY_DEBUG
))
452 retval
= twa_aen_severity_table
[severity_code
];
455 } /* End twa_aen_severity_lookup() */
457 /* This function will sync firmware time with the host time */
458 static void twa_aen_sync_time(TW_Device_Extension
*tw_dev
, int request_id
)
462 TW_Command_Full
*full_command_packet
;
463 TW_Command
*command_packet
;
464 TW_Param_Apache
*param
;
467 /* Fill out the command packet */
468 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
469 memset(full_command_packet
, 0, sizeof(TW_Command_Full
));
470 command_packet
= &full_command_packet
->command
.oldcommand
;
471 command_packet
->opcode__sgloffset
= TW_OPSGL_IN(2, TW_OP_SET_PARAM
);
472 command_packet
->request_id
= request_id
;
473 command_packet
->byte8_offset
.param
.sgl
[0].address
= TW_CPU_TO_SGL(tw_dev
->generic_buffer_phys
[request_id
]);
474 command_packet
->byte8_offset
.param
.sgl
[0].length
= cpu_to_le32(TW_SECTOR_SIZE
);
475 command_packet
->size
= TW_COMMAND_SIZE
;
476 command_packet
->byte6_offset
.parameter_count
= cpu_to_le16(1);
478 /* Setup the param */
479 param
= (TW_Param_Apache
*)tw_dev
->generic_buffer_virt
[request_id
];
480 memset(param
, 0, TW_SECTOR_SIZE
);
481 param
->table_id
= cpu_to_le16(TW_TIMEKEEP_TABLE
| 0x8000); /* Controller time keep table */
482 param
->parameter_id
= cpu_to_le16(0x3); /* SchedulerTime */
483 param
->parameter_size_bytes
= cpu_to_le16(4);
485 /* Convert system time in UTC to local time seconds since last
487 do_gettimeofday(&utc
);
488 local_time
= (u32
)(utc
.tv_sec
- (sys_tz
.tz_minuteswest
* 60));
489 schedulertime
= local_time
- (3 * 86400);
490 schedulertime
= cpu_to_le32(schedulertime
% 604800);
492 memcpy(param
->data
, &schedulertime
, sizeof(u32
));
494 /* Mark internal command */
495 tw_dev
->srb
[request_id
] = NULL
;
497 /* Now post the command */
498 twa_post_command_packet(tw_dev
, request_id
, 1);
499 } /* End twa_aen_sync_time() */
501 /* This function will allocate memory and check if it is correctly aligned */
502 static int twa_allocate_memory(TW_Device_Extension
*tw_dev
, int size
, int which
)
505 dma_addr_t dma_handle
;
506 unsigned long *cpu_addr
;
509 cpu_addr
= pci_alloc_consistent(tw_dev
->tw_pci_dev
, size
*TW_Q_LENGTH
, &dma_handle
);
511 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x5, "Memory allocation failed");
515 if ((unsigned long)cpu_addr
% (TW_ALIGNMENT_9000
)) {
516 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x6, "Failed to allocate correctly aligned memory");
517 pci_free_consistent(tw_dev
->tw_pci_dev
, size
*TW_Q_LENGTH
, cpu_addr
, dma_handle
);
521 memset(cpu_addr
, 0, size
*TW_Q_LENGTH
);
523 for (i
= 0; i
< TW_Q_LENGTH
; i
++) {
526 tw_dev
->command_packet_phys
[i
] = dma_handle
+(i
*size
);
527 tw_dev
->command_packet_virt
[i
] = (TW_Command_Full
*)((unsigned char *)cpu_addr
+ (i
*size
));
530 tw_dev
->generic_buffer_phys
[i
] = dma_handle
+(i
*size
);
531 tw_dev
->generic_buffer_virt
[i
] = (unsigned long *)((unsigned char *)cpu_addr
+ (i
*size
));
538 } /* End twa_allocate_memory() */
540 /* This function will check the status register for unexpected bits */
541 static int twa_check_bits(u32 status_reg_value
)
545 if ((status_reg_value
& TW_STATUS_EXPECTED_BITS
) != TW_STATUS_EXPECTED_BITS
)
547 if ((status_reg_value
& TW_STATUS_UNEXPECTED_BITS
) != 0)
553 } /* End twa_check_bits() */
555 /* This function will check the srl and decide if we are compatible */
556 static int twa_check_srl(TW_Device_Extension
*tw_dev
, int *flashed
)
559 unsigned short fw_on_ctlr_srl
= 0, fw_on_ctlr_arch_id
= 0;
560 unsigned short fw_on_ctlr_branch
= 0, fw_on_ctlr_build
= 0;
561 u32 init_connect_result
= 0;
563 if (twa_initconnection(tw_dev
, TW_INIT_MESSAGE_CREDITS
,
564 TW_EXTENDED_INIT_CONNECT
, TW_CURRENT_DRIVER_SRL
,
565 TW_9000_ARCH_ID
, TW_CURRENT_DRIVER_BRANCH
,
566 TW_CURRENT_DRIVER_BUILD
, &fw_on_ctlr_srl
,
567 &fw_on_ctlr_arch_id
, &fw_on_ctlr_branch
,
568 &fw_on_ctlr_build
, &init_connect_result
)) {
569 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x7, "Initconnection failed while checking SRL");
573 tw_dev
->tw_compat_info
.working_srl
= fw_on_ctlr_srl
;
574 tw_dev
->tw_compat_info
.working_branch
= fw_on_ctlr_branch
;
575 tw_dev
->tw_compat_info
.working_build
= fw_on_ctlr_build
;
577 /* Try base mode compatibility */
578 if (!(init_connect_result
& TW_CTLR_FW_COMPATIBLE
)) {
579 if (twa_initconnection(tw_dev
, TW_INIT_MESSAGE_CREDITS
,
580 TW_EXTENDED_INIT_CONNECT
,
581 TW_BASE_FW_SRL
, TW_9000_ARCH_ID
,
582 TW_BASE_FW_BRANCH
, TW_BASE_FW_BUILD
,
583 &fw_on_ctlr_srl
, &fw_on_ctlr_arch_id
,
584 &fw_on_ctlr_branch
, &fw_on_ctlr_build
,
585 &init_connect_result
)) {
586 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0xa, "Initconnection (base mode) failed while checking SRL");
589 if (!(init_connect_result
& TW_CTLR_FW_COMPATIBLE
)) {
590 if (TW_CURRENT_DRIVER_SRL
> fw_on_ctlr_srl
) {
591 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x32, "Firmware and driver incompatibility: please upgrade firmware");
593 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x33, "Firmware and driver incompatibility: please upgrade driver");
597 tw_dev
->tw_compat_info
.working_srl
= TW_BASE_FW_SRL
;
598 tw_dev
->tw_compat_info
.working_branch
= TW_BASE_FW_BRANCH
;
599 tw_dev
->tw_compat_info
.working_build
= TW_BASE_FW_BUILD
;
602 /* Load rest of compatibility struct */
603 strncpy(tw_dev
->tw_compat_info
.driver_version
, TW_DRIVER_VERSION
, strlen(TW_DRIVER_VERSION
));
604 tw_dev
->tw_compat_info
.driver_srl_high
= TW_CURRENT_DRIVER_SRL
;
605 tw_dev
->tw_compat_info
.driver_branch_high
= TW_CURRENT_DRIVER_BRANCH
;
606 tw_dev
->tw_compat_info
.driver_build_high
= TW_CURRENT_DRIVER_BUILD
;
607 tw_dev
->tw_compat_info
.driver_srl_low
= TW_BASE_FW_SRL
;
608 tw_dev
->tw_compat_info
.driver_branch_low
= TW_BASE_FW_BRANCH
;
609 tw_dev
->tw_compat_info
.driver_build_low
= TW_BASE_FW_BUILD
;
610 tw_dev
->tw_compat_info
.fw_on_ctlr_srl
= fw_on_ctlr_srl
;
611 tw_dev
->tw_compat_info
.fw_on_ctlr_branch
= fw_on_ctlr_branch
;
612 tw_dev
->tw_compat_info
.fw_on_ctlr_build
= fw_on_ctlr_build
;
617 } /* End twa_check_srl() */
619 /* This function handles ioctl for the character device */
620 static int twa_chrdev_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
623 unsigned long *cpu_addr
, data_buffer_length_adjusted
= 0, flags
= 0;
624 dma_addr_t dma_handle
;
626 unsigned int sequence_id
= 0;
627 unsigned char event_index
, start_index
;
628 TW_Ioctl_Driver_Command driver_command
;
629 TW_Ioctl_Buf_Apache
*tw_ioctl
;
631 TW_Command_Full
*full_command_packet
;
632 TW_Compatibility_Info
*tw_compat_info
;
634 struct timeval current_time
;
636 TW_Device_Extension
*tw_dev
= twa_device_extension_list
[iminor(inode
)];
637 int retval
= TW_IOCTL_ERROR_OS_EFAULT
;
638 void __user
*argp
= (void __user
*)arg
;
640 /* Only let one of these through at a time */
641 if (mutex_lock_interruptible(&tw_dev
->ioctl_lock
)) {
642 retval
= TW_IOCTL_ERROR_OS_EINTR
;
646 /* First copy down the driver command */
647 if (copy_from_user(&driver_command
, argp
, sizeof(TW_Ioctl_Driver_Command
)))
650 /* Check data buffer size */
651 if (driver_command
.buffer_length
> TW_MAX_SECTORS
* 2048) {
652 retval
= TW_IOCTL_ERROR_OS_EINVAL
;
656 /* Hardware can only do multiple of 512 byte transfers */
657 data_buffer_length_adjusted
= (driver_command
.buffer_length
+ 511) & ~511;
659 /* Now allocate ioctl buf memory */
660 cpu_addr
= dma_alloc_coherent(&tw_dev
->tw_pci_dev
->dev
, data_buffer_length_adjusted
+sizeof(TW_Ioctl_Buf_Apache
) - 1, &dma_handle
, GFP_KERNEL
);
662 retval
= TW_IOCTL_ERROR_OS_ENOMEM
;
666 tw_ioctl
= (TW_Ioctl_Buf_Apache
*)cpu_addr
;
668 /* Now copy down the entire ioctl */
669 if (copy_from_user(tw_ioctl
, argp
, driver_command
.buffer_length
+ sizeof(TW_Ioctl_Buf_Apache
) - 1))
672 /* See which ioctl we are doing */
674 case TW_IOCTL_FIRMWARE_PASS_THROUGH
:
675 spin_lock_irqsave(tw_dev
->host
->host_lock
, flags
);
676 twa_get_request_id(tw_dev
, &request_id
);
678 /* Flag internal command */
679 tw_dev
->srb
[request_id
] = NULL
;
681 /* Flag chrdev ioctl */
682 tw_dev
->chrdev_request_id
= request_id
;
684 full_command_packet
= &tw_ioctl
->firmware_command
;
686 /* Load request id and sglist for both command types */
687 twa_load_sgl(full_command_packet
, request_id
, dma_handle
, data_buffer_length_adjusted
);
689 memcpy(tw_dev
->command_packet_virt
[request_id
], &(tw_ioctl
->firmware_command
), sizeof(TW_Command_Full
));
691 /* Now post the command packet to the controller */
692 twa_post_command_packet(tw_dev
, request_id
, 1);
693 spin_unlock_irqrestore(tw_dev
->host
->host_lock
, flags
);
695 timeout
= TW_IOCTL_CHRDEV_TIMEOUT
*HZ
;
697 /* Now wait for command to complete */
698 timeout
= wait_event_timeout(tw_dev
->ioctl_wqueue
, tw_dev
->chrdev_request_id
== TW_IOCTL_CHRDEV_FREE
, timeout
);
700 /* We timed out, and didn't get an interrupt */
701 if (tw_dev
->chrdev_request_id
!= TW_IOCTL_CHRDEV_FREE
) {
702 /* Now we need to reset the board */
703 printk(KERN_WARNING
"3w-9xxx: scsi%d: WARNING: (0x%02X:0x%04X): Character ioctl (0x%x) timed out, resetting card.\n",
704 tw_dev
->host
->host_no
, TW_DRIVER
, 0xc,
706 retval
= TW_IOCTL_ERROR_OS_EIO
;
707 twa_reset_device_extension(tw_dev
, 1);
711 /* Now copy in the command packet response */
712 memcpy(&(tw_ioctl
->firmware_command
), tw_dev
->command_packet_virt
[request_id
], sizeof(TW_Command_Full
));
714 /* Now complete the io */
715 spin_lock_irqsave(tw_dev
->host
->host_lock
, flags
);
716 tw_dev
->posted_request_count
--;
717 tw_dev
->state
[request_id
] = TW_S_COMPLETED
;
718 twa_free_request_id(tw_dev
, request_id
);
719 spin_unlock_irqrestore(tw_dev
->host
->host_lock
, flags
);
721 case TW_IOCTL_GET_COMPATIBILITY_INFO
:
722 tw_ioctl
->driver_command
.status
= 0;
723 /* Copy compatiblity struct into ioctl data buffer */
724 tw_compat_info
= (TW_Compatibility_Info
*)tw_ioctl
->data_buffer
;
725 memcpy(tw_compat_info
, &tw_dev
->tw_compat_info
, sizeof(TW_Compatibility_Info
));
727 case TW_IOCTL_GET_LAST_EVENT
:
728 if (tw_dev
->event_queue_wrapped
) {
729 if (tw_dev
->aen_clobber
) {
730 tw_ioctl
->driver_command
.status
= TW_IOCTL_ERROR_STATUS_AEN_CLOBBER
;
731 tw_dev
->aen_clobber
= 0;
733 tw_ioctl
->driver_command
.status
= 0;
735 if (!tw_dev
->error_index
) {
736 tw_ioctl
->driver_command
.status
= TW_IOCTL_ERROR_STATUS_NO_MORE_EVENTS
;
739 tw_ioctl
->driver_command
.status
= 0;
741 event_index
= (tw_dev
->error_index
- 1 + TW_Q_LENGTH
) % TW_Q_LENGTH
;
742 memcpy(tw_ioctl
->data_buffer
, tw_dev
->event_queue
[event_index
], sizeof(TW_Event
));
743 tw_dev
->event_queue
[event_index
]->retrieved
= TW_AEN_RETRIEVED
;
745 case TW_IOCTL_GET_FIRST_EVENT
:
746 if (tw_dev
->event_queue_wrapped
) {
747 if (tw_dev
->aen_clobber
) {
748 tw_ioctl
->driver_command
.status
= TW_IOCTL_ERROR_STATUS_AEN_CLOBBER
;
749 tw_dev
->aen_clobber
= 0;
751 tw_ioctl
->driver_command
.status
= 0;
752 event_index
= tw_dev
->error_index
;
754 if (!tw_dev
->error_index
) {
755 tw_ioctl
->driver_command
.status
= TW_IOCTL_ERROR_STATUS_NO_MORE_EVENTS
;
758 tw_ioctl
->driver_command
.status
= 0;
761 memcpy(tw_ioctl
->data_buffer
, tw_dev
->event_queue
[event_index
], sizeof(TW_Event
));
762 tw_dev
->event_queue
[event_index
]->retrieved
= TW_AEN_RETRIEVED
;
764 case TW_IOCTL_GET_NEXT_EVENT
:
765 event
= (TW_Event
*)tw_ioctl
->data_buffer
;
766 sequence_id
= event
->sequence_id
;
767 tw_ioctl
->driver_command
.status
= 0;
769 if (tw_dev
->event_queue_wrapped
) {
770 if (tw_dev
->aen_clobber
) {
771 tw_ioctl
->driver_command
.status
= TW_IOCTL_ERROR_STATUS_AEN_CLOBBER
;
772 tw_dev
->aen_clobber
= 0;
774 start_index
= tw_dev
->error_index
;
776 if (!tw_dev
->error_index
) {
777 tw_ioctl
->driver_command
.status
= TW_IOCTL_ERROR_STATUS_NO_MORE_EVENTS
;
782 event_index
= (start_index
+ sequence_id
- tw_dev
->event_queue
[start_index
]->sequence_id
+ 1) % TW_Q_LENGTH
;
784 if (!(tw_dev
->event_queue
[event_index
]->sequence_id
> sequence_id
)) {
785 if (tw_ioctl
->driver_command
.status
== TW_IOCTL_ERROR_STATUS_AEN_CLOBBER
)
786 tw_dev
->aen_clobber
= 1;
787 tw_ioctl
->driver_command
.status
= TW_IOCTL_ERROR_STATUS_NO_MORE_EVENTS
;
790 memcpy(tw_ioctl
->data_buffer
, tw_dev
->event_queue
[event_index
], sizeof(TW_Event
));
791 tw_dev
->event_queue
[event_index
]->retrieved
= TW_AEN_RETRIEVED
;
793 case TW_IOCTL_GET_PREVIOUS_EVENT
:
794 event
= (TW_Event
*)tw_ioctl
->data_buffer
;
795 sequence_id
= event
->sequence_id
;
796 tw_ioctl
->driver_command
.status
= 0;
798 if (tw_dev
->event_queue_wrapped
) {
799 if (tw_dev
->aen_clobber
) {
800 tw_ioctl
->driver_command
.status
= TW_IOCTL_ERROR_STATUS_AEN_CLOBBER
;
801 tw_dev
->aen_clobber
= 0;
803 start_index
= tw_dev
->error_index
;
805 if (!tw_dev
->error_index
) {
806 tw_ioctl
->driver_command
.status
= TW_IOCTL_ERROR_STATUS_NO_MORE_EVENTS
;
811 event_index
= (start_index
+ sequence_id
- tw_dev
->event_queue
[start_index
]->sequence_id
- 1) % TW_Q_LENGTH
;
813 if (!(tw_dev
->event_queue
[event_index
]->sequence_id
< sequence_id
)) {
814 if (tw_ioctl
->driver_command
.status
== TW_IOCTL_ERROR_STATUS_AEN_CLOBBER
)
815 tw_dev
->aen_clobber
= 1;
816 tw_ioctl
->driver_command
.status
= TW_IOCTL_ERROR_STATUS_NO_MORE_EVENTS
;
819 memcpy(tw_ioctl
->data_buffer
, tw_dev
->event_queue
[event_index
], sizeof(TW_Event
));
820 tw_dev
->event_queue
[event_index
]->retrieved
= TW_AEN_RETRIEVED
;
822 case TW_IOCTL_GET_LOCK
:
823 tw_lock
= (TW_Lock
*)tw_ioctl
->data_buffer
;
824 do_gettimeofday(¤t_time
);
825 current_time_ms
= (current_time
.tv_sec
* 1000) + (current_time
.tv_usec
/ 1000);
827 if ((tw_lock
->force_flag
== 1) || (tw_dev
->ioctl_sem_lock
== 0) || (current_time_ms
>= tw_dev
->ioctl_msec
)) {
828 tw_dev
->ioctl_sem_lock
= 1;
829 tw_dev
->ioctl_msec
= current_time_ms
+ tw_lock
->timeout_msec
;
830 tw_ioctl
->driver_command
.status
= 0;
831 tw_lock
->time_remaining_msec
= tw_lock
->timeout_msec
;
833 tw_ioctl
->driver_command
.status
= TW_IOCTL_ERROR_STATUS_LOCKED
;
834 tw_lock
->time_remaining_msec
= tw_dev
->ioctl_msec
- current_time_ms
;
837 case TW_IOCTL_RELEASE_LOCK
:
838 if (tw_dev
->ioctl_sem_lock
== 1) {
839 tw_dev
->ioctl_sem_lock
= 0;
840 tw_ioctl
->driver_command
.status
= 0;
842 tw_ioctl
->driver_command
.status
= TW_IOCTL_ERROR_STATUS_NOT_LOCKED
;
846 retval
= TW_IOCTL_ERROR_OS_ENOTTY
;
850 /* Now copy the entire response to userspace */
851 if (copy_to_user(argp
, tw_ioctl
, sizeof(TW_Ioctl_Buf_Apache
) + driver_command
.buffer_length
- 1) == 0)
854 /* Now free ioctl buf memory */
855 dma_free_coherent(&tw_dev
->tw_pci_dev
->dev
, data_buffer_length_adjusted
+sizeof(TW_Ioctl_Buf_Apache
) - 1, cpu_addr
, dma_handle
);
857 mutex_unlock(&tw_dev
->ioctl_lock
);
860 } /* End twa_chrdev_ioctl() */
862 /* This function handles open for the character device */
863 static int twa_chrdev_open(struct inode
*inode
, struct file
*file
)
865 unsigned int minor_number
;
866 int retval
= TW_IOCTL_ERROR_OS_ENODEV
;
868 minor_number
= iminor(inode
);
869 if (minor_number
>= twa_device_extension_count
)
874 } /* End twa_chrdev_open() */
876 /* This function will print readable messages from status register errors */
877 static int twa_decode_bits(TW_Device_Extension
*tw_dev
, u32 status_reg_value
)
881 /* Check for various error conditions and handle them appropriately */
882 if (status_reg_value
& TW_STATUS_PCI_PARITY_ERROR
) {
883 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0xc, "PCI Parity Error: clearing");
884 writel(TW_CONTROL_CLEAR_PARITY_ERROR
, TW_CONTROL_REG_ADDR(tw_dev
));
887 if (status_reg_value
& TW_STATUS_PCI_ABORT
) {
888 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0xd, "PCI Abort: clearing");
889 writel(TW_CONTROL_CLEAR_PCI_ABORT
, TW_CONTROL_REG_ADDR(tw_dev
));
890 pci_write_config_word(tw_dev
->tw_pci_dev
, PCI_STATUS
, TW_PCI_CLEAR_PCI_ABORT
);
893 if (status_reg_value
& TW_STATUS_QUEUE_ERROR
) {
894 if ((tw_dev
->tw_pci_dev
->device
!= PCI_DEVICE_ID_3WARE_9650SE
) || (!test_bit(TW_IN_RESET
, &tw_dev
->flags
)))
895 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0xe, "Controller Queue Error: clearing");
896 writel(TW_CONTROL_CLEAR_QUEUE_ERROR
, TW_CONTROL_REG_ADDR(tw_dev
));
899 if (status_reg_value
& TW_STATUS_MICROCONTROLLER_ERROR
) {
900 if (tw_dev
->reset_print
== 0) {
901 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x10, "Microcontroller Error: clearing");
902 tw_dev
->reset_print
= 1;
909 } /* End twa_decode_bits() */
911 /* This function will empty the response queue */
912 static int twa_empty_response_queue(TW_Device_Extension
*tw_dev
)
914 u32 status_reg_value
, response_que_value
;
915 int count
= 0, retval
= 1;
917 status_reg_value
= readl(TW_STATUS_REG_ADDR(tw_dev
));
919 while (((status_reg_value
& TW_STATUS_RESPONSE_QUEUE_EMPTY
) == 0) && (count
< TW_MAX_RESPONSE_DRAIN
)) {
920 response_que_value
= readl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev
));
921 status_reg_value
= readl(TW_STATUS_REG_ADDR(tw_dev
));
924 if (count
== TW_MAX_RESPONSE_DRAIN
)
930 } /* End twa_empty_response_queue() */
932 /* This function will clear the pchip/response queue on 9550SX */
933 static int twa_empty_response_queue_large(TW_Device_Extension
*tw_dev
)
935 u32 response_que_value
= 0;
936 unsigned long before
;
939 if ((tw_dev
->tw_pci_dev
->device
== PCI_DEVICE_ID_3WARE_9550SX
) ||
940 (tw_dev
->tw_pci_dev
->device
== PCI_DEVICE_ID_3WARE_9650SE
)) {
942 while ((response_que_value
& TW_9550SX_DRAIN_COMPLETED
) != TW_9550SX_DRAIN_COMPLETED
) {
943 response_que_value
= readl(TW_RESPONSE_QUEUE_REG_ADDR_LARGE(tw_dev
));
945 if (time_after(jiffies
, before
+ HZ
* 30))
948 /* P-chip settle time */
955 } /* End twa_empty_response_queue_large() */
957 /* This function passes sense keys from firmware to scsi layer */
958 static int twa_fill_sense(TW_Device_Extension
*tw_dev
, int request_id
, int copy_sense
, int print_host
)
960 TW_Command_Full
*full_command_packet
;
961 unsigned short error
;
965 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
967 /* Check for embedded error string */
968 error_str
= &(full_command_packet
->header
.err_specific_desc
[strlen(full_command_packet
->header
.err_specific_desc
) + 1]);
970 /* Don't print error for Logical unit not supported during rollcall */
971 error
= le16_to_cpu(full_command_packet
->header
.status_block
.error
);
972 if ((error
!= TW_ERROR_LOGICAL_UNIT_NOT_SUPPORTED
) && (error
!= TW_ERROR_UNIT_OFFLINE
)) {
974 printk(KERN_WARNING
"3w-9xxx: scsi%d: ERROR: (0x%02X:0x%04X): %s:%s.\n",
975 tw_dev
->host
->host_no
,
976 TW_MESSAGE_SOURCE_CONTROLLER_ERROR
,
977 full_command_packet
->header
.status_block
.error
,
978 error_str
[0] == '\0' ?
979 twa_string_lookup(twa_error_table
,
980 full_command_packet
->header
.status_block
.error
) : error_str
,
981 full_command_packet
->header
.err_specific_desc
);
983 printk(KERN_WARNING
"3w-9xxx: ERROR: (0x%02X:0x%04X): %s:%s.\n",
984 TW_MESSAGE_SOURCE_CONTROLLER_ERROR
,
985 full_command_packet
->header
.status_block
.error
,
986 error_str
[0] == '\0' ?
987 twa_string_lookup(twa_error_table
,
988 full_command_packet
->header
.status_block
.error
) : error_str
,
989 full_command_packet
->header
.err_specific_desc
);
993 memcpy(tw_dev
->srb
[request_id
]->sense_buffer
, full_command_packet
->header
.sense_data
, TW_SENSE_DATA_LENGTH
);
994 tw_dev
->srb
[request_id
]->result
= (full_command_packet
->command
.newcommand
.status
<< 1);
995 retval
= TW_ISR_DONT_RESULT
;
1001 } /* End twa_fill_sense() */
1003 /* This function will free up device extension resources */
1004 static void twa_free_device_extension(TW_Device_Extension
*tw_dev
)
1006 if (tw_dev
->command_packet_virt
[0])
1007 pci_free_consistent(tw_dev
->tw_pci_dev
,
1008 sizeof(TW_Command_Full
)*TW_Q_LENGTH
,
1009 tw_dev
->command_packet_virt
[0],
1010 tw_dev
->command_packet_phys
[0]);
1012 if (tw_dev
->generic_buffer_virt
[0])
1013 pci_free_consistent(tw_dev
->tw_pci_dev
,
1014 TW_SECTOR_SIZE
*TW_Q_LENGTH
,
1015 tw_dev
->generic_buffer_virt
[0],
1016 tw_dev
->generic_buffer_phys
[0]);
1018 kfree(tw_dev
->event_queue
[0]);
1019 } /* End twa_free_device_extension() */
1021 /* This function will free a request id */
1022 static void twa_free_request_id(TW_Device_Extension
*tw_dev
, int request_id
)
1024 tw_dev
->free_queue
[tw_dev
->free_tail
] = request_id
;
1025 tw_dev
->state
[request_id
] = TW_S_FINISHED
;
1026 tw_dev
->free_tail
= (tw_dev
->free_tail
+ 1) % TW_Q_LENGTH
;
1027 } /* End twa_free_request_id() */
1029 /* This function will get parameter table entries from the firmware */
1030 static void *twa_get_param(TW_Device_Extension
*tw_dev
, int request_id
, int table_id
, int parameter_id
, int parameter_size_bytes
)
1032 TW_Command_Full
*full_command_packet
;
1033 TW_Command
*command_packet
;
1034 TW_Param_Apache
*param
;
1035 unsigned long param_value
;
1036 void *retval
= NULL
;
1038 /* Setup the command packet */
1039 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
1040 memset(full_command_packet
, 0, sizeof(TW_Command_Full
));
1041 command_packet
= &full_command_packet
->command
.oldcommand
;
1043 command_packet
->opcode__sgloffset
= TW_OPSGL_IN(2, TW_OP_GET_PARAM
);
1044 command_packet
->size
= TW_COMMAND_SIZE
;
1045 command_packet
->request_id
= request_id
;
1046 command_packet
->byte6_offset
.block_count
= cpu_to_le16(1);
1048 /* Now setup the param */
1049 param
= (TW_Param_Apache
*)tw_dev
->generic_buffer_virt
[request_id
];
1050 memset(param
, 0, TW_SECTOR_SIZE
);
1051 param
->table_id
= cpu_to_le16(table_id
| 0x8000);
1052 param
->parameter_id
= cpu_to_le16(parameter_id
);
1053 param
->parameter_size_bytes
= cpu_to_le16(parameter_size_bytes
);
1054 param_value
= tw_dev
->generic_buffer_phys
[request_id
];
1056 command_packet
->byte8_offset
.param
.sgl
[0].address
= TW_CPU_TO_SGL(param_value
);
1057 command_packet
->byte8_offset
.param
.sgl
[0].length
= cpu_to_le32(TW_SECTOR_SIZE
);
1059 /* Post the command packet to the board */
1060 twa_post_command_packet(tw_dev
, request_id
, 1);
1062 /* Poll for completion */
1063 if (twa_poll_response(tw_dev
, request_id
, 30))
1064 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x13, "No valid response during get param")
1066 retval
= (void *)&(param
->data
[0]);
1068 tw_dev
->posted_request_count
--;
1069 tw_dev
->state
[request_id
] = TW_S_INITIAL
;
1072 } /* End twa_get_param() */
1074 /* This function will assign an available request id */
1075 static void twa_get_request_id(TW_Device_Extension
*tw_dev
, int *request_id
)
1077 *request_id
= tw_dev
->free_queue
[tw_dev
->free_head
];
1078 tw_dev
->free_head
= (tw_dev
->free_head
+ 1) % TW_Q_LENGTH
;
1079 tw_dev
->state
[*request_id
] = TW_S_STARTED
;
1080 } /* End twa_get_request_id() */
1082 /* This function will send an initconnection command to controller */
1083 static int twa_initconnection(TW_Device_Extension
*tw_dev
, int message_credits
,
1084 u32 set_features
, unsigned short current_fw_srl
,
1085 unsigned short current_fw_arch_id
,
1086 unsigned short current_fw_branch
,
1087 unsigned short current_fw_build
,
1088 unsigned short *fw_on_ctlr_srl
,
1089 unsigned short *fw_on_ctlr_arch_id
,
1090 unsigned short *fw_on_ctlr_branch
,
1091 unsigned short *fw_on_ctlr_build
,
1092 u32
*init_connect_result
)
1094 TW_Command_Full
*full_command_packet
;
1095 TW_Initconnect
*tw_initconnect
;
1096 int request_id
= 0, retval
= 1;
1098 /* Initialize InitConnection command packet */
1099 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
1100 memset(full_command_packet
, 0, sizeof(TW_Command_Full
));
1101 full_command_packet
->header
.header_desc
.size_header
= 128;
1103 tw_initconnect
= (TW_Initconnect
*)&full_command_packet
->command
.oldcommand
;
1104 tw_initconnect
->opcode__reserved
= TW_OPRES_IN(0, TW_OP_INIT_CONNECTION
);
1105 tw_initconnect
->request_id
= request_id
;
1106 tw_initconnect
->message_credits
= cpu_to_le16(message_credits
);
1107 tw_initconnect
->features
= set_features
;
1109 /* Turn on 64-bit sgl support if we need to */
1110 tw_initconnect
->features
|= sizeof(dma_addr_t
) > 4 ? 1 : 0;
1112 tw_initconnect
->features
= cpu_to_le32(tw_initconnect
->features
);
1114 if (set_features
& TW_EXTENDED_INIT_CONNECT
) {
1115 tw_initconnect
->size
= TW_INIT_COMMAND_PACKET_SIZE_EXTENDED
;
1116 tw_initconnect
->fw_srl
= cpu_to_le16(current_fw_srl
);
1117 tw_initconnect
->fw_arch_id
= cpu_to_le16(current_fw_arch_id
);
1118 tw_initconnect
->fw_branch
= cpu_to_le16(current_fw_branch
);
1119 tw_initconnect
->fw_build
= cpu_to_le16(current_fw_build
);
1121 tw_initconnect
->size
= TW_INIT_COMMAND_PACKET_SIZE
;
1123 /* Send command packet to the board */
1124 twa_post_command_packet(tw_dev
, request_id
, 1);
1126 /* Poll for completion */
1127 if (twa_poll_response(tw_dev
, request_id
, 30)) {
1128 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x15, "No valid response during init connection");
1130 if (set_features
& TW_EXTENDED_INIT_CONNECT
) {
1131 *fw_on_ctlr_srl
= le16_to_cpu(tw_initconnect
->fw_srl
);
1132 *fw_on_ctlr_arch_id
= le16_to_cpu(tw_initconnect
->fw_arch_id
);
1133 *fw_on_ctlr_branch
= le16_to_cpu(tw_initconnect
->fw_branch
);
1134 *fw_on_ctlr_build
= le16_to_cpu(tw_initconnect
->fw_build
);
1135 *init_connect_result
= le32_to_cpu(tw_initconnect
->result
);
1140 tw_dev
->posted_request_count
--;
1141 tw_dev
->state
[request_id
] = TW_S_INITIAL
;
1144 } /* End twa_initconnection() */
1146 /* This function will initialize the fields of a device extension */
1147 static int twa_initialize_device_extension(TW_Device_Extension
*tw_dev
)
1151 /* Initialize command packet buffers */
1152 if (twa_allocate_memory(tw_dev
, sizeof(TW_Command_Full
), 0)) {
1153 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x16, "Command packet memory allocation failed");
1157 /* Initialize generic buffer */
1158 if (twa_allocate_memory(tw_dev
, TW_SECTOR_SIZE
, 1)) {
1159 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x17, "Generic memory allocation failed");
1163 /* Allocate event info space */
1164 tw_dev
->event_queue
[0] = kcalloc(TW_Q_LENGTH
, sizeof(TW_Event
), GFP_KERNEL
);
1165 if (!tw_dev
->event_queue
[0]) {
1166 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x18, "Event info memory allocation failed");
1171 for (i
= 0; i
< TW_Q_LENGTH
; i
++) {
1172 tw_dev
->event_queue
[i
] = (TW_Event
*)((unsigned char *)tw_dev
->event_queue
[0] + (i
* sizeof(TW_Event
)));
1173 tw_dev
->free_queue
[i
] = i
;
1174 tw_dev
->state
[i
] = TW_S_INITIAL
;
1177 tw_dev
->pending_head
= TW_Q_START
;
1178 tw_dev
->pending_tail
= TW_Q_START
;
1179 tw_dev
->free_head
= TW_Q_START
;
1180 tw_dev
->free_tail
= TW_Q_START
;
1181 tw_dev
->error_sequence_id
= 1;
1182 tw_dev
->chrdev_request_id
= TW_IOCTL_CHRDEV_FREE
;
1184 mutex_init(&tw_dev
->ioctl_lock
);
1185 init_waitqueue_head(&tw_dev
->ioctl_wqueue
);
1190 } /* End twa_initialize_device_extension() */
1192 /* This function is the interrupt service routine */
1193 static irqreturn_t
twa_interrupt(int irq
, void *dev_instance
)
1195 int request_id
, error
= 0;
1196 u32 status_reg_value
;
1197 TW_Response_Queue response_que
;
1198 TW_Command_Full
*full_command_packet
;
1199 TW_Command
*command_packet
;
1200 TW_Device_Extension
*tw_dev
= (TW_Device_Extension
*)dev_instance
;
1203 /* Get the per adapter lock */
1204 spin_lock(tw_dev
->host
->host_lock
);
1206 /* Read the registers */
1207 status_reg_value
= readl(TW_STATUS_REG_ADDR(tw_dev
));
1209 /* Check if this is our interrupt, otherwise bail */
1210 if (!(status_reg_value
& TW_STATUS_VALID_INTERRUPT
))
1211 goto twa_interrupt_bail
;
1215 /* If we are resetting, bail */
1216 if (test_bit(TW_IN_RESET
, &tw_dev
->flags
))
1217 goto twa_interrupt_bail
;
1219 /* Check controller for errors */
1220 if (twa_check_bits(status_reg_value
)) {
1221 if (twa_decode_bits(tw_dev
, status_reg_value
)) {
1222 TW_CLEAR_ALL_INTERRUPTS(tw_dev
);
1223 goto twa_interrupt_bail
;
1227 /* Handle host interrupt */
1228 if (status_reg_value
& TW_STATUS_HOST_INTERRUPT
)
1229 TW_CLEAR_HOST_INTERRUPT(tw_dev
);
1231 /* Handle attention interrupt */
1232 if (status_reg_value
& TW_STATUS_ATTENTION_INTERRUPT
) {
1233 TW_CLEAR_ATTENTION_INTERRUPT(tw_dev
);
1234 if (!(test_and_set_bit(TW_IN_ATTENTION_LOOP
, &tw_dev
->flags
))) {
1235 twa_get_request_id(tw_dev
, &request_id
);
1237 error
= twa_aen_read_queue(tw_dev
, request_id
);
1239 tw_dev
->state
[request_id
] = TW_S_COMPLETED
;
1240 twa_free_request_id(tw_dev
, request_id
);
1241 clear_bit(TW_IN_ATTENTION_LOOP
, &tw_dev
->flags
);
1246 /* Handle command interrupt */
1247 if (status_reg_value
& TW_STATUS_COMMAND_INTERRUPT
) {
1248 TW_MASK_COMMAND_INTERRUPT(tw_dev
);
1249 /* Drain as many pending commands as we can */
1250 while (tw_dev
->pending_request_count
> 0) {
1251 request_id
= tw_dev
->pending_queue
[tw_dev
->pending_head
];
1252 if (tw_dev
->state
[request_id
] != TW_S_PENDING
) {
1253 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x19, "Found request id that wasn't pending");
1254 TW_CLEAR_ALL_INTERRUPTS(tw_dev
);
1255 goto twa_interrupt_bail
;
1257 if (twa_post_command_packet(tw_dev
, request_id
, 1)==0) {
1258 tw_dev
->pending_head
= (tw_dev
->pending_head
+ 1) % TW_Q_LENGTH
;
1259 tw_dev
->pending_request_count
--;
1261 /* If we get here, we will continue re-posting on the next command interrupt */
1267 /* Handle response interrupt */
1268 if (status_reg_value
& TW_STATUS_RESPONSE_INTERRUPT
) {
1270 /* Drain the response queue from the board */
1271 while ((status_reg_value
& TW_STATUS_RESPONSE_QUEUE_EMPTY
) == 0) {
1272 /* Complete the response */
1273 response_que
.value
= readl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev
));
1274 request_id
= TW_RESID_OUT(response_que
.response_id
);
1275 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
1277 command_packet
= &full_command_packet
->command
.oldcommand
;
1278 /* Check for command packet errors */
1279 if (full_command_packet
->command
.newcommand
.status
!= 0) {
1280 if (tw_dev
->srb
[request_id
] != 0) {
1281 error
= twa_fill_sense(tw_dev
, request_id
, 1, 1);
1283 /* Skip ioctl error prints */
1284 if (request_id
!= tw_dev
->chrdev_request_id
) {
1285 error
= twa_fill_sense(tw_dev
, request_id
, 0, 1);
1290 /* Check for correct state */
1291 if (tw_dev
->state
[request_id
] != TW_S_POSTED
) {
1292 if (tw_dev
->srb
[request_id
] != 0) {
1293 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x1a, "Received a request id that wasn't posted");
1294 TW_CLEAR_ALL_INTERRUPTS(tw_dev
);
1295 goto twa_interrupt_bail
;
1299 /* Check for internal command completion */
1300 if (tw_dev
->srb
[request_id
] == 0) {
1301 if (request_id
!= tw_dev
->chrdev_request_id
) {
1302 if (twa_aen_complete(tw_dev
, request_id
))
1303 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x1b, "Error completing AEN during attention interrupt");
1305 tw_dev
->chrdev_request_id
= TW_IOCTL_CHRDEV_FREE
;
1306 wake_up(&tw_dev
->ioctl_wqueue
);
1309 twa_scsiop_execute_scsi_complete(tw_dev
, request_id
);
1310 /* If no error command was a success */
1312 tw_dev
->srb
[request_id
]->result
= (DID_OK
<< 16);
1315 /* If error, command failed */
1317 /* Ask for a host reset */
1318 tw_dev
->srb
[request_id
]->result
= (DID_OK
<< 16) | (CHECK_CONDITION
<< 1);
1321 /* Report residual bytes for single sgl */
1322 if ((tw_dev
->srb
[request_id
]->use_sg
<= 1) && (full_command_packet
->command
.newcommand
.status
== 0)) {
1323 if (full_command_packet
->command
.newcommand
.sg_list
[0].length
< tw_dev
->srb
[request_id
]->request_bufflen
)
1324 tw_dev
->srb
[request_id
]->resid
= tw_dev
->srb
[request_id
]->request_bufflen
- full_command_packet
->command
.newcommand
.sg_list
[0].length
;
1327 /* Now complete the io */
1328 tw_dev
->state
[request_id
] = TW_S_COMPLETED
;
1329 twa_free_request_id(tw_dev
, request_id
);
1330 tw_dev
->posted_request_count
--;
1331 tw_dev
->srb
[request_id
]->scsi_done(tw_dev
->srb
[request_id
]);
1332 twa_unmap_scsi_data(tw_dev
, request_id
);
1335 /* Check for valid status after each drain */
1336 status_reg_value
= readl(TW_STATUS_REG_ADDR(tw_dev
));
1337 if (twa_check_bits(status_reg_value
)) {
1338 if (twa_decode_bits(tw_dev
, status_reg_value
)) {
1339 TW_CLEAR_ALL_INTERRUPTS(tw_dev
);
1340 goto twa_interrupt_bail
;
1347 spin_unlock(tw_dev
->host
->host_lock
);
1348 return IRQ_RETVAL(handled
);
1349 } /* End twa_interrupt() */
1351 /* This function will load the request id and various sgls for ioctls */
1352 static void twa_load_sgl(TW_Command_Full
*full_command_packet
, int request_id
, dma_addr_t dma_handle
, int length
)
1354 TW_Command
*oldcommand
;
1355 TW_Command_Apache
*newcommand
;
1358 if (TW_OP_OUT(full_command_packet
->command
.newcommand
.opcode__reserved
) == TW_OP_EXECUTE_SCSI
) {
1359 newcommand
= &full_command_packet
->command
.newcommand
;
1360 newcommand
->request_id__lunl
=
1361 cpu_to_le16(TW_REQ_LUN_IN(TW_LUN_OUT(newcommand
->request_id__lunl
), request_id
));
1362 newcommand
->sg_list
[0].address
= TW_CPU_TO_SGL(dma_handle
+ sizeof(TW_Ioctl_Buf_Apache
) - 1);
1363 newcommand
->sg_list
[0].length
= cpu_to_le32(length
);
1364 newcommand
->sgl_entries__lunh
=
1365 cpu_to_le16(TW_REQ_LUN_IN(TW_LUN_OUT(newcommand
->sgl_entries__lunh
), 1));
1367 oldcommand
= &full_command_packet
->command
.oldcommand
;
1368 oldcommand
->request_id
= request_id
;
1370 if (TW_SGL_OUT(oldcommand
->opcode__sgloffset
)) {
1371 /* Load the sg list */
1372 sgl
= (TW_SG_Entry
*)((u32
*)oldcommand
+TW_SGL_OUT(oldcommand
->opcode__sgloffset
));
1373 sgl
->address
= TW_CPU_TO_SGL(dma_handle
+ sizeof(TW_Ioctl_Buf_Apache
) - 1);
1374 sgl
->length
= cpu_to_le32(length
);
1376 if ((sizeof(long) < 8) && (sizeof(dma_addr_t
) > 4))
1377 oldcommand
->size
+= 1;
1380 } /* End twa_load_sgl() */
1382 /* This function will perform a pci-dma mapping for a scatter gather list */
1383 static int twa_map_scsi_sg_data(TW_Device_Extension
*tw_dev
, int request_id
)
1386 struct scsi_cmnd
*cmd
= tw_dev
->srb
[request_id
];
1387 struct pci_dev
*pdev
= tw_dev
->tw_pci_dev
;
1390 if (cmd
->use_sg
== 0)
1393 use_sg
= pci_map_sg(pdev
, cmd
->request_buffer
, cmd
->use_sg
, DMA_BIDIRECTIONAL
);
1396 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x1c, "Failed to map scatter gather list");
1400 cmd
->SCp
.phase
= TW_PHASE_SGLIST
;
1401 cmd
->SCp
.have_data_in
= use_sg
;
1405 } /* End twa_map_scsi_sg_data() */
1407 /* This function will perform a pci-dma map for a single buffer */
1408 static dma_addr_t
twa_map_scsi_single_data(TW_Device_Extension
*tw_dev
, int request_id
)
1411 struct scsi_cmnd
*cmd
= tw_dev
->srb
[request_id
];
1412 struct pci_dev
*pdev
= tw_dev
->tw_pci_dev
;
1413 dma_addr_t retval
= 0;
1415 if (cmd
->request_bufflen
== 0) {
1420 mapping
= pci_map_single(pdev
, cmd
->request_buffer
, cmd
->request_bufflen
, DMA_BIDIRECTIONAL
);
1423 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x1d, "Failed to map page");
1427 cmd
->SCp
.phase
= TW_PHASE_SINGLE
;
1428 cmd
->SCp
.have_data_in
= mapping
;
1432 } /* End twa_map_scsi_single_data() */
1434 /* This function will poll for a response interrupt of a request */
1435 static int twa_poll_response(TW_Device_Extension
*tw_dev
, int request_id
, int seconds
)
1437 int retval
= 1, found
= 0, response_request_id
;
1438 TW_Response_Queue response_queue
;
1439 TW_Command_Full
*full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
1441 if (twa_poll_status_gone(tw_dev
, TW_STATUS_RESPONSE_QUEUE_EMPTY
, seconds
) == 0) {
1442 response_queue
.value
= readl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev
));
1443 response_request_id
= TW_RESID_OUT(response_queue
.response_id
);
1444 if (request_id
!= response_request_id
) {
1445 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x1e, "Found unexpected request id while polling for response");
1448 if (TW_OP_OUT(full_command_packet
->command
.newcommand
.opcode__reserved
) == TW_OP_EXECUTE_SCSI
) {
1449 if (full_command_packet
->command
.newcommand
.status
!= 0) {
1451 twa_fill_sense(tw_dev
, request_id
, 0, 0);
1456 if (full_command_packet
->command
.oldcommand
.status
!= 0) {
1458 twa_fill_sense(tw_dev
, request_id
, 0, 0);
1469 } /* End twa_poll_response() */
1471 /* This function will poll the status register for a flag */
1472 static int twa_poll_status(TW_Device_Extension
*tw_dev
, u32 flag
, int seconds
)
1474 u32 status_reg_value
;
1475 unsigned long before
;
1478 status_reg_value
= readl(TW_STATUS_REG_ADDR(tw_dev
));
1481 if (twa_check_bits(status_reg_value
))
1482 twa_decode_bits(tw_dev
, status_reg_value
);
1484 while ((status_reg_value
& flag
) != flag
) {
1485 status_reg_value
= readl(TW_STATUS_REG_ADDR(tw_dev
));
1487 if (twa_check_bits(status_reg_value
))
1488 twa_decode_bits(tw_dev
, status_reg_value
);
1490 if (time_after(jiffies
, before
+ HZ
* seconds
))
1498 } /* End twa_poll_status() */
1500 /* This function will poll the status register for disappearance of a flag */
1501 static int twa_poll_status_gone(TW_Device_Extension
*tw_dev
, u32 flag
, int seconds
)
1503 u32 status_reg_value
;
1504 unsigned long before
;
1507 status_reg_value
= readl(TW_STATUS_REG_ADDR(tw_dev
));
1510 if (twa_check_bits(status_reg_value
))
1511 twa_decode_bits(tw_dev
, status_reg_value
);
1513 while ((status_reg_value
& flag
) != 0) {
1514 status_reg_value
= readl(TW_STATUS_REG_ADDR(tw_dev
));
1515 if (twa_check_bits(status_reg_value
))
1516 twa_decode_bits(tw_dev
, status_reg_value
);
1518 if (time_after(jiffies
, before
+ HZ
* seconds
))
1526 } /* End twa_poll_status_gone() */
1528 /* This function will attempt to post a command packet to the board */
1529 static int twa_post_command_packet(TW_Device_Extension
*tw_dev
, int request_id
, char internal
)
1531 u32 status_reg_value
;
1532 dma_addr_t command_que_value
;
1535 command_que_value
= tw_dev
->command_packet_phys
[request_id
];
1537 /* For 9650SE write low 4 bytes first */
1538 if (tw_dev
->tw_pci_dev
->device
== PCI_DEVICE_ID_3WARE_9650SE
) {
1539 command_que_value
+= TW_COMMAND_OFFSET
;
1540 writel((u32
)command_que_value
, TW_COMMAND_QUEUE_REG_ADDR_LARGE(tw_dev
));
1543 status_reg_value
= readl(TW_STATUS_REG_ADDR(tw_dev
));
1545 if (twa_check_bits(status_reg_value
))
1546 twa_decode_bits(tw_dev
, status_reg_value
);
1548 if (((tw_dev
->pending_request_count
> 0) && (tw_dev
->state
[request_id
] != TW_S_PENDING
)) || (status_reg_value
& TW_STATUS_COMMAND_QUEUE_FULL
)) {
1550 /* Only pend internal driver commands */
1552 retval
= SCSI_MLQUEUE_HOST_BUSY
;
1556 /* Couldn't post the command packet, so we do it later */
1557 if (tw_dev
->state
[request_id
] != TW_S_PENDING
) {
1558 tw_dev
->state
[request_id
] = TW_S_PENDING
;
1559 tw_dev
->pending_request_count
++;
1560 if (tw_dev
->pending_request_count
> tw_dev
->max_pending_request_count
) {
1561 tw_dev
->max_pending_request_count
= tw_dev
->pending_request_count
;
1563 tw_dev
->pending_queue
[tw_dev
->pending_tail
] = request_id
;
1564 tw_dev
->pending_tail
= (tw_dev
->pending_tail
+ 1) % TW_Q_LENGTH
;
1566 TW_UNMASK_COMMAND_INTERRUPT(tw_dev
);
1569 if (tw_dev
->tw_pci_dev
->device
== PCI_DEVICE_ID_3WARE_9650SE
) {
1570 /* Now write upper 4 bytes */
1571 writel((u32
)((u64
)command_que_value
>> 32), TW_COMMAND_QUEUE_REG_ADDR_LARGE(tw_dev
) + 0x4);
1573 if (sizeof(dma_addr_t
) > 4) {
1574 command_que_value
+= TW_COMMAND_OFFSET
;
1575 writel((u32
)command_que_value
, TW_COMMAND_QUEUE_REG_ADDR(tw_dev
));
1576 writel((u32
)((u64
)command_que_value
>> 32), TW_COMMAND_QUEUE_REG_ADDR(tw_dev
) + 0x4);
1578 writel(TW_COMMAND_OFFSET
+ command_que_value
, TW_COMMAND_QUEUE_REG_ADDR(tw_dev
));
1581 tw_dev
->state
[request_id
] = TW_S_POSTED
;
1582 tw_dev
->posted_request_count
++;
1583 if (tw_dev
->posted_request_count
> tw_dev
->max_posted_request_count
) {
1584 tw_dev
->max_posted_request_count
= tw_dev
->posted_request_count
;
1590 } /* End twa_post_command_packet() */
1592 /* This function will reset a device extension */
1593 static int twa_reset_device_extension(TW_Device_Extension
*tw_dev
, int ioctl_reset
)
1597 unsigned long flags
= 0;
1599 set_bit(TW_IN_RESET
, &tw_dev
->flags
);
1600 TW_DISABLE_INTERRUPTS(tw_dev
);
1601 TW_MASK_COMMAND_INTERRUPT(tw_dev
);
1602 spin_lock_irqsave(tw_dev
->host
->host_lock
, flags
);
1604 /* Abort all requests that are in progress */
1605 for (i
= 0; i
< TW_Q_LENGTH
; i
++) {
1606 if ((tw_dev
->state
[i
] != TW_S_FINISHED
) &&
1607 (tw_dev
->state
[i
] != TW_S_INITIAL
) &&
1608 (tw_dev
->state
[i
] != TW_S_COMPLETED
)) {
1609 if (tw_dev
->srb
[i
]) {
1610 tw_dev
->srb
[i
]->result
= (DID_RESET
<< 16);
1611 tw_dev
->srb
[i
]->scsi_done(tw_dev
->srb
[i
]);
1612 twa_unmap_scsi_data(tw_dev
, i
);
1617 /* Reset queues and counts */
1618 for (i
= 0; i
< TW_Q_LENGTH
; i
++) {
1619 tw_dev
->free_queue
[i
] = i
;
1620 tw_dev
->state
[i
] = TW_S_INITIAL
;
1622 tw_dev
->free_head
= TW_Q_START
;
1623 tw_dev
->free_tail
= TW_Q_START
;
1624 tw_dev
->posted_request_count
= 0;
1625 tw_dev
->pending_request_count
= 0;
1626 tw_dev
->pending_head
= TW_Q_START
;
1627 tw_dev
->pending_tail
= TW_Q_START
;
1628 tw_dev
->reset_print
= 0;
1630 spin_unlock_irqrestore(tw_dev
->host
->host_lock
, flags
);
1632 if (twa_reset_sequence(tw_dev
, 1))
1635 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev
);
1636 clear_bit(TW_IN_RESET
, &tw_dev
->flags
);
1637 tw_dev
->chrdev_request_id
= TW_IOCTL_CHRDEV_FREE
;
1642 } /* End twa_reset_device_extension() */
1644 /* This function will reset a controller */
1645 static int twa_reset_sequence(TW_Device_Extension
*tw_dev
, int soft_reset
)
1647 int tries
= 0, retval
= 1, flashed
= 0, do_soft_reset
= soft_reset
;
1649 while (tries
< TW_MAX_RESET_TRIES
) {
1650 if (do_soft_reset
) {
1651 TW_SOFT_RESET(tw_dev
);
1652 /* Clear pchip/response queue on 9550SX */
1653 if (twa_empty_response_queue_large(tw_dev
)) {
1654 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x36, "Response queue (large) empty failed during reset sequence");
1661 /* Make sure controller is in a good state */
1662 if (twa_poll_status(tw_dev
, TW_STATUS_MICROCONTROLLER_READY
| (do_soft_reset
== 1 ? TW_STATUS_ATTENTION_INTERRUPT
: 0), 60)) {
1663 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x1f, "Microcontroller not ready during reset sequence");
1669 /* Empty response queue */
1670 if (twa_empty_response_queue(tw_dev
)) {
1671 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x20, "Response queue empty failed during reset sequence");
1679 /* Check for compatibility/flash */
1680 if (twa_check_srl(tw_dev
, &flashed
)) {
1681 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x21, "Compatibility check failed during reset sequence");
1692 /* Drain the AEN queue */
1693 if (twa_aen_drain_queue(tw_dev
, soft_reset
)) {
1694 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x22, "AEN drain failed during reset sequence");
1700 /* If we got here, controller is in a good state */
1706 } /* End twa_reset_sequence() */
1708 /* This funciton returns unit geometry in cylinders/heads/sectors */
1709 static int twa_scsi_biosparam(struct scsi_device
*sdev
, struct block_device
*bdev
, sector_t capacity
, int geom
[])
1711 int heads
, sectors
, cylinders
;
1712 TW_Device_Extension
*tw_dev
;
1714 tw_dev
= (TW_Device_Extension
*)sdev
->host
->hostdata
;
1716 if (capacity
>= 0x200000) {
1719 cylinders
= sector_div(capacity
, heads
* sectors
);
1723 cylinders
= sector_div(capacity
, heads
* sectors
);
1728 geom
[2] = cylinders
;
1731 } /* End twa_scsi_biosparam() */
1733 /* This is the new scsi eh reset function */
1734 static int twa_scsi_eh_reset(struct scsi_cmnd
*SCpnt
)
1736 TW_Device_Extension
*tw_dev
= NULL
;
1737 int retval
= FAILED
;
1739 tw_dev
= (TW_Device_Extension
*)SCpnt
->device
->host
->hostdata
;
1741 tw_dev
->num_resets
++;
1743 sdev_printk(KERN_WARNING
, SCpnt
->device
,
1744 "WARNING: (0x%02X:0x%04X): Command (0x%x) timed out, resetting card.\n",
1745 TW_DRIVER
, 0x2c, SCpnt
->cmnd
[0]);
1747 /* Make sure we are not issuing an ioctl or resetting from ioctl */
1748 mutex_lock(&tw_dev
->ioctl_lock
);
1750 /* Now reset the card and some of the device extension data */
1751 if (twa_reset_device_extension(tw_dev
, 0)) {
1752 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x2b, "Controller reset failed during scsi host reset");
1758 mutex_unlock(&tw_dev
->ioctl_lock
);
1760 } /* End twa_scsi_eh_reset() */
1762 /* This is the main scsi queue function to handle scsi opcodes */
1763 static int twa_scsi_queue(struct scsi_cmnd
*SCpnt
, void (*done
)(struct scsi_cmnd
*))
1765 int request_id
, retval
;
1766 TW_Device_Extension
*tw_dev
= (TW_Device_Extension
*)SCpnt
->device
->host
->hostdata
;
1768 /* If we are resetting due to timed out ioctl, report as busy */
1769 if (test_bit(TW_IN_RESET
, &tw_dev
->flags
)) {
1770 retval
= SCSI_MLQUEUE_HOST_BUSY
;
1774 /* Check if this FW supports luns */
1775 if ((SCpnt
->device
->lun
!= 0) && (tw_dev
->tw_compat_info
.working_srl
< TW_FW_SRL_LUNS_SUPPORTED
)) {
1776 SCpnt
->result
= (DID_BAD_TARGET
<< 16);
1782 /* Save done function into scsi_cmnd struct */
1783 SCpnt
->scsi_done
= done
;
1785 /* Get a free request id */
1786 twa_get_request_id(tw_dev
, &request_id
);
1788 /* Save the scsi command for use by the ISR */
1789 tw_dev
->srb
[request_id
] = SCpnt
;
1791 /* Initialize phase to zero */
1792 SCpnt
->SCp
.phase
= TW_PHASE_INITIAL
;
1794 retval
= twa_scsiop_execute_scsi(tw_dev
, request_id
, NULL
, 0, NULL
);
1796 case SCSI_MLQUEUE_HOST_BUSY
:
1797 twa_free_request_id(tw_dev
, request_id
);
1800 tw_dev
->state
[request_id
] = TW_S_COMPLETED
;
1801 twa_free_request_id(tw_dev
, request_id
);
1802 SCpnt
->result
= (DID_ERROR
<< 16);
1808 } /* End twa_scsi_queue() */
1810 /* This function hands scsi cdb's to the firmware */
1811 static int twa_scsiop_execute_scsi(TW_Device_Extension
*tw_dev
, int request_id
, char *cdb
, int use_sg
, TW_SG_Entry
*sglistarg
)
1813 TW_Command_Full
*full_command_packet
;
1814 TW_Command_Apache
*command_packet
;
1815 u32 num_sectors
= 0x0;
1817 struct scsi_cmnd
*srb
= NULL
;
1818 struct scatterlist
*sglist
= NULL
;
1819 dma_addr_t buffaddr
= 0x0;
1822 if (tw_dev
->srb
[request_id
]) {
1823 if (tw_dev
->srb
[request_id
]->request_buffer
) {
1824 sglist
= (struct scatterlist
*)tw_dev
->srb
[request_id
]->request_buffer
;
1826 srb
= tw_dev
->srb
[request_id
];
1829 /* Initialize command packet */
1830 full_command_packet
= tw_dev
->command_packet_virt
[request_id
];
1831 full_command_packet
->header
.header_desc
.size_header
= 128;
1832 full_command_packet
->header
.status_block
.error
= 0;
1833 full_command_packet
->header
.status_block
.severity__reserved
= 0;
1835 command_packet
= &full_command_packet
->command
.newcommand
;
1836 command_packet
->status
= 0;
1837 command_packet
->opcode__reserved
= TW_OPRES_IN(0, TW_OP_EXECUTE_SCSI
);
1839 /* We forced 16 byte cdb use earlier */
1841 memcpy(command_packet
->cdb
, srb
->cmnd
, TW_MAX_CDB_LEN
);
1843 memcpy(command_packet
->cdb
, cdb
, TW_MAX_CDB_LEN
);
1846 command_packet
->unit
= srb
->device
->id
;
1847 command_packet
->request_id__lunl
=
1848 cpu_to_le16(TW_REQ_LUN_IN(srb
->device
->lun
, request_id
));
1850 command_packet
->request_id__lunl
=
1851 cpu_to_le16(TW_REQ_LUN_IN(0, request_id
));
1852 command_packet
->unit
= 0;
1855 command_packet
->sgl_offset
= 16;
1858 /* Map sglist from scsi layer to cmd packet */
1859 if (tw_dev
->srb
[request_id
]->use_sg
== 0) {
1860 if (tw_dev
->srb
[request_id
]->request_bufflen
< TW_MIN_SGL_LENGTH
) {
1861 command_packet
->sg_list
[0].address
= TW_CPU_TO_SGL(tw_dev
->generic_buffer_phys
[request_id
]);
1862 command_packet
->sg_list
[0].length
= cpu_to_le32(TW_MIN_SGL_LENGTH
);
1863 if (tw_dev
->srb
[request_id
]->sc_data_direction
== DMA_TO_DEVICE
|| tw_dev
->srb
[request_id
]->sc_data_direction
== DMA_BIDIRECTIONAL
)
1864 memcpy(tw_dev
->generic_buffer_virt
[request_id
], tw_dev
->srb
[request_id
]->request_buffer
, tw_dev
->srb
[request_id
]->request_bufflen
);
1866 buffaddr
= twa_map_scsi_single_data(tw_dev
, request_id
);
1870 command_packet
->sg_list
[0].address
= TW_CPU_TO_SGL(buffaddr
);
1871 command_packet
->sg_list
[0].length
= cpu_to_le32(tw_dev
->srb
[request_id
]->request_bufflen
);
1873 command_packet
->sgl_entries__lunh
= cpu_to_le16(TW_REQ_LUN_IN((srb
->device
->lun
>> 4), 1));
1875 if (command_packet
->sg_list
[0].address
& TW_CPU_TO_SGL(TW_ALIGNMENT_9000_SGL
)) {
1876 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x2d, "Found unaligned address during execute scsi");
1881 if (tw_dev
->srb
[request_id
]->use_sg
> 0) {
1882 if ((tw_dev
->srb
[request_id
]->use_sg
== 1) && (tw_dev
->srb
[request_id
]->request_bufflen
< TW_MIN_SGL_LENGTH
)) {
1883 if (tw_dev
->srb
[request_id
]->sc_data_direction
== DMA_TO_DEVICE
|| tw_dev
->srb
[request_id
]->sc_data_direction
== DMA_BIDIRECTIONAL
) {
1884 struct scatterlist
*sg
= (struct scatterlist
*)tw_dev
->srb
[request_id
]->request_buffer
;
1885 char *buf
= kmap_atomic(sg
->page
, KM_IRQ0
) + sg
->offset
;
1886 memcpy(tw_dev
->generic_buffer_virt
[request_id
], buf
, sg
->length
);
1887 kunmap_atomic(buf
- sg
->offset
, KM_IRQ0
);
1889 command_packet
->sg_list
[0].address
= TW_CPU_TO_SGL(tw_dev
->generic_buffer_phys
[request_id
]);
1890 command_packet
->sg_list
[0].length
= cpu_to_le32(TW_MIN_SGL_LENGTH
);
1892 sg_count
= twa_map_scsi_sg_data(tw_dev
, request_id
);
1896 for (i
= 0; i
< sg_count
; i
++) {
1897 command_packet
->sg_list
[i
].address
= TW_CPU_TO_SGL(sg_dma_address(&sglist
[i
]));
1898 command_packet
->sg_list
[i
].length
= cpu_to_le32(sg_dma_len(&sglist
[i
]));
1899 if (command_packet
->sg_list
[i
].address
& TW_CPU_TO_SGL(TW_ALIGNMENT_9000_SGL
)) {
1900 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x2e, "Found unaligned sgl address during execute scsi");
1905 command_packet
->sgl_entries__lunh
= cpu_to_le16(TW_REQ_LUN_IN((srb
->device
->lun
>> 4), tw_dev
->srb
[request_id
]->use_sg
));
1908 /* Internal cdb post */
1909 for (i
= 0; i
< use_sg
; i
++) {
1910 command_packet
->sg_list
[i
].address
= TW_CPU_TO_SGL(sglistarg
[i
].address
);
1911 command_packet
->sg_list
[i
].length
= cpu_to_le32(sglistarg
[i
].length
);
1912 if (command_packet
->sg_list
[i
].address
& TW_CPU_TO_SGL(TW_ALIGNMENT_9000_SGL
)) {
1913 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x2f, "Found unaligned sgl address during internal post");
1917 command_packet
->sgl_entries__lunh
= cpu_to_le16(TW_REQ_LUN_IN(0, use_sg
));
1921 if (srb
->cmnd
[0] == READ_6
|| srb
->cmnd
[0] == WRITE_6
)
1922 num_sectors
= (u32
)srb
->cmnd
[4];
1924 if (srb
->cmnd
[0] == READ_10
|| srb
->cmnd
[0] == WRITE_10
)
1925 num_sectors
= (u32
)srb
->cmnd
[8] | ((u32
)srb
->cmnd
[7] << 8);
1928 /* Update sector statistic */
1929 tw_dev
->sector_count
= num_sectors
;
1930 if (tw_dev
->sector_count
> tw_dev
->max_sector_count
)
1931 tw_dev
->max_sector_count
= tw_dev
->sector_count
;
1933 /* Update SG statistics */
1935 tw_dev
->sgl_entries
= tw_dev
->srb
[request_id
]->use_sg
;
1936 if (tw_dev
->sgl_entries
> tw_dev
->max_sgl_entries
)
1937 tw_dev
->max_sgl_entries
= tw_dev
->sgl_entries
;
1940 /* Now post the command to the board */
1942 retval
= twa_post_command_packet(tw_dev
, request_id
, 0);
1944 twa_post_command_packet(tw_dev
, request_id
, 1);
1949 } /* End twa_scsiop_execute_scsi() */
1951 /* This function completes an execute scsi operation */
1952 static void twa_scsiop_execute_scsi_complete(TW_Device_Extension
*tw_dev
, int request_id
)
1954 if (tw_dev
->srb
[request_id
]->request_bufflen
< TW_MIN_SGL_LENGTH
&&
1955 (tw_dev
->srb
[request_id
]->sc_data_direction
== DMA_FROM_DEVICE
||
1956 tw_dev
->srb
[request_id
]->sc_data_direction
== DMA_BIDIRECTIONAL
)) {
1957 if (tw_dev
->srb
[request_id
]->use_sg
== 0) {
1958 memcpy(tw_dev
->srb
[request_id
]->request_buffer
,
1959 tw_dev
->generic_buffer_virt
[request_id
],
1960 tw_dev
->srb
[request_id
]->request_bufflen
);
1962 if (tw_dev
->srb
[request_id
]->use_sg
== 1) {
1963 struct scatterlist
*sg
= (struct scatterlist
*)tw_dev
->srb
[request_id
]->request_buffer
;
1965 unsigned long flags
= 0;
1966 local_irq_save(flags
);
1967 buf
= kmap_atomic(sg
->page
, KM_IRQ0
) + sg
->offset
;
1968 memcpy(buf
, tw_dev
->generic_buffer_virt
[request_id
], sg
->length
);
1969 kunmap_atomic(buf
- sg
->offset
, KM_IRQ0
);
1970 local_irq_restore(flags
);
1973 } /* End twa_scsiop_execute_scsi_complete() */
1975 /* This function tells the controller to shut down */
1976 static void __twa_shutdown(TW_Device_Extension
*tw_dev
)
1978 /* Disable interrupts */
1979 TW_DISABLE_INTERRUPTS(tw_dev
);
1981 /* Free up the IRQ */
1982 free_irq(tw_dev
->tw_pci_dev
->irq
, tw_dev
);
1984 printk(KERN_WARNING
"3w-9xxx: Shutting down host %d.\n", tw_dev
->host
->host_no
);
1986 /* Tell the card we are shutting down */
1987 if (twa_initconnection(tw_dev
, 1, 0, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
)) {
1988 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x31, "Connection shutdown failed");
1990 printk(KERN_WARNING
"3w-9xxx: Shutdown complete.\n");
1993 /* Clear all interrupts just before exit */
1994 TW_CLEAR_ALL_INTERRUPTS(tw_dev
);
1995 } /* End __twa_shutdown() */
1997 /* Wrapper for __twa_shutdown */
1998 static void twa_shutdown(struct pci_dev
*pdev
)
2000 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
2001 TW_Device_Extension
*tw_dev
= (TW_Device_Extension
*)host
->hostdata
;
2003 __twa_shutdown(tw_dev
);
2004 } /* End twa_shutdown() */
2006 /* This function will look up a string */
2007 static char *twa_string_lookup(twa_message_type
*table
, unsigned int code
)
2011 for (index
= 0; ((code
!= table
[index
].code
) &&
2012 (table
[index
].text
!= (char *)0)); index
++);
2013 return(table
[index
].text
);
2014 } /* End twa_string_lookup() */
2016 /* This function will perform a pci-dma unmap */
2017 static void twa_unmap_scsi_data(TW_Device_Extension
*tw_dev
, int request_id
)
2019 struct scsi_cmnd
*cmd
= tw_dev
->srb
[request_id
];
2020 struct pci_dev
*pdev
= tw_dev
->tw_pci_dev
;
2022 switch(cmd
->SCp
.phase
) {
2023 case TW_PHASE_SINGLE
:
2024 pci_unmap_single(pdev
, cmd
->SCp
.have_data_in
, cmd
->request_bufflen
, DMA_BIDIRECTIONAL
);
2026 case TW_PHASE_SGLIST
:
2027 pci_unmap_sg(pdev
, cmd
->request_buffer
, cmd
->use_sg
, DMA_BIDIRECTIONAL
);
2030 } /* End twa_unmap_scsi_data() */
2032 /* scsi_host_template initializer */
2033 static struct scsi_host_template driver_template
= {
2034 .module
= THIS_MODULE
,
2035 .name
= "3ware 9000 Storage Controller",
2036 .queuecommand
= twa_scsi_queue
,
2037 .eh_host_reset_handler
= twa_scsi_eh_reset
,
2038 .bios_param
= twa_scsi_biosparam
,
2039 .change_queue_depth
= twa_change_queue_depth
,
2040 .can_queue
= TW_Q_LENGTH
-2,
2042 .sg_tablesize
= TW_APACHE_MAX_SGL_LENGTH
,
2043 .max_sectors
= TW_MAX_SECTORS
,
2044 .cmd_per_lun
= TW_MAX_CMDS_PER_LUN
,
2045 .use_clustering
= ENABLE_CLUSTERING
,
2046 .shost_attrs
= twa_host_attrs
,
2050 /* This function will probe and initialize a card */
2051 static int __devinit
twa_probe(struct pci_dev
*pdev
, const struct pci_device_id
*dev_id
)
2053 struct Scsi_Host
*host
= NULL
;
2054 TW_Device_Extension
*tw_dev
;
2056 int retval
= -ENODEV
;
2058 retval
= pci_enable_device(pdev
);
2060 TW_PRINTK(host
, TW_DRIVER
, 0x34, "Failed to enable pci device");
2061 goto out_disable_device
;
2064 pci_set_master(pdev
);
2066 if (pci_set_dma_mask(pdev
, DMA_64BIT_MASK
)
2067 || pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
))
2068 if (pci_set_dma_mask(pdev
, DMA_32BIT_MASK
)
2069 || pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
)) {
2070 TW_PRINTK(host
, TW_DRIVER
, 0x23, "Failed to set dma mask");
2072 goto out_disable_device
;
2075 host
= scsi_host_alloc(&driver_template
, sizeof(TW_Device_Extension
));
2077 TW_PRINTK(host
, TW_DRIVER
, 0x24, "Failed to allocate memory for device extension");
2079 goto out_disable_device
;
2081 tw_dev
= (TW_Device_Extension
*)host
->hostdata
;
2083 memset(tw_dev
, 0, sizeof(TW_Device_Extension
));
2085 /* Save values to device extension */
2086 tw_dev
->host
= host
;
2087 tw_dev
->tw_pci_dev
= pdev
;
2089 if (twa_initialize_device_extension(tw_dev
)) {
2090 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x25, "Failed to initialize device extension");
2091 goto out_free_device_extension
;
2094 /* Request IO regions */
2095 retval
= pci_request_regions(pdev
, "3w-9xxx");
2097 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x26, "Failed to get mem region");
2098 goto out_free_device_extension
;
2101 if (pdev
->device
== PCI_DEVICE_ID_3WARE_9000
)
2102 mem_addr
= pci_resource_start(pdev
, 1);
2104 mem_addr
= pci_resource_start(pdev
, 2);
2106 /* Save base address */
2107 tw_dev
->base_addr
= ioremap(mem_addr
, PAGE_SIZE
);
2108 if (!tw_dev
->base_addr
) {
2109 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x35, "Failed to ioremap");
2110 goto out_release_mem_region
;
2113 /* Disable interrupts on the card */
2114 TW_DISABLE_INTERRUPTS(tw_dev
);
2116 /* Initialize the card */
2117 if (twa_reset_sequence(tw_dev
, 0))
2120 /* Set host specific parameters */
2121 if (pdev
->device
== PCI_DEVICE_ID_3WARE_9650SE
)
2122 host
->max_id
= TW_MAX_UNITS_9650SE
;
2124 host
->max_id
= TW_MAX_UNITS
;
2126 host
->max_cmd_len
= TW_MAX_CDB_LEN
;
2128 /* Channels aren't supported by adapter */
2129 host
->max_lun
= TW_MAX_LUNS(tw_dev
->tw_compat_info
.working_srl
);
2130 host
->max_channel
= 0;
2132 /* Register the card with the kernel SCSI layer */
2133 retval
= scsi_add_host(host
, &pdev
->dev
);
2135 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x27, "scsi add host failed");
2139 pci_set_drvdata(pdev
, host
);
2141 printk(KERN_WARNING
"3w-9xxx: scsi%d: Found a 3ware 9000 Storage Controller at 0x%x, IRQ: %d.\n",
2142 host
->host_no
, mem_addr
, pdev
->irq
);
2143 printk(KERN_WARNING
"3w-9xxx: scsi%d: Firmware %s, BIOS %s, Ports: %d.\n",
2145 (char *)twa_get_param(tw_dev
, 0, TW_VERSION_TABLE
,
2146 TW_PARAM_FWVER
, TW_PARAM_FWVER_LENGTH
),
2147 (char *)twa_get_param(tw_dev
, 1, TW_VERSION_TABLE
,
2148 TW_PARAM_BIOSVER
, TW_PARAM_BIOSVER_LENGTH
),
2149 le32_to_cpu(*(int *)twa_get_param(tw_dev
, 2, TW_INFORMATION_TABLE
,
2150 TW_PARAM_PORTCOUNT
, TW_PARAM_PORTCOUNT_LENGTH
)));
2152 /* Now setup the interrupt handler */
2153 retval
= request_irq(pdev
->irq
, twa_interrupt
, IRQF_SHARED
, "3w-9xxx", tw_dev
);
2155 TW_PRINTK(tw_dev
->host
, TW_DRIVER
, 0x30, "Error requesting IRQ");
2156 goto out_remove_host
;
2159 twa_device_extension_list
[twa_device_extension_count
] = tw_dev
;
2160 twa_device_extension_count
++;
2162 /* Re-enable interrupts on the card */
2163 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev
);
2165 /* Finally, scan the host */
2166 scsi_scan_host(host
);
2168 if (twa_major
== -1) {
2169 if ((twa_major
= register_chrdev (0, "twa", &twa_fops
)) < 0)
2170 TW_PRINTK(host
, TW_DRIVER
, 0x29, "Failed to register character device");
2175 scsi_remove_host(host
);
2177 iounmap(tw_dev
->base_addr
);
2178 out_release_mem_region
:
2179 pci_release_regions(pdev
);
2180 out_free_device_extension
:
2181 twa_free_device_extension(tw_dev
);
2182 scsi_host_put(host
);
2184 pci_disable_device(pdev
);
2187 } /* End twa_probe() */
2189 /* This function is called to remove a device */
2190 static void twa_remove(struct pci_dev
*pdev
)
2192 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
2193 TW_Device_Extension
*tw_dev
= (TW_Device_Extension
*)host
->hostdata
;
2195 scsi_remove_host(tw_dev
->host
);
2197 /* Unregister character device */
2198 if (twa_major
>= 0) {
2199 unregister_chrdev(twa_major
, "twa");
2203 /* Shutdown the card */
2204 __twa_shutdown(tw_dev
);
2206 /* Free IO remapping */
2207 iounmap(tw_dev
->base_addr
);
2209 /* Free up the mem region */
2210 pci_release_regions(pdev
);
2212 /* Free up device extension resources */
2213 twa_free_device_extension(tw_dev
);
2215 scsi_host_put(tw_dev
->host
);
2216 pci_disable_device(pdev
);
2217 twa_device_extension_count
--;
2218 } /* End twa_remove() */
2220 /* PCI Devices supported by this driver */
2221 static struct pci_device_id twa_pci_tbl
[] __devinitdata
= {
2222 { PCI_VENDOR_ID_3WARE
, PCI_DEVICE_ID_3WARE_9000
,
2223 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
2224 { PCI_VENDOR_ID_3WARE
, PCI_DEVICE_ID_3WARE_9550SX
,
2225 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
2226 { PCI_VENDOR_ID_3WARE
, PCI_DEVICE_ID_3WARE_9650SE
,
2227 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
2230 MODULE_DEVICE_TABLE(pci
, twa_pci_tbl
);
2232 /* pci_driver initializer */
2233 static struct pci_driver twa_driver
= {
2235 .id_table
= twa_pci_tbl
,
2237 .remove
= twa_remove
,
2238 .shutdown
= twa_shutdown
2241 /* This function is called on driver initialization */
2242 static int __init
twa_init(void)
2244 printk(KERN_WARNING
"3ware 9000 Storage Controller device driver for Linux v%s.\n", TW_DRIVER_VERSION
);
2246 return pci_register_driver(&twa_driver
);
2247 } /* End twa_init() */
2249 /* This function is called on driver exit */
2250 static void __exit
twa_exit(void)
2252 pci_unregister_driver(&twa_driver
);
2253 } /* End twa_exit() */
2255 module_init(twa_init
);
2256 module_exit(twa_exit
);