56 #include <linux/module.h>
57 #include <linux/reboot.h>
61 #include <linux/errno.h>
62 #include <linux/types.h>
64 #include <linux/pci.h>
65 #include <linux/time.h>
67 #include <linux/slab.h>
70 #include <asm/uaccess.h>
71 #include <scsi/scsi.h>
78 #define TW_DRIVER_VERSION "3.26.02.000"
81 static unsigned int twl_device_extension_count;
82 static int twl_major = -1;
108 unsigned long flags = 0;
116 spin_unlock_irqrestore(tw_dev->
host->host_lock,
flags);
124 .name =
"3ware_aen_read",
128 .read = twl_sysfs_aen_read
134 char *outbuf, loff_t offset,
size_t count)
139 unsigned long flags = 0;
147 spin_unlock_irqrestore(tw_dev->
host->host_lock,
flags);
155 .name =
"3ware_compat_info",
159 .read = twl_sysfs_compat_info
168 unsigned long flags = 0;
173 "Current commands posted: %4d\n"
174 "Max commands posted: %4d\n"
175 "Last sgl length: %4d\n"
176 "Max sgl length: %4d\n"
177 "Last sector count: %4d\n"
178 "Max sector count: %4d\n"
179 "SCSI Host Resets: %4d\n"
190 spin_unlock_irqrestore(tw_dev->
host->host_lock,
flags);
210 .name =
"3ware_stats",
213 .show = twl_show_stats
218 &twl_host_stats_attr,
223 static char *twl_aen_severity_lookup(
unsigned char severity_code)
231 retval = twl_aen_severity_table[severity_code];
260 local_time = (
u32)(
time.tv_sec - (
sys_tz.tz_minuteswest * 60));
261 event->time_stamp_sec = local_time;
262 event->aen_code = aen;
315 else if (use_sg < 0) {
321 cmd->
SCp.have_data_in = use_sg;
336 if (tw_dev->
srb[request_id]) {
338 if (scsi_sglist(srb))
339 sglist = scsi_sglist(srb);
349 command_packet->
status = 0;
365 command_packet->
unit = 0;
372 if (scsi_sg_count(srb)) {
373 sg_count = twl_map_scsi_sg_data(tw_dev, request_id);
385 for (i = 0; i < use_sg; i++) {
403 retval = twl_post_command_packet(tw_dev, request_id);
434 if (twl_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) {
456 command_packet = &full_command_packet->command.oldcommand;
474 local_time = (
u32)(utc.tv_sec - (
sys_tz.tz_minuteswest * 60));
475 schedulertime = local_time - (3 * 86400);
476 schedulertime =
cpu_to_le32(schedulertime % 604800);
484 twl_post_command_packet(tw_dev, request_id);
521 if (twl_aen_read_queue(tw_dev, request_id))
534 twl_aen_sync_time(tw_dev, request_id);
538 twl_aen_queue_event(tw_dev, header);
541 if (twl_aen_read_queue(tw_dev, request_id))
551 twl_free_request_id(tw_dev, request_id);
560 unsigned long before;
573 mfa = ((
u64)regh << 32) | regl;
602 int first_reset = 0,
queue = 0, retval = 1;
627 if (twl_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) {
633 if (twl_poll_response(tw_dev, request_id, 30)) {
647 if (first_reset != 1)
653 if (first_reset == 0)
666 twl_aen_queue_event(tw_dev, header);
721 unsigned int pae = 0;
723 if ((
sizeof(
long) < 8) && (
sizeof(
dma_addr_t) > 4))
745 oldcommand->
size += pae;
753 static long twl_chrdev_ioctl(
struct file *
file,
unsigned int cmd,
unsigned long arg)
756 unsigned long *
cpu_addr, data_buffer_length_adjusted = 0,
flags = 0;
760 struct inode *
inode = file->f_dentry->d_inode;
786 data_buffer_length_adjusted = (driver_command.
buffer_length + 511) & ~511;
805 twl_get_request_id(tw_dev, &request_id);
816 twl_load_sgl(tw_dev, full_command_packet, request_id, dma_handle, data_buffer_length_adjusted);
821 twl_post_command_packet(tw_dev, request_id);
822 spin_unlock_irqrestore(tw_dev->
host->host_lock,
flags);
832 printk(
KERN_WARNING "3w-sas: scsi%d: WARNING: (0x%02X:0x%04X): Character ioctl (0x%x) timed out, resetting card.\n",
836 twl_reset_device_extension(tw_dev, 1);
847 twl_free_request_id(tw_dev, request_id);
848 spin_unlock_irqrestore(tw_dev->
host->host_lock,
flags);
869 static int twl_chrdev_open(
struct inode *inode,
struct file *file)
871 unsigned int minor_number;
879 minor_number = iminor(inode);
880 if (minor_number >= twl_device_extension_count)
890 .unlocked_ioctl = twl_chrdev_ioctl,
891 .open = twl_chrdev_open,
897 static int twl_fill_sense(
TW_Device_Extension *tw_dev,
int i,
int request_id,
int copy_sense,
int print_host)
901 unsigned short error;
916 tw_dev->
host->host_no,
964 static void *twl_get_param(
TW_Device_Extension *tw_dev,
int request_id,
int table_id,
int parameter_id,
int parameter_size_bytes)
992 twl_post_command_packet(tw_dev, request_id);
995 if (twl_poll_response(tw_dev, request_id, 30))
998 retval = (
void *)&(param->
data[0]);
1000 tw_dev->posted_request_count--;
1008 u32 set_features,
unsigned short current_fw_srl,
1009 unsigned short current_fw_arch_id,
1010 unsigned short current_fw_branch,
1011 unsigned short current_fw_build,
1012 unsigned short *fw_on_ctlr_srl,
1013 unsigned short *fw_on_ctlr_arch_id,
1014 unsigned short *fw_on_ctlr_branch,
1015 unsigned short *fw_on_ctlr_build,
1016 u32 *init_connect_result)
1020 int request_id = 0, retval = 1;
1023 full_command_packet = tw_dev->command_packet_virt[
request_id];
1031 tw_initconnect->
features = set_features;
1048 twl_post_command_packet(tw_dev, request_id);
1051 if (twl_poll_response(tw_dev, request_id, 30)) {
1054 if (set_features & TW_EXTENDED_INIT_CONNECT) {
1064 tw_dev->posted_request_count--;
1146 twl_get_request_id(tw_dev, &request_id);
1147 if (twl_aen_read_queue(tw_dev, request_id)) {
1149 twl_free_request_id(tw_dev, request_id);
1167 static irqreturn_t twl_interrupt(
int irq,
void *dev_instance)
1170 int i, handled = 0, error = 0;
1176 spin_lock(tw_dev->
host->host_lock);
1183 goto twl_interrupt_bail;
1189 goto twl_interrupt_bail;
1193 if (twl_handle_attention_interrupt(tw_dev)) {
1195 goto twl_interrupt_bail;
1204 mfa = ((
u64)regh << 32) | regl;
1209 response = (
u32)mfa;
1216 if (tw_dev->
srb[request_id] !=
NULL)
1217 error = twl_fill_sense(tw_dev, i, request_id, 1, 1);
1221 error = twl_fill_sense(tw_dev, i, request_id, 0, 1);
1239 if (tw_dev->
srb[request_id] !=
NULL) {
1242 goto twl_interrupt_bail;
1247 if (tw_dev->
srb[request_id] ==
NULL) {
1249 if (twl_aen_complete(tw_dev, request_id))
1269 twl_free_request_id(tw_dev, request_id);
1272 twl_unmap_scsi_data(tw_dev, request_id);
1280 spin_unlock(tw_dev->
host->host_lock);
1287 unsigned long before;
1291 reg_value =
readl(reg);
1294 while ((reg_value & value) != result) {
1295 reg_value =
readl(reg);
1296 if (
time_after(jiffies, before + HZ * seconds))
1311 unsigned short fw_on_ctlr_srl = 0, fw_on_ctlr_arch_id = 0;
1312 unsigned short fw_on_ctlr_branch = 0, fw_on_ctlr_build = 0;
1313 u32 init_connect_result = 0;
1319 if (do_soft_reset) {
1340 &fw_on_ctlr_arch_id, &fw_on_ctlr_branch,
1341 &fw_on_ctlr_build, &init_connect_result)) {
1349 while (i < TW_Q_LENGTH) {
1369 if (twl_aen_drain_queue(tw_dev, soft_reset)) {
1399 int i = 0, retval = 1;
1400 unsigned long flags = 0;
1415 (tw_dev->
state[i] != TW_S_INITIAL) &&
1417 if (tw_dev->
srb[i]) {
1419 tw_dev->
srb[
i]->scsi_done(tw_dev->
srb[i]);
1420 twl_unmap_scsi_data(tw_dev, i);
1434 spin_unlock_irqrestore(tw_dev->
host->host_lock, flags);
1436 if (twl_reset_sequence(tw_dev, 1))
1459 if (capacity >= 0x200000) {
1469 geom[2] =
sector_div(capacity, heads * sectors);
1475 static int twl_scsi_eh_reset(
struct scsi_cmnd *SCpnt)
1485 "WARNING: (0x%02X:0x%04X): Command (0x%x) timed out, resetting card.\n",
1492 if (twl_reset_device_extension(tw_dev, 0)) {
1519 twl_get_request_id(tw_dev, &request_id);
1527 retval = twl_scsiop_execute_scsi(tw_dev, request_id,
NULL, 0,
NULL);
1530 twl_free_request_id(tw_dev, request_id);
1548 free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
1553 if (twl_initconnection(tw_dev, 1, 0, 0, 0, 0, 0,
NULL,
NULL,
NULL,
NULL,
NULL)) {
1564 static void twl_shutdown(
struct pci_dev *pdev)
1566 struct Scsi_Host *host = pci_get_drvdata(pdev);
1575 __twl_shutdown(tw_dev);
1579 static int twl_slave_configure(
struct scsi_device *sdev)
1591 .queuecommand = twl_scsi_queue,
1592 .eh_host_reset_handler = twl_scsi_eh_reset,
1593 .bios_param = twl_scsi_biosparam,
1594 .change_queue_depth = twl_change_queue_depth,
1595 .can_queue = TW_Q_LENGTH-2,
1596 .slave_configure = twl_slave_configure,
1602 .shost_attrs = twl_host_attrs,
1612 int *ptr_phycount, phycount=0;
1617 goto out_disable_device;
1624 || pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(64)))
1626 || pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32))) {
1629 goto out_disable_device;
1636 goto out_disable_device;
1638 tw_dev = shost_priv(host);
1641 tw_dev->
host = host;
1644 if (twl_initialize_device_extension(tw_dev)) {
1646 goto out_free_device_extension;
1653 goto out_free_device_extension;
1657 tw_dev->
base_addr = pci_iomap(pdev, 1, 0);
1660 goto out_release_mem_region;
1667 if (twl_reset_sequence(tw_dev, 0)) {
1679 retval = scsi_add_host(host, &pdev->
dev);
1685 pci_set_drvdata(pdev, host);
1687 printk(
KERN_WARNING "3w-sas: scsi%d: Found an LSI 3ware %s Controller at 0x%llx, IRQ: %d.\n",
1707 if (use_msi && !pci_enable_msi(pdev))
1714 goto out_remove_host;
1717 twl_device_extension_list[twl_device_extension_count] = tw_dev;
1718 twl_device_extension_count++;
1732 if (twl_major == -1) {
1733 if ((twl_major = register_chrdev (0,
"twl", &twl_fops)) < 0)
1745 out_release_mem_region:
1747 out_free_device_extension:
1748 twl_free_device_extension(tw_dev);
1757 static void twl_remove(
struct pci_dev *pdev)
1759 struct Scsi_Host *host = pci_get_drvdata(pdev);
1777 if (twl_major >= 0) {
1778 unregister_chrdev(twl_major,
"twl");
1783 __twl_shutdown(tw_dev);
1796 twl_free_device_extension(tw_dev);
1800 twl_device_extension_count--;
1807 struct Scsi_Host *host = pci_get_drvdata(pdev);
1817 if (twl_initconnection(tw_dev, 1, 0, 0, 0, 0, 0,
NULL,
NULL,
NULL,
NULL,
NULL)) {
1834 static int twl_resume(
struct pci_dev *pdev)
1837 struct Scsi_Host *host = pci_get_drvdata(pdev);
1842 pci_enable_wake(pdev,
PCI_D0, 0);
1855 || pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(64)))
1857 || pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32))) {
1860 goto out_disable_device;
1864 if (twl_reset_sequence(tw_dev, 0)) {
1866 goto out_disable_device;
1874 goto out_disable_device;
1879 pci_enable_msi(pdev);
1905 .id_table = twl_pci_tbl,
1907 .remove = twl_remove,
1909 .suspend = twl_suspend,
1910 .resume = twl_resume,
1912 .shutdown = twl_shutdown
1916 static int __init twl_init(
void)
1920 return pci_register_driver(&twl_driver);
1924 static void __exit twl_exit(
void)