diff options
Diffstat (limited to 'drivers')
26 files changed, 4856 insertions, 310 deletions
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c index a6ac61611f35..a748fbfb6692 100644 --- a/drivers/scsi/3w-9xxx.c +++ b/drivers/scsi/3w-9xxx.c | |||
@@ -60,6 +60,7 @@ | |||
60 | Remove un-needed eh_abort handler. | 60 | Remove un-needed eh_abort handler. |
61 | Add support for embedded firmware error strings. | 61 | Add support for embedded firmware error strings. |
62 | 2.26.02.003 - Correctly handle single sgl's with use_sg=1. | 62 | 2.26.02.003 - Correctly handle single sgl's with use_sg=1. |
63 | 2.26.02.004 - Add support for 9550SX controllers. | ||
63 | */ | 64 | */ |
64 | 65 | ||
65 | #include <linux/module.h> | 66 | #include <linux/module.h> |
@@ -82,7 +83,7 @@ | |||
82 | #include "3w-9xxx.h" | 83 | #include "3w-9xxx.h" |
83 | 84 | ||
84 | /* Globals */ | 85 | /* Globals */ |
85 | #define TW_DRIVER_VERSION "2.26.02.003" | 86 | #define TW_DRIVER_VERSION "2.26.02.004" |
86 | static TW_Device_Extension *twa_device_extension_list[TW_MAX_SLOT]; | 87 | static TW_Device_Extension *twa_device_extension_list[TW_MAX_SLOT]; |
87 | static unsigned int twa_device_extension_count; | 88 | static unsigned int twa_device_extension_count; |
88 | static int twa_major = -1; | 89 | static int twa_major = -1; |
@@ -892,11 +893,6 @@ static int twa_decode_bits(TW_Device_Extension *tw_dev, u32 status_reg_value) | |||
892 | writel(TW_CONTROL_CLEAR_QUEUE_ERROR, TW_CONTROL_REG_ADDR(tw_dev)); | 893 | writel(TW_CONTROL_CLEAR_QUEUE_ERROR, TW_CONTROL_REG_ADDR(tw_dev)); |
893 | } | 894 | } |
894 | 895 | ||
895 | if (status_reg_value & TW_STATUS_SBUF_WRITE_ERROR) { | ||
896 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0xf, "SBUF Write Error: clearing"); | ||
897 | writel(TW_CONTROL_CLEAR_SBUF_WRITE_ERROR, TW_CONTROL_REG_ADDR(tw_dev)); | ||
898 | } | ||
899 | |||
900 | if (status_reg_value & TW_STATUS_MICROCONTROLLER_ERROR) { | 896 | if (status_reg_value & TW_STATUS_MICROCONTROLLER_ERROR) { |
901 | if (tw_dev->reset_print == 0) { | 897 | if (tw_dev->reset_print == 0) { |
902 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x10, "Microcontroller Error: clearing"); | 898 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x10, "Microcontroller Error: clearing"); |
@@ -930,6 +926,36 @@ out: | |||
930 | return retval; | 926 | return retval; |
931 | } /* End twa_empty_response_queue() */ | 927 | } /* End twa_empty_response_queue() */ |
932 | 928 | ||
929 | /* This function will clear the pchip/response queue on 9550SX */ | ||
930 | static int twa_empty_response_queue_large(TW_Device_Extension *tw_dev) | ||
931 | { | ||
932 | u32 status_reg_value, response_que_value; | ||
933 | int count = 0, retval = 1; | ||
934 | |||
935 | if (tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9550SX) { | ||
936 | status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev)); | ||
937 | |||
938 | while (((status_reg_value & TW_STATUS_RESPONSE_QUEUE_EMPTY) == 0) && (count < TW_MAX_RESPONSE_DRAIN)) { | ||
939 | response_que_value = readl(TW_RESPONSE_QUEUE_REG_ADDR_LARGE(tw_dev)); | ||
940 | if ((response_que_value & TW_9550SX_DRAIN_COMPLETED) == TW_9550SX_DRAIN_COMPLETED) { | ||
941 | /* P-chip settle time */ | ||
942 | msleep(500); | ||
943 | retval = 0; | ||
944 | goto out; | ||
945 | } | ||
946 | status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev)); | ||
947 | count++; | ||
948 | } | ||
949 | if (count == TW_MAX_RESPONSE_DRAIN) | ||
950 | goto out; | ||
951 | |||
952 | retval = 0; | ||
953 | } else | ||
954 | retval = 0; | ||
955 | out: | ||
956 | return retval; | ||
957 | } /* End twa_empty_response_queue_large() */ | ||
958 | |||
933 | /* This function passes sense keys from firmware to scsi layer */ | 959 | /* This function passes sense keys from firmware to scsi layer */ |
934 | static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_sense, int print_host) | 960 | static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_sense, int print_host) |
935 | { | 961 | { |
@@ -1613,8 +1639,16 @@ static int twa_reset_sequence(TW_Device_Extension *tw_dev, int soft_reset) | |||
1613 | int tries = 0, retval = 1, flashed = 0, do_soft_reset = soft_reset; | 1639 | int tries = 0, retval = 1, flashed = 0, do_soft_reset = soft_reset; |
1614 | 1640 | ||
1615 | while (tries < TW_MAX_RESET_TRIES) { | 1641 | while (tries < TW_MAX_RESET_TRIES) { |
1616 | if (do_soft_reset) | 1642 | if (do_soft_reset) { |
1617 | TW_SOFT_RESET(tw_dev); | 1643 | TW_SOFT_RESET(tw_dev); |
1644 | /* Clear pchip/response queue on 9550SX */ | ||
1645 | if (twa_empty_response_queue_large(tw_dev)) { | ||
1646 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x36, "Response queue (large) empty failed during reset sequence"); | ||
1647 | do_soft_reset = 1; | ||
1648 | tries++; | ||
1649 | continue; | ||
1650 | } | ||
1651 | } | ||
1618 | 1652 | ||
1619 | /* Make sure controller is in a good state */ | 1653 | /* Make sure controller is in a good state */ |
1620 | if (twa_poll_status(tw_dev, TW_STATUS_MICROCONTROLLER_READY | (do_soft_reset == 1 ? TW_STATUS_ATTENTION_INTERRUPT : 0), 60)) { | 1654 | if (twa_poll_status(tw_dev, TW_STATUS_MICROCONTROLLER_READY | (do_soft_reset == 1 ? TW_STATUS_ATTENTION_INTERRUPT : 0), 60)) { |
@@ -2034,7 +2068,10 @@ static int __devinit twa_probe(struct pci_dev *pdev, const struct pci_device_id | |||
2034 | goto out_free_device_extension; | 2068 | goto out_free_device_extension; |
2035 | } | 2069 | } |
2036 | 2070 | ||
2037 | mem_addr = pci_resource_start(pdev, 1); | 2071 | if (pdev->device == PCI_DEVICE_ID_3WARE_9000) |
2072 | mem_addr = pci_resource_start(pdev, 1); | ||
2073 | else | ||
2074 | mem_addr = pci_resource_start(pdev, 2); | ||
2038 | 2075 | ||
2039 | /* Save base address */ | 2076 | /* Save base address */ |
2040 | tw_dev->base_addr = ioremap(mem_addr, PAGE_SIZE); | 2077 | tw_dev->base_addr = ioremap(mem_addr, PAGE_SIZE); |
@@ -2148,6 +2185,8 @@ static void twa_remove(struct pci_dev *pdev) | |||
2148 | static struct pci_device_id twa_pci_tbl[] __devinitdata = { | 2185 | static struct pci_device_id twa_pci_tbl[] __devinitdata = { |
2149 | { PCI_VENDOR_ID_3WARE, PCI_DEVICE_ID_3WARE_9000, | 2186 | { PCI_VENDOR_ID_3WARE, PCI_DEVICE_ID_3WARE_9000, |
2150 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | 2187 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
2188 | { PCI_VENDOR_ID_3WARE, PCI_DEVICE_ID_3WARE_9550SX, | ||
2189 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
2151 | { } | 2190 | { } |
2152 | }; | 2191 | }; |
2153 | MODULE_DEVICE_TABLE(pci, twa_pci_tbl); | 2192 | MODULE_DEVICE_TABLE(pci, twa_pci_tbl); |
diff --git a/drivers/scsi/3w-9xxx.h b/drivers/scsi/3w-9xxx.h index 8c8ecbed3b58..46f22cdc8298 100644 --- a/drivers/scsi/3w-9xxx.h +++ b/drivers/scsi/3w-9xxx.h | |||
@@ -267,7 +267,6 @@ static twa_message_type twa_error_table[] = { | |||
267 | #define TW_CONTROL_CLEAR_PARITY_ERROR 0x00800000 | 267 | #define TW_CONTROL_CLEAR_PARITY_ERROR 0x00800000 |
268 | #define TW_CONTROL_CLEAR_QUEUE_ERROR 0x00400000 | 268 | #define TW_CONTROL_CLEAR_QUEUE_ERROR 0x00400000 |
269 | #define TW_CONTROL_CLEAR_PCI_ABORT 0x00100000 | 269 | #define TW_CONTROL_CLEAR_PCI_ABORT 0x00100000 |
270 | #define TW_CONTROL_CLEAR_SBUF_WRITE_ERROR 0x00000008 | ||
271 | 270 | ||
272 | /* Status register bit definitions */ | 271 | /* Status register bit definitions */ |
273 | #define TW_STATUS_MAJOR_VERSION_MASK 0xF0000000 | 272 | #define TW_STATUS_MAJOR_VERSION_MASK 0xF0000000 |
@@ -285,9 +284,8 @@ static twa_message_type twa_error_table[] = { | |||
285 | #define TW_STATUS_MICROCONTROLLER_READY 0x00002000 | 284 | #define TW_STATUS_MICROCONTROLLER_READY 0x00002000 |
286 | #define TW_STATUS_COMMAND_QUEUE_EMPTY 0x00001000 | 285 | #define TW_STATUS_COMMAND_QUEUE_EMPTY 0x00001000 |
287 | #define TW_STATUS_EXPECTED_BITS 0x00002000 | 286 | #define TW_STATUS_EXPECTED_BITS 0x00002000 |
288 | #define TW_STATUS_UNEXPECTED_BITS 0x00F00008 | 287 | #define TW_STATUS_UNEXPECTED_BITS 0x00F00000 |
289 | #define TW_STATUS_SBUF_WRITE_ERROR 0x00000008 | 288 | #define TW_STATUS_VALID_INTERRUPT 0x00DF0000 |
290 | #define TW_STATUS_VALID_INTERRUPT 0x00DF0008 | ||
291 | 289 | ||
292 | /* RESPONSE QUEUE BIT DEFINITIONS */ | 290 | /* RESPONSE QUEUE BIT DEFINITIONS */ |
293 | #define TW_RESPONSE_ID_MASK 0x00000FF0 | 291 | #define TW_RESPONSE_ID_MASK 0x00000FF0 |
@@ -324,9 +322,9 @@ static twa_message_type twa_error_table[] = { | |||
324 | 322 | ||
325 | /* Compatibility defines */ | 323 | /* Compatibility defines */ |
326 | #define TW_9000_ARCH_ID 0x5 | 324 | #define TW_9000_ARCH_ID 0x5 |
327 | #define TW_CURRENT_DRIVER_SRL 28 | 325 | #define TW_CURRENT_DRIVER_SRL 30 |
328 | #define TW_CURRENT_DRIVER_BUILD 9 | 326 | #define TW_CURRENT_DRIVER_BUILD 80 |
329 | #define TW_CURRENT_DRIVER_BRANCH 4 | 327 | #define TW_CURRENT_DRIVER_BRANCH 0 |
330 | 328 | ||
331 | /* Phase defines */ | 329 | /* Phase defines */ |
332 | #define TW_PHASE_INITIAL 0 | 330 | #define TW_PHASE_INITIAL 0 |
@@ -334,6 +332,7 @@ static twa_message_type twa_error_table[] = { | |||
334 | #define TW_PHASE_SGLIST 2 | 332 | #define TW_PHASE_SGLIST 2 |
335 | 333 | ||
336 | /* Misc defines */ | 334 | /* Misc defines */ |
335 | #define TW_9550SX_DRAIN_COMPLETED 0xFFFF | ||
337 | #define TW_SECTOR_SIZE 512 | 336 | #define TW_SECTOR_SIZE 512 |
338 | #define TW_ALIGNMENT_9000 4 /* 4 bytes */ | 337 | #define TW_ALIGNMENT_9000 4 /* 4 bytes */ |
339 | #define TW_ALIGNMENT_9000_SGL 0x3 | 338 | #define TW_ALIGNMENT_9000_SGL 0x3 |
@@ -417,6 +416,9 @@ static twa_message_type twa_error_table[] = { | |||
417 | #ifndef PCI_DEVICE_ID_3WARE_9000 | 416 | #ifndef PCI_DEVICE_ID_3WARE_9000 |
418 | #define PCI_DEVICE_ID_3WARE_9000 0x1002 | 417 | #define PCI_DEVICE_ID_3WARE_9000 0x1002 |
419 | #endif | 418 | #endif |
419 | #ifndef PCI_DEVICE_ID_3WARE_9550SX | ||
420 | #define PCI_DEVICE_ID_3WARE_9550SX 0x1003 | ||
421 | #endif | ||
420 | 422 | ||
421 | /* Bitmask macros to eliminate bitfields */ | 423 | /* Bitmask macros to eliminate bitfields */ |
422 | 424 | ||
@@ -443,6 +445,7 @@ static twa_message_type twa_error_table[] = { | |||
443 | #define TW_STATUS_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + 0x4) | 445 | #define TW_STATUS_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + 0x4) |
444 | #define TW_COMMAND_QUEUE_REG_ADDR(x) (sizeof(dma_addr_t) > 4 ? ((unsigned char __iomem *)x->base_addr + 0x20) : ((unsigned char __iomem *)x->base_addr + 0x8)) | 446 | #define TW_COMMAND_QUEUE_REG_ADDR(x) (sizeof(dma_addr_t) > 4 ? ((unsigned char __iomem *)x->base_addr + 0x20) : ((unsigned char __iomem *)x->base_addr + 0x8)) |
445 | #define TW_RESPONSE_QUEUE_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + 0xC) | 447 | #define TW_RESPONSE_QUEUE_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + 0xC) |
448 | #define TW_RESPONSE_QUEUE_REG_ADDR_LARGE(x) ((unsigned char __iomem *)x->base_addr + 0x30) | ||
446 | #define TW_CLEAR_ALL_INTERRUPTS(x) (writel(TW_STATUS_VALID_INTERRUPT, TW_CONTROL_REG_ADDR(x))) | 449 | #define TW_CLEAR_ALL_INTERRUPTS(x) (writel(TW_STATUS_VALID_INTERRUPT, TW_CONTROL_REG_ADDR(x))) |
447 | #define TW_CLEAR_ATTENTION_INTERRUPT(x) (writel(TW_CONTROL_CLEAR_ATTENTION_INTERRUPT, TW_CONTROL_REG_ADDR(x))) | 450 | #define TW_CLEAR_ATTENTION_INTERRUPT(x) (writel(TW_CONTROL_CLEAR_ATTENTION_INTERRUPT, TW_CONTROL_REG_ADDR(x))) |
448 | #define TW_CLEAR_HOST_INTERRUPT(x) (writel(TW_CONTROL_CLEAR_HOST_INTERRUPT, TW_CONTROL_REG_ADDR(x))) | 451 | #define TW_CLEAR_HOST_INTERRUPT(x) (writel(TW_CONTROL_CLEAR_HOST_INTERRUPT, TW_CONTROL_REG_ADDR(x))) |
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile index 1e4edbdf2730..48529d180ca8 100644 --- a/drivers/scsi/Makefile +++ b/drivers/scsi/Makefile | |||
@@ -99,6 +99,7 @@ obj-$(CONFIG_SCSI_DC395x) += dc395x.o | |||
99 | obj-$(CONFIG_SCSI_DC390T) += tmscsim.o | 99 | obj-$(CONFIG_SCSI_DC390T) += tmscsim.o |
100 | obj-$(CONFIG_MEGARAID_LEGACY) += megaraid.o | 100 | obj-$(CONFIG_MEGARAID_LEGACY) += megaraid.o |
101 | obj-$(CONFIG_MEGARAID_NEWGEN) += megaraid/ | 101 | obj-$(CONFIG_MEGARAID_NEWGEN) += megaraid/ |
102 | obj-$(CONFIG_MEGARAID_SAS) += megaraid/ | ||
102 | obj-$(CONFIG_SCSI_ACARD) += atp870u.o | 103 | obj-$(CONFIG_SCSI_ACARD) += atp870u.o |
103 | obj-$(CONFIG_SCSI_SUNESP) += esp.o | 104 | obj-$(CONFIG_SCSI_SUNESP) += esp.o |
104 | obj-$(CONFIG_SCSI_GDTH) += gdth.o | 105 | obj-$(CONFIG_SCSI_GDTH) += gdth.o |
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c index a8e3dfcd0dc7..93416f760e5a 100644 --- a/drivers/scsi/aacraid/aachba.c +++ b/drivers/scsi/aacraid/aachba.c | |||
@@ -313,18 +313,37 @@ int aac_get_containers(struct aac_dev *dev) | |||
313 | } | 313 | } |
314 | dresp = (struct aac_mount *)fib_data(fibptr); | 314 | dresp = (struct aac_mount *)fib_data(fibptr); |
315 | 315 | ||
316 | if ((le32_to_cpu(dresp->status) == ST_OK) && | ||
317 | (le32_to_cpu(dresp->mnt[0].vol) == CT_NONE)) { | ||
318 | dinfo->command = cpu_to_le32(VM_NameServe64); | ||
319 | dinfo->count = cpu_to_le32(index); | ||
320 | dinfo->type = cpu_to_le32(FT_FILESYS); | ||
321 | |||
322 | if (fib_send(ContainerCommand, | ||
323 | fibptr, | ||
324 | sizeof(struct aac_query_mount), | ||
325 | FsaNormal, | ||
326 | 1, 1, | ||
327 | NULL, NULL) < 0) | ||
328 | continue; | ||
329 | } else | ||
330 | dresp->mnt[0].capacityhigh = 0; | ||
331 | |||
316 | dprintk ((KERN_DEBUG | 332 | dprintk ((KERN_DEBUG |
317 | "VM_NameServe cid=%d status=%d vol=%d state=%d cap=%u\n", | 333 | "VM_NameServe cid=%d status=%d vol=%d state=%d cap=%llu\n", |
318 | (int)index, (int)le32_to_cpu(dresp->status), | 334 | (int)index, (int)le32_to_cpu(dresp->status), |
319 | (int)le32_to_cpu(dresp->mnt[0].vol), | 335 | (int)le32_to_cpu(dresp->mnt[0].vol), |
320 | (int)le32_to_cpu(dresp->mnt[0].state), | 336 | (int)le32_to_cpu(dresp->mnt[0].state), |
321 | (unsigned)le32_to_cpu(dresp->mnt[0].capacity))); | 337 | ((u64)le32_to_cpu(dresp->mnt[0].capacity)) + |
338 | (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32))); | ||
322 | if ((le32_to_cpu(dresp->status) == ST_OK) && | 339 | if ((le32_to_cpu(dresp->status) == ST_OK) && |
323 | (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) && | 340 | (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) && |
324 | (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) { | 341 | (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) { |
325 | fsa_dev_ptr[index].valid = 1; | 342 | fsa_dev_ptr[index].valid = 1; |
326 | fsa_dev_ptr[index].type = le32_to_cpu(dresp->mnt[0].vol); | 343 | fsa_dev_ptr[index].type = le32_to_cpu(dresp->mnt[0].vol); |
327 | fsa_dev_ptr[index].size = le32_to_cpu(dresp->mnt[0].capacity); | 344 | fsa_dev_ptr[index].size |
345 | = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) + | ||
346 | (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32); | ||
328 | if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) | 347 | if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) |
329 | fsa_dev_ptr[index].ro = 1; | 348 | fsa_dev_ptr[index].ro = 1; |
330 | } | 349 | } |
@@ -460,7 +479,7 @@ static int aac_get_container_name(struct scsi_cmnd * scsicmd, int cid) | |||
460 | * is updated in the struct fsa_dev_info structure rather than returned. | 479 | * is updated in the struct fsa_dev_info structure rather than returned. |
461 | */ | 480 | */ |
462 | 481 | ||
463 | static int probe_container(struct aac_dev *dev, int cid) | 482 | int probe_container(struct aac_dev *dev, int cid) |
464 | { | 483 | { |
465 | struct fsa_dev_info *fsa_dev_ptr; | 484 | struct fsa_dev_info *fsa_dev_ptr; |
466 | int status; | 485 | int status; |
@@ -497,11 +516,29 @@ static int probe_container(struct aac_dev *dev, int cid) | |||
497 | dresp = (struct aac_mount *) fib_data(fibptr); | 516 | dresp = (struct aac_mount *) fib_data(fibptr); |
498 | 517 | ||
499 | if ((le32_to_cpu(dresp->status) == ST_OK) && | 518 | if ((le32_to_cpu(dresp->status) == ST_OK) && |
519 | (le32_to_cpu(dresp->mnt[0].vol) == CT_NONE)) { | ||
520 | dinfo->command = cpu_to_le32(VM_NameServe64); | ||
521 | dinfo->count = cpu_to_le32(cid); | ||
522 | dinfo->type = cpu_to_le32(FT_FILESYS); | ||
523 | |||
524 | if (fib_send(ContainerCommand, | ||
525 | fibptr, | ||
526 | sizeof(struct aac_query_mount), | ||
527 | FsaNormal, | ||
528 | 1, 1, | ||
529 | NULL, NULL) < 0) | ||
530 | goto error; | ||
531 | } else | ||
532 | dresp->mnt[0].capacityhigh = 0; | ||
533 | |||
534 | if ((le32_to_cpu(dresp->status) == ST_OK) && | ||
500 | (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) && | 535 | (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) && |
501 | (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) { | 536 | (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) { |
502 | fsa_dev_ptr[cid].valid = 1; | 537 | fsa_dev_ptr[cid].valid = 1; |
503 | fsa_dev_ptr[cid].type = le32_to_cpu(dresp->mnt[0].vol); | 538 | fsa_dev_ptr[cid].type = le32_to_cpu(dresp->mnt[0].vol); |
504 | fsa_dev_ptr[cid].size = le32_to_cpu(dresp->mnt[0].capacity); | 539 | fsa_dev_ptr[cid].size |
540 | = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) + | ||
541 | (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32); | ||
505 | if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) | 542 | if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) |
506 | fsa_dev_ptr[cid].ro = 1; | 543 | fsa_dev_ptr[cid].ro = 1; |
507 | } | 544 | } |
@@ -655,7 +692,7 @@ int aac_get_adapter_info(struct aac_dev* dev) | |||
655 | fibptr, | 692 | fibptr, |
656 | sizeof(*info), | 693 | sizeof(*info), |
657 | FsaNormal, | 694 | FsaNormal, |
658 | 1, 1, | 695 | -1, 1, /* First `interrupt' command uses special wait */ |
659 | NULL, | 696 | NULL, |
660 | NULL); | 697 | NULL); |
661 | 698 | ||
@@ -806,8 +843,8 @@ int aac_get_adapter_info(struct aac_dev* dev) | |||
806 | if (!(dev->raw_io_interface)) { | 843 | if (!(dev->raw_io_interface)) { |
807 | dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size - | 844 | dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size - |
808 | sizeof(struct aac_fibhdr) - | 845 | sizeof(struct aac_fibhdr) - |
809 | sizeof(struct aac_write) + sizeof(struct sgmap)) / | 846 | sizeof(struct aac_write) + sizeof(struct sgentry)) / |
810 | sizeof(struct sgmap); | 847 | sizeof(struct sgentry); |
811 | if (dev->dac_support) { | 848 | if (dev->dac_support) { |
812 | /* | 849 | /* |
813 | * 38 scatter gather elements | 850 | * 38 scatter gather elements |
@@ -816,8 +853,8 @@ int aac_get_adapter_info(struct aac_dev* dev) | |||
816 | (dev->max_fib_size - | 853 | (dev->max_fib_size - |
817 | sizeof(struct aac_fibhdr) - | 854 | sizeof(struct aac_fibhdr) - |
818 | sizeof(struct aac_write64) + | 855 | sizeof(struct aac_write64) + |
819 | sizeof(struct sgmap64)) / | 856 | sizeof(struct sgentry64)) / |
820 | sizeof(struct sgmap64); | 857 | sizeof(struct sgentry64); |
821 | } | 858 | } |
822 | dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT; | 859 | dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT; |
823 | if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) { | 860 | if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) { |
@@ -854,7 +891,40 @@ static void io_callback(void *context, struct fib * fibptr) | |||
854 | dev = (struct aac_dev *)scsicmd->device->host->hostdata; | 891 | dev = (struct aac_dev *)scsicmd->device->host->hostdata; |
855 | cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun); | 892 | cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun); |
856 | 893 | ||
857 | dprintk((KERN_DEBUG "io_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3], jiffies)); | 894 | if (nblank(dprintk(x))) { |
895 | u64 lba; | ||
896 | switch (scsicmd->cmnd[0]) { | ||
897 | case WRITE_6: | ||
898 | case READ_6: | ||
899 | lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | | ||
900 | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3]; | ||
901 | break; | ||
902 | case WRITE_16: | ||
903 | case READ_16: | ||
904 | lba = ((u64)scsicmd->cmnd[2] << 56) | | ||
905 | ((u64)scsicmd->cmnd[3] << 48) | | ||
906 | ((u64)scsicmd->cmnd[4] << 40) | | ||
907 | ((u64)scsicmd->cmnd[5] << 32) | | ||
908 | ((u64)scsicmd->cmnd[6] << 24) | | ||
909 | (scsicmd->cmnd[7] << 16) | | ||
910 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; | ||
911 | break; | ||
912 | case WRITE_12: | ||
913 | case READ_12: | ||
914 | lba = ((u64)scsicmd->cmnd[2] << 24) | | ||
915 | (scsicmd->cmnd[3] << 16) | | ||
916 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; | ||
917 | break; | ||
918 | default: | ||
919 | lba = ((u64)scsicmd->cmnd[2] << 24) | | ||
920 | (scsicmd->cmnd[3] << 16) | | ||
921 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; | ||
922 | break; | ||
923 | } | ||
924 | printk(KERN_DEBUG | ||
925 | "io_callback[cpu %d]: lba = %llu, t = %ld.\n", | ||
926 | smp_processor_id(), (unsigned long long)lba, jiffies); | ||
927 | } | ||
858 | 928 | ||
859 | if (fibptr == NULL) | 929 | if (fibptr == NULL) |
860 | BUG(); | 930 | BUG(); |
@@ -895,7 +965,7 @@ static void io_callback(void *context, struct fib * fibptr) | |||
895 | 965 | ||
896 | static int aac_read(struct scsi_cmnd * scsicmd, int cid) | 966 | static int aac_read(struct scsi_cmnd * scsicmd, int cid) |
897 | { | 967 | { |
898 | u32 lba; | 968 | u64 lba; |
899 | u32 count; | 969 | u32 count; |
900 | int status; | 970 | int status; |
901 | 971 | ||
@@ -907,23 +977,69 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid) | |||
907 | /* | 977 | /* |
908 | * Get block address and transfer length | 978 | * Get block address and transfer length |
909 | */ | 979 | */ |
910 | if (scsicmd->cmnd[0] == READ_6) /* 6 byte command */ | 980 | switch (scsicmd->cmnd[0]) { |
911 | { | 981 | case READ_6: |
912 | dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", cid)); | 982 | dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", cid)); |
913 | 983 | ||
914 | lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3]; | 984 | lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | |
985 | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3]; | ||
915 | count = scsicmd->cmnd[4]; | 986 | count = scsicmd->cmnd[4]; |
916 | 987 | ||
917 | if (count == 0) | 988 | if (count == 0) |
918 | count = 256; | 989 | count = 256; |
919 | } else { | 990 | break; |
991 | case READ_16: | ||
992 | dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", cid)); | ||
993 | |||
994 | lba = ((u64)scsicmd->cmnd[2] << 56) | | ||
995 | ((u64)scsicmd->cmnd[3] << 48) | | ||
996 | ((u64)scsicmd->cmnd[4] << 40) | | ||
997 | ((u64)scsicmd->cmnd[5] << 32) | | ||
998 | ((u64)scsicmd->cmnd[6] << 24) | | ||
999 | (scsicmd->cmnd[7] << 16) | | ||
1000 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; | ||
1001 | count = (scsicmd->cmnd[10] << 24) | | ||
1002 | (scsicmd->cmnd[11] << 16) | | ||
1003 | (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13]; | ||
1004 | break; | ||
1005 | case READ_12: | ||
1006 | dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", cid)); | ||
1007 | |||
1008 | lba = ((u64)scsicmd->cmnd[2] << 24) | | ||
1009 | (scsicmd->cmnd[3] << 16) | | ||
1010 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; | ||
1011 | count = (scsicmd->cmnd[6] << 24) | | ||
1012 | (scsicmd->cmnd[7] << 16) | | ||
1013 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; | ||
1014 | break; | ||
1015 | default: | ||
920 | dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", cid)); | 1016 | dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", cid)); |
921 | 1017 | ||
922 | lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; | 1018 | lba = ((u64)scsicmd->cmnd[2] << 24) | |
1019 | (scsicmd->cmnd[3] << 16) | | ||
1020 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; | ||
923 | count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8]; | 1021 | count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8]; |
1022 | break; | ||
924 | } | 1023 | } |
925 | dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %u, t = %ld.\n", | 1024 | dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n", |
926 | smp_processor_id(), (unsigned long long)lba, jiffies)); | 1025 | smp_processor_id(), (unsigned long long)lba, jiffies)); |
1026 | if ((!(dev->raw_io_interface) || !(dev->raw_io_64)) && | ||
1027 | (lba & 0xffffffff00000000LL)) { | ||
1028 | dprintk((KERN_DEBUG "aac_read: Illegal lba\n")); | ||
1029 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | | ||
1030 | SAM_STAT_CHECK_CONDITION; | ||
1031 | set_sense((u8 *) &dev->fsa_dev[cid].sense_data, | ||
1032 | HARDWARE_ERROR, | ||
1033 | SENCODE_INTERNAL_TARGET_FAILURE, | ||
1034 | ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0, | ||
1035 | 0, 0); | ||
1036 | memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, | ||
1037 | (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer)) | ||
1038 | ? sizeof(scsicmd->sense_buffer) | ||
1039 | : sizeof(dev->fsa_dev[cid].sense_data)); | ||
1040 | scsicmd->scsi_done(scsicmd); | ||
1041 | return 0; | ||
1042 | } | ||
927 | /* | 1043 | /* |
928 | * Alocate and initialize a Fib | 1044 | * Alocate and initialize a Fib |
929 | */ | 1045 | */ |
@@ -936,8 +1052,8 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid) | |||
936 | if (dev->raw_io_interface) { | 1052 | if (dev->raw_io_interface) { |
937 | struct aac_raw_io *readcmd; | 1053 | struct aac_raw_io *readcmd; |
938 | readcmd = (struct aac_raw_io *) fib_data(cmd_fibcontext); | 1054 | readcmd = (struct aac_raw_io *) fib_data(cmd_fibcontext); |
939 | readcmd->block[0] = cpu_to_le32(lba); | 1055 | readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff)); |
940 | readcmd->block[1] = 0; | 1056 | readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32)); |
941 | readcmd->count = cpu_to_le32(count<<9); | 1057 | readcmd->count = cpu_to_le32(count<<9); |
942 | readcmd->cid = cpu_to_le16(cid); | 1058 | readcmd->cid = cpu_to_le16(cid); |
943 | readcmd->flags = cpu_to_le16(1); | 1059 | readcmd->flags = cpu_to_le16(1); |
@@ -964,7 +1080,7 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid) | |||
964 | readcmd->command = cpu_to_le32(VM_CtHostRead64); | 1080 | readcmd->command = cpu_to_le32(VM_CtHostRead64); |
965 | readcmd->cid = cpu_to_le16(cid); | 1081 | readcmd->cid = cpu_to_le16(cid); |
966 | readcmd->sector_count = cpu_to_le16(count); | 1082 | readcmd->sector_count = cpu_to_le16(count); |
967 | readcmd->block = cpu_to_le32(lba); | 1083 | readcmd->block = cpu_to_le32((u32)(lba&0xffffffff)); |
968 | readcmd->pad = 0; | 1084 | readcmd->pad = 0; |
969 | readcmd->flags = 0; | 1085 | readcmd->flags = 0; |
970 | 1086 | ||
@@ -989,7 +1105,7 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid) | |||
989 | readcmd = (struct aac_read *) fib_data(cmd_fibcontext); | 1105 | readcmd = (struct aac_read *) fib_data(cmd_fibcontext); |
990 | readcmd->command = cpu_to_le32(VM_CtBlockRead); | 1106 | readcmd->command = cpu_to_le32(VM_CtBlockRead); |
991 | readcmd->cid = cpu_to_le32(cid); | 1107 | readcmd->cid = cpu_to_le32(cid); |
992 | readcmd->block = cpu_to_le32(lba); | 1108 | readcmd->block = cpu_to_le32((u32)(lba&0xffffffff)); |
993 | readcmd->count = cpu_to_le32(count * 512); | 1109 | readcmd->count = cpu_to_le32(count * 512); |
994 | 1110 | ||
995 | aac_build_sg(scsicmd, &readcmd->sg); | 1111 | aac_build_sg(scsicmd, &readcmd->sg); |
@@ -1031,7 +1147,7 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid) | |||
1031 | 1147 | ||
1032 | static int aac_write(struct scsi_cmnd * scsicmd, int cid) | 1148 | static int aac_write(struct scsi_cmnd * scsicmd, int cid) |
1033 | { | 1149 | { |
1034 | u32 lba; | 1150 | u64 lba; |
1035 | u32 count; | 1151 | u32 count; |
1036 | int status; | 1152 | int status; |
1037 | u16 fibsize; | 1153 | u16 fibsize; |
@@ -1048,13 +1164,48 @@ static int aac_write(struct scsi_cmnd * scsicmd, int cid) | |||
1048 | count = scsicmd->cmnd[4]; | 1164 | count = scsicmd->cmnd[4]; |
1049 | if (count == 0) | 1165 | if (count == 0) |
1050 | count = 256; | 1166 | count = 256; |
1167 | } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */ | ||
1168 | dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", cid)); | ||
1169 | |||
1170 | lba = ((u64)scsicmd->cmnd[2] << 56) | | ||
1171 | ((u64)scsicmd->cmnd[3] << 48) | | ||
1172 | ((u64)scsicmd->cmnd[4] << 40) | | ||
1173 | ((u64)scsicmd->cmnd[5] << 32) | | ||
1174 | ((u64)scsicmd->cmnd[6] << 24) | | ||
1175 | (scsicmd->cmnd[7] << 16) | | ||
1176 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; | ||
1177 | count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) | | ||
1178 | (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13]; | ||
1179 | } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */ | ||
1180 | dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", cid)); | ||
1181 | |||
1182 | lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | ||
1183 | | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; | ||
1184 | count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16) | ||
1185 | | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; | ||
1051 | } else { | 1186 | } else { |
1052 | dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", cid)); | 1187 | dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", cid)); |
1053 | lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; | 1188 | lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; |
1054 | count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8]; | 1189 | count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8]; |
1055 | } | 1190 | } |
1056 | dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %u, t = %ld.\n", | 1191 | dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n", |
1057 | smp_processor_id(), (unsigned long long)lba, jiffies)); | 1192 | smp_processor_id(), (unsigned long long)lba, jiffies)); |
1193 | if ((!(dev->raw_io_interface) || !(dev->raw_io_64)) | ||
1194 | && (lba & 0xffffffff00000000LL)) { | ||
1195 | dprintk((KERN_DEBUG "aac_write: Illegal lba\n")); | ||
1196 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; | ||
1197 | set_sense((u8 *) &dev->fsa_dev[cid].sense_data, | ||
1198 | HARDWARE_ERROR, | ||
1199 | SENCODE_INTERNAL_TARGET_FAILURE, | ||
1200 | ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0, | ||
1201 | 0, 0); | ||
1202 | memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, | ||
1203 | (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer)) | ||
1204 | ? sizeof(scsicmd->sense_buffer) | ||
1205 | : sizeof(dev->fsa_dev[cid].sense_data)); | ||
1206 | scsicmd->scsi_done(scsicmd); | ||
1207 | return 0; | ||
1208 | } | ||
1058 | /* | 1209 | /* |
1059 | * Allocate and initialize a Fib then setup a BlockWrite command | 1210 | * Allocate and initialize a Fib then setup a BlockWrite command |
1060 | */ | 1211 | */ |
@@ -1068,8 +1219,8 @@ static int aac_write(struct scsi_cmnd * scsicmd, int cid) | |||
1068 | if (dev->raw_io_interface) { | 1219 | if (dev->raw_io_interface) { |
1069 | struct aac_raw_io *writecmd; | 1220 | struct aac_raw_io *writecmd; |
1070 | writecmd = (struct aac_raw_io *) fib_data(cmd_fibcontext); | 1221 | writecmd = (struct aac_raw_io *) fib_data(cmd_fibcontext); |
1071 | writecmd->block[0] = cpu_to_le32(lba); | 1222 | writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff)); |
1072 | writecmd->block[1] = 0; | 1223 | writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32)); |
1073 | writecmd->count = cpu_to_le32(count<<9); | 1224 | writecmd->count = cpu_to_le32(count<<9); |
1074 | writecmd->cid = cpu_to_le16(cid); | 1225 | writecmd->cid = cpu_to_le16(cid); |
1075 | writecmd->flags = 0; | 1226 | writecmd->flags = 0; |
@@ -1096,7 +1247,7 @@ static int aac_write(struct scsi_cmnd * scsicmd, int cid) | |||
1096 | writecmd->command = cpu_to_le32(VM_CtHostWrite64); | 1247 | writecmd->command = cpu_to_le32(VM_CtHostWrite64); |
1097 | writecmd->cid = cpu_to_le16(cid); | 1248 | writecmd->cid = cpu_to_le16(cid); |
1098 | writecmd->sector_count = cpu_to_le16(count); | 1249 | writecmd->sector_count = cpu_to_le16(count); |
1099 | writecmd->block = cpu_to_le32(lba); | 1250 | writecmd->block = cpu_to_le32((u32)(lba&0xffffffff)); |
1100 | writecmd->pad = 0; | 1251 | writecmd->pad = 0; |
1101 | writecmd->flags = 0; | 1252 | writecmd->flags = 0; |
1102 | 1253 | ||
@@ -1121,7 +1272,7 @@ static int aac_write(struct scsi_cmnd * scsicmd, int cid) | |||
1121 | writecmd = (struct aac_write *) fib_data(cmd_fibcontext); | 1272 | writecmd = (struct aac_write *) fib_data(cmd_fibcontext); |
1122 | writecmd->command = cpu_to_le32(VM_CtBlockWrite); | 1273 | writecmd->command = cpu_to_le32(VM_CtBlockWrite); |
1123 | writecmd->cid = cpu_to_le32(cid); | 1274 | writecmd->cid = cpu_to_le32(cid); |
1124 | writecmd->block = cpu_to_le32(lba); | 1275 | writecmd->block = cpu_to_le32((u32)(lba&0xffffffff)); |
1125 | writecmd->count = cpu_to_le32(count * 512); | 1276 | writecmd->count = cpu_to_le32(count * 512); |
1126 | writecmd->sg.count = cpu_to_le32(1); | 1277 | writecmd->sg.count = cpu_to_le32(1); |
1127 | /* ->stable is not used - it did mean which type of write */ | 1278 | /* ->stable is not used - it did mean which type of write */ |
@@ -1310,11 +1461,18 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) | |||
1310 | */ | 1461 | */ |
1311 | if ((fsa_dev_ptr[cid].valid & 1) == 0) { | 1462 | if ((fsa_dev_ptr[cid].valid & 1) == 0) { |
1312 | switch (scsicmd->cmnd[0]) { | 1463 | switch (scsicmd->cmnd[0]) { |
1464 | case SERVICE_ACTION_IN: | ||
1465 | if (!(dev->raw_io_interface) || | ||
1466 | !(dev->raw_io_64) || | ||
1467 | ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16)) | ||
1468 | break; | ||
1313 | case INQUIRY: | 1469 | case INQUIRY: |
1314 | case READ_CAPACITY: | 1470 | case READ_CAPACITY: |
1315 | case TEST_UNIT_READY: | 1471 | case TEST_UNIT_READY: |
1316 | spin_unlock_irq(host->host_lock); | 1472 | spin_unlock_irq(host->host_lock); |
1317 | probe_container(dev, cid); | 1473 | probe_container(dev, cid); |
1474 | if ((fsa_dev_ptr[cid].valid & 1) == 0) | ||
1475 | fsa_dev_ptr[cid].valid = 0; | ||
1318 | spin_lock_irq(host->host_lock); | 1476 | spin_lock_irq(host->host_lock); |
1319 | if (fsa_dev_ptr[cid].valid == 0) { | 1477 | if (fsa_dev_ptr[cid].valid == 0) { |
1320 | scsicmd->result = DID_NO_CONNECT << 16; | 1478 | scsicmd->result = DID_NO_CONNECT << 16; |
@@ -1375,7 +1533,6 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) | |||
1375 | memset(&inq_data, 0, sizeof (struct inquiry_data)); | 1533 | memset(&inq_data, 0, sizeof (struct inquiry_data)); |
1376 | 1534 | ||
1377 | inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */ | 1535 | inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */ |
1378 | inq_data.inqd_dtq = 0x80; /* set RMB bit to one indicating that the medium is removable */ | ||
1379 | inq_data.inqd_rdf = 2; /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */ | 1536 | inq_data.inqd_rdf = 2; /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */ |
1380 | inq_data.inqd_len = 31; | 1537 | inq_data.inqd_len = 31; |
1381 | /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */ | 1538 | /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */ |
@@ -1397,13 +1554,55 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) | |||
1397 | aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data)); | 1554 | aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data)); |
1398 | return aac_get_container_name(scsicmd, cid); | 1555 | return aac_get_container_name(scsicmd, cid); |
1399 | } | 1556 | } |
1557 | case SERVICE_ACTION_IN: | ||
1558 | if (!(dev->raw_io_interface) || | ||
1559 | !(dev->raw_io_64) || | ||
1560 | ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16)) | ||
1561 | break; | ||
1562 | { | ||
1563 | u64 capacity; | ||
1564 | char cp[12]; | ||
1565 | unsigned int offset = 0; | ||
1566 | |||
1567 | dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n")); | ||
1568 | capacity = fsa_dev_ptr[cid].size - 1; | ||
1569 | if (scsicmd->cmnd[13] > 12) { | ||
1570 | offset = scsicmd->cmnd[13] - 12; | ||
1571 | if (offset > sizeof(cp)) | ||
1572 | break; | ||
1573 | memset(cp, 0, offset); | ||
1574 | aac_internal_transfer(scsicmd, cp, 0, offset); | ||
1575 | } | ||
1576 | cp[0] = (capacity >> 56) & 0xff; | ||
1577 | cp[1] = (capacity >> 48) & 0xff; | ||
1578 | cp[2] = (capacity >> 40) & 0xff; | ||
1579 | cp[3] = (capacity >> 32) & 0xff; | ||
1580 | cp[4] = (capacity >> 24) & 0xff; | ||
1581 | cp[5] = (capacity >> 16) & 0xff; | ||
1582 | cp[6] = (capacity >> 8) & 0xff; | ||
1583 | cp[7] = (capacity >> 0) & 0xff; | ||
1584 | cp[8] = 0; | ||
1585 | cp[9] = 0; | ||
1586 | cp[10] = 2; | ||
1587 | cp[11] = 0; | ||
1588 | aac_internal_transfer(scsicmd, cp, offset, sizeof(cp)); | ||
1589 | |||
1590 | /* Do not cache partition table for arrays */ | ||
1591 | scsicmd->device->removable = 1; | ||
1592 | |||
1593 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; | ||
1594 | scsicmd->scsi_done(scsicmd); | ||
1595 | |||
1596 | return 0; | ||
1597 | } | ||
1598 | |||
1400 | case READ_CAPACITY: | 1599 | case READ_CAPACITY: |
1401 | { | 1600 | { |
1402 | u32 capacity; | 1601 | u32 capacity; |
1403 | char cp[8]; | 1602 | char cp[8]; |
1404 | 1603 | ||
1405 | dprintk((KERN_DEBUG "READ CAPACITY command.\n")); | 1604 | dprintk((KERN_DEBUG "READ CAPACITY command.\n")); |
1406 | if (fsa_dev_ptr[cid].size <= 0x100000000LL) | 1605 | if (fsa_dev_ptr[cid].size <= 0x100000000ULL) |
1407 | capacity = fsa_dev_ptr[cid].size - 1; | 1606 | capacity = fsa_dev_ptr[cid].size - 1; |
1408 | else | 1607 | else |
1409 | capacity = (u32)-1; | 1608 | capacity = (u32)-1; |
@@ -1417,6 +1616,8 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) | |||
1417 | cp[6] = 2; | 1616 | cp[6] = 2; |
1418 | cp[7] = 0; | 1617 | cp[7] = 0; |
1419 | aac_internal_transfer(scsicmd, cp, 0, sizeof(cp)); | 1618 | aac_internal_transfer(scsicmd, cp, 0, sizeof(cp)); |
1619 | /* Do not cache partition table for arrays */ | ||
1620 | scsicmd->device->removable = 1; | ||
1420 | 1621 | ||
1421 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; | 1622 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; |
1422 | scsicmd->scsi_done(scsicmd); | 1623 | scsicmd->scsi_done(scsicmd); |
@@ -1497,6 +1698,8 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) | |||
1497 | { | 1698 | { |
1498 | case READ_6: | 1699 | case READ_6: |
1499 | case READ_10: | 1700 | case READ_10: |
1701 | case READ_12: | ||
1702 | case READ_16: | ||
1500 | /* | 1703 | /* |
1501 | * Hack to keep track of ordinal number of the device that | 1704 | * Hack to keep track of ordinal number of the device that |
1502 | * corresponds to a container. Needed to convert | 1705 | * corresponds to a container. Needed to convert |
@@ -1504,17 +1707,19 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) | |||
1504 | */ | 1707 | */ |
1505 | 1708 | ||
1506 | spin_unlock_irq(host->host_lock); | 1709 | spin_unlock_irq(host->host_lock); |
1507 | if (scsicmd->request->rq_disk) | 1710 | if (scsicmd->request->rq_disk) |
1508 | memcpy(fsa_dev_ptr[cid].devname, | 1711 | strlcpy(fsa_dev_ptr[cid].devname, |
1509 | scsicmd->request->rq_disk->disk_name, | 1712 | scsicmd->request->rq_disk->disk_name, |
1510 | 8); | 1713 | min(sizeof(fsa_dev_ptr[cid].devname), |
1511 | 1714 | sizeof(scsicmd->request->rq_disk->disk_name) + 1)); | |
1512 | ret = aac_read(scsicmd, cid); | 1715 | ret = aac_read(scsicmd, cid); |
1513 | spin_lock_irq(host->host_lock); | 1716 | spin_lock_irq(host->host_lock); |
1514 | return ret; | 1717 | return ret; |
1515 | 1718 | ||
1516 | case WRITE_6: | 1719 | case WRITE_6: |
1517 | case WRITE_10: | 1720 | case WRITE_10: |
1721 | case WRITE_12: | ||
1722 | case WRITE_16: | ||
1518 | spin_unlock_irq(host->host_lock); | 1723 | spin_unlock_irq(host->host_lock); |
1519 | ret = aac_write(scsicmd, cid); | 1724 | ret = aac_write(scsicmd, cid); |
1520 | spin_lock_irq(host->host_lock); | 1725 | spin_lock_irq(host->host_lock); |
@@ -1745,6 +1950,8 @@ static void aac_srb_callback(void *context, struct fib * fibptr) | |||
1745 | case WRITE_10: | 1950 | case WRITE_10: |
1746 | case READ_12: | 1951 | case READ_12: |
1747 | case WRITE_12: | 1952 | case WRITE_12: |
1953 | case READ_16: | ||
1954 | case WRITE_16: | ||
1748 | if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) { | 1955 | if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) { |
1749 | printk(KERN_WARNING"aacraid: SCSI CMD underflow\n"); | 1956 | printk(KERN_WARNING"aacraid: SCSI CMD underflow\n"); |
1750 | } else { | 1957 | } else { |
@@ -1850,8 +2057,8 @@ static void aac_srb_callback(void *context, struct fib * fibptr) | |||
1850 | sizeof(scsicmd->sense_buffer) : | 2057 | sizeof(scsicmd->sense_buffer) : |
1851 | le32_to_cpu(srbreply->sense_data_size); | 2058 | le32_to_cpu(srbreply->sense_data_size); |
1852 | #ifdef AAC_DETAILED_STATUS_INFO | 2059 | #ifdef AAC_DETAILED_STATUS_INFO |
1853 | dprintk((KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n", | 2060 | printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n", |
1854 | le32_to_cpu(srbreply->status), len)); | 2061 | le32_to_cpu(srbreply->status), len); |
1855 | #endif | 2062 | #endif |
1856 | memcpy(scsicmd->sense_buffer, srbreply->sense_data, len); | 2063 | memcpy(scsicmd->sense_buffer, srbreply->sense_data, len); |
1857 | 2064 | ||
diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h index e40528185d48..4a99d2f000f4 100644 --- a/drivers/scsi/aacraid/aacraid.h +++ b/drivers/scsi/aacraid/aacraid.h | |||
@@ -1,6 +1,10 @@ | |||
1 | #if (!defined(dprintk)) | 1 | #if (!defined(dprintk)) |
2 | # define dprintk(x) | 2 | # define dprintk(x) |
3 | #endif | 3 | #endif |
4 | /* eg: if (nblank(dprintk(x))) */ | ||
5 | #define _nblank(x) #x | ||
6 | #define nblank(x) _nblank(x)[0] | ||
7 | |||
4 | 8 | ||
5 | /*------------------------------------------------------------------------------ | 9 | /*------------------------------------------------------------------------------ |
6 | * D E F I N E S | 10 | * D E F I N E S |
@@ -302,7 +306,6 @@ enum aac_queue_types { | |||
302 | */ | 306 | */ |
303 | 307 | ||
304 | #define FsaNormal 1 | 308 | #define FsaNormal 1 |
305 | #define FsaHigh 2 | ||
306 | 309 | ||
307 | /* | 310 | /* |
308 | * Define the FIB. The FIB is the where all the requested data and | 311 | * Define the FIB. The FIB is the where all the requested data and |
@@ -546,8 +549,6 @@ struct aac_queue { | |||
546 | /* This is only valid for adapter to host command queues. */ | 549 | /* This is only valid for adapter to host command queues. */ |
547 | spinlock_t *lock; /* Spinlock for this queue must take this lock before accessing the lock */ | 550 | spinlock_t *lock; /* Spinlock for this queue must take this lock before accessing the lock */ |
548 | spinlock_t lockdata; /* Actual lock (used only on one side of the lock) */ | 551 | spinlock_t lockdata; /* Actual lock (used only on one side of the lock) */ |
549 | unsigned long SavedIrql; /* Previous IRQL when the spin lock is taken */ | ||
550 | u32 padding; /* Padding - FIXME - can remove I believe */ | ||
551 | struct list_head cmdq; /* A queue of FIBs which need to be prcessed by the FS thread. This is */ | 552 | struct list_head cmdq; /* A queue of FIBs which need to be prcessed by the FS thread. This is */ |
552 | /* only valid for command queues which receive entries from the adapter. */ | 553 | /* only valid for command queues which receive entries from the adapter. */ |
553 | struct list_head pendingq; /* A queue of outstanding fib's to the adapter. */ | 554 | struct list_head pendingq; /* A queue of outstanding fib's to the adapter. */ |
@@ -776,7 +777,9 @@ struct fsa_dev_info { | |||
776 | u64 last; | 777 | u64 last; |
777 | u64 size; | 778 | u64 size; |
778 | u32 type; | 779 | u32 type; |
780 | u32 config_waiting_on; | ||
779 | u16 queue_depth; | 781 | u16 queue_depth; |
782 | u8 config_needed; | ||
780 | u8 valid; | 783 | u8 valid; |
781 | u8 ro; | 784 | u8 ro; |
782 | u8 locked; | 785 | u8 locked; |
@@ -1012,6 +1015,7 @@ struct aac_dev | |||
1012 | /* macro side-effects BEWARE */ | 1015 | /* macro side-effects BEWARE */ |
1013 | # define raw_io_interface \ | 1016 | # define raw_io_interface \ |
1014 | init->InitStructRevision==cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4) | 1017 | init->InitStructRevision==cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4) |
1018 | u8 raw_io_64; | ||
1015 | u8 printf_enabled; | 1019 | u8 printf_enabled; |
1016 | }; | 1020 | }; |
1017 | 1021 | ||
@@ -1362,8 +1366,10 @@ struct aac_srb_reply | |||
1362 | #define VM_CtBlockVerify64 18 | 1366 | #define VM_CtBlockVerify64 18 |
1363 | #define VM_CtHostRead64 19 | 1367 | #define VM_CtHostRead64 19 |
1364 | #define VM_CtHostWrite64 20 | 1368 | #define VM_CtHostWrite64 20 |
1369 | #define VM_DrvErrTblLog 21 | ||
1370 | #define VM_NameServe64 22 | ||
1365 | 1371 | ||
1366 | #define MAX_VMCOMMAND_NUM 21 /* used for sizing stats array - leave last */ | 1372 | #define MAX_VMCOMMAND_NUM 23 /* used for sizing stats array - leave last */ |
1367 | 1373 | ||
1368 | /* | 1374 | /* |
1369 | * Descriptive information (eg, vital stats) | 1375 | * Descriptive information (eg, vital stats) |
@@ -1472,6 +1478,7 @@ struct aac_mntent { | |||
1472 | manager (eg, filesystem) */ | 1478 | manager (eg, filesystem) */ |
1473 | __le32 altoid; /* != oid <==> snapshot or | 1479 | __le32 altoid; /* != oid <==> snapshot or |
1474 | broken mirror exists */ | 1480 | broken mirror exists */ |
1481 | __le32 capacityhigh; | ||
1475 | }; | 1482 | }; |
1476 | 1483 | ||
1477 | #define FSCS_NOTCLEAN 0x0001 /* fsck is neccessary before mounting */ | 1484 | #define FSCS_NOTCLEAN 0x0001 /* fsck is neccessary before mounting */ |
@@ -1707,6 +1714,7 @@ extern struct aac_common aac_config; | |||
1707 | #define AifCmdJobProgress 2 /* Progress report */ | 1714 | #define AifCmdJobProgress 2 /* Progress report */ |
1708 | #define AifJobCtrZero 101 /* Array Zero progress */ | 1715 | #define AifJobCtrZero 101 /* Array Zero progress */ |
1709 | #define AifJobStsSuccess 1 /* Job completes */ | 1716 | #define AifJobStsSuccess 1 /* Job completes */ |
1717 | #define AifJobStsRunning 102 /* Job running */ | ||
1710 | #define AifCmdAPIReport 3 /* Report from other user of API */ | 1718 | #define AifCmdAPIReport 3 /* Report from other user of API */ |
1711 | #define AifCmdDriverNotify 4 /* Notify host driver of event */ | 1719 | #define AifCmdDriverNotify 4 /* Notify host driver of event */ |
1712 | #define AifDenMorphComplete 200 /* A morph operation completed */ | 1720 | #define AifDenMorphComplete 200 /* A morph operation completed */ |
@@ -1777,6 +1785,7 @@ int fib_adapter_complete(struct fib * fibptr, unsigned short size); | |||
1777 | struct aac_driver_ident* aac_get_driver_ident(int devtype); | 1785 | struct aac_driver_ident* aac_get_driver_ident(int devtype); |
1778 | int aac_get_adapter_info(struct aac_dev* dev); | 1786 | int aac_get_adapter_info(struct aac_dev* dev); |
1779 | int aac_send_shutdown(struct aac_dev *dev); | 1787 | int aac_send_shutdown(struct aac_dev *dev); |
1788 | int probe_container(struct aac_dev *dev, int cid); | ||
1780 | extern int numacb; | 1789 | extern int numacb; |
1781 | extern int acbsize; | 1790 | extern int acbsize; |
1782 | extern char aac_driver_version[]; | 1791 | extern char aac_driver_version[]; |
diff --git a/drivers/scsi/aacraid/comminit.c b/drivers/scsi/aacraid/comminit.c index 75abd0453289..59a341b2aedc 100644 --- a/drivers/scsi/aacraid/comminit.c +++ b/drivers/scsi/aacraid/comminit.c | |||
@@ -195,7 +195,7 @@ int aac_send_shutdown(struct aac_dev * dev) | |||
195 | fibctx, | 195 | fibctx, |
196 | sizeof(struct aac_close), | 196 | sizeof(struct aac_close), |
197 | FsaNormal, | 197 | FsaNormal, |
198 | 1, 1, | 198 | -2 /* Timeout silently */, 1, |
199 | NULL, NULL); | 199 | NULL, NULL); |
200 | 200 | ||
201 | if (status == 0) | 201 | if (status == 0) |
@@ -313,8 +313,15 @@ struct aac_dev *aac_init_adapter(struct aac_dev *dev) | |||
313 | dev->max_fib_size = sizeof(struct hw_fib); | 313 | dev->max_fib_size = sizeof(struct hw_fib); |
314 | dev->sg_tablesize = host->sg_tablesize = (dev->max_fib_size | 314 | dev->sg_tablesize = host->sg_tablesize = (dev->max_fib_size |
315 | - sizeof(struct aac_fibhdr) | 315 | - sizeof(struct aac_fibhdr) |
316 | - sizeof(struct aac_write) + sizeof(struct sgmap)) | 316 | - sizeof(struct aac_write) + sizeof(struct sgentry)) |
317 | / sizeof(struct sgmap); | 317 | / sizeof(struct sgentry); |
318 | dev->raw_io_64 = 0; | ||
319 | if ((!aac_adapter_sync_cmd(dev, GET_ADAPTER_PROPERTIES, | ||
320 | 0, 0, 0, 0, 0, 0, status+0, status+1, status+2, NULL, NULL)) && | ||
321 | (status[0] == 0x00000001)) { | ||
322 | if (status[1] & AAC_OPT_NEW_COMM_64) | ||
323 | dev->raw_io_64 = 1; | ||
324 | } | ||
318 | if ((!aac_adapter_sync_cmd(dev, GET_COMM_PREFERRED_SETTINGS, | 325 | if ((!aac_adapter_sync_cmd(dev, GET_COMM_PREFERRED_SETTINGS, |
319 | 0, 0, 0, 0, 0, 0, | 326 | 0, 0, 0, 0, 0, 0, |
320 | status+0, status+1, status+2, status+3, status+4)) | 327 | status+0, status+1, status+2, status+3, status+4)) |
@@ -342,8 +349,8 @@ struct aac_dev *aac_init_adapter(struct aac_dev *dev) | |||
342 | dev->max_fib_size = 512; | 349 | dev->max_fib_size = 512; |
343 | dev->sg_tablesize = host->sg_tablesize | 350 | dev->sg_tablesize = host->sg_tablesize |
344 | = (512 - sizeof(struct aac_fibhdr) | 351 | = (512 - sizeof(struct aac_fibhdr) |
345 | - sizeof(struct aac_write) + sizeof(struct sgmap)) | 352 | - sizeof(struct aac_write) + sizeof(struct sgentry)) |
346 | / sizeof(struct sgmap); | 353 | / sizeof(struct sgentry); |
347 | host->can_queue = AAC_NUM_IO_FIB; | 354 | host->can_queue = AAC_NUM_IO_FIB; |
348 | } else if (acbsize == 2048) { | 355 | } else if (acbsize == 2048) { |
349 | host->max_sectors = 512; | 356 | host->max_sectors = 512; |
diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c index a1d303f03480..e4d543a474ae 100644 --- a/drivers/scsi/aacraid/commsup.c +++ b/drivers/scsi/aacraid/commsup.c | |||
@@ -39,7 +39,9 @@ | |||
39 | #include <linux/completion.h> | 39 | #include <linux/completion.h> |
40 | #include <linux/blkdev.h> | 40 | #include <linux/blkdev.h> |
41 | #include <scsi/scsi_host.h> | 41 | #include <scsi/scsi_host.h> |
42 | #include <scsi/scsi_device.h> | ||
42 | #include <asm/semaphore.h> | 43 | #include <asm/semaphore.h> |
44 | #include <asm/delay.h> | ||
43 | 45 | ||
44 | #include "aacraid.h" | 46 | #include "aacraid.h" |
45 | 47 | ||
@@ -269,40 +271,22 @@ static int aac_get_entry (struct aac_dev * dev, u32 qid, struct aac_entry **entr | |||
269 | /* Interrupt Moderation, only interrupt for first two entries */ | 271 | /* Interrupt Moderation, only interrupt for first two entries */ |
270 | if (idx != le32_to_cpu(*(q->headers.consumer))) { | 272 | if (idx != le32_to_cpu(*(q->headers.consumer))) { |
271 | if (--idx == 0) { | 273 | if (--idx == 0) { |
272 | if (qid == AdapHighCmdQueue) | 274 | if (qid == AdapNormCmdQueue) |
273 | idx = ADAP_HIGH_CMD_ENTRIES; | ||
274 | else if (qid == AdapNormCmdQueue) | ||
275 | idx = ADAP_NORM_CMD_ENTRIES; | 275 | idx = ADAP_NORM_CMD_ENTRIES; |
276 | else if (qid == AdapHighRespQueue) | 276 | else |
277 | idx = ADAP_HIGH_RESP_ENTRIES; | ||
278 | else if (qid == AdapNormRespQueue) | ||
279 | idx = ADAP_NORM_RESP_ENTRIES; | 277 | idx = ADAP_NORM_RESP_ENTRIES; |
280 | } | 278 | } |
281 | if (idx != le32_to_cpu(*(q->headers.consumer))) | 279 | if (idx != le32_to_cpu(*(q->headers.consumer))) |
282 | *nonotify = 1; | 280 | *nonotify = 1; |
283 | } | 281 | } |
284 | 282 | ||
285 | if (qid == AdapHighCmdQueue) { | 283 | if (qid == AdapNormCmdQueue) { |
286 | if (*index >= ADAP_HIGH_CMD_ENTRIES) | ||
287 | *index = 0; | ||
288 | } else if (qid == AdapNormCmdQueue) { | ||
289 | if (*index >= ADAP_NORM_CMD_ENTRIES) | 284 | if (*index >= ADAP_NORM_CMD_ENTRIES) |
290 | *index = 0; /* Wrap to front of the Producer Queue. */ | 285 | *index = 0; /* Wrap to front of the Producer Queue. */ |
291 | } | 286 | } else { |
292 | else if (qid == AdapHighRespQueue) | ||
293 | { | ||
294 | if (*index >= ADAP_HIGH_RESP_ENTRIES) | ||
295 | *index = 0; | ||
296 | } | ||
297 | else if (qid == AdapNormRespQueue) | ||
298 | { | ||
299 | if (*index >= ADAP_NORM_RESP_ENTRIES) | 287 | if (*index >= ADAP_NORM_RESP_ENTRIES) |
300 | *index = 0; /* Wrap to front of the Producer Queue. */ | 288 | *index = 0; /* Wrap to front of the Producer Queue. */ |
301 | } | 289 | } |
302 | else { | ||
303 | printk("aacraid: invalid qid\n"); | ||
304 | BUG(); | ||
305 | } | ||
306 | 290 | ||
307 | if ((*index + 1) == le32_to_cpu(*(q->headers.consumer))) { /* Queue is full */ | 291 | if ((*index + 1) == le32_to_cpu(*(q->headers.consumer))) { /* Queue is full */ |
308 | printk(KERN_WARNING "Queue %d full, %u outstanding.\n", | 292 | printk(KERN_WARNING "Queue %d full, %u outstanding.\n", |
@@ -334,12 +318,8 @@ static int aac_queue_get(struct aac_dev * dev, u32 * index, u32 qid, struct hw_f | |||
334 | { | 318 | { |
335 | struct aac_entry * entry = NULL; | 319 | struct aac_entry * entry = NULL; |
336 | int map = 0; | 320 | int map = 0; |
337 | struct aac_queue * q = &dev->queues->queue[qid]; | ||
338 | |||
339 | spin_lock_irqsave(q->lock, q->SavedIrql); | ||
340 | 321 | ||
341 | if (qid == AdapHighCmdQueue || qid == AdapNormCmdQueue) | 322 | if (qid == AdapNormCmdQueue) { |
342 | { | ||
343 | /* if no entries wait for some if caller wants to */ | 323 | /* if no entries wait for some if caller wants to */ |
344 | while (!aac_get_entry(dev, qid, &entry, index, nonotify)) | 324 | while (!aac_get_entry(dev, qid, &entry, index, nonotify)) |
345 | { | 325 | { |
@@ -350,9 +330,7 @@ static int aac_queue_get(struct aac_dev * dev, u32 * index, u32 qid, struct hw_f | |||
350 | */ | 330 | */ |
351 | entry->size = cpu_to_le32(le16_to_cpu(hw_fib->header.Size)); | 331 | entry->size = cpu_to_le32(le16_to_cpu(hw_fib->header.Size)); |
352 | map = 1; | 332 | map = 1; |
353 | } | 333 | } else { |
354 | else if (qid == AdapHighRespQueue || qid == AdapNormRespQueue) | ||
355 | { | ||
356 | while(!aac_get_entry(dev, qid, &entry, index, nonotify)) | 334 | while(!aac_get_entry(dev, qid, &entry, index, nonotify)) |
357 | { | 335 | { |
358 | /* if no entries wait for some if caller wants to */ | 336 | /* if no entries wait for some if caller wants to */ |
@@ -375,42 +353,6 @@ static int aac_queue_get(struct aac_dev * dev, u32 * index, u32 qid, struct hw_f | |||
375 | return 0; | 353 | return 0; |
376 | } | 354 | } |
377 | 355 | ||
378 | |||
379 | /** | ||
380 | * aac_insert_entry - insert a queue entry | ||
381 | * @dev: Adapter | ||
382 | * @index: Index of entry to insert | ||
383 | * @qid: Queue number | ||
384 | * @nonotify: Suppress adapter notification | ||
385 | * | ||
386 | * Gets the next free QE off the requested priorty adapter command | ||
387 | * queue and associates the Fib with the QE. The QE represented by | ||
388 | * index is ready to insert on the queue when this routine returns | ||
389 | * success. | ||
390 | */ | ||
391 | |||
392 | static int aac_insert_entry(struct aac_dev * dev, u32 index, u32 qid, unsigned long nonotify) | ||
393 | { | ||
394 | struct aac_queue * q = &dev->queues->queue[qid]; | ||
395 | |||
396 | if(q == NULL) | ||
397 | BUG(); | ||
398 | *(q->headers.producer) = cpu_to_le32(index + 1); | ||
399 | spin_unlock_irqrestore(q->lock, q->SavedIrql); | ||
400 | |||
401 | if (qid == AdapHighCmdQueue || | ||
402 | qid == AdapNormCmdQueue || | ||
403 | qid == AdapHighRespQueue || | ||
404 | qid == AdapNormRespQueue) | ||
405 | { | ||
406 | if (!nonotify) | ||
407 | aac_adapter_notify(dev, qid); | ||
408 | } | ||
409 | else | ||
410 | printk("Suprise insert!\n"); | ||
411 | return 0; | ||
412 | } | ||
413 | |||
414 | /* | 356 | /* |
415 | * Define the highest level of host to adapter communication routines. | 357 | * Define the highest level of host to adapter communication routines. |
416 | * These routines will support host to adapter FS commuication. These | 358 | * These routines will support host to adapter FS commuication. These |
@@ -439,12 +381,13 @@ static int aac_insert_entry(struct aac_dev * dev, u32 index, u32 qid, unsigned l | |||
439 | int fib_send(u16 command, struct fib * fibptr, unsigned long size, int priority, int wait, int reply, fib_callback callback, void * callback_data) | 381 | int fib_send(u16 command, struct fib * fibptr, unsigned long size, int priority, int wait, int reply, fib_callback callback, void * callback_data) |
440 | { | 382 | { |
441 | u32 index; | 383 | u32 index; |
442 | u32 qid; | ||
443 | struct aac_dev * dev = fibptr->dev; | 384 | struct aac_dev * dev = fibptr->dev; |
444 | unsigned long nointr = 0; | 385 | unsigned long nointr = 0; |
445 | struct hw_fib * hw_fib = fibptr->hw_fib; | 386 | struct hw_fib * hw_fib = fibptr->hw_fib; |
446 | struct aac_queue * q; | 387 | struct aac_queue * q; |
447 | unsigned long flags = 0; | 388 | unsigned long flags = 0; |
389 | unsigned long qflags; | ||
390 | |||
448 | if (!(hw_fib->header.XferState & cpu_to_le32(HostOwned))) | 391 | if (!(hw_fib->header.XferState & cpu_to_le32(HostOwned))) |
449 | return -EBUSY; | 392 | return -EBUSY; |
450 | /* | 393 | /* |
@@ -497,26 +440,8 @@ int fib_send(u16 command, struct fib * fibptr, unsigned long size, int priority | |||
497 | * Get a queue entry connect the FIB to it and send an notify | 440 | * Get a queue entry connect the FIB to it and send an notify |
498 | * the adapter a command is ready. | 441 | * the adapter a command is ready. |
499 | */ | 442 | */ |
500 | if (priority == FsaHigh) { | 443 | hw_fib->header.XferState |= cpu_to_le32(NormalPriority); |
501 | hw_fib->header.XferState |= cpu_to_le32(HighPriority); | ||
502 | qid = AdapHighCmdQueue; | ||
503 | } else { | ||
504 | hw_fib->header.XferState |= cpu_to_le32(NormalPriority); | ||
505 | qid = AdapNormCmdQueue; | ||
506 | } | ||
507 | q = &dev->queues->queue[qid]; | ||
508 | 444 | ||
509 | if(wait) | ||
510 | spin_lock_irqsave(&fibptr->event_lock, flags); | ||
511 | if(aac_queue_get( dev, &index, qid, hw_fib, 1, fibptr, &nointr)<0) | ||
512 | return -EWOULDBLOCK; | ||
513 | dprintk((KERN_DEBUG "fib_send: inserting a queue entry at index %d.\n",index)); | ||
514 | dprintk((KERN_DEBUG "Fib contents:.\n")); | ||
515 | dprintk((KERN_DEBUG " Command = %d.\n", hw_fib->header.Command)); | ||
516 | dprintk((KERN_DEBUG " XferState = %x.\n", hw_fib->header.XferState)); | ||
517 | dprintk((KERN_DEBUG " hw_fib va being sent=%p\n",fibptr->hw_fib)); | ||
518 | dprintk((KERN_DEBUG " hw_fib pa being sent=%lx\n",(ulong)fibptr->hw_fib_pa)); | ||
519 | dprintk((KERN_DEBUG " fib being sent=%p\n",fibptr)); | ||
520 | /* | 445 | /* |
521 | * Fill in the Callback and CallbackContext if we are not | 446 | * Fill in the Callback and CallbackContext if we are not |
522 | * going to wait. | 447 | * going to wait. |
@@ -525,22 +450,67 @@ int fib_send(u16 command, struct fib * fibptr, unsigned long size, int priority | |||
525 | fibptr->callback = callback; | 450 | fibptr->callback = callback; |
526 | fibptr->callback_data = callback_data; | 451 | fibptr->callback_data = callback_data; |
527 | } | 452 | } |
528 | FIB_COUNTER_INCREMENT(aac_config.FibsSent); | ||
529 | list_add_tail(&fibptr->queue, &q->pendingq); | ||
530 | q->numpending++; | ||
531 | 453 | ||
532 | fibptr->done = 0; | 454 | fibptr->done = 0; |
533 | fibptr->flags = 0; | 455 | fibptr->flags = 0; |
534 | 456 | ||
535 | if(aac_insert_entry(dev, index, qid, (nointr & aac_config.irq_mod)) < 0) | 457 | FIB_COUNTER_INCREMENT(aac_config.FibsSent); |
536 | return -EWOULDBLOCK; | 458 | |
459 | dprintk((KERN_DEBUG "fib_send: inserting a queue entry at index %d.\n",index)); | ||
460 | dprintk((KERN_DEBUG "Fib contents:.\n")); | ||
461 | dprintk((KERN_DEBUG " Command = %d.\n", hw_fib->header.Command)); | ||
462 | dprintk((KERN_DEBUG " XferState = %x.\n", hw_fib->header.XferState)); | ||
463 | dprintk((KERN_DEBUG " hw_fib va being sent=%p\n",fibptr->hw_fib)); | ||
464 | dprintk((KERN_DEBUG " hw_fib pa being sent=%lx\n",(ulong)fibptr->hw_fib_pa)); | ||
465 | dprintk((KERN_DEBUG " fib being sent=%p\n",fibptr)); | ||
466 | |||
467 | q = &dev->queues->queue[AdapNormCmdQueue]; | ||
468 | |||
469 | if(wait) | ||
470 | spin_lock_irqsave(&fibptr->event_lock, flags); | ||
471 | spin_lock_irqsave(q->lock, qflags); | ||
472 | aac_queue_get( dev, &index, AdapNormCmdQueue, hw_fib, 1, fibptr, &nointr); | ||
473 | |||
474 | list_add_tail(&fibptr->queue, &q->pendingq); | ||
475 | q->numpending++; | ||
476 | *(q->headers.producer) = cpu_to_le32(index + 1); | ||
477 | spin_unlock_irqrestore(q->lock, qflags); | ||
478 | if (!(nointr & aac_config.irq_mod)) | ||
479 | aac_adapter_notify(dev, AdapNormCmdQueue); | ||
537 | /* | 480 | /* |
538 | * If the caller wanted us to wait for response wait now. | 481 | * If the caller wanted us to wait for response wait now. |
539 | */ | 482 | */ |
540 | 483 | ||
541 | if (wait) { | 484 | if (wait) { |
542 | spin_unlock_irqrestore(&fibptr->event_lock, flags); | 485 | spin_unlock_irqrestore(&fibptr->event_lock, flags); |
543 | down(&fibptr->event_wait); | 486 | /* Only set for first known interruptable command */ |
487 | if (wait < 0) { | ||
488 | /* | ||
489 | * *VERY* Dangerous to time out a command, the | ||
490 | * assumption is made that we have no hope of | ||
491 | * functioning because an interrupt routing or other | ||
492 | * hardware failure has occurred. | ||
493 | */ | ||
494 | unsigned long count = 36000000L; /* 3 minutes */ | ||
495 | unsigned long qflags; | ||
496 | while (down_trylock(&fibptr->event_wait)) { | ||
497 | if (--count == 0) { | ||
498 | spin_lock_irqsave(q->lock, qflags); | ||
499 | q->numpending--; | ||
500 | list_del(&fibptr->queue); | ||
501 | spin_unlock_irqrestore(q->lock, qflags); | ||
502 | if (wait == -1) { | ||
503 | printk(KERN_ERR "aacraid: fib_send: first asynchronous command timed out.\n" | ||
504 | "Usually a result of a PCI interrupt routing problem;\n" | ||
505 | "update mother board BIOS or consider utilizing one of\n" | ||
506 | "the SAFE mode kernel options (acpi, apic etc)\n"); | ||
507 | } | ||
508 | return -ETIMEDOUT; | ||
509 | } | ||
510 | udelay(5); | ||
511 | } | ||
512 | } else | ||
513 | down(&fibptr->event_wait); | ||
544 | if(fibptr->done == 0) | 514 | if(fibptr->done == 0) |
545 | BUG(); | 515 | BUG(); |
546 | 516 | ||
@@ -622,15 +592,9 @@ void aac_consumer_free(struct aac_dev * dev, struct aac_queue *q, u32 qid) | |||
622 | case HostNormCmdQueue: | 592 | case HostNormCmdQueue: |
623 | notify = HostNormCmdNotFull; | 593 | notify = HostNormCmdNotFull; |
624 | break; | 594 | break; |
625 | case HostHighCmdQueue: | ||
626 | notify = HostHighCmdNotFull; | ||
627 | break; | ||
628 | case HostNormRespQueue: | 595 | case HostNormRespQueue: |
629 | notify = HostNormRespNotFull; | 596 | notify = HostNormRespNotFull; |
630 | break; | 597 | break; |
631 | case HostHighRespQueue: | ||
632 | notify = HostHighRespNotFull; | ||
633 | break; | ||
634 | default: | 598 | default: |
635 | BUG(); | 599 | BUG(); |
636 | return; | 600 | return; |
@@ -652,9 +616,13 @@ int fib_adapter_complete(struct fib * fibptr, unsigned short size) | |||
652 | { | 616 | { |
653 | struct hw_fib * hw_fib = fibptr->hw_fib; | 617 | struct hw_fib * hw_fib = fibptr->hw_fib; |
654 | struct aac_dev * dev = fibptr->dev; | 618 | struct aac_dev * dev = fibptr->dev; |
619 | struct aac_queue * q; | ||
655 | unsigned long nointr = 0; | 620 | unsigned long nointr = 0; |
656 | if (hw_fib->header.XferState == 0) | 621 | unsigned long qflags; |
622 | |||
623 | if (hw_fib->header.XferState == 0) { | ||
657 | return 0; | 624 | return 0; |
625 | } | ||
658 | /* | 626 | /* |
659 | * If we plan to do anything check the structure type first. | 627 | * If we plan to do anything check the structure type first. |
660 | */ | 628 | */ |
@@ -669,37 +637,21 @@ int fib_adapter_complete(struct fib * fibptr, unsigned short size) | |||
669 | * send the completed cdb to the adapter. | 637 | * send the completed cdb to the adapter. |
670 | */ | 638 | */ |
671 | if (hw_fib->header.XferState & cpu_to_le32(SentFromAdapter)) { | 639 | if (hw_fib->header.XferState & cpu_to_le32(SentFromAdapter)) { |
640 | u32 index; | ||
672 | hw_fib->header.XferState |= cpu_to_le32(HostProcessed); | 641 | hw_fib->header.XferState |= cpu_to_le32(HostProcessed); |
673 | if (hw_fib->header.XferState & cpu_to_le32(HighPriority)) { | 642 | if (size) { |
674 | u32 index; | 643 | size += sizeof(struct aac_fibhdr); |
675 | if (size) | 644 | if (size > le16_to_cpu(hw_fib->header.SenderSize)) |
676 | { | 645 | return -EMSGSIZE; |
677 | size += sizeof(struct aac_fibhdr); | 646 | hw_fib->header.Size = cpu_to_le16(size); |
678 | if (size > le16_to_cpu(hw_fib->header.SenderSize)) | ||
679 | return -EMSGSIZE; | ||
680 | hw_fib->header.Size = cpu_to_le16(size); | ||
681 | } | ||
682 | if(aac_queue_get(dev, &index, AdapHighRespQueue, hw_fib, 1, NULL, &nointr) < 0) { | ||
683 | return -EWOULDBLOCK; | ||
684 | } | ||
685 | if (aac_insert_entry(dev, index, AdapHighRespQueue, (nointr & (int)aac_config.irq_mod)) != 0) { | ||
686 | } | ||
687 | } else if (hw_fib->header.XferState & | ||
688 | cpu_to_le32(NormalPriority)) { | ||
689 | u32 index; | ||
690 | |||
691 | if (size) { | ||
692 | size += sizeof(struct aac_fibhdr); | ||
693 | if (size > le16_to_cpu(hw_fib->header.SenderSize)) | ||
694 | return -EMSGSIZE; | ||
695 | hw_fib->header.Size = cpu_to_le16(size); | ||
696 | } | ||
697 | if (aac_queue_get(dev, &index, AdapNormRespQueue, hw_fib, 1, NULL, &nointr) < 0) | ||
698 | return -EWOULDBLOCK; | ||
699 | if (aac_insert_entry(dev, index, AdapNormRespQueue, (nointr & (int)aac_config.irq_mod)) != 0) | ||
700 | { | ||
701 | } | ||
702 | } | 647 | } |
648 | q = &dev->queues->queue[AdapNormRespQueue]; | ||
649 | spin_lock_irqsave(q->lock, qflags); | ||
650 | aac_queue_get(dev, &index, AdapNormRespQueue, hw_fib, 1, NULL, &nointr); | ||
651 | *(q->headers.producer) = cpu_to_le32(index + 1); | ||
652 | spin_unlock_irqrestore(q->lock, qflags); | ||
653 | if (!(nointr & (int)aac_config.irq_mod)) | ||
654 | aac_adapter_notify(dev, AdapNormRespQueue); | ||
703 | } | 655 | } |
704 | else | 656 | else |
705 | { | 657 | { |
@@ -791,6 +743,268 @@ void aac_printf(struct aac_dev *dev, u32 val) | |||
791 | memset(cp, 0, 256); | 743 | memset(cp, 0, 256); |
792 | } | 744 | } |
793 | 745 | ||
746 | |||
747 | /** | ||
748 | * aac_handle_aif - Handle a message from the firmware | ||
749 | * @dev: Which adapter this fib is from | ||
750 | * @fibptr: Pointer to fibptr from adapter | ||
751 | * | ||
752 | * This routine handles a driver notify fib from the adapter and | ||
753 | * dispatches it to the appropriate routine for handling. | ||
754 | */ | ||
755 | |||
756 | static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr) | ||
757 | { | ||
758 | struct hw_fib * hw_fib = fibptr->hw_fib; | ||
759 | struct aac_aifcmd * aifcmd = (struct aac_aifcmd *)hw_fib->data; | ||
760 | int busy; | ||
761 | u32 container; | ||
762 | struct scsi_device *device; | ||
763 | enum { | ||
764 | NOTHING, | ||
765 | DELETE, | ||
766 | ADD, | ||
767 | CHANGE | ||
768 | } device_config_needed; | ||
769 | |||
770 | /* Sniff for container changes */ | ||
771 | |||
772 | if (!dev) | ||
773 | return; | ||
774 | container = (u32)-1; | ||
775 | |||
776 | /* | ||
777 | * We have set this up to try and minimize the number of | ||
778 | * re-configures that take place. As a result of this when | ||
779 | * certain AIF's come in we will set a flag waiting for another | ||
780 | * type of AIF before setting the re-config flag. | ||
781 | */ | ||
782 | switch (le32_to_cpu(aifcmd->command)) { | ||
783 | case AifCmdDriverNotify: | ||
784 | switch (le32_to_cpu(((u32 *)aifcmd->data)[0])) { | ||
785 | /* | ||
786 | * Morph or Expand complete | ||
787 | */ | ||
788 | case AifDenMorphComplete: | ||
789 | case AifDenVolumeExtendComplete: | ||
790 | container = le32_to_cpu(((u32 *)aifcmd->data)[1]); | ||
791 | if (container >= dev->maximum_num_containers) | ||
792 | break; | ||
793 | |||
794 | /* | ||
795 | * Find the Scsi_Device associated with the SCSI | ||
796 | * address. Make sure we have the right array, and if | ||
797 | * so set the flag to initiate a new re-config once we | ||
798 | * see an AifEnConfigChange AIF come through. | ||
799 | */ | ||
800 | |||
801 | if ((dev != NULL) && (dev->scsi_host_ptr != NULL)) { | ||
802 | device = scsi_device_lookup(dev->scsi_host_ptr, | ||
803 | CONTAINER_TO_CHANNEL(container), | ||
804 | CONTAINER_TO_ID(container), | ||
805 | CONTAINER_TO_LUN(container)); | ||
806 | if (device) { | ||
807 | dev->fsa_dev[container].config_needed = CHANGE; | ||
808 | dev->fsa_dev[container].config_waiting_on = AifEnConfigChange; | ||
809 | scsi_device_put(device); | ||
810 | } | ||
811 | } | ||
812 | } | ||
813 | |||
814 | /* | ||
815 | * If we are waiting on something and this happens to be | ||
816 | * that thing then set the re-configure flag. | ||
817 | */ | ||
818 | if (container != (u32)-1) { | ||
819 | if (container >= dev->maximum_num_containers) | ||
820 | break; | ||
821 | if (dev->fsa_dev[container].config_waiting_on == | ||
822 | le32_to_cpu(*(u32 *)aifcmd->data)) | ||
823 | dev->fsa_dev[container].config_waiting_on = 0; | ||
824 | } else for (container = 0; | ||
825 | container < dev->maximum_num_containers; ++container) { | ||
826 | if (dev->fsa_dev[container].config_waiting_on == | ||
827 | le32_to_cpu(*(u32 *)aifcmd->data)) | ||
828 | dev->fsa_dev[container].config_waiting_on = 0; | ||
829 | } | ||
830 | break; | ||
831 | |||
832 | case AifCmdEventNotify: | ||
833 | switch (le32_to_cpu(((u32 *)aifcmd->data)[0])) { | ||
834 | /* | ||
835 | * Add an Array. | ||
836 | */ | ||
837 | case AifEnAddContainer: | ||
838 | container = le32_to_cpu(((u32 *)aifcmd->data)[1]); | ||
839 | if (container >= dev->maximum_num_containers) | ||
840 | break; | ||
841 | dev->fsa_dev[container].config_needed = ADD; | ||
842 | dev->fsa_dev[container].config_waiting_on = | ||
843 | AifEnConfigChange; | ||
844 | break; | ||
845 | |||
846 | /* | ||
847 | * Delete an Array. | ||
848 | */ | ||
849 | case AifEnDeleteContainer: | ||
850 | container = le32_to_cpu(((u32 *)aifcmd->data)[1]); | ||
851 | if (container >= dev->maximum_num_containers) | ||
852 | break; | ||
853 | dev->fsa_dev[container].config_needed = DELETE; | ||
854 | dev->fsa_dev[container].config_waiting_on = | ||
855 | AifEnConfigChange; | ||
856 | break; | ||
857 | |||
858 | /* | ||
859 | * Container change detected. If we currently are not | ||
860 | * waiting on something else, setup to wait on a Config Change. | ||
861 | */ | ||
862 | case AifEnContainerChange: | ||
863 | container = le32_to_cpu(((u32 *)aifcmd->data)[1]); | ||
864 | if (container >= dev->maximum_num_containers) | ||
865 | break; | ||
866 | if (dev->fsa_dev[container].config_waiting_on) | ||
867 | break; | ||
868 | dev->fsa_dev[container].config_needed = CHANGE; | ||
869 | dev->fsa_dev[container].config_waiting_on = | ||
870 | AifEnConfigChange; | ||
871 | break; | ||
872 | |||
873 | case AifEnConfigChange: | ||
874 | break; | ||
875 | |||
876 | } | ||
877 | |||
878 | /* | ||
879 | * If we are waiting on something and this happens to be | ||
880 | * that thing then set the re-configure flag. | ||
881 | */ | ||
882 | if (container != (u32)-1) { | ||
883 | if (container >= dev->maximum_num_containers) | ||
884 | break; | ||
885 | if (dev->fsa_dev[container].config_waiting_on == | ||
886 | le32_to_cpu(*(u32 *)aifcmd->data)) | ||
887 | dev->fsa_dev[container].config_waiting_on = 0; | ||
888 | } else for (container = 0; | ||
889 | container < dev->maximum_num_containers; ++container) { | ||
890 | if (dev->fsa_dev[container].config_waiting_on == | ||
891 | le32_to_cpu(*(u32 *)aifcmd->data)) | ||
892 | dev->fsa_dev[container].config_waiting_on = 0; | ||
893 | } | ||
894 | break; | ||
895 | |||
896 | case AifCmdJobProgress: | ||
897 | /* | ||
898 | * These are job progress AIF's. When a Clear is being | ||
899 | * done on a container it is initially created then hidden from | ||
900 | * the OS. When the clear completes we don't get a config | ||
901 | * change so we monitor the job status complete on a clear then | ||
902 | * wait for a container change. | ||
903 | */ | ||
904 | |||
905 | if ((((u32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero)) | ||
906 | && ((((u32 *)aifcmd->data)[6] == ((u32 *)aifcmd->data)[5]) | ||
907 | || (((u32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsSuccess)))) { | ||
908 | for (container = 0; | ||
909 | container < dev->maximum_num_containers; | ||
910 | ++container) { | ||
911 | /* | ||
912 | * Stomp on all config sequencing for all | ||
913 | * containers? | ||
914 | */ | ||
915 | dev->fsa_dev[container].config_waiting_on = | ||
916 | AifEnContainerChange; | ||
917 | dev->fsa_dev[container].config_needed = ADD; | ||
918 | } | ||
919 | } | ||
920 | if ((((u32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero)) | ||
921 | && (((u32 *)aifcmd->data)[6] == 0) | ||
922 | && (((u32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsRunning))) { | ||
923 | for (container = 0; | ||
924 | container < dev->maximum_num_containers; | ||
925 | ++container) { | ||
926 | /* | ||
927 | * Stomp on all config sequencing for all | ||
928 | * containers? | ||
929 | */ | ||
930 | dev->fsa_dev[container].config_waiting_on = | ||
931 | AifEnContainerChange; | ||
932 | dev->fsa_dev[container].config_needed = DELETE; | ||
933 | } | ||
934 | } | ||
935 | break; | ||
936 | } | ||
937 | |||
938 | device_config_needed = NOTHING; | ||
939 | for (container = 0; container < dev->maximum_num_containers; | ||
940 | ++container) { | ||
941 | if ((dev->fsa_dev[container].config_waiting_on == 0) | ||
942 | && (dev->fsa_dev[container].config_needed != NOTHING)) { | ||
943 | device_config_needed = | ||
944 | dev->fsa_dev[container].config_needed; | ||
945 | dev->fsa_dev[container].config_needed = NOTHING; | ||
946 | break; | ||
947 | } | ||
948 | } | ||
949 | if (device_config_needed == NOTHING) | ||
950 | return; | ||
951 | |||
952 | /* | ||
953 | * If we decided that a re-configuration needs to be done, | ||
954 | * schedule it here on the way out the door, please close the door | ||
955 | * behind you. | ||
956 | */ | ||
957 | |||
958 | busy = 0; | ||
959 | |||
960 | |||
961 | /* | ||
962 | * Find the Scsi_Device associated with the SCSI address, | ||
963 | * and mark it as changed, invalidating the cache. This deals | ||
964 | * with changes to existing device IDs. | ||
965 | */ | ||
966 | |||
967 | if (!dev || !dev->scsi_host_ptr) | ||
968 | return; | ||
969 | /* | ||
970 | * force reload of disk info via probe_container | ||
971 | */ | ||
972 | if ((device_config_needed == CHANGE) | ||
973 | && (dev->fsa_dev[container].valid == 1)) | ||
974 | dev->fsa_dev[container].valid = 2; | ||
975 | if ((device_config_needed == CHANGE) || | ||
976 | (device_config_needed == ADD)) | ||
977 | probe_container(dev, container); | ||
978 | device = scsi_device_lookup(dev->scsi_host_ptr, | ||
979 | CONTAINER_TO_CHANNEL(container), | ||
980 | CONTAINER_TO_ID(container), | ||
981 | CONTAINER_TO_LUN(container)); | ||
982 | if (device) { | ||
983 | switch (device_config_needed) { | ||
984 | case DELETE: | ||
985 | scsi_remove_device(device); | ||
986 | break; | ||
987 | case CHANGE: | ||
988 | if (!dev->fsa_dev[container].valid) { | ||
989 | scsi_remove_device(device); | ||
990 | break; | ||
991 | } | ||
992 | scsi_rescan_device(&device->sdev_gendev); | ||
993 | |||
994 | default: | ||
995 | break; | ||
996 | } | ||
997 | scsi_device_put(device); | ||
998 | } | ||
999 | if (device_config_needed == ADD) { | ||
1000 | scsi_add_device(dev->scsi_host_ptr, | ||
1001 | CONTAINER_TO_CHANNEL(container), | ||
1002 | CONTAINER_TO_ID(container), | ||
1003 | CONTAINER_TO_LUN(container)); | ||
1004 | } | ||
1005 | |||
1006 | } | ||
1007 | |||
794 | /** | 1008 | /** |
795 | * aac_command_thread - command processing thread | 1009 | * aac_command_thread - command processing thread |
796 | * @dev: Adapter to monitor | 1010 | * @dev: Adapter to monitor |
@@ -805,7 +1019,6 @@ int aac_command_thread(struct aac_dev * dev) | |||
805 | { | 1019 | { |
806 | struct hw_fib *hw_fib, *hw_newfib; | 1020 | struct hw_fib *hw_fib, *hw_newfib; |
807 | struct fib *fib, *newfib; | 1021 | struct fib *fib, *newfib; |
808 | struct aac_queue_block *queues = dev->queues; | ||
809 | struct aac_fib_context *fibctx; | 1022 | struct aac_fib_context *fibctx; |
810 | unsigned long flags; | 1023 | unsigned long flags; |
811 | DECLARE_WAITQUEUE(wait, current); | 1024 | DECLARE_WAITQUEUE(wait, current); |
@@ -825,21 +1038,22 @@ int aac_command_thread(struct aac_dev * dev) | |||
825 | * Let the DPC know it has a place to send the AIF's to. | 1038 | * Let the DPC know it has a place to send the AIF's to. |
826 | */ | 1039 | */ |
827 | dev->aif_thread = 1; | 1040 | dev->aif_thread = 1; |
828 | add_wait_queue(&queues->queue[HostNormCmdQueue].cmdready, &wait); | 1041 | add_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait); |
829 | set_current_state(TASK_INTERRUPTIBLE); | 1042 | set_current_state(TASK_INTERRUPTIBLE); |
1043 | dprintk ((KERN_INFO "aac_command_thread start\n")); | ||
830 | while(1) | 1044 | while(1) |
831 | { | 1045 | { |
832 | spin_lock_irqsave(queues->queue[HostNormCmdQueue].lock, flags); | 1046 | spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags); |
833 | while(!list_empty(&(queues->queue[HostNormCmdQueue].cmdq))) { | 1047 | while(!list_empty(&(dev->queues->queue[HostNormCmdQueue].cmdq))) { |
834 | struct list_head *entry; | 1048 | struct list_head *entry; |
835 | struct aac_aifcmd * aifcmd; | 1049 | struct aac_aifcmd * aifcmd; |
836 | 1050 | ||
837 | set_current_state(TASK_RUNNING); | 1051 | set_current_state(TASK_RUNNING); |
838 | 1052 | ||
839 | entry = queues->queue[HostNormCmdQueue].cmdq.next; | 1053 | entry = dev->queues->queue[HostNormCmdQueue].cmdq.next; |
840 | list_del(entry); | 1054 | list_del(entry); |
841 | 1055 | ||
842 | spin_unlock_irqrestore(queues->queue[HostNormCmdQueue].lock, flags); | 1056 | spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags); |
843 | fib = list_entry(entry, struct fib, fiblink); | 1057 | fib = list_entry(entry, struct fib, fiblink); |
844 | /* | 1058 | /* |
845 | * We will process the FIB here or pass it to a | 1059 | * We will process the FIB here or pass it to a |
@@ -860,6 +1074,7 @@ int aac_command_thread(struct aac_dev * dev) | |||
860 | aifcmd = (struct aac_aifcmd *) hw_fib->data; | 1074 | aifcmd = (struct aac_aifcmd *) hw_fib->data; |
861 | if (aifcmd->command == cpu_to_le32(AifCmdDriverNotify)) { | 1075 | if (aifcmd->command == cpu_to_le32(AifCmdDriverNotify)) { |
862 | /* Handle Driver Notify Events */ | 1076 | /* Handle Driver Notify Events */ |
1077 | aac_handle_aif(dev, fib); | ||
863 | *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK); | 1078 | *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK); |
864 | fib_adapter_complete(fib, (u16)sizeof(u32)); | 1079 | fib_adapter_complete(fib, (u16)sizeof(u32)); |
865 | } else { | 1080 | } else { |
@@ -869,9 +1084,62 @@ int aac_command_thread(struct aac_dev * dev) | |||
869 | 1084 | ||
870 | u32 time_now, time_last; | 1085 | u32 time_now, time_last; |
871 | unsigned long flagv; | 1086 | unsigned long flagv; |
872 | 1087 | unsigned num; | |
1088 | struct hw_fib ** hw_fib_pool, ** hw_fib_p; | ||
1089 | struct fib ** fib_pool, ** fib_p; | ||
1090 | |||
1091 | /* Sniff events */ | ||
1092 | if ((aifcmd->command == | ||
1093 | cpu_to_le32(AifCmdEventNotify)) || | ||
1094 | (aifcmd->command == | ||
1095 | cpu_to_le32(AifCmdJobProgress))) { | ||
1096 | aac_handle_aif(dev, fib); | ||
1097 | } | ||
1098 | |||
873 | time_now = jiffies/HZ; | 1099 | time_now = jiffies/HZ; |
874 | 1100 | ||
1101 | /* | ||
1102 | * Warning: no sleep allowed while | ||
1103 | * holding spinlock. We take the estimate | ||
1104 | * and pre-allocate a set of fibs outside the | ||
1105 | * lock. | ||
1106 | */ | ||
1107 | num = le32_to_cpu(dev->init->AdapterFibsSize) | ||
1108 | / sizeof(struct hw_fib); /* some extra */ | ||
1109 | spin_lock_irqsave(&dev->fib_lock, flagv); | ||
1110 | entry = dev->fib_list.next; | ||
1111 | while (entry != &dev->fib_list) { | ||
1112 | entry = entry->next; | ||
1113 | ++num; | ||
1114 | } | ||
1115 | spin_unlock_irqrestore(&dev->fib_lock, flagv); | ||
1116 | hw_fib_pool = NULL; | ||
1117 | fib_pool = NULL; | ||
1118 | if (num | ||
1119 | && ((hw_fib_pool = kmalloc(sizeof(struct hw_fib *) * num, GFP_KERNEL))) | ||
1120 | && ((fib_pool = kmalloc(sizeof(struct fib *) * num, GFP_KERNEL)))) { | ||
1121 | hw_fib_p = hw_fib_pool; | ||
1122 | fib_p = fib_pool; | ||
1123 | while (hw_fib_p < &hw_fib_pool[num]) { | ||
1124 | if (!(*(hw_fib_p++) = kmalloc(sizeof(struct hw_fib), GFP_KERNEL))) { | ||
1125 | --hw_fib_p; | ||
1126 | break; | ||
1127 | } | ||
1128 | if (!(*(fib_p++) = kmalloc(sizeof(struct fib), GFP_KERNEL))) { | ||
1129 | kfree(*(--hw_fib_p)); | ||
1130 | break; | ||
1131 | } | ||
1132 | } | ||
1133 | if ((num = hw_fib_p - hw_fib_pool) == 0) { | ||
1134 | kfree(fib_pool); | ||
1135 | fib_pool = NULL; | ||
1136 | kfree(hw_fib_pool); | ||
1137 | hw_fib_pool = NULL; | ||
1138 | } | ||
1139 | } else if (hw_fib_pool) { | ||
1140 | kfree(hw_fib_pool); | ||
1141 | hw_fib_pool = NULL; | ||
1142 | } | ||
875 | spin_lock_irqsave(&dev->fib_lock, flagv); | 1143 | spin_lock_irqsave(&dev->fib_lock, flagv); |
876 | entry = dev->fib_list.next; | 1144 | entry = dev->fib_list.next; |
877 | /* | 1145 | /* |
@@ -880,6 +1148,8 @@ int aac_command_thread(struct aac_dev * dev) | |||
880 | * fib, and then set the event to wake up the | 1148 | * fib, and then set the event to wake up the |
881 | * thread that is waiting for it. | 1149 | * thread that is waiting for it. |
882 | */ | 1150 | */ |
1151 | hw_fib_p = hw_fib_pool; | ||
1152 | fib_p = fib_pool; | ||
883 | while (entry != &dev->fib_list) { | 1153 | while (entry != &dev->fib_list) { |
884 | /* | 1154 | /* |
885 | * Extract the fibctx | 1155 | * Extract the fibctx |
@@ -912,9 +1182,11 @@ int aac_command_thread(struct aac_dev * dev) | |||
912 | * Warning: no sleep allowed while | 1182 | * Warning: no sleep allowed while |
913 | * holding spinlock | 1183 | * holding spinlock |
914 | */ | 1184 | */ |
915 | hw_newfib = kmalloc(sizeof(struct hw_fib), GFP_ATOMIC); | 1185 | if (hw_fib_p < &hw_fib_pool[num]) { |
916 | newfib = kmalloc(sizeof(struct fib), GFP_ATOMIC); | 1186 | hw_newfib = *hw_fib_p; |
917 | if (newfib && hw_newfib) { | 1187 | *(hw_fib_p++) = NULL; |
1188 | newfib = *fib_p; | ||
1189 | *(fib_p++) = NULL; | ||
918 | /* | 1190 | /* |
919 | * Make the copy of the FIB | 1191 | * Make the copy of the FIB |
920 | */ | 1192 | */ |
@@ -929,15 +1201,11 @@ int aac_command_thread(struct aac_dev * dev) | |||
929 | fibctx->count++; | 1201 | fibctx->count++; |
930 | /* | 1202 | /* |
931 | * Set the event to wake up the | 1203 | * Set the event to wake up the |
932 | * thread that will waiting. | 1204 | * thread that is waiting. |
933 | */ | 1205 | */ |
934 | up(&fibctx->wait_sem); | 1206 | up(&fibctx->wait_sem); |
935 | } else { | 1207 | } else { |
936 | printk(KERN_WARNING "aifd: didn't allocate NewFib.\n"); | 1208 | printk(KERN_WARNING "aifd: didn't allocate NewFib.\n"); |
937 | if(newfib) | ||
938 | kfree(newfib); | ||
939 | if(hw_newfib) | ||
940 | kfree(hw_newfib); | ||
941 | } | 1209 | } |
942 | entry = entry->next; | 1210 | entry = entry->next; |
943 | } | 1211 | } |
@@ -947,21 +1215,38 @@ int aac_command_thread(struct aac_dev * dev) | |||
947 | *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK); | 1215 | *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK); |
948 | fib_adapter_complete(fib, sizeof(u32)); | 1216 | fib_adapter_complete(fib, sizeof(u32)); |
949 | spin_unlock_irqrestore(&dev->fib_lock, flagv); | 1217 | spin_unlock_irqrestore(&dev->fib_lock, flagv); |
1218 | /* Free up the remaining resources */ | ||
1219 | hw_fib_p = hw_fib_pool; | ||
1220 | fib_p = fib_pool; | ||
1221 | while (hw_fib_p < &hw_fib_pool[num]) { | ||
1222 | if (*hw_fib_p) | ||
1223 | kfree(*hw_fib_p); | ||
1224 | if (*fib_p) | ||
1225 | kfree(*fib_p); | ||
1226 | ++fib_p; | ||
1227 | ++hw_fib_p; | ||
1228 | } | ||
1229 | if (hw_fib_pool) | ||
1230 | kfree(hw_fib_pool); | ||
1231 | if (fib_pool) | ||
1232 | kfree(fib_pool); | ||
950 | } | 1233 | } |
951 | spin_lock_irqsave(queues->queue[HostNormCmdQueue].lock, flags); | ||
952 | kfree(fib); | 1234 | kfree(fib); |
1235 | spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags); | ||
953 | } | 1236 | } |
954 | /* | 1237 | /* |
955 | * There are no more AIF's | 1238 | * There are no more AIF's |
956 | */ | 1239 | */ |
957 | spin_unlock_irqrestore(queues->queue[HostNormCmdQueue].lock, flags); | 1240 | spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags); |
958 | schedule(); | 1241 | schedule(); |
959 | 1242 | ||
960 | if(signal_pending(current)) | 1243 | if(signal_pending(current)) |
961 | break; | 1244 | break; |
962 | set_current_state(TASK_INTERRUPTIBLE); | 1245 | set_current_state(TASK_INTERRUPTIBLE); |
963 | } | 1246 | } |
964 | remove_wait_queue(&queues->queue[HostNormCmdQueue].cmdready, &wait); | 1247 | if (dev->queues) |
1248 | remove_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait); | ||
965 | dev->aif_thread = 0; | 1249 | dev->aif_thread = 0; |
966 | complete_and_exit(&dev->aif_completion, 0); | 1250 | complete_and_exit(&dev->aif_completion, 0); |
1251 | return 0; | ||
967 | } | 1252 | } |
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c index 4ff29d7f5825..de8490a92831 100644 --- a/drivers/scsi/aacraid/linit.c +++ b/drivers/scsi/aacraid/linit.c | |||
@@ -748,7 +748,8 @@ static int __devinit aac_probe_one(struct pci_dev *pdev, | |||
748 | unique_id++; | 748 | unique_id++; |
749 | } | 749 | } |
750 | 750 | ||
751 | if (pci_enable_device(pdev)) | 751 | error = pci_enable_device(pdev); |
752 | if (error) | ||
752 | goto out; | 753 | goto out; |
753 | 754 | ||
754 | if (pci_set_dma_mask(pdev, 0xFFFFFFFFULL) || | 755 | if (pci_set_dma_mask(pdev, 0xFFFFFFFFULL) || |
@@ -772,6 +773,7 @@ static int __devinit aac_probe_one(struct pci_dev *pdev, | |||
772 | shost->irq = pdev->irq; | 773 | shost->irq = pdev->irq; |
773 | shost->base = pci_resource_start(pdev, 0); | 774 | shost->base = pci_resource_start(pdev, 0); |
774 | shost->unique_id = unique_id; | 775 | shost->unique_id = unique_id; |
776 | shost->max_cmd_len = 16; | ||
775 | 777 | ||
776 | aac = (struct aac_dev *)shost->hostdata; | 778 | aac = (struct aac_dev *)shost->hostdata; |
777 | aac->scsi_host_ptr = shost; | 779 | aac->scsi_host_ptr = shost; |
@@ -799,7 +801,9 @@ static int __devinit aac_probe_one(struct pci_dev *pdev, | |||
799 | goto out_free_fibs; | 801 | goto out_free_fibs; |
800 | 802 | ||
801 | aac->maximum_num_channels = aac_drivers[index].channels; | 803 | aac->maximum_num_channels = aac_drivers[index].channels; |
802 | aac_get_adapter_info(aac); | 804 | error = aac_get_adapter_info(aac); |
805 | if (error < 0) | ||
806 | goto out_deinit; | ||
803 | 807 | ||
804 | /* | 808 | /* |
805 | * Lets override negotiations and drop the maximum SG limit to 34 | 809 | * Lets override negotiations and drop the maximum SG limit to 34 |
@@ -927,8 +931,8 @@ static int __init aac_init(void) | |||
927 | printk(KERN_INFO "Adaptec %s driver (%s)\n", | 931 | printk(KERN_INFO "Adaptec %s driver (%s)\n", |
928 | AAC_DRIVERNAME, aac_driver_version); | 932 | AAC_DRIVERNAME, aac_driver_version); |
929 | 933 | ||
930 | error = pci_module_init(&aac_pci_driver); | 934 | error = pci_register_driver(&aac_pci_driver); |
931 | if (error) | 935 | if (error < 0) |
932 | return error; | 936 | return error; |
933 | 937 | ||
934 | aac_cfg_major = register_chrdev( 0, "aac", &aac_cfg_fops); | 938 | aac_cfg_major = register_chrdev( 0, "aac", &aac_cfg_fops); |
diff --git a/drivers/scsi/aic7xxx/aic7770_osm.c b/drivers/scsi/aic7xxx/aic7770_osm.c index 70c5fb59c9ea..d754b3267863 100644 --- a/drivers/scsi/aic7xxx/aic7770_osm.c +++ b/drivers/scsi/aic7xxx/aic7770_osm.c | |||
@@ -112,6 +112,9 @@ aic7770_remove(struct device *dev) | |||
112 | struct ahc_softc *ahc = dev_get_drvdata(dev); | 112 | struct ahc_softc *ahc = dev_get_drvdata(dev); |
113 | u_long s; | 113 | u_long s; |
114 | 114 | ||
115 | if (ahc->platform_data && ahc->platform_data->host) | ||
116 | scsi_remove_host(ahc->platform_data->host); | ||
117 | |||
115 | ahc_lock(ahc, &s); | 118 | ahc_lock(ahc, &s); |
116 | ahc_intr_enable(ahc, FALSE); | 119 | ahc_intr_enable(ahc, FALSE); |
117 | ahc_unlock(ahc, &s); | 120 | ahc_unlock(ahc, &s); |
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c index 6b6d4e287793..95c285cc83e4 100644 --- a/drivers/scsi/aic7xxx/aic79xx_osm.c +++ b/drivers/scsi/aic7xxx/aic79xx_osm.c | |||
@@ -1192,11 +1192,6 @@ ahd_platform_free(struct ahd_softc *ahd) | |||
1192 | int i, j; | 1192 | int i, j; |
1193 | 1193 | ||
1194 | if (ahd->platform_data != NULL) { | 1194 | if (ahd->platform_data != NULL) { |
1195 | if (ahd->platform_data->host != NULL) { | ||
1196 | scsi_remove_host(ahd->platform_data->host); | ||
1197 | scsi_host_put(ahd->platform_data->host); | ||
1198 | } | ||
1199 | |||
1200 | /* destroy all of the device and target objects */ | 1195 | /* destroy all of the device and target objects */ |
1201 | for (i = 0; i < AHD_NUM_TARGETS; i++) { | 1196 | for (i = 0; i < AHD_NUM_TARGETS; i++) { |
1202 | starget = ahd->platform_data->starget[i]; | 1197 | starget = ahd->platform_data->starget[i]; |
@@ -1226,6 +1221,9 @@ ahd_platform_free(struct ahd_softc *ahd) | |||
1226 | release_mem_region(ahd->platform_data->mem_busaddr, | 1221 | release_mem_region(ahd->platform_data->mem_busaddr, |
1227 | 0x1000); | 1222 | 0x1000); |
1228 | } | 1223 | } |
1224 | if (ahd->platform_data->host) | ||
1225 | scsi_host_put(ahd->platform_data->host); | ||
1226 | |||
1229 | free(ahd->platform_data, M_DEVBUF); | 1227 | free(ahd->platform_data, M_DEVBUF); |
1230 | } | 1228 | } |
1231 | } | 1229 | } |
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c index 390b53852d4b..bf360ae021ab 100644 --- a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c +++ b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c | |||
@@ -95,6 +95,9 @@ ahd_linux_pci_dev_remove(struct pci_dev *pdev) | |||
95 | struct ahd_softc *ahd = pci_get_drvdata(pdev); | 95 | struct ahd_softc *ahd = pci_get_drvdata(pdev); |
96 | u_long s; | 96 | u_long s; |
97 | 97 | ||
98 | if (ahd->platform_data && ahd->platform_data->host) | ||
99 | scsi_remove_host(ahd->platform_data->host); | ||
100 | |||
98 | ahd_lock(ahd, &s); | 101 | ahd_lock(ahd, &s); |
99 | ahd_intr_enable(ahd, FALSE); | 102 | ahd_intr_enable(ahd, FALSE); |
100 | ahd_unlock(ahd, &s); | 103 | ahd_unlock(ahd, &s); |
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c index 876d1de8480d..6ee1435d37fa 100644 --- a/drivers/scsi/aic7xxx/aic7xxx_osm.c +++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c | |||
@@ -1209,11 +1209,6 @@ ahc_platform_free(struct ahc_softc *ahc) | |||
1209 | int i, j; | 1209 | int i, j; |
1210 | 1210 | ||
1211 | if (ahc->platform_data != NULL) { | 1211 | if (ahc->platform_data != NULL) { |
1212 | if (ahc->platform_data->host != NULL) { | ||
1213 | scsi_remove_host(ahc->platform_data->host); | ||
1214 | scsi_host_put(ahc->platform_data->host); | ||
1215 | } | ||
1216 | |||
1217 | /* destroy all of the device and target objects */ | 1212 | /* destroy all of the device and target objects */ |
1218 | for (i = 0; i < AHC_NUM_TARGETS; i++) { | 1213 | for (i = 0; i < AHC_NUM_TARGETS; i++) { |
1219 | starget = ahc->platform_data->starget[i]; | 1214 | starget = ahc->platform_data->starget[i]; |
@@ -1242,6 +1237,9 @@ ahc_platform_free(struct ahc_softc *ahc) | |||
1242 | 0x1000); | 1237 | 0x1000); |
1243 | } | 1238 | } |
1244 | 1239 | ||
1240 | if (ahc->platform_data->host) | ||
1241 | scsi_host_put(ahc->platform_data->host); | ||
1242 | |||
1245 | free(ahc->platform_data, M_DEVBUF); | 1243 | free(ahc->platform_data, M_DEVBUF); |
1246 | } | 1244 | } |
1247 | } | 1245 | } |
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c index 3ce77ddc889e..cb30d9c1153d 100644 --- a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c +++ b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c | |||
@@ -143,6 +143,9 @@ ahc_linux_pci_dev_remove(struct pci_dev *pdev) | |||
143 | struct ahc_softc *ahc = pci_get_drvdata(pdev); | 143 | struct ahc_softc *ahc = pci_get_drvdata(pdev); |
144 | u_long s; | 144 | u_long s; |
145 | 145 | ||
146 | if (ahc->platform_data && ahc->platform_data->host) | ||
147 | scsi_remove_host(ahc->platform_data->host); | ||
148 | |||
146 | ahc_lock(ahc, &s); | 149 | ahc_lock(ahc, &s); |
147 | ahc_intr_enable(ahc, FALSE); | 150 | ahc_intr_enable(ahc, FALSE); |
148 | ahc_unlock(ahc, &s); | 151 | ahc_unlock(ahc, &s); |
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index f2a72d33132c..02fe371b0ab8 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c | |||
@@ -176,6 +176,7 @@ void scsi_remove_host(struct Scsi_Host *shost) | |||
176 | transport_unregister_device(&shost->shost_gendev); | 176 | transport_unregister_device(&shost->shost_gendev); |
177 | class_device_unregister(&shost->shost_classdev); | 177 | class_device_unregister(&shost->shost_classdev); |
178 | device_del(&shost->shost_gendev); | 178 | device_del(&shost->shost_gendev); |
179 | scsi_proc_hostdir_rm(shost->hostt); | ||
179 | } | 180 | } |
180 | EXPORT_SYMBOL(scsi_remove_host); | 181 | EXPORT_SYMBOL(scsi_remove_host); |
181 | 182 | ||
@@ -262,7 +263,6 @@ static void scsi_host_dev_release(struct device *dev) | |||
262 | if (shost->work_q) | 263 | if (shost->work_q) |
263 | destroy_workqueue(shost->work_q); | 264 | destroy_workqueue(shost->work_q); |
264 | 265 | ||
265 | scsi_proc_hostdir_rm(shost->hostt); | ||
266 | scsi_destroy_command_freelist(shost); | 266 | scsi_destroy_command_freelist(shost); |
267 | kfree(shost->shost_data); | 267 | kfree(shost->shost_data); |
268 | 268 | ||
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c index 86eaf6d408d5..acae7c48ef7d 100644 --- a/drivers/scsi/lpfc/lpfc_attr.c +++ b/drivers/scsi/lpfc/lpfc_attr.c | |||
@@ -973,10 +973,10 @@ lpfc_get_host_fabric_name (struct Scsi_Host *shost) | |||
973 | if ((phba->fc_flag & FC_FABRIC) || | 973 | if ((phba->fc_flag & FC_FABRIC) || |
974 | ((phba->fc_topology == TOPOLOGY_LOOP) && | 974 | ((phba->fc_topology == TOPOLOGY_LOOP) && |
975 | (phba->fc_flag & FC_PUBLIC_LOOP))) | 975 | (phba->fc_flag & FC_PUBLIC_LOOP))) |
976 | node_name = wwn_to_u64(phba->fc_fabparam.nodeName.wwn); | 976 | node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn); |
977 | else | 977 | else |
978 | /* fabric is local port if there is no F/FL_Port */ | 978 | /* fabric is local port if there is no F/FL_Port */ |
979 | node_name = wwn_to_u64(phba->fc_nodename.wwn); | 979 | node_name = wwn_to_u64(phba->fc_nodename.u.wwn); |
980 | 980 | ||
981 | spin_unlock_irq(shost->host_lock); | 981 | spin_unlock_irq(shost->host_lock); |
982 | 982 | ||
@@ -1110,7 +1110,7 @@ lpfc_get_starget_node_name(struct scsi_target *starget) | |||
1110 | /* Search the mapped list for this target ID */ | 1110 | /* Search the mapped list for this target ID */ |
1111 | list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { | 1111 | list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { |
1112 | if (starget->id == ndlp->nlp_sid) { | 1112 | if (starget->id == ndlp->nlp_sid) { |
1113 | node_name = wwn_to_u64(ndlp->nlp_nodename.wwn); | 1113 | node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
1114 | break; | 1114 | break; |
1115 | } | 1115 | } |
1116 | } | 1116 | } |
@@ -1131,7 +1131,7 @@ lpfc_get_starget_port_name(struct scsi_target *starget) | |||
1131 | /* Search the mapped list for this target ID */ | 1131 | /* Search the mapped list for this target ID */ |
1132 | list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { | 1132 | list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { |
1133 | if (starget->id == ndlp->nlp_sid) { | 1133 | if (starget->id == ndlp->nlp_sid) { |
1134 | port_name = wwn_to_u64(ndlp->nlp_portname.wwn); | 1134 | port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
1135 | break; | 1135 | break; |
1136 | } | 1136 | } |
1137 | } | 1137 | } |
diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c index 4fb8eb0c84cf..56052f4510c3 100644 --- a/drivers/scsi/lpfc/lpfc_hbadisc.c +++ b/drivers/scsi/lpfc/lpfc_hbadisc.c | |||
@@ -1019,8 +1019,8 @@ lpfc_register_remote_port(struct lpfc_hba * phba, | |||
1019 | struct fc_rport_identifiers rport_ids; | 1019 | struct fc_rport_identifiers rport_ids; |
1020 | 1020 | ||
1021 | /* Remote port has reappeared. Re-register w/ FC transport */ | 1021 | /* Remote port has reappeared. Re-register w/ FC transport */ |
1022 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.wwn); | 1022 | rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
1023 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.wwn); | 1023 | rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
1024 | rport_ids.port_id = ndlp->nlp_DID; | 1024 | rport_ids.port_id = ndlp->nlp_DID; |
1025 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; | 1025 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
1026 | if (ndlp->nlp_type & NLP_FCP_TARGET) | 1026 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
diff --git a/drivers/scsi/lpfc/lpfc_hw.h b/drivers/scsi/lpfc/lpfc_hw.h index 047a87c26cc0..86c41981188b 100644 --- a/drivers/scsi/lpfc/lpfc_hw.h +++ b/drivers/scsi/lpfc/lpfc_hw.h | |||
@@ -280,9 +280,9 @@ struct lpfc_name { | |||
280 | #define NAME_CCITT_GR_TYPE 0xE | 280 | #define NAME_CCITT_GR_TYPE 0xE |
281 | uint8_t IEEEextLsb; /* FC Word 0, bit 16:23, IEEE extended Lsb */ | 281 | uint8_t IEEEextLsb; /* FC Word 0, bit 16:23, IEEE extended Lsb */ |
282 | uint8_t IEEE[6]; /* FC IEEE address */ | 282 | uint8_t IEEE[6]; /* FC IEEE address */ |
283 | }; | 283 | } s; |
284 | uint8_t wwn[8]; | 284 | uint8_t wwn[8]; |
285 | }; | 285 | } u; |
286 | }; | 286 | }; |
287 | 287 | ||
288 | struct csp { | 288 | struct csp { |
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c index 454058f655db..0856ff7d3b33 100644 --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c | |||
@@ -285,7 +285,7 @@ lpfc_config_port_post(struct lpfc_hba * phba) | |||
285 | if (phba->SerialNumber[0] == 0) { | 285 | if (phba->SerialNumber[0] == 0) { |
286 | uint8_t *outptr; | 286 | uint8_t *outptr; |
287 | 287 | ||
288 | outptr = (uint8_t *) & phba->fc_nodename.IEEE[0]; | 288 | outptr = &phba->fc_nodename.u.s.IEEE[0]; |
289 | for (i = 0; i < 12; i++) { | 289 | for (i = 0; i < 12; i++) { |
290 | status = *outptr++; | 290 | status = *outptr++; |
291 | j = ((status & 0xf0) >> 4); | 291 | j = ((status & 0xf0) >> 4); |
@@ -1523,8 +1523,8 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | |||
1523 | * Must done after lpfc_sli_hba_setup() | 1523 | * Must done after lpfc_sli_hba_setup() |
1524 | */ | 1524 | */ |
1525 | 1525 | ||
1526 | fc_host_node_name(host) = wwn_to_u64(phba->fc_nodename.wwn); | 1526 | fc_host_node_name(host) = wwn_to_u64(phba->fc_nodename.u.wwn); |
1527 | fc_host_port_name(host) = wwn_to_u64(phba->fc_portname.wwn); | 1527 | fc_host_port_name(host) = wwn_to_u64(phba->fc_portname.u.wwn); |
1528 | fc_host_supported_classes(host) = FC_COS_CLASS3; | 1528 | fc_host_supported_classes(host) = FC_COS_CLASS3; |
1529 | 1529 | ||
1530 | memset(fc_host_supported_fc4s(host), 0, | 1530 | memset(fc_host_supported_fc4s(host), 0, |
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c index 6f308ebe3e79..61a6fd810bb4 100644 --- a/drivers/scsi/megaraid.c +++ b/drivers/scsi/megaraid.c | |||
@@ -621,8 +621,6 @@ mega_build_cmd(adapter_t *adapter, Scsi_Cmnd *cmd, int *busy) | |||
621 | if(islogical) { | 621 | if(islogical) { |
622 | switch (cmd->cmnd[0]) { | 622 | switch (cmd->cmnd[0]) { |
623 | case TEST_UNIT_READY: | 623 | case TEST_UNIT_READY: |
624 | memset(cmd->request_buffer, 0, cmd->request_bufflen); | ||
625 | |||
626 | #if MEGA_HAVE_CLUSTERING | 624 | #if MEGA_HAVE_CLUSTERING |
627 | /* | 625 | /* |
628 | * Do we support clustering and is the support enabled | 626 | * Do we support clustering and is the support enabled |
@@ -652,11 +650,28 @@ mega_build_cmd(adapter_t *adapter, Scsi_Cmnd *cmd, int *busy) | |||
652 | return NULL; | 650 | return NULL; |
653 | #endif | 651 | #endif |
654 | 652 | ||
655 | case MODE_SENSE: | 653 | case MODE_SENSE: { |
654 | char *buf; | ||
655 | |||
656 | if (cmd->use_sg) { | ||
657 | struct scatterlist *sg; | ||
658 | |||
659 | sg = (struct scatterlist *)cmd->request_buffer; | ||
660 | buf = kmap_atomic(sg->page, KM_IRQ0) + | ||
661 | sg->offset; | ||
662 | } else | ||
663 | buf = cmd->request_buffer; | ||
656 | memset(cmd->request_buffer, 0, cmd->cmnd[4]); | 664 | memset(cmd->request_buffer, 0, cmd->cmnd[4]); |
665 | if (cmd->use_sg) { | ||
666 | struct scatterlist *sg; | ||
667 | |||
668 | sg = (struct scatterlist *)cmd->request_buffer; | ||
669 | kunmap_atomic(buf - sg->offset, KM_IRQ0); | ||
670 | } | ||
657 | cmd->result = (DID_OK << 16); | 671 | cmd->result = (DID_OK << 16); |
658 | cmd->scsi_done(cmd); | 672 | cmd->scsi_done(cmd); |
659 | return NULL; | 673 | return NULL; |
674 | } | ||
660 | 675 | ||
661 | case READ_CAPACITY: | 676 | case READ_CAPACITY: |
662 | case INQUIRY: | 677 | case INQUIRY: |
@@ -1685,14 +1700,23 @@ mega_rundoneq (adapter_t *adapter) | |||
1685 | static void | 1700 | static void |
1686 | mega_free_scb(adapter_t *adapter, scb_t *scb) | 1701 | mega_free_scb(adapter_t *adapter, scb_t *scb) |
1687 | { | 1702 | { |
1703 | unsigned long length; | ||
1704 | |||
1688 | switch( scb->dma_type ) { | 1705 | switch( scb->dma_type ) { |
1689 | 1706 | ||
1690 | case MEGA_DMA_TYPE_NONE: | 1707 | case MEGA_DMA_TYPE_NONE: |
1691 | break; | 1708 | break; |
1692 | 1709 | ||
1693 | case MEGA_BULK_DATA: | 1710 | case MEGA_BULK_DATA: |
1711 | if (scb->cmd->use_sg == 0) | ||
1712 | length = scb->cmd->request_bufflen; | ||
1713 | else { | ||
1714 | struct scatterlist *sgl = | ||
1715 | (struct scatterlist *)scb->cmd->request_buffer; | ||
1716 | length = sgl->length; | ||
1717 | } | ||
1694 | pci_unmap_page(adapter->dev, scb->dma_h_bulkdata, | 1718 | pci_unmap_page(adapter->dev, scb->dma_h_bulkdata, |
1695 | scb->cmd->request_bufflen, scb->dma_direction); | 1719 | length, scb->dma_direction); |
1696 | break; | 1720 | break; |
1697 | 1721 | ||
1698 | case MEGA_SGLIST: | 1722 | case MEGA_SGLIST: |
@@ -1741,6 +1765,7 @@ mega_build_sglist(adapter_t *adapter, scb_t *scb, u32 *buf, u32 *len) | |||
1741 | struct scatterlist *sgl; | 1765 | struct scatterlist *sgl; |
1742 | struct page *page; | 1766 | struct page *page; |
1743 | unsigned long offset; | 1767 | unsigned long offset; |
1768 | unsigned int length; | ||
1744 | Scsi_Cmnd *cmd; | 1769 | Scsi_Cmnd *cmd; |
1745 | int sgcnt; | 1770 | int sgcnt; |
1746 | int idx; | 1771 | int idx; |
@@ -1748,14 +1773,23 @@ mega_build_sglist(adapter_t *adapter, scb_t *scb, u32 *buf, u32 *len) | |||
1748 | cmd = scb->cmd; | 1773 | cmd = scb->cmd; |
1749 | 1774 | ||
1750 | /* Scatter-gather not used */ | 1775 | /* Scatter-gather not used */ |
1751 | if( !cmd->use_sg ) { | 1776 | if( cmd->use_sg == 0 || (cmd->use_sg == 1 && |
1752 | 1777 | !adapter->has_64bit_addr)) { | |
1753 | page = virt_to_page(cmd->request_buffer); | 1778 | |
1754 | offset = offset_in_page(cmd->request_buffer); | 1779 | if (cmd->use_sg == 0) { |
1780 | page = virt_to_page(cmd->request_buffer); | ||
1781 | offset = offset_in_page(cmd->request_buffer); | ||
1782 | length = cmd->request_bufflen; | ||
1783 | } else { | ||
1784 | sgl = (struct scatterlist *)cmd->request_buffer; | ||
1785 | page = sgl->page; | ||
1786 | offset = sgl->offset; | ||
1787 | length = sgl->length; | ||
1788 | } | ||
1755 | 1789 | ||
1756 | scb->dma_h_bulkdata = pci_map_page(adapter->dev, | 1790 | scb->dma_h_bulkdata = pci_map_page(adapter->dev, |
1757 | page, offset, | 1791 | page, offset, |
1758 | cmd->request_bufflen, | 1792 | length, |
1759 | scb->dma_direction); | 1793 | scb->dma_direction); |
1760 | scb->dma_type = MEGA_BULK_DATA; | 1794 | scb->dma_type = MEGA_BULK_DATA; |
1761 | 1795 | ||
@@ -1765,14 +1799,14 @@ mega_build_sglist(adapter_t *adapter, scb_t *scb, u32 *buf, u32 *len) | |||
1765 | */ | 1799 | */ |
1766 | if( adapter->has_64bit_addr ) { | 1800 | if( adapter->has_64bit_addr ) { |
1767 | scb->sgl64[0].address = scb->dma_h_bulkdata; | 1801 | scb->sgl64[0].address = scb->dma_h_bulkdata; |
1768 | scb->sgl64[0].length = cmd->request_bufflen; | 1802 | scb->sgl64[0].length = length; |
1769 | *buf = (u32)scb->sgl_dma_addr; | 1803 | *buf = (u32)scb->sgl_dma_addr; |
1770 | *len = (u32)cmd->request_bufflen; | 1804 | *len = (u32)length; |
1771 | return 1; | 1805 | return 1; |
1772 | } | 1806 | } |
1773 | else { | 1807 | else { |
1774 | *buf = (u32)scb->dma_h_bulkdata; | 1808 | *buf = (u32)scb->dma_h_bulkdata; |
1775 | *len = (u32)cmd->request_bufflen; | 1809 | *len = (u32)length; |
1776 | } | 1810 | } |
1777 | return 0; | 1811 | return 0; |
1778 | } | 1812 | } |
@@ -1791,27 +1825,23 @@ mega_build_sglist(adapter_t *adapter, scb_t *scb, u32 *buf, u32 *len) | |||
1791 | 1825 | ||
1792 | if( sgcnt > adapter->sglen ) BUG(); | 1826 | if( sgcnt > adapter->sglen ) BUG(); |
1793 | 1827 | ||
1828 | *len = 0; | ||
1829 | |||
1794 | for( idx = 0; idx < sgcnt; idx++, sgl++ ) { | 1830 | for( idx = 0; idx < sgcnt; idx++, sgl++ ) { |
1795 | 1831 | ||
1796 | if( adapter->has_64bit_addr ) { | 1832 | if( adapter->has_64bit_addr ) { |
1797 | scb->sgl64[idx].address = sg_dma_address(sgl); | 1833 | scb->sgl64[idx].address = sg_dma_address(sgl); |
1798 | scb->sgl64[idx].length = sg_dma_len(sgl); | 1834 | *len += scb->sgl64[idx].length = sg_dma_len(sgl); |
1799 | } | 1835 | } |
1800 | else { | 1836 | else { |
1801 | scb->sgl[idx].address = sg_dma_address(sgl); | 1837 | scb->sgl[idx].address = sg_dma_address(sgl); |
1802 | scb->sgl[idx].length = sg_dma_len(sgl); | 1838 | *len += scb->sgl[idx].length = sg_dma_len(sgl); |
1803 | } | 1839 | } |
1804 | } | 1840 | } |
1805 | 1841 | ||
1806 | /* Reset pointer and length fields */ | 1842 | /* Reset pointer and length fields */ |
1807 | *buf = scb->sgl_dma_addr; | 1843 | *buf = scb->sgl_dma_addr; |
1808 | 1844 | ||
1809 | /* | ||
1810 | * For passthru command, dataxferlen must be set, even for commands | ||
1811 | * with a sg list | ||
1812 | */ | ||
1813 | *len = (u32)cmd->request_bufflen; | ||
1814 | |||
1815 | /* Return count of SG requests */ | 1845 | /* Return count of SG requests */ |
1816 | return sgcnt; | 1846 | return sgcnt; |
1817 | } | 1847 | } |
diff --git a/drivers/scsi/megaraid/Kconfig.megaraid b/drivers/scsi/megaraid/Kconfig.megaraid index 917d591d90b2..7363e12663ac 100644 --- a/drivers/scsi/megaraid/Kconfig.megaraid +++ b/drivers/scsi/megaraid/Kconfig.megaraid | |||
@@ -76,3 +76,12 @@ config MEGARAID_LEGACY | |||
76 | To compile this driver as a module, choose M here: the | 76 | To compile this driver as a module, choose M here: the |
77 | module will be called megaraid | 77 | module will be called megaraid |
78 | endif | 78 | endif |
79 | |||
80 | config MEGARAID_SAS | ||
81 | tristate "LSI Logic MegaRAID SAS RAID Module" | ||
82 | depends on PCI && SCSI | ||
83 | help | ||
84 | Module for LSI Logic's SAS based RAID controllers. | ||
85 | To compile this driver as a module, choose 'm' here. | ||
86 | Module will be called megaraid_sas | ||
87 | |||
diff --git a/drivers/scsi/megaraid/Makefile b/drivers/scsi/megaraid/Makefile index 6dd99f275722..f469915b97c3 100644 --- a/drivers/scsi/megaraid/Makefile +++ b/drivers/scsi/megaraid/Makefile | |||
@@ -1,2 +1,3 @@ | |||
1 | obj-$(CONFIG_MEGARAID_MM) += megaraid_mm.o | 1 | obj-$(CONFIG_MEGARAID_MM) += megaraid_mm.o |
2 | obj-$(CONFIG_MEGARAID_MAILBOX) += megaraid_mbox.o | 2 | obj-$(CONFIG_MEGARAID_MAILBOX) += megaraid_mbox.o |
3 | obj-$(CONFIG_MEGARAID_SAS) += megaraid_sas.o | ||
diff --git a/drivers/scsi/megaraid/megaraid_sas.c b/drivers/scsi/megaraid/megaraid_sas.c new file mode 100644 index 000000000000..1b3148e842af --- /dev/null +++ b/drivers/scsi/megaraid/megaraid_sas.c | |||
@@ -0,0 +1,2805 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Linux MegaRAID driver for SAS based RAID controllers | ||
4 | * | ||
5 | * Copyright (c) 2003-2005 LSI Logic Corporation. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * as published by the Free Software Foundation; either version | ||
10 | * 2 of the License, or (at your option) any later version. | ||
11 | * | ||
12 | * FILE : megaraid_sas.c | ||
13 | * Version : v00.00.02.00-rc4 | ||
14 | * | ||
15 | * Authors: | ||
16 | * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsil.com> | ||
17 | * Sumant Patro <Sumant.Patro@lsil.com> | ||
18 | * | ||
19 | * List of supported controllers | ||
20 | * | ||
21 | * OEM Product Name VID DID SSVID SSID | ||
22 | * --- ------------ --- --- ---- ---- | ||
23 | */ | ||
24 | |||
25 | #include <linux/kernel.h> | ||
26 | #include <linux/types.h> | ||
27 | #include <linux/pci.h> | ||
28 | #include <linux/list.h> | ||
29 | #include <linux/version.h> | ||
30 | #include <linux/moduleparam.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/spinlock.h> | ||
33 | #include <linux/interrupt.h> | ||
34 | #include <linux/delay.h> | ||
35 | #include <linux/uio.h> | ||
36 | #include <asm/uaccess.h> | ||
37 | #include <linux/compat.h> | ||
38 | |||
39 | #include <scsi/scsi.h> | ||
40 | #include <scsi/scsi_cmnd.h> | ||
41 | #include <scsi/scsi_device.h> | ||
42 | #include <scsi/scsi_host.h> | ||
43 | #include "megaraid_sas.h" | ||
44 | |||
45 | MODULE_LICENSE("GPL"); | ||
46 | MODULE_VERSION(MEGASAS_VERSION); | ||
47 | MODULE_AUTHOR("sreenivas.bagalkote@lsil.com"); | ||
48 | MODULE_DESCRIPTION("LSI Logic MegaRAID SAS Driver"); | ||
49 | |||
50 | /* | ||
51 | * PCI ID table for all supported controllers | ||
52 | */ | ||
53 | static struct pci_device_id megasas_pci_table[] = { | ||
54 | |||
55 | { | ||
56 | PCI_VENDOR_ID_LSI_LOGIC, | ||
57 | PCI_DEVICE_ID_LSI_SAS1064R, | ||
58 | PCI_ANY_ID, | ||
59 | PCI_ANY_ID, | ||
60 | }, | ||
61 | { | ||
62 | PCI_VENDOR_ID_DELL, | ||
63 | PCI_DEVICE_ID_DELL_PERC5, | ||
64 | PCI_ANY_ID, | ||
65 | PCI_ANY_ID, | ||
66 | }, | ||
67 | {0} /* Terminating entry */ | ||
68 | }; | ||
69 | |||
70 | MODULE_DEVICE_TABLE(pci, megasas_pci_table); | ||
71 | |||
72 | static int megasas_mgmt_majorno; | ||
73 | static struct megasas_mgmt_info megasas_mgmt_info; | ||
74 | static struct fasync_struct *megasas_async_queue; | ||
75 | static DECLARE_MUTEX(megasas_async_queue_mutex); | ||
76 | |||
77 | /** | ||
78 | * megasas_get_cmd - Get a command from the free pool | ||
79 | * @instance: Adapter soft state | ||
80 | * | ||
81 | * Returns a free command from the pool | ||
82 | */ | ||
83 | static inline struct megasas_cmd *megasas_get_cmd(struct megasas_instance | ||
84 | *instance) | ||
85 | { | ||
86 | unsigned long flags; | ||
87 | struct megasas_cmd *cmd = NULL; | ||
88 | |||
89 | spin_lock_irqsave(&instance->cmd_pool_lock, flags); | ||
90 | |||
91 | if (!list_empty(&instance->cmd_pool)) { | ||
92 | cmd = list_entry((&instance->cmd_pool)->next, | ||
93 | struct megasas_cmd, list); | ||
94 | list_del_init(&cmd->list); | ||
95 | } else { | ||
96 | printk(KERN_ERR "megasas: Command pool empty!\n"); | ||
97 | } | ||
98 | |||
99 | spin_unlock_irqrestore(&instance->cmd_pool_lock, flags); | ||
100 | return cmd; | ||
101 | } | ||
102 | |||
103 | /** | ||
104 | * megasas_return_cmd - Return a cmd to free command pool | ||
105 | * @instance: Adapter soft state | ||
106 | * @cmd: Command packet to be returned to free command pool | ||
107 | */ | ||
108 | static inline void | ||
109 | megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) | ||
110 | { | ||
111 | unsigned long flags; | ||
112 | |||
113 | spin_lock_irqsave(&instance->cmd_pool_lock, flags); | ||
114 | |||
115 | cmd->scmd = NULL; | ||
116 | list_add_tail(&cmd->list, &instance->cmd_pool); | ||
117 | |||
118 | spin_unlock_irqrestore(&instance->cmd_pool_lock, flags); | ||
119 | } | ||
120 | |||
121 | /** | ||
122 | * megasas_enable_intr - Enables interrupts | ||
123 | * @regs: MFI register set | ||
124 | */ | ||
125 | static inline void | ||
126 | megasas_enable_intr(struct megasas_register_set __iomem * regs) | ||
127 | { | ||
128 | writel(1, &(regs)->outbound_intr_mask); | ||
129 | |||
130 | /* Dummy readl to force pci flush */ | ||
131 | readl(®s->outbound_intr_mask); | ||
132 | } | ||
133 | |||
134 | /** | ||
135 | * megasas_disable_intr - Disables interrupts | ||
136 | * @regs: MFI register set | ||
137 | */ | ||
138 | static inline void | ||
139 | megasas_disable_intr(struct megasas_register_set __iomem * regs) | ||
140 | { | ||
141 | u32 mask = readl(®s->outbound_intr_mask) & (~0x00000001); | ||
142 | writel(mask, ®s->outbound_intr_mask); | ||
143 | |||
144 | /* Dummy readl to force pci flush */ | ||
145 | readl(®s->outbound_intr_mask); | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * megasas_issue_polled - Issues a polling command | ||
150 | * @instance: Adapter soft state | ||
151 | * @cmd: Command packet to be issued | ||
152 | * | ||
153 | * For polling, MFI requires the cmd_status to be set to 0xFF before posting. | ||
154 | */ | ||
155 | static int | ||
156 | megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd) | ||
157 | { | ||
158 | int i; | ||
159 | u32 msecs = MFI_POLL_TIMEOUT_SECS * 1000; | ||
160 | |||
161 | struct megasas_header *frame_hdr = &cmd->frame->hdr; | ||
162 | |||
163 | frame_hdr->cmd_status = 0xFF; | ||
164 | frame_hdr->flags |= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE; | ||
165 | |||
166 | /* | ||
167 | * Issue the frame using inbound queue port | ||
168 | */ | ||
169 | writel(cmd->frame_phys_addr >> 3, | ||
170 | &instance->reg_set->inbound_queue_port); | ||
171 | |||
172 | /* | ||
173 | * Wait for cmd_status to change | ||
174 | */ | ||
175 | for (i = 0; (i < msecs) && (frame_hdr->cmd_status == 0xff); i++) { | ||
176 | rmb(); | ||
177 | msleep(1); | ||
178 | } | ||
179 | |||
180 | if (frame_hdr->cmd_status == 0xff) | ||
181 | return -ETIME; | ||
182 | |||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | /** | ||
187 | * megasas_issue_blocked_cmd - Synchronous wrapper around regular FW cmds | ||
188 | * @instance: Adapter soft state | ||
189 | * @cmd: Command to be issued | ||
190 | * | ||
191 | * This function waits on an event for the command to be returned from ISR. | ||
192 | * Used to issue ioctl commands. | ||
193 | */ | ||
194 | static int | ||
195 | megasas_issue_blocked_cmd(struct megasas_instance *instance, | ||
196 | struct megasas_cmd *cmd) | ||
197 | { | ||
198 | cmd->cmd_status = ENODATA; | ||
199 | |||
200 | writel(cmd->frame_phys_addr >> 3, | ||
201 | &instance->reg_set->inbound_queue_port); | ||
202 | |||
203 | wait_event(instance->int_cmd_wait_q, (cmd->cmd_status != ENODATA)); | ||
204 | |||
205 | return 0; | ||
206 | } | ||
207 | |||
208 | /** | ||
209 | * megasas_issue_blocked_abort_cmd - Aborts previously issued cmd | ||
210 | * @instance: Adapter soft state | ||
211 | * @cmd_to_abort: Previously issued cmd to be aborted | ||
212 | * | ||
213 | * MFI firmware can abort previously issued AEN comamnd (automatic event | ||
214 | * notification). The megasas_issue_blocked_abort_cmd() issues such abort | ||
215 | * cmd and blocks till it is completed. | ||
216 | */ | ||
217 | static int | ||
218 | megasas_issue_blocked_abort_cmd(struct megasas_instance *instance, | ||
219 | struct megasas_cmd *cmd_to_abort) | ||
220 | { | ||
221 | struct megasas_cmd *cmd; | ||
222 | struct megasas_abort_frame *abort_fr; | ||
223 | |||
224 | cmd = megasas_get_cmd(instance); | ||
225 | |||
226 | if (!cmd) | ||
227 | return -1; | ||
228 | |||
229 | abort_fr = &cmd->frame->abort; | ||
230 | |||
231 | /* | ||
232 | * Prepare and issue the abort frame | ||
233 | */ | ||
234 | abort_fr->cmd = MFI_CMD_ABORT; | ||
235 | abort_fr->cmd_status = 0xFF; | ||
236 | abort_fr->flags = 0; | ||
237 | abort_fr->abort_context = cmd_to_abort->index; | ||
238 | abort_fr->abort_mfi_phys_addr_lo = cmd_to_abort->frame_phys_addr; | ||
239 | abort_fr->abort_mfi_phys_addr_hi = 0; | ||
240 | |||
241 | cmd->sync_cmd = 1; | ||
242 | cmd->cmd_status = 0xFF; | ||
243 | |||
244 | writel(cmd->frame_phys_addr >> 3, | ||
245 | &instance->reg_set->inbound_queue_port); | ||
246 | |||
247 | /* | ||
248 | * Wait for this cmd to complete | ||
249 | */ | ||
250 | wait_event(instance->abort_cmd_wait_q, (cmd->cmd_status != 0xFF)); | ||
251 | |||
252 | megasas_return_cmd(instance, cmd); | ||
253 | return 0; | ||
254 | } | ||
255 | |||
256 | /** | ||
257 | * megasas_make_sgl32 - Prepares 32-bit SGL | ||
258 | * @instance: Adapter soft state | ||
259 | * @scp: SCSI command from the mid-layer | ||
260 | * @mfi_sgl: SGL to be filled in | ||
261 | * | ||
262 | * If successful, this function returns the number of SG elements. Otherwise, | ||
263 | * it returnes -1. | ||
264 | */ | ||
265 | static inline int | ||
266 | megasas_make_sgl32(struct megasas_instance *instance, struct scsi_cmnd *scp, | ||
267 | union megasas_sgl *mfi_sgl) | ||
268 | { | ||
269 | int i; | ||
270 | int sge_count; | ||
271 | struct scatterlist *os_sgl; | ||
272 | |||
273 | /* | ||
274 | * Return 0 if there is no data transfer | ||
275 | */ | ||
276 | if (!scp->request_buffer || !scp->request_bufflen) | ||
277 | return 0; | ||
278 | |||
279 | if (!scp->use_sg) { | ||
280 | mfi_sgl->sge32[0].phys_addr = pci_map_single(instance->pdev, | ||
281 | scp-> | ||
282 | request_buffer, | ||
283 | scp-> | ||
284 | request_bufflen, | ||
285 | scp-> | ||
286 | sc_data_direction); | ||
287 | mfi_sgl->sge32[0].length = scp->request_bufflen; | ||
288 | |||
289 | return 1; | ||
290 | } | ||
291 | |||
292 | os_sgl = (struct scatterlist *)scp->request_buffer; | ||
293 | sge_count = pci_map_sg(instance->pdev, os_sgl, scp->use_sg, | ||
294 | scp->sc_data_direction); | ||
295 | |||
296 | for (i = 0; i < sge_count; i++, os_sgl++) { | ||
297 | mfi_sgl->sge32[i].length = sg_dma_len(os_sgl); | ||
298 | mfi_sgl->sge32[i].phys_addr = sg_dma_address(os_sgl); | ||
299 | } | ||
300 | |||
301 | return sge_count; | ||
302 | } | ||
303 | |||
304 | /** | ||
305 | * megasas_make_sgl64 - Prepares 64-bit SGL | ||
306 | * @instance: Adapter soft state | ||
307 | * @scp: SCSI command from the mid-layer | ||
308 | * @mfi_sgl: SGL to be filled in | ||
309 | * | ||
310 | * If successful, this function returns the number of SG elements. Otherwise, | ||
311 | * it returnes -1. | ||
312 | */ | ||
313 | static inline int | ||
314 | megasas_make_sgl64(struct megasas_instance *instance, struct scsi_cmnd *scp, | ||
315 | union megasas_sgl *mfi_sgl) | ||
316 | { | ||
317 | int i; | ||
318 | int sge_count; | ||
319 | struct scatterlist *os_sgl; | ||
320 | |||
321 | /* | ||
322 | * Return 0 if there is no data transfer | ||
323 | */ | ||
324 | if (!scp->request_buffer || !scp->request_bufflen) | ||
325 | return 0; | ||
326 | |||
327 | if (!scp->use_sg) { | ||
328 | mfi_sgl->sge64[0].phys_addr = pci_map_single(instance->pdev, | ||
329 | scp-> | ||
330 | request_buffer, | ||
331 | scp-> | ||
332 | request_bufflen, | ||
333 | scp-> | ||
334 | sc_data_direction); | ||
335 | |||
336 | mfi_sgl->sge64[0].length = scp->request_bufflen; | ||
337 | |||
338 | return 1; | ||
339 | } | ||
340 | |||
341 | os_sgl = (struct scatterlist *)scp->request_buffer; | ||
342 | sge_count = pci_map_sg(instance->pdev, os_sgl, scp->use_sg, | ||
343 | scp->sc_data_direction); | ||
344 | |||
345 | for (i = 0; i < sge_count; i++, os_sgl++) { | ||
346 | mfi_sgl->sge64[i].length = sg_dma_len(os_sgl); | ||
347 | mfi_sgl->sge64[i].phys_addr = sg_dma_address(os_sgl); | ||
348 | } | ||
349 | |||
350 | return sge_count; | ||
351 | } | ||
352 | |||
353 | /** | ||
354 | * megasas_build_dcdb - Prepares a direct cdb (DCDB) command | ||
355 | * @instance: Adapter soft state | ||
356 | * @scp: SCSI command | ||
357 | * @cmd: Command to be prepared in | ||
358 | * | ||
359 | * This function prepares CDB commands. These are typcially pass-through | ||
360 | * commands to the devices. | ||
361 | */ | ||
362 | static inline int | ||
363 | megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, | ||
364 | struct megasas_cmd *cmd) | ||
365 | { | ||
366 | u32 sge_sz; | ||
367 | int sge_bytes; | ||
368 | u32 is_logical; | ||
369 | u32 device_id; | ||
370 | u16 flags = 0; | ||
371 | struct megasas_pthru_frame *pthru; | ||
372 | |||
373 | is_logical = MEGASAS_IS_LOGICAL(scp); | ||
374 | device_id = MEGASAS_DEV_INDEX(instance, scp); | ||
375 | pthru = (struct megasas_pthru_frame *)cmd->frame; | ||
376 | |||
377 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) | ||
378 | flags = MFI_FRAME_DIR_WRITE; | ||
379 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) | ||
380 | flags = MFI_FRAME_DIR_READ; | ||
381 | else if (scp->sc_data_direction == PCI_DMA_NONE) | ||
382 | flags = MFI_FRAME_DIR_NONE; | ||
383 | |||
384 | /* | ||
385 | * Prepare the DCDB frame | ||
386 | */ | ||
387 | pthru->cmd = (is_logical) ? MFI_CMD_LD_SCSI_IO : MFI_CMD_PD_SCSI_IO; | ||
388 | pthru->cmd_status = 0x0; | ||
389 | pthru->scsi_status = 0x0; | ||
390 | pthru->target_id = device_id; | ||
391 | pthru->lun = scp->device->lun; | ||
392 | pthru->cdb_len = scp->cmd_len; | ||
393 | pthru->timeout = 0; | ||
394 | pthru->flags = flags; | ||
395 | pthru->data_xfer_len = scp->request_bufflen; | ||
396 | |||
397 | memcpy(pthru->cdb, scp->cmnd, scp->cmd_len); | ||
398 | |||
399 | /* | ||
400 | * Construct SGL | ||
401 | */ | ||
402 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : | ||
403 | sizeof(struct megasas_sge32); | ||
404 | |||
405 | if (IS_DMA64) { | ||
406 | pthru->flags |= MFI_FRAME_SGL64; | ||
407 | pthru->sge_count = megasas_make_sgl64(instance, scp, | ||
408 | &pthru->sgl); | ||
409 | } else | ||
410 | pthru->sge_count = megasas_make_sgl32(instance, scp, | ||
411 | &pthru->sgl); | ||
412 | |||
413 | /* | ||
414 | * Sense info specific | ||
415 | */ | ||
416 | pthru->sense_len = SCSI_SENSE_BUFFERSIZE; | ||
417 | pthru->sense_buf_phys_addr_hi = 0; | ||
418 | pthru->sense_buf_phys_addr_lo = cmd->sense_phys_addr; | ||
419 | |||
420 | sge_bytes = sge_sz * pthru->sge_count; | ||
421 | |||
422 | /* | ||
423 | * Compute the total number of frames this command consumes. FW uses | ||
424 | * this number to pull sufficient number of frames from host memory. | ||
425 | */ | ||
426 | cmd->frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + | ||
427 | ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) + 1; | ||
428 | |||
429 | if (cmd->frame_count > 7) | ||
430 | cmd->frame_count = 8; | ||
431 | |||
432 | return cmd->frame_count; | ||
433 | } | ||
434 | |||
435 | /** | ||
436 | * megasas_build_ldio - Prepares IOs to logical devices | ||
437 | * @instance: Adapter soft state | ||
438 | * @scp: SCSI command | ||
439 | * @cmd: Command to to be prepared | ||
440 | * | ||
441 | * Frames (and accompanying SGLs) for regular SCSI IOs use this function. | ||
442 | */ | ||
443 | static inline int | ||
444 | megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp, | ||
445 | struct megasas_cmd *cmd) | ||
446 | { | ||
447 | u32 sge_sz; | ||
448 | int sge_bytes; | ||
449 | u32 device_id; | ||
450 | u8 sc = scp->cmnd[0]; | ||
451 | u16 flags = 0; | ||
452 | struct megasas_io_frame *ldio; | ||
453 | |||
454 | device_id = MEGASAS_DEV_INDEX(instance, scp); | ||
455 | ldio = (struct megasas_io_frame *)cmd->frame; | ||
456 | |||
457 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) | ||
458 | flags = MFI_FRAME_DIR_WRITE; | ||
459 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) | ||
460 | flags = MFI_FRAME_DIR_READ; | ||
461 | |||
462 | /* | ||
463 | * Preare the Logical IO frame: 2nd bit is zero for all read cmds | ||
464 | */ | ||
465 | ldio->cmd = (sc & 0x02) ? MFI_CMD_LD_WRITE : MFI_CMD_LD_READ; | ||
466 | ldio->cmd_status = 0x0; | ||
467 | ldio->scsi_status = 0x0; | ||
468 | ldio->target_id = device_id; | ||
469 | ldio->timeout = 0; | ||
470 | ldio->reserved_0 = 0; | ||
471 | ldio->pad_0 = 0; | ||
472 | ldio->flags = flags; | ||
473 | ldio->start_lba_hi = 0; | ||
474 | ldio->access_byte = (scp->cmd_len != 6) ? scp->cmnd[1] : 0; | ||
475 | |||
476 | /* | ||
477 | * 6-byte READ(0x08) or WRITE(0x0A) cdb | ||
478 | */ | ||
479 | if (scp->cmd_len == 6) { | ||
480 | ldio->lba_count = (u32) scp->cmnd[4]; | ||
481 | ldio->start_lba_lo = ((u32) scp->cmnd[1] << 16) | | ||
482 | ((u32) scp->cmnd[2] << 8) | (u32) scp->cmnd[3]; | ||
483 | |||
484 | ldio->start_lba_lo &= 0x1FFFFF; | ||
485 | } | ||
486 | |||
487 | /* | ||
488 | * 10-byte READ(0x28) or WRITE(0x2A) cdb | ||
489 | */ | ||
490 | else if (scp->cmd_len == 10) { | ||
491 | ldio->lba_count = (u32) scp->cmnd[8] | | ||
492 | ((u32) scp->cmnd[7] << 8); | ||
493 | ldio->start_lba_lo = ((u32) scp->cmnd[2] << 24) | | ||
494 | ((u32) scp->cmnd[3] << 16) | | ||
495 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; | ||
496 | } | ||
497 | |||
498 | /* | ||
499 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb | ||
500 | */ | ||
501 | else if (scp->cmd_len == 12) { | ||
502 | ldio->lba_count = ((u32) scp->cmnd[6] << 24) | | ||
503 | ((u32) scp->cmnd[7] << 16) | | ||
504 | ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9]; | ||
505 | |||
506 | ldio->start_lba_lo = ((u32) scp->cmnd[2] << 24) | | ||
507 | ((u32) scp->cmnd[3] << 16) | | ||
508 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; | ||
509 | } | ||
510 | |||
511 | /* | ||
512 | * 16-byte READ(0x88) or WRITE(0x8A) cdb | ||
513 | */ | ||
514 | else if (scp->cmd_len == 16) { | ||
515 | ldio->lba_count = ((u32) scp->cmnd[10] << 24) | | ||
516 | ((u32) scp->cmnd[11] << 16) | | ||
517 | ((u32) scp->cmnd[12] << 8) | (u32) scp->cmnd[13]; | ||
518 | |||
519 | ldio->start_lba_lo = ((u32) scp->cmnd[6] << 24) | | ||
520 | ((u32) scp->cmnd[7] << 16) | | ||
521 | ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9]; | ||
522 | |||
523 | ldio->start_lba_hi = ((u32) scp->cmnd[2] << 24) | | ||
524 | ((u32) scp->cmnd[3] << 16) | | ||
525 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; | ||
526 | |||
527 | } | ||
528 | |||
529 | /* | ||
530 | * Construct SGL | ||
531 | */ | ||
532 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : | ||
533 | sizeof(struct megasas_sge32); | ||
534 | |||
535 | if (IS_DMA64) { | ||
536 | ldio->flags |= MFI_FRAME_SGL64; | ||
537 | ldio->sge_count = megasas_make_sgl64(instance, scp, &ldio->sgl); | ||
538 | } else | ||
539 | ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl); | ||
540 | |||
541 | /* | ||
542 | * Sense info specific | ||
543 | */ | ||
544 | ldio->sense_len = SCSI_SENSE_BUFFERSIZE; | ||
545 | ldio->sense_buf_phys_addr_hi = 0; | ||
546 | ldio->sense_buf_phys_addr_lo = cmd->sense_phys_addr; | ||
547 | |||
548 | sge_bytes = sge_sz * ldio->sge_count; | ||
549 | |||
550 | cmd->frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + | ||
551 | ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) + 1; | ||
552 | |||
553 | if (cmd->frame_count > 7) | ||
554 | cmd->frame_count = 8; | ||
555 | |||
556 | return cmd->frame_count; | ||
557 | } | ||
558 | |||
559 | /** | ||
560 | * megasas_build_cmd - Prepares a command packet | ||
561 | * @instance: Adapter soft state | ||
562 | * @scp: SCSI command | ||
563 | * @frame_count: [OUT] Number of frames used to prepare this command | ||
564 | */ | ||
565 | static inline struct megasas_cmd *megasas_build_cmd(struct megasas_instance | ||
566 | *instance, | ||
567 | struct scsi_cmnd *scp, | ||
568 | int *frame_count) | ||
569 | { | ||
570 | u32 logical_cmd; | ||
571 | struct megasas_cmd *cmd; | ||
572 | |||
573 | /* | ||
574 | * Find out if this is logical or physical drive command. | ||
575 | */ | ||
576 | logical_cmd = MEGASAS_IS_LOGICAL(scp); | ||
577 | |||
578 | /* | ||
579 | * Logical drive command | ||
580 | */ | ||
581 | if (logical_cmd) { | ||
582 | |||
583 | if (scp->device->id >= MEGASAS_MAX_LD) { | ||
584 | scp->result = DID_BAD_TARGET << 16; | ||
585 | return NULL; | ||
586 | } | ||
587 | |||
588 | switch (scp->cmnd[0]) { | ||
589 | |||
590 | case READ_10: | ||
591 | case WRITE_10: | ||
592 | case READ_12: | ||
593 | case WRITE_12: | ||
594 | case READ_6: | ||
595 | case WRITE_6: | ||
596 | case READ_16: | ||
597 | case WRITE_16: | ||
598 | /* | ||
599 | * Fail for LUN > 0 | ||
600 | */ | ||
601 | if (scp->device->lun) { | ||
602 | scp->result = DID_BAD_TARGET << 16; | ||
603 | return NULL; | ||
604 | } | ||
605 | |||
606 | cmd = megasas_get_cmd(instance); | ||
607 | |||
608 | if (!cmd) { | ||
609 | scp->result = DID_IMM_RETRY << 16; | ||
610 | return NULL; | ||
611 | } | ||
612 | |||
613 | *frame_count = megasas_build_ldio(instance, scp, cmd); | ||
614 | |||
615 | if (!(*frame_count)) { | ||
616 | megasas_return_cmd(instance, cmd); | ||
617 | return NULL; | ||
618 | } | ||
619 | |||
620 | return cmd; | ||
621 | |||
622 | default: | ||
623 | /* | ||
624 | * Fail for LUN > 0 | ||
625 | */ | ||
626 | if (scp->device->lun) { | ||
627 | scp->result = DID_BAD_TARGET << 16; | ||
628 | return NULL; | ||
629 | } | ||
630 | |||
631 | cmd = megasas_get_cmd(instance); | ||
632 | |||
633 | if (!cmd) { | ||
634 | scp->result = DID_IMM_RETRY << 16; | ||
635 | return NULL; | ||
636 | } | ||
637 | |||
638 | *frame_count = megasas_build_dcdb(instance, scp, cmd); | ||
639 | |||
640 | if (!(*frame_count)) { | ||
641 | megasas_return_cmd(instance, cmd); | ||
642 | return NULL; | ||
643 | } | ||
644 | |||
645 | return cmd; | ||
646 | } | ||
647 | } else { | ||
648 | cmd = megasas_get_cmd(instance); | ||
649 | |||
650 | if (!cmd) { | ||
651 | scp->result = DID_IMM_RETRY << 16; | ||
652 | return NULL; | ||
653 | } | ||
654 | |||
655 | *frame_count = megasas_build_dcdb(instance, scp, cmd); | ||
656 | |||
657 | if (!(*frame_count)) { | ||
658 | megasas_return_cmd(instance, cmd); | ||
659 | return NULL; | ||
660 | } | ||
661 | |||
662 | return cmd; | ||
663 | } | ||
664 | |||
665 | return NULL; | ||
666 | } | ||
667 | |||
668 | /** | ||
669 | * megasas_queue_command - Queue entry point | ||
670 | * @scmd: SCSI command to be queued | ||
671 | * @done: Callback entry point | ||
672 | */ | ||
673 | static int | ||
674 | megasas_queue_command(struct scsi_cmnd *scmd, void (*done) (struct scsi_cmnd *)) | ||
675 | { | ||
676 | u32 frame_count; | ||
677 | unsigned long flags; | ||
678 | struct megasas_cmd *cmd; | ||
679 | struct megasas_instance *instance; | ||
680 | |||
681 | instance = (struct megasas_instance *) | ||
682 | scmd->device->host->hostdata; | ||
683 | scmd->scsi_done = done; | ||
684 | scmd->result = 0; | ||
685 | |||
686 | cmd = megasas_build_cmd(instance, scmd, &frame_count); | ||
687 | |||
688 | if (!cmd) { | ||
689 | done(scmd); | ||
690 | return 0; | ||
691 | } | ||
692 | |||
693 | cmd->scmd = scmd; | ||
694 | scmd->SCp.ptr = (char *)cmd; | ||
695 | scmd->SCp.sent_command = jiffies; | ||
696 | |||
697 | /* | ||
698 | * Issue the command to the FW | ||
699 | */ | ||
700 | spin_lock_irqsave(&instance->instance_lock, flags); | ||
701 | instance->fw_outstanding++; | ||
702 | spin_unlock_irqrestore(&instance->instance_lock, flags); | ||
703 | |||
704 | writel(((cmd->frame_phys_addr >> 3) | (cmd->frame_count - 1)), | ||
705 | &instance->reg_set->inbound_queue_port); | ||
706 | |||
707 | return 0; | ||
708 | } | ||
709 | |||
710 | /** | ||
711 | * megasas_wait_for_outstanding - Wait for all outstanding cmds | ||
712 | * @instance: Adapter soft state | ||
713 | * | ||
714 | * This function waits for upto MEGASAS_RESET_WAIT_TIME seconds for FW to | ||
715 | * complete all its outstanding commands. Returns error if one or more IOs | ||
716 | * are pending after this time period. It also marks the controller dead. | ||
717 | */ | ||
718 | static int megasas_wait_for_outstanding(struct megasas_instance *instance) | ||
719 | { | ||
720 | int i; | ||
721 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; | ||
722 | |||
723 | for (i = 0; i < wait_time; i++) { | ||
724 | |||
725 | if (!instance->fw_outstanding) | ||
726 | break; | ||
727 | |||
728 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { | ||
729 | printk(KERN_NOTICE "megasas: [%2d]waiting for %d " | ||
730 | "commands to complete\n", i, | ||
731 | instance->fw_outstanding); | ||
732 | } | ||
733 | |||
734 | msleep(1000); | ||
735 | } | ||
736 | |||
737 | if (instance->fw_outstanding) { | ||
738 | instance->hw_crit_error = 1; | ||
739 | return FAILED; | ||
740 | } | ||
741 | |||
742 | return SUCCESS; | ||
743 | } | ||
744 | |||
745 | /** | ||
746 | * megasas_generic_reset - Generic reset routine | ||
747 | * @scmd: Mid-layer SCSI command | ||
748 | * | ||
749 | * This routine implements a generic reset handler for device, bus and host | ||
750 | * reset requests. Device, bus and host specific reset handlers can use this | ||
751 | * function after they do their specific tasks. | ||
752 | */ | ||
753 | static int megasas_generic_reset(struct scsi_cmnd *scmd) | ||
754 | { | ||
755 | int ret_val; | ||
756 | struct megasas_instance *instance; | ||
757 | |||
758 | instance = (struct megasas_instance *)scmd->device->host->hostdata; | ||
759 | |||
760 | printk(KERN_NOTICE "megasas: RESET -%ld cmd=%x <c=%d t=%d l=%d>\n", | ||
761 | scmd->serial_number, scmd->cmnd[0], scmd->device->channel, | ||
762 | scmd->device->id, scmd->device->lun); | ||
763 | |||
764 | if (instance->hw_crit_error) { | ||
765 | printk(KERN_ERR "megasas: cannot recover from previous reset " | ||
766 | "failures\n"); | ||
767 | return FAILED; | ||
768 | } | ||
769 | |||
770 | spin_unlock(scmd->device->host->host_lock); | ||
771 | |||
772 | ret_val = megasas_wait_for_outstanding(instance); | ||
773 | |||
774 | if (ret_val == SUCCESS) | ||
775 | printk(KERN_NOTICE "megasas: reset successful \n"); | ||
776 | else | ||
777 | printk(KERN_ERR "megasas: failed to do reset\n"); | ||
778 | |||
779 | spin_lock(scmd->device->host->host_lock); | ||
780 | |||
781 | return ret_val; | ||
782 | } | ||
783 | |||
784 | static enum scsi_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd) | ||
785 | { | ||
786 | unsigned long seconds; | ||
787 | |||
788 | if (scmd->SCp.ptr) { | ||
789 | seconds = (jiffies - scmd->SCp.sent_command) / HZ; | ||
790 | |||
791 | if (seconds < 90) { | ||
792 | return EH_RESET_TIMER; | ||
793 | } else { | ||
794 | return EH_NOT_HANDLED; | ||
795 | } | ||
796 | } | ||
797 | |||
798 | return EH_HANDLED; | ||
799 | } | ||
800 | |||
801 | /** | ||
802 | * megasas_reset_device - Device reset handler entry point | ||
803 | */ | ||
804 | static int megasas_reset_device(struct scsi_cmnd *scmd) | ||
805 | { | ||
806 | int ret; | ||
807 | |||
808 | /* | ||
809 | * First wait for all commands to complete | ||
810 | */ | ||
811 | ret = megasas_generic_reset(scmd); | ||
812 | |||
813 | return ret; | ||
814 | } | ||
815 | |||
816 | /** | ||
817 | * megasas_reset_bus_host - Bus & host reset handler entry point | ||
818 | */ | ||
819 | static int megasas_reset_bus_host(struct scsi_cmnd *scmd) | ||
820 | { | ||
821 | int ret; | ||
822 | |||
823 | /* | ||
824 | * Frist wait for all commands to complete | ||
825 | */ | ||
826 | ret = megasas_generic_reset(scmd); | ||
827 | |||
828 | return ret; | ||
829 | } | ||
830 | |||
831 | /** | ||
832 | * megasas_service_aen - Processes an event notification | ||
833 | * @instance: Adapter soft state | ||
834 | * @cmd: AEN command completed by the ISR | ||
835 | * | ||
836 | * For AEN, driver sends a command down to FW that is held by the FW till an | ||
837 | * event occurs. When an event of interest occurs, FW completes the command | ||
838 | * that it was previously holding. | ||
839 | * | ||
840 | * This routines sends SIGIO signal to processes that have registered with the | ||
841 | * driver for AEN. | ||
842 | */ | ||
843 | static void | ||
844 | megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd) | ||
845 | { | ||
846 | /* | ||
847 | * Don't signal app if it is just an aborted previously registered aen | ||
848 | */ | ||
849 | if (!cmd->abort_aen) | ||
850 | kill_fasync(&megasas_async_queue, SIGIO, POLL_IN); | ||
851 | else | ||
852 | cmd->abort_aen = 0; | ||
853 | |||
854 | instance->aen_cmd = NULL; | ||
855 | megasas_return_cmd(instance, cmd); | ||
856 | } | ||
857 | |||
858 | /* | ||
859 | * Scsi host template for megaraid_sas driver | ||
860 | */ | ||
861 | static struct scsi_host_template megasas_template = { | ||
862 | |||
863 | .module = THIS_MODULE, | ||
864 | .name = "LSI Logic SAS based MegaRAID driver", | ||
865 | .proc_name = "megaraid_sas", | ||
866 | .queuecommand = megasas_queue_command, | ||
867 | .eh_device_reset_handler = megasas_reset_device, | ||
868 | .eh_bus_reset_handler = megasas_reset_bus_host, | ||
869 | .eh_host_reset_handler = megasas_reset_bus_host, | ||
870 | .eh_timed_out = megasas_reset_timer, | ||
871 | .use_clustering = ENABLE_CLUSTERING, | ||
872 | }; | ||
873 | |||
874 | /** | ||
875 | * megasas_complete_int_cmd - Completes an internal command | ||
876 | * @instance: Adapter soft state | ||
877 | * @cmd: Command to be completed | ||
878 | * | ||
879 | * The megasas_issue_blocked_cmd() function waits for a command to complete | ||
880 | * after it issues a command. This function wakes up that waiting routine by | ||
881 | * calling wake_up() on the wait queue. | ||
882 | */ | ||
883 | static void | ||
884 | megasas_complete_int_cmd(struct megasas_instance *instance, | ||
885 | struct megasas_cmd *cmd) | ||
886 | { | ||
887 | cmd->cmd_status = cmd->frame->io.cmd_status; | ||
888 | |||
889 | if (cmd->cmd_status == ENODATA) { | ||
890 | cmd->cmd_status = 0; | ||
891 | } | ||
892 | wake_up(&instance->int_cmd_wait_q); | ||
893 | } | ||
894 | |||
895 | /** | ||
896 | * megasas_complete_abort - Completes aborting a command | ||
897 | * @instance: Adapter soft state | ||
898 | * @cmd: Cmd that was issued to abort another cmd | ||
899 | * | ||
900 | * The megasas_issue_blocked_abort_cmd() function waits on abort_cmd_wait_q | ||
901 | * after it issues an abort on a previously issued command. This function | ||
902 | * wakes up all functions waiting on the same wait queue. | ||
903 | */ | ||
904 | static void | ||
905 | megasas_complete_abort(struct megasas_instance *instance, | ||
906 | struct megasas_cmd *cmd) | ||
907 | { | ||
908 | if (cmd->sync_cmd) { | ||
909 | cmd->sync_cmd = 0; | ||
910 | cmd->cmd_status = 0; | ||
911 | wake_up(&instance->abort_cmd_wait_q); | ||
912 | } | ||
913 | |||
914 | return; | ||
915 | } | ||
916 | |||
917 | /** | ||
918 | * megasas_unmap_sgbuf - Unmap SG buffers | ||
919 | * @instance: Adapter soft state | ||
920 | * @cmd: Completed command | ||
921 | */ | ||
922 | static inline void | ||
923 | megasas_unmap_sgbuf(struct megasas_instance *instance, struct megasas_cmd *cmd) | ||
924 | { | ||
925 | dma_addr_t buf_h; | ||
926 | u8 opcode; | ||
927 | |||
928 | if (cmd->scmd->use_sg) { | ||
929 | pci_unmap_sg(instance->pdev, cmd->scmd->request_buffer, | ||
930 | cmd->scmd->use_sg, cmd->scmd->sc_data_direction); | ||
931 | return; | ||
932 | } | ||
933 | |||
934 | if (!cmd->scmd->request_bufflen) | ||
935 | return; | ||
936 | |||
937 | opcode = cmd->frame->hdr.cmd; | ||
938 | |||
939 | if ((opcode == MFI_CMD_LD_READ) || (opcode == MFI_CMD_LD_WRITE)) { | ||
940 | if (IS_DMA64) | ||
941 | buf_h = cmd->frame->io.sgl.sge64[0].phys_addr; | ||
942 | else | ||
943 | buf_h = cmd->frame->io.sgl.sge32[0].phys_addr; | ||
944 | } else { | ||
945 | if (IS_DMA64) | ||
946 | buf_h = cmd->frame->pthru.sgl.sge64[0].phys_addr; | ||
947 | else | ||
948 | buf_h = cmd->frame->pthru.sgl.sge32[0].phys_addr; | ||
949 | } | ||
950 | |||
951 | pci_unmap_single(instance->pdev, buf_h, cmd->scmd->request_bufflen, | ||
952 | cmd->scmd->sc_data_direction); | ||
953 | return; | ||
954 | } | ||
955 | |||
956 | /** | ||
957 | * megasas_complete_cmd - Completes a command | ||
958 | * @instance: Adapter soft state | ||
959 | * @cmd: Command to be completed | ||
960 | * @alt_status: If non-zero, use this value as status to | ||
961 | * SCSI mid-layer instead of the value returned | ||
962 | * by the FW. This should be used if caller wants | ||
963 | * an alternate status (as in the case of aborted | ||
964 | * commands) | ||
965 | */ | ||
966 | static inline void | ||
967 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, | ||
968 | u8 alt_status) | ||
969 | { | ||
970 | int exception = 0; | ||
971 | struct megasas_header *hdr = &cmd->frame->hdr; | ||
972 | unsigned long flags; | ||
973 | |||
974 | if (cmd->scmd) { | ||
975 | cmd->scmd->SCp.ptr = (char *)0; | ||
976 | } | ||
977 | |||
978 | switch (hdr->cmd) { | ||
979 | |||
980 | case MFI_CMD_PD_SCSI_IO: | ||
981 | case MFI_CMD_LD_SCSI_IO: | ||
982 | |||
983 | /* | ||
984 | * MFI_CMD_PD_SCSI_IO and MFI_CMD_LD_SCSI_IO could have been | ||
985 | * issued either through an IO path or an IOCTL path. If it | ||
986 | * was via IOCTL, we will send it to internal completion. | ||
987 | */ | ||
988 | if (cmd->sync_cmd) { | ||
989 | cmd->sync_cmd = 0; | ||
990 | megasas_complete_int_cmd(instance, cmd); | ||
991 | break; | ||
992 | } | ||
993 | |||
994 | /* | ||
995 | * Don't export physical disk devices to mid-layer. | ||
996 | */ | ||
997 | if (!MEGASAS_IS_LOGICAL(cmd->scmd) && | ||
998 | (hdr->cmd_status == MFI_STAT_OK) && | ||
999 | (cmd->scmd->cmnd[0] == INQUIRY)) { | ||
1000 | |||
1001 | if (((*(u8 *) cmd->scmd->request_buffer) & 0x1F) == | ||
1002 | TYPE_DISK) { | ||
1003 | cmd->scmd->result = DID_BAD_TARGET << 16; | ||
1004 | exception = 1; | ||
1005 | } | ||
1006 | } | ||
1007 | |||
1008 | case MFI_CMD_LD_READ: | ||
1009 | case MFI_CMD_LD_WRITE: | ||
1010 | |||
1011 | if (alt_status) { | ||
1012 | cmd->scmd->result = alt_status << 16; | ||
1013 | exception = 1; | ||
1014 | } | ||
1015 | |||
1016 | if (exception) { | ||
1017 | |||
1018 | spin_lock_irqsave(&instance->instance_lock, flags); | ||
1019 | instance->fw_outstanding--; | ||
1020 | spin_unlock_irqrestore(&instance->instance_lock, flags); | ||
1021 | |||
1022 | megasas_unmap_sgbuf(instance, cmd); | ||
1023 | cmd->scmd->scsi_done(cmd->scmd); | ||
1024 | megasas_return_cmd(instance, cmd); | ||
1025 | |||
1026 | break; | ||
1027 | } | ||
1028 | |||
1029 | switch (hdr->cmd_status) { | ||
1030 | |||
1031 | case MFI_STAT_OK: | ||
1032 | cmd->scmd->result = DID_OK << 16; | ||
1033 | break; | ||
1034 | |||
1035 | case MFI_STAT_SCSI_IO_FAILED: | ||
1036 | case MFI_STAT_LD_INIT_IN_PROGRESS: | ||
1037 | cmd->scmd->result = | ||
1038 | (DID_ERROR << 16) | hdr->scsi_status; | ||
1039 | break; | ||
1040 | |||
1041 | case MFI_STAT_SCSI_DONE_WITH_ERROR: | ||
1042 | |||
1043 | cmd->scmd->result = (DID_OK << 16) | hdr->scsi_status; | ||
1044 | |||
1045 | if (hdr->scsi_status == SAM_STAT_CHECK_CONDITION) { | ||
1046 | memset(cmd->scmd->sense_buffer, 0, | ||
1047 | SCSI_SENSE_BUFFERSIZE); | ||
1048 | memcpy(cmd->scmd->sense_buffer, cmd->sense, | ||
1049 | hdr->sense_len); | ||
1050 | |||
1051 | cmd->scmd->result |= DRIVER_SENSE << 24; | ||
1052 | } | ||
1053 | |||
1054 | break; | ||
1055 | |||
1056 | case MFI_STAT_LD_OFFLINE: | ||
1057 | case MFI_STAT_DEVICE_NOT_FOUND: | ||
1058 | cmd->scmd->result = DID_BAD_TARGET << 16; | ||
1059 | break; | ||
1060 | |||
1061 | default: | ||
1062 | printk(KERN_DEBUG "megasas: MFI FW status %#x\n", | ||
1063 | hdr->cmd_status); | ||
1064 | cmd->scmd->result = DID_ERROR << 16; | ||
1065 | break; | ||
1066 | } | ||
1067 | |||
1068 | spin_lock_irqsave(&instance->instance_lock, flags); | ||
1069 | instance->fw_outstanding--; | ||
1070 | spin_unlock_irqrestore(&instance->instance_lock, flags); | ||
1071 | |||
1072 | megasas_unmap_sgbuf(instance, cmd); | ||
1073 | cmd->scmd->scsi_done(cmd->scmd); | ||
1074 | megasas_return_cmd(instance, cmd); | ||
1075 | |||
1076 | break; | ||
1077 | |||
1078 | case MFI_CMD_SMP: | ||
1079 | case MFI_CMD_STP: | ||
1080 | case MFI_CMD_DCMD: | ||
1081 | |||
1082 | /* | ||
1083 | * See if got an event notification | ||
1084 | */ | ||
1085 | if (cmd->frame->dcmd.opcode == MR_DCMD_CTRL_EVENT_WAIT) | ||
1086 | megasas_service_aen(instance, cmd); | ||
1087 | else | ||
1088 | megasas_complete_int_cmd(instance, cmd); | ||
1089 | |||
1090 | break; | ||
1091 | |||
1092 | case MFI_CMD_ABORT: | ||
1093 | /* | ||
1094 | * Cmd issued to abort another cmd returned | ||
1095 | */ | ||
1096 | megasas_complete_abort(instance, cmd); | ||
1097 | break; | ||
1098 | |||
1099 | default: | ||
1100 | printk("megasas: Unknown command completed! [0x%X]\n", | ||
1101 | hdr->cmd); | ||
1102 | break; | ||
1103 | } | ||
1104 | } | ||
1105 | |||
1106 | /** | ||
1107 | * megasas_deplete_reply_queue - Processes all completed commands | ||
1108 | * @instance: Adapter soft state | ||
1109 | * @alt_status: Alternate status to be returned to | ||
1110 | * SCSI mid-layer instead of the status | ||
1111 | * returned by the FW | ||
1112 | */ | ||
1113 | static inline int | ||
1114 | megasas_deplete_reply_queue(struct megasas_instance *instance, u8 alt_status) | ||
1115 | { | ||
1116 | u32 status; | ||
1117 | u32 producer; | ||
1118 | u32 consumer; | ||
1119 | u32 context; | ||
1120 | struct megasas_cmd *cmd; | ||
1121 | |||
1122 | /* | ||
1123 | * Check if it is our interrupt | ||
1124 | */ | ||
1125 | status = readl(&instance->reg_set->outbound_intr_status); | ||
1126 | |||
1127 | if (!(status & MFI_OB_INTR_STATUS_MASK)) { | ||
1128 | return IRQ_NONE; | ||
1129 | } | ||
1130 | |||
1131 | /* | ||
1132 | * Clear the interrupt by writing back the same value | ||
1133 | */ | ||
1134 | writel(status, &instance->reg_set->outbound_intr_status); | ||
1135 | |||
1136 | producer = *instance->producer; | ||
1137 | consumer = *instance->consumer; | ||
1138 | |||
1139 | while (consumer != producer) { | ||
1140 | context = instance->reply_queue[consumer]; | ||
1141 | |||
1142 | cmd = instance->cmd_list[context]; | ||
1143 | |||
1144 | megasas_complete_cmd(instance, cmd, alt_status); | ||
1145 | |||
1146 | consumer++; | ||
1147 | if (consumer == (instance->max_fw_cmds + 1)) { | ||
1148 | consumer = 0; | ||
1149 | } | ||
1150 | } | ||
1151 | |||
1152 | *instance->consumer = producer; | ||
1153 | |||
1154 | return IRQ_HANDLED; | ||
1155 | } | ||
1156 | |||
1157 | /** | ||
1158 | * megasas_isr - isr entry point | ||
1159 | */ | ||
1160 | static irqreturn_t megasas_isr(int irq, void *devp, struct pt_regs *regs) | ||
1161 | { | ||
1162 | return megasas_deplete_reply_queue((struct megasas_instance *)devp, | ||
1163 | DID_OK); | ||
1164 | } | ||
1165 | |||
1166 | /** | ||
1167 | * megasas_transition_to_ready - Move the FW to READY state | ||
1168 | * @reg_set: MFI register set | ||
1169 | * | ||
1170 | * During the initialization, FW passes can potentially be in any one of | ||
1171 | * several possible states. If the FW in operational, waiting-for-handshake | ||
1172 | * states, driver must take steps to bring it to ready state. Otherwise, it | ||
1173 | * has to wait for the ready state. | ||
1174 | */ | ||
1175 | static int | ||
1176 | megasas_transition_to_ready(struct megasas_register_set __iomem * reg_set) | ||
1177 | { | ||
1178 | int i; | ||
1179 | u8 max_wait; | ||
1180 | u32 fw_state; | ||
1181 | u32 cur_state; | ||
1182 | |||
1183 | fw_state = readl(®_set->outbound_msg_0) & MFI_STATE_MASK; | ||
1184 | |||
1185 | while (fw_state != MFI_STATE_READY) { | ||
1186 | |||
1187 | printk(KERN_INFO "megasas: Waiting for FW to come to ready" | ||
1188 | " state\n"); | ||
1189 | switch (fw_state) { | ||
1190 | |||
1191 | case MFI_STATE_FAULT: | ||
1192 | |||
1193 | printk(KERN_DEBUG "megasas: FW in FAULT state!!\n"); | ||
1194 | return -ENODEV; | ||
1195 | |||
1196 | case MFI_STATE_WAIT_HANDSHAKE: | ||
1197 | /* | ||
1198 | * Set the CLR bit in inbound doorbell | ||
1199 | */ | ||
1200 | writel(MFI_INIT_CLEAR_HANDSHAKE, | ||
1201 | ®_set->inbound_doorbell); | ||
1202 | |||
1203 | max_wait = 2; | ||
1204 | cur_state = MFI_STATE_WAIT_HANDSHAKE; | ||
1205 | break; | ||
1206 | |||
1207 | case MFI_STATE_OPERATIONAL: | ||
1208 | /* | ||
1209 | * Bring it to READY state; assuming max wait 2 secs | ||
1210 | */ | ||
1211 | megasas_disable_intr(reg_set); | ||
1212 | writel(MFI_INIT_READY, ®_set->inbound_doorbell); | ||
1213 | |||
1214 | max_wait = 10; | ||
1215 | cur_state = MFI_STATE_OPERATIONAL; | ||
1216 | break; | ||
1217 | |||
1218 | case MFI_STATE_UNDEFINED: | ||
1219 | /* | ||
1220 | * This state should not last for more than 2 seconds | ||
1221 | */ | ||
1222 | max_wait = 2; | ||
1223 | cur_state = MFI_STATE_UNDEFINED; | ||
1224 | break; | ||
1225 | |||
1226 | case MFI_STATE_BB_INIT: | ||
1227 | max_wait = 2; | ||
1228 | cur_state = MFI_STATE_BB_INIT; | ||
1229 | break; | ||
1230 | |||
1231 | case MFI_STATE_FW_INIT: | ||
1232 | max_wait = 20; | ||
1233 | cur_state = MFI_STATE_FW_INIT; | ||
1234 | break; | ||
1235 | |||
1236 | case MFI_STATE_FW_INIT_2: | ||
1237 | max_wait = 20; | ||
1238 | cur_state = MFI_STATE_FW_INIT_2; | ||
1239 | break; | ||
1240 | |||
1241 | case MFI_STATE_DEVICE_SCAN: | ||
1242 | max_wait = 20; | ||
1243 | cur_state = MFI_STATE_DEVICE_SCAN; | ||
1244 | break; | ||
1245 | |||
1246 | case MFI_STATE_FLUSH_CACHE: | ||
1247 | max_wait = 20; | ||
1248 | cur_state = MFI_STATE_FLUSH_CACHE; | ||
1249 | break; | ||
1250 | |||
1251 | default: | ||
1252 | printk(KERN_DEBUG "megasas: Unknown state 0x%x\n", | ||
1253 | fw_state); | ||
1254 | return -ENODEV; | ||
1255 | } | ||
1256 | |||
1257 | /* | ||
1258 | * The cur_state should not last for more than max_wait secs | ||
1259 | */ | ||
1260 | for (i = 0; i < (max_wait * 1000); i++) { | ||
1261 | fw_state = MFI_STATE_MASK & | ||
1262 | readl(®_set->outbound_msg_0); | ||
1263 | |||
1264 | if (fw_state == cur_state) { | ||
1265 | msleep(1); | ||
1266 | } else | ||
1267 | break; | ||
1268 | } | ||
1269 | |||
1270 | /* | ||
1271 | * Return error if fw_state hasn't changed after max_wait | ||
1272 | */ | ||
1273 | if (fw_state == cur_state) { | ||
1274 | printk(KERN_DEBUG "FW state [%d] hasn't changed " | ||
1275 | "in %d secs\n", fw_state, max_wait); | ||
1276 | return -ENODEV; | ||
1277 | } | ||
1278 | }; | ||
1279 | |||
1280 | return 0; | ||
1281 | } | ||
1282 | |||
1283 | /** | ||
1284 | * megasas_teardown_frame_pool - Destroy the cmd frame DMA pool | ||
1285 | * @instance: Adapter soft state | ||
1286 | */ | ||
1287 | static void megasas_teardown_frame_pool(struct megasas_instance *instance) | ||
1288 | { | ||
1289 | int i; | ||
1290 | u32 max_cmd = instance->max_fw_cmds; | ||
1291 | struct megasas_cmd *cmd; | ||
1292 | |||
1293 | if (!instance->frame_dma_pool) | ||
1294 | return; | ||
1295 | |||
1296 | /* | ||
1297 | * Return all frames to pool | ||
1298 | */ | ||
1299 | for (i = 0; i < max_cmd; i++) { | ||
1300 | |||
1301 | cmd = instance->cmd_list[i]; | ||
1302 | |||
1303 | if (cmd->frame) | ||
1304 | pci_pool_free(instance->frame_dma_pool, cmd->frame, | ||
1305 | cmd->frame_phys_addr); | ||
1306 | |||
1307 | if (cmd->sense) | ||
1308 | pci_pool_free(instance->sense_dma_pool, cmd->frame, | ||
1309 | cmd->sense_phys_addr); | ||
1310 | } | ||
1311 | |||
1312 | /* | ||
1313 | * Now destroy the pool itself | ||
1314 | */ | ||
1315 | pci_pool_destroy(instance->frame_dma_pool); | ||
1316 | pci_pool_destroy(instance->sense_dma_pool); | ||
1317 | |||
1318 | instance->frame_dma_pool = NULL; | ||
1319 | instance->sense_dma_pool = NULL; | ||
1320 | } | ||
1321 | |||
1322 | /** | ||
1323 | * megasas_create_frame_pool - Creates DMA pool for cmd frames | ||
1324 | * @instance: Adapter soft state | ||
1325 | * | ||
1326 | * Each command packet has an embedded DMA memory buffer that is used for | ||
1327 | * filling MFI frame and the SG list that immediately follows the frame. This | ||
1328 | * function creates those DMA memory buffers for each command packet by using | ||
1329 | * PCI pool facility. | ||
1330 | */ | ||
1331 | static int megasas_create_frame_pool(struct megasas_instance *instance) | ||
1332 | { | ||
1333 | int i; | ||
1334 | u32 max_cmd; | ||
1335 | u32 sge_sz; | ||
1336 | u32 sgl_sz; | ||
1337 | u32 total_sz; | ||
1338 | u32 frame_count; | ||
1339 | struct megasas_cmd *cmd; | ||
1340 | |||
1341 | max_cmd = instance->max_fw_cmds; | ||
1342 | |||
1343 | /* | ||
1344 | * Size of our frame is 64 bytes for MFI frame, followed by max SG | ||
1345 | * elements and finally SCSI_SENSE_BUFFERSIZE bytes for sense buffer | ||
1346 | */ | ||
1347 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : | ||
1348 | sizeof(struct megasas_sge32); | ||
1349 | |||
1350 | /* | ||
1351 | * Calculated the number of 64byte frames required for SGL | ||
1352 | */ | ||
1353 | sgl_sz = sge_sz * instance->max_num_sge; | ||
1354 | frame_count = (sgl_sz + MEGAMFI_FRAME_SIZE - 1) / MEGAMFI_FRAME_SIZE; | ||
1355 | |||
1356 | /* | ||
1357 | * We need one extra frame for the MFI command | ||
1358 | */ | ||
1359 | frame_count++; | ||
1360 | |||
1361 | total_sz = MEGAMFI_FRAME_SIZE * frame_count; | ||
1362 | /* | ||
1363 | * Use DMA pool facility provided by PCI layer | ||
1364 | */ | ||
1365 | instance->frame_dma_pool = pci_pool_create("megasas frame pool", | ||
1366 | instance->pdev, total_sz, 64, | ||
1367 | 0); | ||
1368 | |||
1369 | if (!instance->frame_dma_pool) { | ||
1370 | printk(KERN_DEBUG "megasas: failed to setup frame pool\n"); | ||
1371 | return -ENOMEM; | ||
1372 | } | ||
1373 | |||
1374 | instance->sense_dma_pool = pci_pool_create("megasas sense pool", | ||
1375 | instance->pdev, 128, 4, 0); | ||
1376 | |||
1377 | if (!instance->sense_dma_pool) { | ||
1378 | printk(KERN_DEBUG "megasas: failed to setup sense pool\n"); | ||
1379 | |||
1380 | pci_pool_destroy(instance->frame_dma_pool); | ||
1381 | instance->frame_dma_pool = NULL; | ||
1382 | |||
1383 | return -ENOMEM; | ||
1384 | } | ||
1385 | |||
1386 | /* | ||
1387 | * Allocate and attach a frame to each of the commands in cmd_list. | ||
1388 | * By making cmd->index as the context instead of the &cmd, we can | ||
1389 | * always use 32bit context regardless of the architecture | ||
1390 | */ | ||
1391 | for (i = 0; i < max_cmd; i++) { | ||
1392 | |||
1393 | cmd = instance->cmd_list[i]; | ||
1394 | |||
1395 | cmd->frame = pci_pool_alloc(instance->frame_dma_pool, | ||
1396 | GFP_KERNEL, &cmd->frame_phys_addr); | ||
1397 | |||
1398 | cmd->sense = pci_pool_alloc(instance->sense_dma_pool, | ||
1399 | GFP_KERNEL, &cmd->sense_phys_addr); | ||
1400 | |||
1401 | /* | ||
1402 | * megasas_teardown_frame_pool() takes care of freeing | ||
1403 | * whatever has been allocated | ||
1404 | */ | ||
1405 | if (!cmd->frame || !cmd->sense) { | ||
1406 | printk(KERN_DEBUG "megasas: pci_pool_alloc failed \n"); | ||
1407 | megasas_teardown_frame_pool(instance); | ||
1408 | return -ENOMEM; | ||
1409 | } | ||
1410 | |||
1411 | cmd->frame->io.context = cmd->index; | ||
1412 | } | ||
1413 | |||
1414 | return 0; | ||
1415 | } | ||
1416 | |||
1417 | /** | ||
1418 | * megasas_free_cmds - Free all the cmds in the free cmd pool | ||
1419 | * @instance: Adapter soft state | ||
1420 | */ | ||
1421 | static void megasas_free_cmds(struct megasas_instance *instance) | ||
1422 | { | ||
1423 | int i; | ||
1424 | /* First free the MFI frame pool */ | ||
1425 | megasas_teardown_frame_pool(instance); | ||
1426 | |||
1427 | /* Free all the commands in the cmd_list */ | ||
1428 | for (i = 0; i < instance->max_fw_cmds; i++) | ||
1429 | kfree(instance->cmd_list[i]); | ||
1430 | |||
1431 | /* Free the cmd_list buffer itself */ | ||
1432 | kfree(instance->cmd_list); | ||
1433 | instance->cmd_list = NULL; | ||
1434 | |||
1435 | INIT_LIST_HEAD(&instance->cmd_pool); | ||
1436 | } | ||
1437 | |||
1438 | /** | ||
1439 | * megasas_alloc_cmds - Allocates the command packets | ||
1440 | * @instance: Adapter soft state | ||
1441 | * | ||
1442 | * Each command that is issued to the FW, whether IO commands from the OS or | ||
1443 | * internal commands like IOCTLs, are wrapped in local data structure called | ||
1444 | * megasas_cmd. The frame embedded in this megasas_cmd is actually issued to | ||
1445 | * the FW. | ||
1446 | * | ||
1447 | * Each frame has a 32-bit field called context (tag). This context is used | ||
1448 | * to get back the megasas_cmd from the frame when a frame gets completed in | ||
1449 | * the ISR. Typically the address of the megasas_cmd itself would be used as | ||
1450 | * the context. But we wanted to keep the differences between 32 and 64 bit | ||
1451 | * systems to the mininum. We always use 32 bit integers for the context. In | ||
1452 | * this driver, the 32 bit values are the indices into an array cmd_list. | ||
1453 | * This array is used only to look up the megasas_cmd given the context. The | ||
1454 | * free commands themselves are maintained in a linked list called cmd_pool. | ||
1455 | */ | ||
1456 | static int megasas_alloc_cmds(struct megasas_instance *instance) | ||
1457 | { | ||
1458 | int i; | ||
1459 | int j; | ||
1460 | u32 max_cmd; | ||
1461 | struct megasas_cmd *cmd; | ||
1462 | |||
1463 | max_cmd = instance->max_fw_cmds; | ||
1464 | |||
1465 | /* | ||
1466 | * instance->cmd_list is an array of struct megasas_cmd pointers. | ||
1467 | * Allocate the dynamic array first and then allocate individual | ||
1468 | * commands. | ||
1469 | */ | ||
1470 | instance->cmd_list = kmalloc(sizeof(struct megasas_cmd *) * max_cmd, | ||
1471 | GFP_KERNEL); | ||
1472 | |||
1473 | if (!instance->cmd_list) { | ||
1474 | printk(KERN_DEBUG "megasas: out of memory\n"); | ||
1475 | return -ENOMEM; | ||
1476 | } | ||
1477 | |||
1478 | memset(instance->cmd_list, 0, sizeof(struct megasas_cmd *) * max_cmd); | ||
1479 | |||
1480 | for (i = 0; i < max_cmd; i++) { | ||
1481 | instance->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd), | ||
1482 | GFP_KERNEL); | ||
1483 | |||
1484 | if (!instance->cmd_list[i]) { | ||
1485 | |||
1486 | for (j = 0; j < i; j++) | ||
1487 | kfree(instance->cmd_list[j]); | ||
1488 | |||
1489 | kfree(instance->cmd_list); | ||
1490 | instance->cmd_list = NULL; | ||
1491 | |||
1492 | return -ENOMEM; | ||
1493 | } | ||
1494 | } | ||
1495 | |||
1496 | /* | ||
1497 | * Add all the commands to command pool (instance->cmd_pool) | ||
1498 | */ | ||
1499 | for (i = 0; i < max_cmd; i++) { | ||
1500 | cmd = instance->cmd_list[i]; | ||
1501 | memset(cmd, 0, sizeof(struct megasas_cmd)); | ||
1502 | cmd->index = i; | ||
1503 | cmd->instance = instance; | ||
1504 | |||
1505 | list_add_tail(&cmd->list, &instance->cmd_pool); | ||
1506 | } | ||
1507 | |||
1508 | /* | ||
1509 | * Create a frame pool and assign one frame to each cmd | ||
1510 | */ | ||
1511 | if (megasas_create_frame_pool(instance)) { | ||
1512 | printk(KERN_DEBUG "megasas: Error creating frame DMA pool\n"); | ||
1513 | megasas_free_cmds(instance); | ||
1514 | } | ||
1515 | |||
1516 | return 0; | ||
1517 | } | ||
1518 | |||
1519 | /** | ||
1520 | * megasas_get_controller_info - Returns FW's controller structure | ||
1521 | * @instance: Adapter soft state | ||
1522 | * @ctrl_info: Controller information structure | ||
1523 | * | ||
1524 | * Issues an internal command (DCMD) to get the FW's controller structure. | ||
1525 | * This information is mainly used to find out the maximum IO transfer per | ||
1526 | * command supported by the FW. | ||
1527 | */ | ||
1528 | static int | ||
1529 | megasas_get_ctrl_info(struct megasas_instance *instance, | ||
1530 | struct megasas_ctrl_info *ctrl_info) | ||
1531 | { | ||
1532 | int ret = 0; | ||
1533 | struct megasas_cmd *cmd; | ||
1534 | struct megasas_dcmd_frame *dcmd; | ||
1535 | struct megasas_ctrl_info *ci; | ||
1536 | dma_addr_t ci_h = 0; | ||
1537 | |||
1538 | cmd = megasas_get_cmd(instance); | ||
1539 | |||
1540 | if (!cmd) { | ||
1541 | printk(KERN_DEBUG "megasas: Failed to get a free cmd\n"); | ||
1542 | return -ENOMEM; | ||
1543 | } | ||
1544 | |||
1545 | dcmd = &cmd->frame->dcmd; | ||
1546 | |||
1547 | ci = pci_alloc_consistent(instance->pdev, | ||
1548 | sizeof(struct megasas_ctrl_info), &ci_h); | ||
1549 | |||
1550 | if (!ci) { | ||
1551 | printk(KERN_DEBUG "Failed to alloc mem for ctrl info\n"); | ||
1552 | megasas_return_cmd(instance, cmd); | ||
1553 | return -ENOMEM; | ||
1554 | } | ||
1555 | |||
1556 | memset(ci, 0, sizeof(*ci)); | ||
1557 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); | ||
1558 | |||
1559 | dcmd->cmd = MFI_CMD_DCMD; | ||
1560 | dcmd->cmd_status = 0xFF; | ||
1561 | dcmd->sge_count = 1; | ||
1562 | dcmd->flags = MFI_FRAME_DIR_READ; | ||
1563 | dcmd->timeout = 0; | ||
1564 | dcmd->data_xfer_len = sizeof(struct megasas_ctrl_info); | ||
1565 | dcmd->opcode = MR_DCMD_CTRL_GET_INFO; | ||
1566 | dcmd->sgl.sge32[0].phys_addr = ci_h; | ||
1567 | dcmd->sgl.sge32[0].length = sizeof(struct megasas_ctrl_info); | ||
1568 | |||
1569 | if (!megasas_issue_polled(instance, cmd)) { | ||
1570 | ret = 0; | ||
1571 | memcpy(ctrl_info, ci, sizeof(struct megasas_ctrl_info)); | ||
1572 | } else { | ||
1573 | ret = -1; | ||
1574 | } | ||
1575 | |||
1576 | pci_free_consistent(instance->pdev, sizeof(struct megasas_ctrl_info), | ||
1577 | ci, ci_h); | ||
1578 | |||
1579 | megasas_return_cmd(instance, cmd); | ||
1580 | return ret; | ||
1581 | } | ||
1582 | |||
1583 | /** | ||
1584 | * megasas_init_mfi - Initializes the FW | ||
1585 | * @instance: Adapter soft state | ||
1586 | * | ||
1587 | * This is the main function for initializing MFI firmware. | ||
1588 | */ | ||
1589 | static int megasas_init_mfi(struct megasas_instance *instance) | ||
1590 | { | ||
1591 | u32 context_sz; | ||
1592 | u32 reply_q_sz; | ||
1593 | u32 max_sectors_1; | ||
1594 | u32 max_sectors_2; | ||
1595 | struct megasas_register_set __iomem *reg_set; | ||
1596 | |||
1597 | struct megasas_cmd *cmd; | ||
1598 | struct megasas_ctrl_info *ctrl_info; | ||
1599 | |||
1600 | struct megasas_init_frame *init_frame; | ||
1601 | struct megasas_init_queue_info *initq_info; | ||
1602 | dma_addr_t init_frame_h; | ||
1603 | dma_addr_t initq_info_h; | ||
1604 | |||
1605 | /* | ||
1606 | * Map the message registers | ||
1607 | */ | ||
1608 | instance->base_addr = pci_resource_start(instance->pdev, 0); | ||
1609 | |||
1610 | if (pci_request_regions(instance->pdev, "megasas: LSI Logic")) { | ||
1611 | printk(KERN_DEBUG "megasas: IO memory region busy!\n"); | ||
1612 | return -EBUSY; | ||
1613 | } | ||
1614 | |||
1615 | instance->reg_set = ioremap_nocache(instance->base_addr, 8192); | ||
1616 | |||
1617 | if (!instance->reg_set) { | ||
1618 | printk(KERN_DEBUG "megasas: Failed to map IO mem\n"); | ||
1619 | goto fail_ioremap; | ||
1620 | } | ||
1621 | |||
1622 | reg_set = instance->reg_set; | ||
1623 | |||
1624 | /* | ||
1625 | * We expect the FW state to be READY | ||
1626 | */ | ||
1627 | if (megasas_transition_to_ready(instance->reg_set)) | ||
1628 | goto fail_ready_state; | ||
1629 | |||
1630 | /* | ||
1631 | * Get various operational parameters from status register | ||
1632 | */ | ||
1633 | instance->max_fw_cmds = readl(®_set->outbound_msg_0) & 0x00FFFF; | ||
1634 | instance->max_num_sge = (readl(®_set->outbound_msg_0) & 0xFF0000) >> | ||
1635 | 0x10; | ||
1636 | /* | ||
1637 | * Create a pool of commands | ||
1638 | */ | ||
1639 | if (megasas_alloc_cmds(instance)) | ||
1640 | goto fail_alloc_cmds; | ||
1641 | |||
1642 | /* | ||
1643 | * Allocate memory for reply queue. Length of reply queue should | ||
1644 | * be _one_ more than the maximum commands handled by the firmware. | ||
1645 | * | ||
1646 | * Note: When FW completes commands, it places corresponding contex | ||
1647 | * values in this circular reply queue. This circular queue is a fairly | ||
1648 | * typical producer-consumer queue. FW is the producer (of completed | ||
1649 | * commands) and the driver is the consumer. | ||
1650 | */ | ||
1651 | context_sz = sizeof(u32); | ||
1652 | reply_q_sz = context_sz * (instance->max_fw_cmds + 1); | ||
1653 | |||
1654 | instance->reply_queue = pci_alloc_consistent(instance->pdev, | ||
1655 | reply_q_sz, | ||
1656 | &instance->reply_queue_h); | ||
1657 | |||
1658 | if (!instance->reply_queue) { | ||
1659 | printk(KERN_DEBUG "megasas: Out of DMA mem for reply queue\n"); | ||
1660 | goto fail_reply_queue; | ||
1661 | } | ||
1662 | |||
1663 | /* | ||
1664 | * Prepare a init frame. Note the init frame points to queue info | ||
1665 | * structure. Each frame has SGL allocated after first 64 bytes. For | ||
1666 | * this frame - since we don't need any SGL - we use SGL's space as | ||
1667 | * queue info structure | ||
1668 | * | ||
1669 | * We will not get a NULL command below. We just created the pool. | ||
1670 | */ | ||
1671 | cmd = megasas_get_cmd(instance); | ||
1672 | |||
1673 | init_frame = (struct megasas_init_frame *)cmd->frame; | ||
1674 | initq_info = (struct megasas_init_queue_info *) | ||
1675 | ((unsigned long)init_frame + 64); | ||
1676 | |||
1677 | init_frame_h = cmd->frame_phys_addr; | ||
1678 | initq_info_h = init_frame_h + 64; | ||
1679 | |||
1680 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); | ||
1681 | memset(initq_info, 0, sizeof(struct megasas_init_queue_info)); | ||
1682 | |||
1683 | initq_info->reply_queue_entries = instance->max_fw_cmds + 1; | ||
1684 | initq_info->reply_queue_start_phys_addr_lo = instance->reply_queue_h; | ||
1685 | |||
1686 | initq_info->producer_index_phys_addr_lo = instance->producer_h; | ||
1687 | initq_info->consumer_index_phys_addr_lo = instance->consumer_h; | ||
1688 | |||
1689 | init_frame->cmd = MFI_CMD_INIT; | ||
1690 | init_frame->cmd_status = 0xFF; | ||
1691 | init_frame->queue_info_new_phys_addr_lo = initq_info_h; | ||
1692 | |||
1693 | init_frame->data_xfer_len = sizeof(struct megasas_init_queue_info); | ||
1694 | |||
1695 | /* | ||
1696 | * Issue the init frame in polled mode | ||
1697 | */ | ||
1698 | if (megasas_issue_polled(instance, cmd)) { | ||
1699 | printk(KERN_DEBUG "megasas: Failed to init firmware\n"); | ||
1700 | goto fail_fw_init; | ||
1701 | } | ||
1702 | |||
1703 | megasas_return_cmd(instance, cmd); | ||
1704 | |||
1705 | ctrl_info = kmalloc(sizeof(struct megasas_ctrl_info), GFP_KERNEL); | ||
1706 | |||
1707 | /* | ||
1708 | * Compute the max allowed sectors per IO: The controller info has two | ||
1709 | * limits on max sectors. Driver should use the minimum of these two. | ||
1710 | * | ||
1711 | * 1 << stripe_sz_ops.min = max sectors per strip | ||
1712 | * | ||
1713 | * Note that older firmwares ( < FW ver 30) didn't report information | ||
1714 | * to calculate max_sectors_1. So the number ended up as zero always. | ||
1715 | */ | ||
1716 | if (ctrl_info && !megasas_get_ctrl_info(instance, ctrl_info)) { | ||
1717 | |||
1718 | max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) * | ||
1719 | ctrl_info->max_strips_per_io; | ||
1720 | max_sectors_2 = ctrl_info->max_request_size; | ||
1721 | |||
1722 | instance->max_sectors_per_req = (max_sectors_1 < max_sectors_2) | ||
1723 | ? max_sectors_1 : max_sectors_2; | ||
1724 | } else | ||
1725 | instance->max_sectors_per_req = instance->max_num_sge * | ||
1726 | PAGE_SIZE / 512; | ||
1727 | |||
1728 | kfree(ctrl_info); | ||
1729 | |||
1730 | return 0; | ||
1731 | |||
1732 | fail_fw_init: | ||
1733 | megasas_return_cmd(instance, cmd); | ||
1734 | |||
1735 | pci_free_consistent(instance->pdev, reply_q_sz, | ||
1736 | instance->reply_queue, instance->reply_queue_h); | ||
1737 | fail_reply_queue: | ||
1738 | megasas_free_cmds(instance); | ||
1739 | |||
1740 | fail_alloc_cmds: | ||
1741 | fail_ready_state: | ||
1742 | iounmap(instance->reg_set); | ||
1743 | |||
1744 | fail_ioremap: | ||
1745 | pci_release_regions(instance->pdev); | ||
1746 | |||
1747 | return -EINVAL; | ||
1748 | } | ||
1749 | |||
1750 | /** | ||
1751 | * megasas_release_mfi - Reverses the FW initialization | ||
1752 | * @intance: Adapter soft state | ||
1753 | */ | ||
1754 | static void megasas_release_mfi(struct megasas_instance *instance) | ||
1755 | { | ||
1756 | u32 reply_q_sz = sizeof(u32) * (instance->max_fw_cmds + 1); | ||
1757 | |||
1758 | pci_free_consistent(instance->pdev, reply_q_sz, | ||
1759 | instance->reply_queue, instance->reply_queue_h); | ||
1760 | |||
1761 | megasas_free_cmds(instance); | ||
1762 | |||
1763 | iounmap(instance->reg_set); | ||
1764 | |||
1765 | pci_release_regions(instance->pdev); | ||
1766 | } | ||
1767 | |||
1768 | /** | ||
1769 | * megasas_get_seq_num - Gets latest event sequence numbers | ||
1770 | * @instance: Adapter soft state | ||
1771 | * @eli: FW event log sequence numbers information | ||
1772 | * | ||
1773 | * FW maintains a log of all events in a non-volatile area. Upper layers would | ||
1774 | * usually find out the latest sequence number of the events, the seq number at | ||
1775 | * the boot etc. They would "read" all the events below the latest seq number | ||
1776 | * by issuing a direct fw cmd (DCMD). For the future events (beyond latest seq | ||
1777 | * number), they would subsribe to AEN (asynchronous event notification) and | ||
1778 | * wait for the events to happen. | ||
1779 | */ | ||
1780 | static int | ||
1781 | megasas_get_seq_num(struct megasas_instance *instance, | ||
1782 | struct megasas_evt_log_info *eli) | ||
1783 | { | ||
1784 | struct megasas_cmd *cmd; | ||
1785 | struct megasas_dcmd_frame *dcmd; | ||
1786 | struct megasas_evt_log_info *el_info; | ||
1787 | dma_addr_t el_info_h = 0; | ||
1788 | |||
1789 | cmd = megasas_get_cmd(instance); | ||
1790 | |||
1791 | if (!cmd) { | ||
1792 | return -ENOMEM; | ||
1793 | } | ||
1794 | |||
1795 | dcmd = &cmd->frame->dcmd; | ||
1796 | el_info = pci_alloc_consistent(instance->pdev, | ||
1797 | sizeof(struct megasas_evt_log_info), | ||
1798 | &el_info_h); | ||
1799 | |||
1800 | if (!el_info) { | ||
1801 | megasas_return_cmd(instance, cmd); | ||
1802 | return -ENOMEM; | ||
1803 | } | ||
1804 | |||
1805 | memset(el_info, 0, sizeof(*el_info)); | ||
1806 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); | ||
1807 | |||
1808 | dcmd->cmd = MFI_CMD_DCMD; | ||
1809 | dcmd->cmd_status = 0x0; | ||
1810 | dcmd->sge_count = 1; | ||
1811 | dcmd->flags = MFI_FRAME_DIR_READ; | ||
1812 | dcmd->timeout = 0; | ||
1813 | dcmd->data_xfer_len = sizeof(struct megasas_evt_log_info); | ||
1814 | dcmd->opcode = MR_DCMD_CTRL_EVENT_GET_INFO; | ||
1815 | dcmd->sgl.sge32[0].phys_addr = el_info_h; | ||
1816 | dcmd->sgl.sge32[0].length = sizeof(struct megasas_evt_log_info); | ||
1817 | |||
1818 | megasas_issue_blocked_cmd(instance, cmd); | ||
1819 | |||
1820 | /* | ||
1821 | * Copy the data back into callers buffer | ||
1822 | */ | ||
1823 | memcpy(eli, el_info, sizeof(struct megasas_evt_log_info)); | ||
1824 | |||
1825 | pci_free_consistent(instance->pdev, sizeof(struct megasas_evt_log_info), | ||
1826 | el_info, el_info_h); | ||
1827 | |||
1828 | megasas_return_cmd(instance, cmd); | ||
1829 | |||
1830 | return 0; | ||
1831 | } | ||
1832 | |||
1833 | /** | ||
1834 | * megasas_register_aen - Registers for asynchronous event notification | ||
1835 | * @instance: Adapter soft state | ||
1836 | * @seq_num: The starting sequence number | ||
1837 | * @class_locale: Class of the event | ||
1838 | * | ||
1839 | * This function subscribes for AEN for events beyond the @seq_num. It requests | ||
1840 | * to be notified if and only if the event is of type @class_locale | ||
1841 | */ | ||
1842 | static int | ||
1843 | megasas_register_aen(struct megasas_instance *instance, u32 seq_num, | ||
1844 | u32 class_locale_word) | ||
1845 | { | ||
1846 | int ret_val; | ||
1847 | struct megasas_cmd *cmd; | ||
1848 | struct megasas_dcmd_frame *dcmd; | ||
1849 | union megasas_evt_class_locale curr_aen; | ||
1850 | union megasas_evt_class_locale prev_aen; | ||
1851 | |||
1852 | /* | ||
1853 | * If there an AEN pending already (aen_cmd), check if the | ||
1854 | * class_locale of that pending AEN is inclusive of the new | ||
1855 | * AEN request we currently have. If it is, then we don't have | ||
1856 | * to do anything. In other words, whichever events the current | ||
1857 | * AEN request is subscribing to, have already been subscribed | ||
1858 | * to. | ||
1859 | * | ||
1860 | * If the old_cmd is _not_ inclusive, then we have to abort | ||
1861 | * that command, form a class_locale that is superset of both | ||
1862 | * old and current and re-issue to the FW | ||
1863 | */ | ||
1864 | |||
1865 | curr_aen.word = class_locale_word; | ||
1866 | |||
1867 | if (instance->aen_cmd) { | ||
1868 | |||
1869 | prev_aen.word = instance->aen_cmd->frame->dcmd.mbox.w[1]; | ||
1870 | |||
1871 | /* | ||
1872 | * A class whose enum value is smaller is inclusive of all | ||
1873 | * higher values. If a PROGRESS (= -1) was previously | ||
1874 | * registered, then a new registration requests for higher | ||
1875 | * classes need not be sent to FW. They are automatically | ||
1876 | * included. | ||
1877 | * | ||
1878 | * Locale numbers don't have such hierarchy. They are bitmap | ||
1879 | * values | ||
1880 | */ | ||
1881 | if ((prev_aen.members.class <= curr_aen.members.class) && | ||
1882 | !((prev_aen.members.locale & curr_aen.members.locale) ^ | ||
1883 | curr_aen.members.locale)) { | ||
1884 | /* | ||
1885 | * Previously issued event registration includes | ||
1886 | * current request. Nothing to do. | ||
1887 | */ | ||
1888 | return 0; | ||
1889 | } else { | ||
1890 | curr_aen.members.locale |= prev_aen.members.locale; | ||
1891 | |||
1892 | if (prev_aen.members.class < curr_aen.members.class) | ||
1893 | curr_aen.members.class = prev_aen.members.class; | ||
1894 | |||
1895 | instance->aen_cmd->abort_aen = 1; | ||
1896 | ret_val = megasas_issue_blocked_abort_cmd(instance, | ||
1897 | instance-> | ||
1898 | aen_cmd); | ||
1899 | |||
1900 | if (ret_val) { | ||
1901 | printk(KERN_DEBUG "megasas: Failed to abort " | ||
1902 | "previous AEN command\n"); | ||
1903 | return ret_val; | ||
1904 | } | ||
1905 | } | ||
1906 | } | ||
1907 | |||
1908 | cmd = megasas_get_cmd(instance); | ||
1909 | |||
1910 | if (!cmd) | ||
1911 | return -ENOMEM; | ||
1912 | |||
1913 | dcmd = &cmd->frame->dcmd; | ||
1914 | |||
1915 | memset(instance->evt_detail, 0, sizeof(struct megasas_evt_detail)); | ||
1916 | |||
1917 | /* | ||
1918 | * Prepare DCMD for aen registration | ||
1919 | */ | ||
1920 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); | ||
1921 | |||
1922 | dcmd->cmd = MFI_CMD_DCMD; | ||
1923 | dcmd->cmd_status = 0x0; | ||
1924 | dcmd->sge_count = 1; | ||
1925 | dcmd->flags = MFI_FRAME_DIR_READ; | ||
1926 | dcmd->timeout = 0; | ||
1927 | dcmd->data_xfer_len = sizeof(struct megasas_evt_detail); | ||
1928 | dcmd->opcode = MR_DCMD_CTRL_EVENT_WAIT; | ||
1929 | dcmd->mbox.w[0] = seq_num; | ||
1930 | dcmd->mbox.w[1] = curr_aen.word; | ||
1931 | dcmd->sgl.sge32[0].phys_addr = (u32) instance->evt_detail_h; | ||
1932 | dcmd->sgl.sge32[0].length = sizeof(struct megasas_evt_detail); | ||
1933 | |||
1934 | /* | ||
1935 | * Store reference to the cmd used to register for AEN. When an | ||
1936 | * application wants us to register for AEN, we have to abort this | ||
1937 | * cmd and re-register with a new EVENT LOCALE supplied by that app | ||
1938 | */ | ||
1939 | instance->aen_cmd = cmd; | ||
1940 | |||
1941 | /* | ||
1942 | * Issue the aen registration frame | ||
1943 | */ | ||
1944 | writel(cmd->frame_phys_addr >> 3, | ||
1945 | &instance->reg_set->inbound_queue_port); | ||
1946 | |||
1947 | return 0; | ||
1948 | } | ||
1949 | |||
1950 | /** | ||
1951 | * megasas_start_aen - Subscribes to AEN during driver load time | ||
1952 | * @instance: Adapter soft state | ||
1953 | */ | ||
1954 | static int megasas_start_aen(struct megasas_instance *instance) | ||
1955 | { | ||
1956 | struct megasas_evt_log_info eli; | ||
1957 | union megasas_evt_class_locale class_locale; | ||
1958 | |||
1959 | /* | ||
1960 | * Get the latest sequence number from FW | ||
1961 | */ | ||
1962 | memset(&eli, 0, sizeof(eli)); | ||
1963 | |||
1964 | if (megasas_get_seq_num(instance, &eli)) | ||
1965 | return -1; | ||
1966 | |||
1967 | /* | ||
1968 | * Register AEN with FW for latest sequence number plus 1 | ||
1969 | */ | ||
1970 | class_locale.members.reserved = 0; | ||
1971 | class_locale.members.locale = MR_EVT_LOCALE_ALL; | ||
1972 | class_locale.members.class = MR_EVT_CLASS_DEBUG; | ||
1973 | |||
1974 | return megasas_register_aen(instance, eli.newest_seq_num + 1, | ||
1975 | class_locale.word); | ||
1976 | } | ||
1977 | |||
1978 | /** | ||
1979 | * megasas_io_attach - Attaches this driver to SCSI mid-layer | ||
1980 | * @instance: Adapter soft state | ||
1981 | */ | ||
1982 | static int megasas_io_attach(struct megasas_instance *instance) | ||
1983 | { | ||
1984 | struct Scsi_Host *host = instance->host; | ||
1985 | |||
1986 | /* | ||
1987 | * Export parameters required by SCSI mid-layer | ||
1988 | */ | ||
1989 | host->irq = instance->pdev->irq; | ||
1990 | host->unique_id = instance->unique_id; | ||
1991 | host->can_queue = instance->max_fw_cmds - MEGASAS_INT_CMDS; | ||
1992 | host->this_id = instance->init_id; | ||
1993 | host->sg_tablesize = instance->max_num_sge; | ||
1994 | host->max_sectors = instance->max_sectors_per_req; | ||
1995 | host->cmd_per_lun = 128; | ||
1996 | host->max_channel = MEGASAS_MAX_CHANNELS - 1; | ||
1997 | host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL; | ||
1998 | host->max_lun = MEGASAS_MAX_LUN; | ||
1999 | |||
2000 | /* | ||
2001 | * Notify the mid-layer about the new controller | ||
2002 | */ | ||
2003 | if (scsi_add_host(host, &instance->pdev->dev)) { | ||
2004 | printk(KERN_DEBUG "megasas: scsi_add_host failed\n"); | ||
2005 | return -ENODEV; | ||
2006 | } | ||
2007 | |||
2008 | /* | ||
2009 | * Trigger SCSI to scan our drives | ||
2010 | */ | ||
2011 | scsi_scan_host(host); | ||
2012 | return 0; | ||
2013 | } | ||
2014 | |||
2015 | /** | ||
2016 | * megasas_probe_one - PCI hotplug entry point | ||
2017 | * @pdev: PCI device structure | ||
2018 | * @id: PCI ids of supported hotplugged adapter | ||
2019 | */ | ||
2020 | static int __devinit | ||
2021 | megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) | ||
2022 | { | ||
2023 | int rval; | ||
2024 | struct Scsi_Host *host; | ||
2025 | struct megasas_instance *instance; | ||
2026 | |||
2027 | /* | ||
2028 | * Announce PCI information | ||
2029 | */ | ||
2030 | printk(KERN_INFO "megasas: %#4.04x:%#4.04x:%#4.04x:%#4.04x: ", | ||
2031 | pdev->vendor, pdev->device, pdev->subsystem_vendor, | ||
2032 | pdev->subsystem_device); | ||
2033 | |||
2034 | printk("bus %d:slot %d:func %d\n", | ||
2035 | pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); | ||
2036 | |||
2037 | /* | ||
2038 | * PCI prepping: enable device set bus mastering and dma mask | ||
2039 | */ | ||
2040 | rval = pci_enable_device(pdev); | ||
2041 | |||
2042 | if (rval) { | ||
2043 | return rval; | ||
2044 | } | ||
2045 | |||
2046 | pci_set_master(pdev); | ||
2047 | |||
2048 | /* | ||
2049 | * All our contollers are capable of performing 64-bit DMA | ||
2050 | */ | ||
2051 | if (IS_DMA64) { | ||
2052 | if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) != 0) { | ||
2053 | |||
2054 | if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) | ||
2055 | goto fail_set_dma_mask; | ||
2056 | } | ||
2057 | } else { | ||
2058 | if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) | ||
2059 | goto fail_set_dma_mask; | ||
2060 | } | ||
2061 | |||
2062 | host = scsi_host_alloc(&megasas_template, | ||
2063 | sizeof(struct megasas_instance)); | ||
2064 | |||
2065 | if (!host) { | ||
2066 | printk(KERN_DEBUG "megasas: scsi_host_alloc failed\n"); | ||
2067 | goto fail_alloc_instance; | ||
2068 | } | ||
2069 | |||
2070 | instance = (struct megasas_instance *)host->hostdata; | ||
2071 | memset(instance, 0, sizeof(*instance)); | ||
2072 | |||
2073 | instance->producer = pci_alloc_consistent(pdev, sizeof(u32), | ||
2074 | &instance->producer_h); | ||
2075 | instance->consumer = pci_alloc_consistent(pdev, sizeof(u32), | ||
2076 | &instance->consumer_h); | ||
2077 | |||
2078 | if (!instance->producer || !instance->consumer) { | ||
2079 | printk(KERN_DEBUG "megasas: Failed to allocate memory for " | ||
2080 | "producer, consumer\n"); | ||
2081 | goto fail_alloc_dma_buf; | ||
2082 | } | ||
2083 | |||
2084 | *instance->producer = 0; | ||
2085 | *instance->consumer = 0; | ||
2086 | |||
2087 | instance->evt_detail = pci_alloc_consistent(pdev, | ||
2088 | sizeof(struct | ||
2089 | megasas_evt_detail), | ||
2090 | &instance->evt_detail_h); | ||
2091 | |||
2092 | if (!instance->evt_detail) { | ||
2093 | printk(KERN_DEBUG "megasas: Failed to allocate memory for " | ||
2094 | "event detail structure\n"); | ||
2095 | goto fail_alloc_dma_buf; | ||
2096 | } | ||
2097 | |||
2098 | /* | ||
2099 | * Initialize locks and queues | ||
2100 | */ | ||
2101 | INIT_LIST_HEAD(&instance->cmd_pool); | ||
2102 | |||
2103 | init_waitqueue_head(&instance->int_cmd_wait_q); | ||
2104 | init_waitqueue_head(&instance->abort_cmd_wait_q); | ||
2105 | |||
2106 | spin_lock_init(&instance->cmd_pool_lock); | ||
2107 | spin_lock_init(&instance->instance_lock); | ||
2108 | |||
2109 | sema_init(&instance->aen_mutex, 1); | ||
2110 | sema_init(&instance->ioctl_sem, MEGASAS_INT_CMDS); | ||
2111 | |||
2112 | /* | ||
2113 | * Initialize PCI related and misc parameters | ||
2114 | */ | ||
2115 | instance->pdev = pdev; | ||
2116 | instance->host = host; | ||
2117 | instance->unique_id = pdev->bus->number << 8 | pdev->devfn; | ||
2118 | instance->init_id = MEGASAS_DEFAULT_INIT_ID; | ||
2119 | |||
2120 | /* | ||
2121 | * Initialize MFI Firmware | ||
2122 | */ | ||
2123 | if (megasas_init_mfi(instance)) | ||
2124 | goto fail_init_mfi; | ||
2125 | |||
2126 | /* | ||
2127 | * Register IRQ | ||
2128 | */ | ||
2129 | if (request_irq(pdev->irq, megasas_isr, SA_SHIRQ, "megasas", instance)) { | ||
2130 | printk(KERN_DEBUG "megasas: Failed to register IRQ\n"); | ||
2131 | goto fail_irq; | ||
2132 | } | ||
2133 | |||
2134 | megasas_enable_intr(instance->reg_set); | ||
2135 | |||
2136 | /* | ||
2137 | * Store instance in PCI softstate | ||
2138 | */ | ||
2139 | pci_set_drvdata(pdev, instance); | ||
2140 | |||
2141 | /* | ||
2142 | * Add this controller to megasas_mgmt_info structure so that it | ||
2143 | * can be exported to management applications | ||
2144 | */ | ||
2145 | megasas_mgmt_info.count++; | ||
2146 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = instance; | ||
2147 | megasas_mgmt_info.max_index++; | ||
2148 | |||
2149 | /* | ||
2150 | * Initiate AEN (Asynchronous Event Notification) | ||
2151 | */ | ||
2152 | if (megasas_start_aen(instance)) { | ||
2153 | printk(KERN_DEBUG "megasas: start aen failed\n"); | ||
2154 | goto fail_start_aen; | ||
2155 | } | ||
2156 | |||
2157 | /* | ||
2158 | * Register with SCSI mid-layer | ||
2159 | */ | ||
2160 | if (megasas_io_attach(instance)) | ||
2161 | goto fail_io_attach; | ||
2162 | |||
2163 | return 0; | ||
2164 | |||
2165 | fail_start_aen: | ||
2166 | fail_io_attach: | ||
2167 | megasas_mgmt_info.count--; | ||
2168 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL; | ||
2169 | megasas_mgmt_info.max_index--; | ||
2170 | |||
2171 | pci_set_drvdata(pdev, NULL); | ||
2172 | megasas_disable_intr(instance->reg_set); | ||
2173 | free_irq(instance->pdev->irq, instance); | ||
2174 | |||
2175 | megasas_release_mfi(instance); | ||
2176 | |||
2177 | fail_irq: | ||
2178 | fail_init_mfi: | ||
2179 | fail_alloc_dma_buf: | ||
2180 | if (instance->evt_detail) | ||
2181 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), | ||
2182 | instance->evt_detail, | ||
2183 | instance->evt_detail_h); | ||
2184 | |||
2185 | if (instance->producer) | ||
2186 | pci_free_consistent(pdev, sizeof(u32), instance->producer, | ||
2187 | instance->producer_h); | ||
2188 | if (instance->consumer) | ||
2189 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, | ||
2190 | instance->consumer_h); | ||
2191 | scsi_host_put(host); | ||
2192 | |||
2193 | fail_alloc_instance: | ||
2194 | fail_set_dma_mask: | ||
2195 | pci_disable_device(pdev); | ||
2196 | |||
2197 | return -ENODEV; | ||
2198 | } | ||
2199 | |||
2200 | /** | ||
2201 | * megasas_flush_cache - Requests FW to flush all its caches | ||
2202 | * @instance: Adapter soft state | ||
2203 | */ | ||
2204 | static void megasas_flush_cache(struct megasas_instance *instance) | ||
2205 | { | ||
2206 | struct megasas_cmd *cmd; | ||
2207 | struct megasas_dcmd_frame *dcmd; | ||
2208 | |||
2209 | cmd = megasas_get_cmd(instance); | ||
2210 | |||
2211 | if (!cmd) | ||
2212 | return; | ||
2213 | |||
2214 | dcmd = &cmd->frame->dcmd; | ||
2215 | |||
2216 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); | ||
2217 | |||
2218 | dcmd->cmd = MFI_CMD_DCMD; | ||
2219 | dcmd->cmd_status = 0x0; | ||
2220 | dcmd->sge_count = 0; | ||
2221 | dcmd->flags = MFI_FRAME_DIR_NONE; | ||
2222 | dcmd->timeout = 0; | ||
2223 | dcmd->data_xfer_len = 0; | ||
2224 | dcmd->opcode = MR_DCMD_CTRL_CACHE_FLUSH; | ||
2225 | dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE; | ||
2226 | |||
2227 | megasas_issue_blocked_cmd(instance, cmd); | ||
2228 | |||
2229 | megasas_return_cmd(instance, cmd); | ||
2230 | |||
2231 | return; | ||
2232 | } | ||
2233 | |||
2234 | /** | ||
2235 | * megasas_shutdown_controller - Instructs FW to shutdown the controller | ||
2236 | * @instance: Adapter soft state | ||
2237 | */ | ||
2238 | static void megasas_shutdown_controller(struct megasas_instance *instance) | ||
2239 | { | ||
2240 | struct megasas_cmd *cmd; | ||
2241 | struct megasas_dcmd_frame *dcmd; | ||
2242 | |||
2243 | cmd = megasas_get_cmd(instance); | ||
2244 | |||
2245 | if (!cmd) | ||
2246 | return; | ||
2247 | |||
2248 | if (instance->aen_cmd) | ||
2249 | megasas_issue_blocked_abort_cmd(instance, instance->aen_cmd); | ||
2250 | |||
2251 | dcmd = &cmd->frame->dcmd; | ||
2252 | |||
2253 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); | ||
2254 | |||
2255 | dcmd->cmd = MFI_CMD_DCMD; | ||
2256 | dcmd->cmd_status = 0x0; | ||
2257 | dcmd->sge_count = 0; | ||
2258 | dcmd->flags = MFI_FRAME_DIR_NONE; | ||
2259 | dcmd->timeout = 0; | ||
2260 | dcmd->data_xfer_len = 0; | ||
2261 | dcmd->opcode = MR_DCMD_CTRL_SHUTDOWN; | ||
2262 | |||
2263 | megasas_issue_blocked_cmd(instance, cmd); | ||
2264 | |||
2265 | megasas_return_cmd(instance, cmd); | ||
2266 | |||
2267 | return; | ||
2268 | } | ||
2269 | |||
2270 | /** | ||
2271 | * megasas_detach_one - PCI hot"un"plug entry point | ||
2272 | * @pdev: PCI device structure | ||
2273 | */ | ||
2274 | static void megasas_detach_one(struct pci_dev *pdev) | ||
2275 | { | ||
2276 | int i; | ||
2277 | struct Scsi_Host *host; | ||
2278 | struct megasas_instance *instance; | ||
2279 | |||
2280 | instance = pci_get_drvdata(pdev); | ||
2281 | host = instance->host; | ||
2282 | |||
2283 | scsi_remove_host(instance->host); | ||
2284 | megasas_flush_cache(instance); | ||
2285 | megasas_shutdown_controller(instance); | ||
2286 | |||
2287 | /* | ||
2288 | * Take the instance off the instance array. Note that we will not | ||
2289 | * decrement the max_index. We let this array be sparse array | ||
2290 | */ | ||
2291 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { | ||
2292 | if (megasas_mgmt_info.instance[i] == instance) { | ||
2293 | megasas_mgmt_info.count--; | ||
2294 | megasas_mgmt_info.instance[i] = NULL; | ||
2295 | |||
2296 | break; | ||
2297 | } | ||
2298 | } | ||
2299 | |||
2300 | pci_set_drvdata(instance->pdev, NULL); | ||
2301 | |||
2302 | megasas_disable_intr(instance->reg_set); | ||
2303 | |||
2304 | free_irq(instance->pdev->irq, instance); | ||
2305 | |||
2306 | megasas_release_mfi(instance); | ||
2307 | |||
2308 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), | ||
2309 | instance->evt_detail, instance->evt_detail_h); | ||
2310 | |||
2311 | pci_free_consistent(pdev, sizeof(u32), instance->producer, | ||
2312 | instance->producer_h); | ||
2313 | |||
2314 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, | ||
2315 | instance->consumer_h); | ||
2316 | |||
2317 | scsi_host_put(host); | ||
2318 | |||
2319 | pci_set_drvdata(pdev, NULL); | ||
2320 | |||
2321 | pci_disable_device(pdev); | ||
2322 | |||
2323 | return; | ||
2324 | } | ||
2325 | |||
2326 | /** | ||
2327 | * megasas_shutdown - Shutdown entry point | ||
2328 | * @device: Generic device structure | ||
2329 | */ | ||
2330 | static void megasas_shutdown(struct pci_dev *pdev) | ||
2331 | { | ||
2332 | struct megasas_instance *instance = pci_get_drvdata(pdev); | ||
2333 | megasas_flush_cache(instance); | ||
2334 | } | ||
2335 | |||
2336 | /** | ||
2337 | * megasas_mgmt_open - char node "open" entry point | ||
2338 | */ | ||
2339 | static int megasas_mgmt_open(struct inode *inode, struct file *filep) | ||
2340 | { | ||
2341 | /* | ||
2342 | * Allow only those users with admin rights | ||
2343 | */ | ||
2344 | if (!capable(CAP_SYS_ADMIN)) | ||
2345 | return -EACCES; | ||
2346 | |||
2347 | return 0; | ||
2348 | } | ||
2349 | |||
2350 | /** | ||
2351 | * megasas_mgmt_release - char node "release" entry point | ||
2352 | */ | ||
2353 | static int megasas_mgmt_release(struct inode *inode, struct file *filep) | ||
2354 | { | ||
2355 | filep->private_data = NULL; | ||
2356 | fasync_helper(-1, filep, 0, &megasas_async_queue); | ||
2357 | |||
2358 | return 0; | ||
2359 | } | ||
2360 | |||
2361 | /** | ||
2362 | * megasas_mgmt_fasync - Async notifier registration from applications | ||
2363 | * | ||
2364 | * This function adds the calling process to a driver global queue. When an | ||
2365 | * event occurs, SIGIO will be sent to all processes in this queue. | ||
2366 | */ | ||
2367 | static int megasas_mgmt_fasync(int fd, struct file *filep, int mode) | ||
2368 | { | ||
2369 | int rc; | ||
2370 | |||
2371 | down(&megasas_async_queue_mutex); | ||
2372 | |||
2373 | rc = fasync_helper(fd, filep, mode, &megasas_async_queue); | ||
2374 | |||
2375 | up(&megasas_async_queue_mutex); | ||
2376 | |||
2377 | if (rc >= 0) { | ||
2378 | /* For sanity check when we get ioctl */ | ||
2379 | filep->private_data = filep; | ||
2380 | return 0; | ||
2381 | } | ||
2382 | |||
2383 | printk(KERN_DEBUG "megasas: fasync_helper failed [%d]\n", rc); | ||
2384 | |||
2385 | return rc; | ||
2386 | } | ||
2387 | |||
2388 | /** | ||
2389 | * megasas_mgmt_fw_ioctl - Issues management ioctls to FW | ||
2390 | * @instance: Adapter soft state | ||
2391 | * @argp: User's ioctl packet | ||
2392 | */ | ||
2393 | static int | ||
2394 | megasas_mgmt_fw_ioctl(struct megasas_instance *instance, | ||
2395 | struct megasas_iocpacket __user * user_ioc, | ||
2396 | struct megasas_iocpacket *ioc) | ||
2397 | { | ||
2398 | struct megasas_sge32 *kern_sge32; | ||
2399 | struct megasas_cmd *cmd; | ||
2400 | void *kbuff_arr[MAX_IOCTL_SGE]; | ||
2401 | dma_addr_t buf_handle = 0; | ||
2402 | int error = 0, i; | ||
2403 | void *sense = NULL; | ||
2404 | dma_addr_t sense_handle; | ||
2405 | u32 *sense_ptr; | ||
2406 | |||
2407 | memset(kbuff_arr, 0, sizeof(kbuff_arr)); | ||
2408 | |||
2409 | if (ioc->sge_count > MAX_IOCTL_SGE) { | ||
2410 | printk(KERN_DEBUG "megasas: SGE count [%d] > max limit [%d]\n", | ||
2411 | ioc->sge_count, MAX_IOCTL_SGE); | ||
2412 | return -EINVAL; | ||
2413 | } | ||
2414 | |||
2415 | cmd = megasas_get_cmd(instance); | ||
2416 | if (!cmd) { | ||
2417 | printk(KERN_DEBUG "megasas: Failed to get a cmd packet\n"); | ||
2418 | return -ENOMEM; | ||
2419 | } | ||
2420 | |||
2421 | /* | ||
2422 | * User's IOCTL packet has 2 frames (maximum). Copy those two | ||
2423 | * frames into our cmd's frames. cmd->frame's context will get | ||
2424 | * overwritten when we copy from user's frames. So set that value | ||
2425 | * alone separately | ||
2426 | */ | ||
2427 | memcpy(cmd->frame, ioc->frame.raw, 2 * MEGAMFI_FRAME_SIZE); | ||
2428 | cmd->frame->hdr.context = cmd->index; | ||
2429 | |||
2430 | /* | ||
2431 | * The management interface between applications and the fw uses | ||
2432 | * MFI frames. E.g, RAID configuration changes, LD property changes | ||
2433 | * etc are accomplishes through different kinds of MFI frames. The | ||
2434 | * driver needs to care only about substituting user buffers with | ||
2435 | * kernel buffers in SGLs. The location of SGL is embedded in the | ||
2436 | * struct iocpacket itself. | ||
2437 | */ | ||
2438 | kern_sge32 = (struct megasas_sge32 *) | ||
2439 | ((unsigned long)cmd->frame + ioc->sgl_off); | ||
2440 | |||
2441 | /* | ||
2442 | * For each user buffer, create a mirror buffer and copy in | ||
2443 | */ | ||
2444 | for (i = 0; i < ioc->sge_count; i++) { | ||
2445 | kbuff_arr[i] = pci_alloc_consistent(instance->pdev, | ||
2446 | ioc->sgl[i].iov_len, | ||
2447 | &buf_handle); | ||
2448 | if (!kbuff_arr[i]) { | ||
2449 | printk(KERN_DEBUG "megasas: Failed to alloc " | ||
2450 | "kernel SGL buffer for IOCTL \n"); | ||
2451 | error = -ENOMEM; | ||
2452 | goto out; | ||
2453 | } | ||
2454 | |||
2455 | /* | ||
2456 | * We don't change the dma_coherent_mask, so | ||
2457 | * pci_alloc_consistent only returns 32bit addresses | ||
2458 | */ | ||
2459 | kern_sge32[i].phys_addr = (u32) buf_handle; | ||
2460 | kern_sge32[i].length = ioc->sgl[i].iov_len; | ||
2461 | |||
2462 | /* | ||
2463 | * We created a kernel buffer corresponding to the | ||
2464 | * user buffer. Now copy in from the user buffer | ||
2465 | */ | ||
2466 | if (copy_from_user(kbuff_arr[i], ioc->sgl[i].iov_base, | ||
2467 | (u32) (ioc->sgl[i].iov_len))) { | ||
2468 | error = -EFAULT; | ||
2469 | goto out; | ||
2470 | } | ||
2471 | } | ||
2472 | |||
2473 | if (ioc->sense_len) { | ||
2474 | sense = pci_alloc_consistent(instance->pdev, ioc->sense_len, | ||
2475 | &sense_handle); | ||
2476 | if (!sense) { | ||
2477 | error = -ENOMEM; | ||
2478 | goto out; | ||
2479 | } | ||
2480 | |||
2481 | sense_ptr = | ||
2482 | (u32 *) ((unsigned long)cmd->frame + ioc->sense_off); | ||
2483 | *sense_ptr = sense_handle; | ||
2484 | } | ||
2485 | |||
2486 | /* | ||
2487 | * Set the sync_cmd flag so that the ISR knows not to complete this | ||
2488 | * cmd to the SCSI mid-layer | ||
2489 | */ | ||
2490 | cmd->sync_cmd = 1; | ||
2491 | megasas_issue_blocked_cmd(instance, cmd); | ||
2492 | cmd->sync_cmd = 0; | ||
2493 | |||
2494 | /* | ||
2495 | * copy out the kernel buffers to user buffers | ||
2496 | */ | ||
2497 | for (i = 0; i < ioc->sge_count; i++) { | ||
2498 | if (copy_to_user(ioc->sgl[i].iov_base, kbuff_arr[i], | ||
2499 | ioc->sgl[i].iov_len)) { | ||
2500 | error = -EFAULT; | ||
2501 | goto out; | ||
2502 | } | ||
2503 | } | ||
2504 | |||
2505 | /* | ||
2506 | * copy out the sense | ||
2507 | */ | ||
2508 | if (ioc->sense_len) { | ||
2509 | /* | ||
2510 | * sense_ptr points to the location that has the user | ||
2511 | * sense buffer address | ||
2512 | */ | ||
2513 | sense_ptr = (u32 *) ((unsigned long)ioc->frame.raw + | ||
2514 | ioc->sense_off); | ||
2515 | |||
2516 | if (copy_to_user((void __user *)((unsigned long)(*sense_ptr)), | ||
2517 | sense, ioc->sense_len)) { | ||
2518 | error = -EFAULT; | ||
2519 | goto out; | ||
2520 | } | ||
2521 | } | ||
2522 | |||
2523 | /* | ||
2524 | * copy the status codes returned by the fw | ||
2525 | */ | ||
2526 | if (copy_to_user(&user_ioc->frame.hdr.cmd_status, | ||
2527 | &cmd->frame->hdr.cmd_status, sizeof(u8))) { | ||
2528 | printk(KERN_DEBUG "megasas: Error copying out cmd_status\n"); | ||
2529 | error = -EFAULT; | ||
2530 | } | ||
2531 | |||
2532 | out: | ||
2533 | if (sense) { | ||
2534 | pci_free_consistent(instance->pdev, ioc->sense_len, | ||
2535 | sense, sense_handle); | ||
2536 | } | ||
2537 | |||
2538 | for (i = 0; i < ioc->sge_count && kbuff_arr[i]; i++) { | ||
2539 | pci_free_consistent(instance->pdev, | ||
2540 | kern_sge32[i].length, | ||
2541 | kbuff_arr[i], kern_sge32[i].phys_addr); | ||
2542 | } | ||
2543 | |||
2544 | megasas_return_cmd(instance, cmd); | ||
2545 | return error; | ||
2546 | } | ||
2547 | |||
2548 | static struct megasas_instance *megasas_lookup_instance(u16 host_no) | ||
2549 | { | ||
2550 | int i; | ||
2551 | |||
2552 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { | ||
2553 | |||
2554 | if ((megasas_mgmt_info.instance[i]) && | ||
2555 | (megasas_mgmt_info.instance[i]->host->host_no == host_no)) | ||
2556 | return megasas_mgmt_info.instance[i]; | ||
2557 | } | ||
2558 | |||
2559 | return NULL; | ||
2560 | } | ||
2561 | |||
2562 | static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) | ||
2563 | { | ||
2564 | struct megasas_iocpacket __user *user_ioc = | ||
2565 | (struct megasas_iocpacket __user *)arg; | ||
2566 | struct megasas_iocpacket *ioc; | ||
2567 | struct megasas_instance *instance; | ||
2568 | int error; | ||
2569 | |||
2570 | ioc = kmalloc(sizeof(*ioc), GFP_KERNEL); | ||
2571 | if (!ioc) | ||
2572 | return -ENOMEM; | ||
2573 | |||
2574 | if (copy_from_user(ioc, user_ioc, sizeof(*ioc))) { | ||
2575 | error = -EFAULT; | ||
2576 | goto out_kfree_ioc; | ||
2577 | } | ||
2578 | |||
2579 | instance = megasas_lookup_instance(ioc->host_no); | ||
2580 | if (!instance) { | ||
2581 | error = -ENODEV; | ||
2582 | goto out_kfree_ioc; | ||
2583 | } | ||
2584 | |||
2585 | /* | ||
2586 | * We will allow only MEGASAS_INT_CMDS number of parallel ioctl cmds | ||
2587 | */ | ||
2588 | if (down_interruptible(&instance->ioctl_sem)) { | ||
2589 | error = -ERESTARTSYS; | ||
2590 | goto out_kfree_ioc; | ||
2591 | } | ||
2592 | error = megasas_mgmt_fw_ioctl(instance, user_ioc, ioc); | ||
2593 | up(&instance->ioctl_sem); | ||
2594 | |||
2595 | out_kfree_ioc: | ||
2596 | kfree(ioc); | ||
2597 | return error; | ||
2598 | } | ||
2599 | |||
2600 | static int megasas_mgmt_ioctl_aen(struct file *file, unsigned long arg) | ||
2601 | { | ||
2602 | struct megasas_instance *instance; | ||
2603 | struct megasas_aen aen; | ||
2604 | int error; | ||
2605 | |||
2606 | if (file->private_data != file) { | ||
2607 | printk(KERN_DEBUG "megasas: fasync_helper was not " | ||
2608 | "called first\n"); | ||
2609 | return -EINVAL; | ||
2610 | } | ||
2611 | |||
2612 | if (copy_from_user(&aen, (void __user *)arg, sizeof(aen))) | ||
2613 | return -EFAULT; | ||
2614 | |||
2615 | instance = megasas_lookup_instance(aen.host_no); | ||
2616 | |||
2617 | if (!instance) | ||
2618 | return -ENODEV; | ||
2619 | |||
2620 | down(&instance->aen_mutex); | ||
2621 | error = megasas_register_aen(instance, aen.seq_num, | ||
2622 | aen.class_locale_word); | ||
2623 | up(&instance->aen_mutex); | ||
2624 | return error; | ||
2625 | } | ||
2626 | |||
2627 | /** | ||
2628 | * megasas_mgmt_ioctl - char node ioctl entry point | ||
2629 | */ | ||
2630 | static long | ||
2631 | megasas_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | ||
2632 | { | ||
2633 | switch (cmd) { | ||
2634 | case MEGASAS_IOC_FIRMWARE: | ||
2635 | return megasas_mgmt_ioctl_fw(file, arg); | ||
2636 | |||
2637 | case MEGASAS_IOC_GET_AEN: | ||
2638 | return megasas_mgmt_ioctl_aen(file, arg); | ||
2639 | } | ||
2640 | |||
2641 | return -ENOTTY; | ||
2642 | } | ||
2643 | |||
2644 | #ifdef CONFIG_COMPAT | ||
2645 | static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg) | ||
2646 | { | ||
2647 | struct compat_megasas_iocpacket __user *cioc = | ||
2648 | (struct compat_megasas_iocpacket __user *)arg; | ||
2649 | struct megasas_iocpacket __user *ioc = | ||
2650 | compat_alloc_user_space(sizeof(struct megasas_iocpacket)); | ||
2651 | int i; | ||
2652 | int error = 0; | ||
2653 | |||
2654 | clear_user(ioc, sizeof(*ioc)); | ||
2655 | |||
2656 | if (copy_in_user(&ioc->host_no, &cioc->host_no, sizeof(u16)) || | ||
2657 | copy_in_user(&ioc->sgl_off, &cioc->sgl_off, sizeof(u32)) || | ||
2658 | copy_in_user(&ioc->sense_off, &cioc->sense_off, sizeof(u32)) || | ||
2659 | copy_in_user(&ioc->sense_len, &cioc->sense_len, sizeof(u32)) || | ||
2660 | copy_in_user(ioc->frame.raw, cioc->frame.raw, 128) || | ||
2661 | copy_in_user(&ioc->sge_count, &cioc->sge_count, sizeof(u32))) | ||
2662 | return -EFAULT; | ||
2663 | |||
2664 | for (i = 0; i < MAX_IOCTL_SGE; i++) { | ||
2665 | compat_uptr_t ptr; | ||
2666 | |||
2667 | if (get_user(ptr, &cioc->sgl[i].iov_base) || | ||
2668 | put_user(compat_ptr(ptr), &ioc->sgl[i].iov_base) || | ||
2669 | copy_in_user(&ioc->sgl[i].iov_len, | ||
2670 | &cioc->sgl[i].iov_len, sizeof(compat_size_t))) | ||
2671 | return -EFAULT; | ||
2672 | } | ||
2673 | |||
2674 | error = megasas_mgmt_ioctl_fw(file, (unsigned long)ioc); | ||
2675 | |||
2676 | if (copy_in_user(&cioc->frame.hdr.cmd_status, | ||
2677 | &ioc->frame.hdr.cmd_status, sizeof(u8))) { | ||
2678 | printk(KERN_DEBUG "megasas: error copy_in_user cmd_status\n"); | ||
2679 | return -EFAULT; | ||
2680 | } | ||
2681 | return error; | ||
2682 | } | ||
2683 | |||
2684 | static long | ||
2685 | megasas_mgmt_compat_ioctl(struct file *file, unsigned int cmd, | ||
2686 | unsigned long arg) | ||
2687 | { | ||
2688 | switch (cmd) { | ||
2689 | case MEGASAS_IOC_FIRMWARE:{ | ||
2690 | return megasas_mgmt_compat_ioctl_fw(file, arg); | ||
2691 | } | ||
2692 | case MEGASAS_IOC_GET_AEN: | ||
2693 | return megasas_mgmt_ioctl_aen(file, arg); | ||
2694 | } | ||
2695 | |||
2696 | return -ENOTTY; | ||
2697 | } | ||
2698 | #endif | ||
2699 | |||
2700 | /* | ||
2701 | * File operations structure for management interface | ||
2702 | */ | ||
2703 | static struct file_operations megasas_mgmt_fops = { | ||
2704 | .owner = THIS_MODULE, | ||
2705 | .open = megasas_mgmt_open, | ||
2706 | .release = megasas_mgmt_release, | ||
2707 | .fasync = megasas_mgmt_fasync, | ||
2708 | .unlocked_ioctl = megasas_mgmt_ioctl, | ||
2709 | #ifdef CONFIG_COMPAT | ||
2710 | .compat_ioctl = megasas_mgmt_compat_ioctl, | ||
2711 | #endif | ||
2712 | }; | ||
2713 | |||
2714 | /* | ||
2715 | * PCI hotplug support registration structure | ||
2716 | */ | ||
2717 | static struct pci_driver megasas_pci_driver = { | ||
2718 | |||
2719 | .name = "megaraid_sas", | ||
2720 | .id_table = megasas_pci_table, | ||
2721 | .probe = megasas_probe_one, | ||
2722 | .remove = __devexit_p(megasas_detach_one), | ||
2723 | .shutdown = megasas_shutdown, | ||
2724 | }; | ||
2725 | |||
2726 | /* | ||
2727 | * Sysfs driver attributes | ||
2728 | */ | ||
2729 | static ssize_t megasas_sysfs_show_version(struct device_driver *dd, char *buf) | ||
2730 | { | ||
2731 | return snprintf(buf, strlen(MEGASAS_VERSION) + 2, "%s\n", | ||
2732 | MEGASAS_VERSION); | ||
2733 | } | ||
2734 | |||
2735 | static DRIVER_ATTR(version, S_IRUGO, megasas_sysfs_show_version, NULL); | ||
2736 | |||
2737 | static ssize_t | ||
2738 | megasas_sysfs_show_release_date(struct device_driver *dd, char *buf) | ||
2739 | { | ||
2740 | return snprintf(buf, strlen(MEGASAS_RELDATE) + 2, "%s\n", | ||
2741 | MEGASAS_RELDATE); | ||
2742 | } | ||
2743 | |||
2744 | static DRIVER_ATTR(release_date, S_IRUGO, megasas_sysfs_show_release_date, | ||
2745 | NULL); | ||
2746 | |||
2747 | /** | ||
2748 | * megasas_init - Driver load entry point | ||
2749 | */ | ||
2750 | static int __init megasas_init(void) | ||
2751 | { | ||
2752 | int rval; | ||
2753 | |||
2754 | /* | ||
2755 | * Announce driver version and other information | ||
2756 | */ | ||
2757 | printk(KERN_INFO "megasas: %s %s\n", MEGASAS_VERSION, | ||
2758 | MEGASAS_EXT_VERSION); | ||
2759 | |||
2760 | memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info)); | ||
2761 | |||
2762 | /* | ||
2763 | * Register character device node | ||
2764 | */ | ||
2765 | rval = register_chrdev(0, "megaraid_sas_ioctl", &megasas_mgmt_fops); | ||
2766 | |||
2767 | if (rval < 0) { | ||
2768 | printk(KERN_DEBUG "megasas: failed to open device node\n"); | ||
2769 | return rval; | ||
2770 | } | ||
2771 | |||
2772 | megasas_mgmt_majorno = rval; | ||
2773 | |||
2774 | /* | ||
2775 | * Register ourselves as PCI hotplug module | ||
2776 | */ | ||
2777 | rval = pci_module_init(&megasas_pci_driver); | ||
2778 | |||
2779 | if (rval) { | ||
2780 | printk(KERN_DEBUG "megasas: PCI hotplug regisration failed \n"); | ||
2781 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); | ||
2782 | } | ||
2783 | |||
2784 | driver_create_file(&megasas_pci_driver.driver, &driver_attr_version); | ||
2785 | driver_create_file(&megasas_pci_driver.driver, | ||
2786 | &driver_attr_release_date); | ||
2787 | |||
2788 | return rval; | ||
2789 | } | ||
2790 | |||
2791 | /** | ||
2792 | * megasas_exit - Driver unload entry point | ||
2793 | */ | ||
2794 | static void __exit megasas_exit(void) | ||
2795 | { | ||
2796 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); | ||
2797 | driver_remove_file(&megasas_pci_driver.driver, | ||
2798 | &driver_attr_release_date); | ||
2799 | |||
2800 | pci_unregister_driver(&megasas_pci_driver); | ||
2801 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); | ||
2802 | } | ||
2803 | |||
2804 | module_init(megasas_init); | ||
2805 | module_exit(megasas_exit); | ||
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h new file mode 100644 index 000000000000..eaec9d531424 --- /dev/null +++ b/drivers/scsi/megaraid/megaraid_sas.h | |||
@@ -0,0 +1,1142 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Linux MegaRAID driver for SAS based RAID controllers | ||
4 | * | ||
5 | * Copyright (c) 2003-2005 LSI Logic Corporation. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * as published by the Free Software Foundation; either version | ||
10 | * 2 of the License, or (at your option) any later version. | ||
11 | * | ||
12 | * FILE : megaraid_sas.h | ||
13 | */ | ||
14 | |||
15 | #ifndef LSI_MEGARAID_SAS_H | ||
16 | #define LSI_MEGARAID_SAS_H | ||
17 | |||
18 | /** | ||
19 | * MegaRAID SAS Driver meta data | ||
20 | */ | ||
21 | #define MEGASAS_VERSION "00.00.02.00-rc4" | ||
22 | #define MEGASAS_RELDATE "Sep 16, 2005" | ||
23 | #define MEGASAS_EXT_VERSION "Fri Sep 16 12:37:08 EDT 2005" | ||
24 | |||
25 | /* | ||
26 | * ===================================== | ||
27 | * MegaRAID SAS MFI firmware definitions | ||
28 | * ===================================== | ||
29 | */ | ||
30 | |||
31 | /* | ||
32 | * MFI stands for MegaRAID SAS FW Interface. This is just a moniker for | ||
33 | * protocol between the software and firmware. Commands are issued using | ||
34 | * "message frames" | ||
35 | */ | ||
36 | |||
37 | /** | ||
38 | * FW posts its state in upper 4 bits of outbound_msg_0 register | ||
39 | */ | ||
40 | #define MFI_STATE_MASK 0xF0000000 | ||
41 | #define MFI_STATE_UNDEFINED 0x00000000 | ||
42 | #define MFI_STATE_BB_INIT 0x10000000 | ||
43 | #define MFI_STATE_FW_INIT 0x40000000 | ||
44 | #define MFI_STATE_WAIT_HANDSHAKE 0x60000000 | ||
45 | #define MFI_STATE_FW_INIT_2 0x70000000 | ||
46 | #define MFI_STATE_DEVICE_SCAN 0x80000000 | ||
47 | #define MFI_STATE_FLUSH_CACHE 0xA0000000 | ||
48 | #define MFI_STATE_READY 0xB0000000 | ||
49 | #define MFI_STATE_OPERATIONAL 0xC0000000 | ||
50 | #define MFI_STATE_FAULT 0xF0000000 | ||
51 | |||
52 | #define MEGAMFI_FRAME_SIZE 64 | ||
53 | |||
54 | /** | ||
55 | * During FW init, clear pending cmds & reset state using inbound_msg_0 | ||
56 | * | ||
57 | * ABORT : Abort all pending cmds | ||
58 | * READY : Move from OPERATIONAL to READY state; discard queue info | ||
59 | * MFIMODE : Discard (possible) low MFA posted in 64-bit mode (??) | ||
60 | * CLR_HANDSHAKE: FW is waiting for HANDSHAKE from BIOS or Driver | ||
61 | */ | ||
62 | #define MFI_INIT_ABORT 0x00000000 | ||
63 | #define MFI_INIT_READY 0x00000002 | ||
64 | #define MFI_INIT_MFIMODE 0x00000004 | ||
65 | #define MFI_INIT_CLEAR_HANDSHAKE 0x00000008 | ||
66 | #define MFI_RESET_FLAGS MFI_INIT_READY|MFI_INIT_MFIMODE | ||
67 | |||
68 | /** | ||
69 | * MFI frame flags | ||
70 | */ | ||
71 | #define MFI_FRAME_POST_IN_REPLY_QUEUE 0x0000 | ||
72 | #define MFI_FRAME_DONT_POST_IN_REPLY_QUEUE 0x0001 | ||
73 | #define MFI_FRAME_SGL32 0x0000 | ||
74 | #define MFI_FRAME_SGL64 0x0002 | ||
75 | #define MFI_FRAME_SENSE32 0x0000 | ||
76 | #define MFI_FRAME_SENSE64 0x0004 | ||
77 | #define MFI_FRAME_DIR_NONE 0x0000 | ||
78 | #define MFI_FRAME_DIR_WRITE 0x0008 | ||
79 | #define MFI_FRAME_DIR_READ 0x0010 | ||
80 | #define MFI_FRAME_DIR_BOTH 0x0018 | ||
81 | |||
82 | /** | ||
83 | * Definition for cmd_status | ||
84 | */ | ||
85 | #define MFI_CMD_STATUS_POLL_MODE 0xFF | ||
86 | |||
87 | /** | ||
88 | * MFI command opcodes | ||
89 | */ | ||
90 | #define MFI_CMD_INIT 0x00 | ||
91 | #define MFI_CMD_LD_READ 0x01 | ||
92 | #define MFI_CMD_LD_WRITE 0x02 | ||
93 | #define MFI_CMD_LD_SCSI_IO 0x03 | ||
94 | #define MFI_CMD_PD_SCSI_IO 0x04 | ||
95 | #define MFI_CMD_DCMD 0x05 | ||
96 | #define MFI_CMD_ABORT 0x06 | ||
97 | #define MFI_CMD_SMP 0x07 | ||
98 | #define MFI_CMD_STP 0x08 | ||
99 | |||
100 | #define MR_DCMD_CTRL_GET_INFO 0x01010000 | ||
101 | |||
102 | #define MR_DCMD_CTRL_CACHE_FLUSH 0x01101000 | ||
103 | #define MR_FLUSH_CTRL_CACHE 0x01 | ||
104 | #define MR_FLUSH_DISK_CACHE 0x02 | ||
105 | |||
106 | #define MR_DCMD_CTRL_SHUTDOWN 0x01050000 | ||
107 | #define MR_ENABLE_DRIVE_SPINDOWN 0x01 | ||
108 | |||
109 | #define MR_DCMD_CTRL_EVENT_GET_INFO 0x01040100 | ||
110 | #define MR_DCMD_CTRL_EVENT_GET 0x01040300 | ||
111 | #define MR_DCMD_CTRL_EVENT_WAIT 0x01040500 | ||
112 | #define MR_DCMD_LD_GET_PROPERTIES 0x03030000 | ||
113 | |||
114 | #define MR_DCMD_CLUSTER 0x08000000 | ||
115 | #define MR_DCMD_CLUSTER_RESET_ALL 0x08010100 | ||
116 | #define MR_DCMD_CLUSTER_RESET_LD 0x08010200 | ||
117 | |||
118 | /** | ||
119 | * MFI command completion codes | ||
120 | */ | ||
121 | enum MFI_STAT { | ||
122 | MFI_STAT_OK = 0x00, | ||
123 | MFI_STAT_INVALID_CMD = 0x01, | ||
124 | MFI_STAT_INVALID_DCMD = 0x02, | ||
125 | MFI_STAT_INVALID_PARAMETER = 0x03, | ||
126 | MFI_STAT_INVALID_SEQUENCE_NUMBER = 0x04, | ||
127 | MFI_STAT_ABORT_NOT_POSSIBLE = 0x05, | ||
128 | MFI_STAT_APP_HOST_CODE_NOT_FOUND = 0x06, | ||
129 | MFI_STAT_APP_IN_USE = 0x07, | ||
130 | MFI_STAT_APP_NOT_INITIALIZED = 0x08, | ||
131 | MFI_STAT_ARRAY_INDEX_INVALID = 0x09, | ||
132 | MFI_STAT_ARRAY_ROW_NOT_EMPTY = 0x0a, | ||
133 | MFI_STAT_CONFIG_RESOURCE_CONFLICT = 0x0b, | ||
134 | MFI_STAT_DEVICE_NOT_FOUND = 0x0c, | ||
135 | MFI_STAT_DRIVE_TOO_SMALL = 0x0d, | ||
136 | MFI_STAT_FLASH_ALLOC_FAIL = 0x0e, | ||
137 | MFI_STAT_FLASH_BUSY = 0x0f, | ||
138 | MFI_STAT_FLASH_ERROR = 0x10, | ||
139 | MFI_STAT_FLASH_IMAGE_BAD = 0x11, | ||
140 | MFI_STAT_FLASH_IMAGE_INCOMPLETE = 0x12, | ||
141 | MFI_STAT_FLASH_NOT_OPEN = 0x13, | ||
142 | MFI_STAT_FLASH_NOT_STARTED = 0x14, | ||
143 | MFI_STAT_FLUSH_FAILED = 0x15, | ||
144 | MFI_STAT_HOST_CODE_NOT_FOUNT = 0x16, | ||
145 | MFI_STAT_LD_CC_IN_PROGRESS = 0x17, | ||
146 | MFI_STAT_LD_INIT_IN_PROGRESS = 0x18, | ||
147 | MFI_STAT_LD_LBA_OUT_OF_RANGE = 0x19, | ||
148 | MFI_STAT_LD_MAX_CONFIGURED = 0x1a, | ||
149 | MFI_STAT_LD_NOT_OPTIMAL = 0x1b, | ||
150 | MFI_STAT_LD_RBLD_IN_PROGRESS = 0x1c, | ||
151 | MFI_STAT_LD_RECON_IN_PROGRESS = 0x1d, | ||
152 | MFI_STAT_LD_WRONG_RAID_LEVEL = 0x1e, | ||
153 | MFI_STAT_MAX_SPARES_EXCEEDED = 0x1f, | ||
154 | MFI_STAT_MEMORY_NOT_AVAILABLE = 0x20, | ||
155 | MFI_STAT_MFC_HW_ERROR = 0x21, | ||
156 | MFI_STAT_NO_HW_PRESENT = 0x22, | ||
157 | MFI_STAT_NOT_FOUND = 0x23, | ||
158 | MFI_STAT_NOT_IN_ENCL = 0x24, | ||
159 | MFI_STAT_PD_CLEAR_IN_PROGRESS = 0x25, | ||
160 | MFI_STAT_PD_TYPE_WRONG = 0x26, | ||
161 | MFI_STAT_PR_DISABLED = 0x27, | ||
162 | MFI_STAT_ROW_INDEX_INVALID = 0x28, | ||
163 | MFI_STAT_SAS_CONFIG_INVALID_ACTION = 0x29, | ||
164 | MFI_STAT_SAS_CONFIG_INVALID_DATA = 0x2a, | ||
165 | MFI_STAT_SAS_CONFIG_INVALID_PAGE = 0x2b, | ||
166 | MFI_STAT_SAS_CONFIG_INVALID_TYPE = 0x2c, | ||
167 | MFI_STAT_SCSI_DONE_WITH_ERROR = 0x2d, | ||
168 | MFI_STAT_SCSI_IO_FAILED = 0x2e, | ||
169 | MFI_STAT_SCSI_RESERVATION_CONFLICT = 0x2f, | ||
170 | MFI_STAT_SHUTDOWN_FAILED = 0x30, | ||
171 | MFI_STAT_TIME_NOT_SET = 0x31, | ||
172 | MFI_STAT_WRONG_STATE = 0x32, | ||
173 | MFI_STAT_LD_OFFLINE = 0x33, | ||
174 | MFI_STAT_PEER_NOTIFICATION_REJECTED = 0x34, | ||
175 | MFI_STAT_PEER_NOTIFICATION_FAILED = 0x35, | ||
176 | MFI_STAT_RESERVATION_IN_PROGRESS = 0x36, | ||
177 | MFI_STAT_I2C_ERRORS_DETECTED = 0x37, | ||
178 | MFI_STAT_PCI_ERRORS_DETECTED = 0x38, | ||
179 | |||
180 | MFI_STAT_INVALID_STATUS = 0xFF | ||
181 | }; | ||
182 | |||
183 | /* | ||
184 | * Number of mailbox bytes in DCMD message frame | ||
185 | */ | ||
186 | #define MFI_MBOX_SIZE 12 | ||
187 | |||
188 | enum MR_EVT_CLASS { | ||
189 | |||
190 | MR_EVT_CLASS_DEBUG = -2, | ||
191 | MR_EVT_CLASS_PROGRESS = -1, | ||
192 | MR_EVT_CLASS_INFO = 0, | ||
193 | MR_EVT_CLASS_WARNING = 1, | ||
194 | MR_EVT_CLASS_CRITICAL = 2, | ||
195 | MR_EVT_CLASS_FATAL = 3, | ||
196 | MR_EVT_CLASS_DEAD = 4, | ||
197 | |||
198 | }; | ||
199 | |||
200 | enum MR_EVT_LOCALE { | ||
201 | |||
202 | MR_EVT_LOCALE_LD = 0x0001, | ||
203 | MR_EVT_LOCALE_PD = 0x0002, | ||
204 | MR_EVT_LOCALE_ENCL = 0x0004, | ||
205 | MR_EVT_LOCALE_BBU = 0x0008, | ||
206 | MR_EVT_LOCALE_SAS = 0x0010, | ||
207 | MR_EVT_LOCALE_CTRL = 0x0020, | ||
208 | MR_EVT_LOCALE_CONFIG = 0x0040, | ||
209 | MR_EVT_LOCALE_CLUSTER = 0x0080, | ||
210 | MR_EVT_LOCALE_ALL = 0xffff, | ||
211 | |||
212 | }; | ||
213 | |||
214 | enum MR_EVT_ARGS { | ||
215 | |||
216 | MR_EVT_ARGS_NONE, | ||
217 | MR_EVT_ARGS_CDB_SENSE, | ||
218 | MR_EVT_ARGS_LD, | ||
219 | MR_EVT_ARGS_LD_COUNT, | ||
220 | MR_EVT_ARGS_LD_LBA, | ||
221 | MR_EVT_ARGS_LD_OWNER, | ||
222 | MR_EVT_ARGS_LD_LBA_PD_LBA, | ||
223 | MR_EVT_ARGS_LD_PROG, | ||
224 | MR_EVT_ARGS_LD_STATE, | ||
225 | MR_EVT_ARGS_LD_STRIP, | ||
226 | MR_EVT_ARGS_PD, | ||
227 | MR_EVT_ARGS_PD_ERR, | ||
228 | MR_EVT_ARGS_PD_LBA, | ||
229 | MR_EVT_ARGS_PD_LBA_LD, | ||
230 | MR_EVT_ARGS_PD_PROG, | ||
231 | MR_EVT_ARGS_PD_STATE, | ||
232 | MR_EVT_ARGS_PCI, | ||
233 | MR_EVT_ARGS_RATE, | ||
234 | MR_EVT_ARGS_STR, | ||
235 | MR_EVT_ARGS_TIME, | ||
236 | MR_EVT_ARGS_ECC, | ||
237 | |||
238 | }; | ||
239 | |||
240 | /* | ||
241 | * SAS controller properties | ||
242 | */ | ||
243 | struct megasas_ctrl_prop { | ||
244 | |||
245 | u16 seq_num; | ||
246 | u16 pred_fail_poll_interval; | ||
247 | u16 intr_throttle_count; | ||
248 | u16 intr_throttle_timeouts; | ||
249 | u8 rebuild_rate; | ||
250 | u8 patrol_read_rate; | ||
251 | u8 bgi_rate; | ||
252 | u8 cc_rate; | ||
253 | u8 recon_rate; | ||
254 | u8 cache_flush_interval; | ||
255 | u8 spinup_drv_count; | ||
256 | u8 spinup_delay; | ||
257 | u8 cluster_enable; | ||
258 | u8 coercion_mode; | ||
259 | u8 alarm_enable; | ||
260 | u8 disable_auto_rebuild; | ||
261 | u8 disable_battery_warn; | ||
262 | u8 ecc_bucket_size; | ||
263 | u16 ecc_bucket_leak_rate; | ||
264 | u8 restore_hotspare_on_insertion; | ||
265 | u8 expose_encl_devices; | ||
266 | u8 reserved[38]; | ||
267 | |||
268 | } __attribute__ ((packed)); | ||
269 | |||
270 | /* | ||
271 | * SAS controller information | ||
272 | */ | ||
273 | struct megasas_ctrl_info { | ||
274 | |||
275 | /* | ||
276 | * PCI device information | ||
277 | */ | ||
278 | struct { | ||
279 | |||
280 | u16 vendor_id; | ||
281 | u16 device_id; | ||
282 | u16 sub_vendor_id; | ||
283 | u16 sub_device_id; | ||
284 | u8 reserved[24]; | ||
285 | |||
286 | } __attribute__ ((packed)) pci; | ||
287 | |||
288 | /* | ||
289 | * Host interface information | ||
290 | */ | ||
291 | struct { | ||
292 | |||
293 | u8 PCIX:1; | ||
294 | u8 PCIE:1; | ||
295 | u8 iSCSI:1; | ||
296 | u8 SAS_3G:1; | ||
297 | u8 reserved_0:4; | ||
298 | u8 reserved_1[6]; | ||
299 | u8 port_count; | ||
300 | u64 port_addr[8]; | ||
301 | |||
302 | } __attribute__ ((packed)) host_interface; | ||
303 | |||
304 | /* | ||
305 | * Device (backend) interface information | ||
306 | */ | ||
307 | struct { | ||
308 | |||
309 | u8 SPI:1; | ||
310 | u8 SAS_3G:1; | ||
311 | u8 SATA_1_5G:1; | ||
312 | u8 SATA_3G:1; | ||
313 | u8 reserved_0:4; | ||
314 | u8 reserved_1[6]; | ||
315 | u8 port_count; | ||
316 | u64 port_addr[8]; | ||
317 | |||
318 | } __attribute__ ((packed)) device_interface; | ||
319 | |||
320 | /* | ||
321 | * List of components residing in flash. All str are null terminated | ||
322 | */ | ||
323 | u32 image_check_word; | ||
324 | u32 image_component_count; | ||
325 | |||
326 | struct { | ||
327 | |||
328 | char name[8]; | ||
329 | char version[32]; | ||
330 | char build_date[16]; | ||
331 | char built_time[16]; | ||
332 | |||
333 | } __attribute__ ((packed)) image_component[8]; | ||
334 | |||
335 | /* | ||
336 | * List of flash components that have been flashed on the card, but | ||
337 | * are not in use, pending reset of the adapter. This list will be | ||
338 | * empty if a flash operation has not occurred. All stings are null | ||
339 | * terminated | ||
340 | */ | ||
341 | u32 pending_image_component_count; | ||
342 | |||
343 | struct { | ||
344 | |||
345 | char name[8]; | ||
346 | char version[32]; | ||
347 | char build_date[16]; | ||
348 | char build_time[16]; | ||
349 | |||
350 | } __attribute__ ((packed)) pending_image_component[8]; | ||
351 | |||
352 | u8 max_arms; | ||
353 | u8 max_spans; | ||
354 | u8 max_arrays; | ||
355 | u8 max_lds; | ||
356 | |||
357 | char product_name[80]; | ||
358 | char serial_no[32]; | ||
359 | |||
360 | /* | ||
361 | * Other physical/controller/operation information. Indicates the | ||
362 | * presence of the hardware | ||
363 | */ | ||
364 | struct { | ||
365 | |||
366 | u32 bbu:1; | ||
367 | u32 alarm:1; | ||
368 | u32 nvram:1; | ||
369 | u32 uart:1; | ||
370 | u32 reserved:28; | ||
371 | |||
372 | } __attribute__ ((packed)) hw_present; | ||
373 | |||
374 | u32 current_fw_time; | ||
375 | |||
376 | /* | ||
377 | * Maximum data transfer sizes | ||
378 | */ | ||
379 | u16 max_concurrent_cmds; | ||
380 | u16 max_sge_count; | ||
381 | u32 max_request_size; | ||
382 | |||
383 | /* | ||
384 | * Logical and physical device counts | ||
385 | */ | ||
386 | u16 ld_present_count; | ||
387 | u16 ld_degraded_count; | ||
388 | u16 ld_offline_count; | ||
389 | |||
390 | u16 pd_present_count; | ||
391 | u16 pd_disk_present_count; | ||
392 | u16 pd_disk_pred_failure_count; | ||
393 | u16 pd_disk_failed_count; | ||
394 | |||
395 | /* | ||
396 | * Memory size information | ||
397 | */ | ||
398 | u16 nvram_size; | ||
399 | u16 memory_size; | ||
400 | u16 flash_size; | ||
401 | |||
402 | /* | ||
403 | * Error counters | ||
404 | */ | ||
405 | u16 mem_correctable_error_count; | ||
406 | u16 mem_uncorrectable_error_count; | ||
407 | |||
408 | /* | ||
409 | * Cluster information | ||
410 | */ | ||
411 | u8 cluster_permitted; | ||
412 | u8 cluster_active; | ||
413 | |||
414 | /* | ||
415 | * Additional max data transfer sizes | ||
416 | */ | ||
417 | u16 max_strips_per_io; | ||
418 | |||
419 | /* | ||
420 | * Controller capabilities structures | ||
421 | */ | ||
422 | struct { | ||
423 | |||
424 | u32 raid_level_0:1; | ||
425 | u32 raid_level_1:1; | ||
426 | u32 raid_level_5:1; | ||
427 | u32 raid_level_1E:1; | ||
428 | u32 raid_level_6:1; | ||
429 | u32 reserved:27; | ||
430 | |||
431 | } __attribute__ ((packed)) raid_levels; | ||
432 | |||
433 | struct { | ||
434 | |||
435 | u32 rbld_rate:1; | ||
436 | u32 cc_rate:1; | ||
437 | u32 bgi_rate:1; | ||
438 | u32 recon_rate:1; | ||
439 | u32 patrol_rate:1; | ||
440 | u32 alarm_control:1; | ||
441 | u32 cluster_supported:1; | ||
442 | u32 bbu:1; | ||
443 | u32 spanning_allowed:1; | ||
444 | u32 dedicated_hotspares:1; | ||
445 | u32 revertible_hotspares:1; | ||
446 | u32 foreign_config_import:1; | ||
447 | u32 self_diagnostic:1; | ||
448 | u32 mixed_redundancy_arr:1; | ||
449 | u32 global_hot_spares:1; | ||
450 | u32 reserved:17; | ||
451 | |||
452 | } __attribute__ ((packed)) adapter_operations; | ||
453 | |||
454 | struct { | ||
455 | |||
456 | u32 read_policy:1; | ||
457 | u32 write_policy:1; | ||
458 | u32 io_policy:1; | ||
459 | u32 access_policy:1; | ||
460 | u32 disk_cache_policy:1; | ||
461 | u32 reserved:27; | ||
462 | |||
463 | } __attribute__ ((packed)) ld_operations; | ||
464 | |||
465 | struct { | ||
466 | |||
467 | u8 min; | ||
468 | u8 max; | ||
469 | u8 reserved[2]; | ||
470 | |||
471 | } __attribute__ ((packed)) stripe_sz_ops; | ||
472 | |||
473 | struct { | ||
474 | |||
475 | u32 force_online:1; | ||
476 | u32 force_offline:1; | ||
477 | u32 force_rebuild:1; | ||
478 | u32 reserved:29; | ||
479 | |||
480 | } __attribute__ ((packed)) pd_operations; | ||
481 | |||
482 | struct { | ||
483 | |||
484 | u32 ctrl_supports_sas:1; | ||
485 | u32 ctrl_supports_sata:1; | ||
486 | u32 allow_mix_in_encl:1; | ||
487 | u32 allow_mix_in_ld:1; | ||
488 | u32 allow_sata_in_cluster:1; | ||
489 | u32 reserved:27; | ||
490 | |||
491 | } __attribute__ ((packed)) pd_mix_support; | ||
492 | |||
493 | /* | ||
494 | * Define ECC single-bit-error bucket information | ||
495 | */ | ||
496 | u8 ecc_bucket_count; | ||
497 | u8 reserved_2[11]; | ||
498 | |||
499 | /* | ||
500 | * Include the controller properties (changeable items) | ||
501 | */ | ||
502 | struct megasas_ctrl_prop properties; | ||
503 | |||
504 | /* | ||
505 | * Define FW pkg version (set in envt v'bles on OEM basis) | ||
506 | */ | ||
507 | char package_version[0x60]; | ||
508 | |||
509 | u8 pad[0x800 - 0x6a0]; | ||
510 | |||
511 | } __attribute__ ((packed)); | ||
512 | |||
513 | /* | ||
514 | * =============================== | ||
515 | * MegaRAID SAS driver definitions | ||
516 | * =============================== | ||
517 | */ | ||
518 | #define MEGASAS_MAX_PD_CHANNELS 2 | ||
519 | #define MEGASAS_MAX_LD_CHANNELS 2 | ||
520 | #define MEGASAS_MAX_CHANNELS (MEGASAS_MAX_PD_CHANNELS + \ | ||
521 | MEGASAS_MAX_LD_CHANNELS) | ||
522 | #define MEGASAS_MAX_DEV_PER_CHANNEL 128 | ||
523 | #define MEGASAS_DEFAULT_INIT_ID -1 | ||
524 | #define MEGASAS_MAX_LUN 8 | ||
525 | #define MEGASAS_MAX_LD 64 | ||
526 | |||
527 | /* | ||
528 | * When SCSI mid-layer calls driver's reset routine, driver waits for | ||
529 | * MEGASAS_RESET_WAIT_TIME seconds for all outstanding IO to complete. Note | ||
530 | * that the driver cannot _actually_ abort or reset pending commands. While | ||
531 | * it is waiting for the commands to complete, it prints a diagnostic message | ||
532 | * every MEGASAS_RESET_NOTICE_INTERVAL seconds | ||
533 | */ | ||
534 | #define MEGASAS_RESET_WAIT_TIME 180 | ||
535 | #define MEGASAS_RESET_NOTICE_INTERVAL 5 | ||
536 | |||
537 | #define MEGASAS_IOCTL_CMD 0 | ||
538 | |||
539 | /* | ||
540 | * FW reports the maximum of number of commands that it can accept (maximum | ||
541 | * commands that can be outstanding) at any time. The driver must report a | ||
542 | * lower number to the mid layer because it can issue a few internal commands | ||
543 | * itself (E.g, AEN, abort cmd, IOCTLs etc). The number of commands it needs | ||
544 | * is shown below | ||
545 | */ | ||
546 | #define MEGASAS_INT_CMDS 32 | ||
547 | |||
548 | /* | ||
549 | * FW can accept both 32 and 64 bit SGLs. We want to allocate 32/64 bit | ||
550 | * SGLs based on the size of dma_addr_t | ||
551 | */ | ||
552 | #define IS_DMA64 (sizeof(dma_addr_t) == 8) | ||
553 | |||
554 | #define MFI_OB_INTR_STATUS_MASK 0x00000002 | ||
555 | #define MFI_POLL_TIMEOUT_SECS 10 | ||
556 | |||
557 | struct megasas_register_set { | ||
558 | |||
559 | u32 reserved_0[4]; /*0000h */ | ||
560 | |||
561 | u32 inbound_msg_0; /*0010h */ | ||
562 | u32 inbound_msg_1; /*0014h */ | ||
563 | u32 outbound_msg_0; /*0018h */ | ||
564 | u32 outbound_msg_1; /*001Ch */ | ||
565 | |||
566 | u32 inbound_doorbell; /*0020h */ | ||
567 | u32 inbound_intr_status; /*0024h */ | ||
568 | u32 inbound_intr_mask; /*0028h */ | ||
569 | |||
570 | u32 outbound_doorbell; /*002Ch */ | ||
571 | u32 outbound_intr_status; /*0030h */ | ||
572 | u32 outbound_intr_mask; /*0034h */ | ||
573 | |||
574 | u32 reserved_1[2]; /*0038h */ | ||
575 | |||
576 | u32 inbound_queue_port; /*0040h */ | ||
577 | u32 outbound_queue_port; /*0044h */ | ||
578 | |||
579 | u32 reserved_2; /*004Ch */ | ||
580 | |||
581 | u32 index_registers[1004]; /*0050h */ | ||
582 | |||
583 | } __attribute__ ((packed)); | ||
584 | |||
585 | struct megasas_sge32 { | ||
586 | |||
587 | u32 phys_addr; | ||
588 | u32 length; | ||
589 | |||
590 | } __attribute__ ((packed)); | ||
591 | |||
592 | struct megasas_sge64 { | ||
593 | |||
594 | u64 phys_addr; | ||
595 | u32 length; | ||
596 | |||
597 | } __attribute__ ((packed)); | ||
598 | |||
599 | union megasas_sgl { | ||
600 | |||
601 | struct megasas_sge32 sge32[1]; | ||
602 | struct megasas_sge64 sge64[1]; | ||
603 | |||
604 | } __attribute__ ((packed)); | ||
605 | |||
606 | struct megasas_header { | ||
607 | |||
608 | u8 cmd; /*00h */ | ||
609 | u8 sense_len; /*01h */ | ||
610 | u8 cmd_status; /*02h */ | ||
611 | u8 scsi_status; /*03h */ | ||
612 | |||
613 | u8 target_id; /*04h */ | ||
614 | u8 lun; /*05h */ | ||
615 | u8 cdb_len; /*06h */ | ||
616 | u8 sge_count; /*07h */ | ||
617 | |||
618 | u32 context; /*08h */ | ||
619 | u32 pad_0; /*0Ch */ | ||
620 | |||
621 | u16 flags; /*10h */ | ||
622 | u16 timeout; /*12h */ | ||
623 | u32 data_xferlen; /*14h */ | ||
624 | |||
625 | } __attribute__ ((packed)); | ||
626 | |||
627 | union megasas_sgl_frame { | ||
628 | |||
629 | struct megasas_sge32 sge32[8]; | ||
630 | struct megasas_sge64 sge64[5]; | ||
631 | |||
632 | } __attribute__ ((packed)); | ||
633 | |||
634 | struct megasas_init_frame { | ||
635 | |||
636 | u8 cmd; /*00h */ | ||
637 | u8 reserved_0; /*01h */ | ||
638 | u8 cmd_status; /*02h */ | ||
639 | |||
640 | u8 reserved_1; /*03h */ | ||
641 | u32 reserved_2; /*04h */ | ||
642 | |||
643 | u32 context; /*08h */ | ||
644 | u32 pad_0; /*0Ch */ | ||
645 | |||
646 | u16 flags; /*10h */ | ||
647 | u16 reserved_3; /*12h */ | ||
648 | u32 data_xfer_len; /*14h */ | ||
649 | |||
650 | u32 queue_info_new_phys_addr_lo; /*18h */ | ||
651 | u32 queue_info_new_phys_addr_hi; /*1Ch */ | ||
652 | u32 queue_info_old_phys_addr_lo; /*20h */ | ||
653 | u32 queue_info_old_phys_addr_hi; /*24h */ | ||
654 | |||
655 | u32 reserved_4[6]; /*28h */ | ||
656 | |||
657 | } __attribute__ ((packed)); | ||
658 | |||
659 | struct megasas_init_queue_info { | ||
660 | |||
661 | u32 init_flags; /*00h */ | ||
662 | u32 reply_queue_entries; /*04h */ | ||
663 | |||
664 | u32 reply_queue_start_phys_addr_lo; /*08h */ | ||
665 | u32 reply_queue_start_phys_addr_hi; /*0Ch */ | ||
666 | u32 producer_index_phys_addr_lo; /*10h */ | ||
667 | u32 producer_index_phys_addr_hi; /*14h */ | ||
668 | u32 consumer_index_phys_addr_lo; /*18h */ | ||
669 | u32 consumer_index_phys_addr_hi; /*1Ch */ | ||
670 | |||
671 | } __attribute__ ((packed)); | ||
672 | |||
673 | struct megasas_io_frame { | ||
674 | |||
675 | u8 cmd; /*00h */ | ||
676 | u8 sense_len; /*01h */ | ||
677 | u8 cmd_status; /*02h */ | ||
678 | u8 scsi_status; /*03h */ | ||
679 | |||
680 | u8 target_id; /*04h */ | ||
681 | u8 access_byte; /*05h */ | ||
682 | u8 reserved_0; /*06h */ | ||
683 | u8 sge_count; /*07h */ | ||
684 | |||
685 | u32 context; /*08h */ | ||
686 | u32 pad_0; /*0Ch */ | ||
687 | |||
688 | u16 flags; /*10h */ | ||
689 | u16 timeout; /*12h */ | ||
690 | u32 lba_count; /*14h */ | ||
691 | |||
692 | u32 sense_buf_phys_addr_lo; /*18h */ | ||
693 | u32 sense_buf_phys_addr_hi; /*1Ch */ | ||
694 | |||
695 | u32 start_lba_lo; /*20h */ | ||
696 | u32 start_lba_hi; /*24h */ | ||
697 | |||
698 | union megasas_sgl sgl; /*28h */ | ||
699 | |||
700 | } __attribute__ ((packed)); | ||
701 | |||
702 | struct megasas_pthru_frame { | ||
703 | |||
704 | u8 cmd; /*00h */ | ||
705 | u8 sense_len; /*01h */ | ||
706 | u8 cmd_status; /*02h */ | ||
707 | u8 scsi_status; /*03h */ | ||
708 | |||
709 | u8 target_id; /*04h */ | ||
710 | u8 lun; /*05h */ | ||
711 | u8 cdb_len; /*06h */ | ||
712 | u8 sge_count; /*07h */ | ||
713 | |||
714 | u32 context; /*08h */ | ||
715 | u32 pad_0; /*0Ch */ | ||
716 | |||
717 | u16 flags; /*10h */ | ||
718 | u16 timeout; /*12h */ | ||
719 | u32 data_xfer_len; /*14h */ | ||
720 | |||
721 | u32 sense_buf_phys_addr_lo; /*18h */ | ||
722 | u32 sense_buf_phys_addr_hi; /*1Ch */ | ||
723 | |||
724 | u8 cdb[16]; /*20h */ | ||
725 | union megasas_sgl sgl; /*30h */ | ||
726 | |||
727 | } __attribute__ ((packed)); | ||
728 | |||
729 | struct megasas_dcmd_frame { | ||
730 | |||
731 | u8 cmd; /*00h */ | ||
732 | u8 reserved_0; /*01h */ | ||
733 | u8 cmd_status; /*02h */ | ||
734 | u8 reserved_1[4]; /*03h */ | ||
735 | u8 sge_count; /*07h */ | ||
736 | |||
737 | u32 context; /*08h */ | ||
738 | u32 pad_0; /*0Ch */ | ||
739 | |||
740 | u16 flags; /*10h */ | ||
741 | u16 timeout; /*12h */ | ||
742 | |||
743 | u32 data_xfer_len; /*14h */ | ||
744 | u32 opcode; /*18h */ | ||
745 | |||
746 | union { /*1Ch */ | ||
747 | u8 b[12]; | ||
748 | u16 s[6]; | ||
749 | u32 w[3]; | ||
750 | } mbox; | ||
751 | |||
752 | union megasas_sgl sgl; /*28h */ | ||
753 | |||
754 | } __attribute__ ((packed)); | ||
755 | |||
756 | struct megasas_abort_frame { | ||
757 | |||
758 | u8 cmd; /*00h */ | ||
759 | u8 reserved_0; /*01h */ | ||
760 | u8 cmd_status; /*02h */ | ||
761 | |||
762 | u8 reserved_1; /*03h */ | ||
763 | u32 reserved_2; /*04h */ | ||
764 | |||
765 | u32 context; /*08h */ | ||
766 | u32 pad_0; /*0Ch */ | ||
767 | |||
768 | u16 flags; /*10h */ | ||
769 | u16 reserved_3; /*12h */ | ||
770 | u32 reserved_4; /*14h */ | ||
771 | |||
772 | u32 abort_context; /*18h */ | ||
773 | u32 pad_1; /*1Ch */ | ||
774 | |||
775 | u32 abort_mfi_phys_addr_lo; /*20h */ | ||
776 | u32 abort_mfi_phys_addr_hi; /*24h */ | ||
777 | |||
778 | u32 reserved_5[6]; /*28h */ | ||
779 | |||
780 | } __attribute__ ((packed)); | ||
781 | |||
782 | struct megasas_smp_frame { | ||
783 | |||
784 | u8 cmd; /*00h */ | ||
785 | u8 reserved_1; /*01h */ | ||
786 | u8 cmd_status; /*02h */ | ||
787 | u8 connection_status; /*03h */ | ||
788 | |||
789 | u8 reserved_2[3]; /*04h */ | ||
790 | u8 sge_count; /*07h */ | ||
791 | |||
792 | u32 context; /*08h */ | ||
793 | u32 pad_0; /*0Ch */ | ||
794 | |||
795 | u16 flags; /*10h */ | ||
796 | u16 timeout; /*12h */ | ||
797 | |||
798 | u32 data_xfer_len; /*14h */ | ||
799 | u64 sas_addr; /*18h */ | ||
800 | |||
801 | union { | ||
802 | struct megasas_sge32 sge32[2]; /* [0]: resp [1]: req */ | ||
803 | struct megasas_sge64 sge64[2]; /* [0]: resp [1]: req */ | ||
804 | } sgl; | ||
805 | |||
806 | } __attribute__ ((packed)); | ||
807 | |||
808 | struct megasas_stp_frame { | ||
809 | |||
810 | u8 cmd; /*00h */ | ||
811 | u8 reserved_1; /*01h */ | ||
812 | u8 cmd_status; /*02h */ | ||
813 | u8 reserved_2; /*03h */ | ||
814 | |||
815 | u8 target_id; /*04h */ | ||
816 | u8 reserved_3[2]; /*05h */ | ||
817 | u8 sge_count; /*07h */ | ||
818 | |||
819 | u32 context; /*08h */ | ||
820 | u32 pad_0; /*0Ch */ | ||
821 | |||
822 | u16 flags; /*10h */ | ||
823 | u16 timeout; /*12h */ | ||
824 | |||
825 | u32 data_xfer_len; /*14h */ | ||
826 | |||
827 | u16 fis[10]; /*18h */ | ||
828 | u32 stp_flags; | ||
829 | |||
830 | union { | ||
831 | struct megasas_sge32 sge32[2]; /* [0]: resp [1]: data */ | ||
832 | struct megasas_sge64 sge64[2]; /* [0]: resp [1]: data */ | ||
833 | } sgl; | ||
834 | |||
835 | } __attribute__ ((packed)); | ||
836 | |||
837 | union megasas_frame { | ||
838 | |||
839 | struct megasas_header hdr; | ||
840 | struct megasas_init_frame init; | ||
841 | struct megasas_io_frame io; | ||
842 | struct megasas_pthru_frame pthru; | ||
843 | struct megasas_dcmd_frame dcmd; | ||
844 | struct megasas_abort_frame abort; | ||
845 | struct megasas_smp_frame smp; | ||
846 | struct megasas_stp_frame stp; | ||
847 | |||
848 | u8 raw_bytes[64]; | ||
849 | }; | ||
850 | |||
851 | struct megasas_cmd; | ||
852 | |||
853 | union megasas_evt_class_locale { | ||
854 | |||
855 | struct { | ||
856 | u16 locale; | ||
857 | u8 reserved; | ||
858 | s8 class; | ||
859 | } __attribute__ ((packed)) members; | ||
860 | |||
861 | u32 word; | ||
862 | |||
863 | } __attribute__ ((packed)); | ||
864 | |||
865 | struct megasas_evt_log_info { | ||
866 | u32 newest_seq_num; | ||
867 | u32 oldest_seq_num; | ||
868 | u32 clear_seq_num; | ||
869 | u32 shutdown_seq_num; | ||
870 | u32 boot_seq_num; | ||
871 | |||
872 | } __attribute__ ((packed)); | ||
873 | |||
874 | struct megasas_progress { | ||
875 | |||
876 | u16 progress; | ||
877 | u16 elapsed_seconds; | ||
878 | |||
879 | } __attribute__ ((packed)); | ||
880 | |||
881 | struct megasas_evtarg_ld { | ||
882 | |||
883 | u16 target_id; | ||
884 | u8 ld_index; | ||
885 | u8 reserved; | ||
886 | |||
887 | } __attribute__ ((packed)); | ||
888 | |||
889 | struct megasas_evtarg_pd { | ||
890 | u16 device_id; | ||
891 | u8 encl_index; | ||
892 | u8 slot_number; | ||
893 | |||
894 | } __attribute__ ((packed)); | ||
895 | |||
896 | struct megasas_evt_detail { | ||
897 | |||
898 | u32 seq_num; | ||
899 | u32 time_stamp; | ||
900 | u32 code; | ||
901 | union megasas_evt_class_locale cl; | ||
902 | u8 arg_type; | ||
903 | u8 reserved1[15]; | ||
904 | |||
905 | union { | ||
906 | struct { | ||
907 | struct megasas_evtarg_pd pd; | ||
908 | u8 cdb_length; | ||
909 | u8 sense_length; | ||
910 | u8 reserved[2]; | ||
911 | u8 cdb[16]; | ||
912 | u8 sense[64]; | ||
913 | } __attribute__ ((packed)) cdbSense; | ||
914 | |||
915 | struct megasas_evtarg_ld ld; | ||
916 | |||
917 | struct { | ||
918 | struct megasas_evtarg_ld ld; | ||
919 | u64 count; | ||
920 | } __attribute__ ((packed)) ld_count; | ||
921 | |||
922 | struct { | ||
923 | u64 lba; | ||
924 | struct megasas_evtarg_ld ld; | ||
925 | } __attribute__ ((packed)) ld_lba; | ||
926 | |||
927 | struct { | ||
928 | struct megasas_evtarg_ld ld; | ||
929 | u32 prevOwner; | ||
930 | u32 newOwner; | ||
931 | } __attribute__ ((packed)) ld_owner; | ||
932 | |||
933 | struct { | ||
934 | u64 ld_lba; | ||
935 | u64 pd_lba; | ||
936 | struct megasas_evtarg_ld ld; | ||
937 | struct megasas_evtarg_pd pd; | ||
938 | } __attribute__ ((packed)) ld_lba_pd_lba; | ||
939 | |||
940 | struct { | ||
941 | struct megasas_evtarg_ld ld; | ||
942 | struct megasas_progress prog; | ||
943 | } __attribute__ ((packed)) ld_prog; | ||
944 | |||
945 | struct { | ||
946 | struct megasas_evtarg_ld ld; | ||
947 | u32 prev_state; | ||
948 | u32 new_state; | ||
949 | } __attribute__ ((packed)) ld_state; | ||
950 | |||
951 | struct { | ||
952 | u64 strip; | ||
953 | struct megasas_evtarg_ld ld; | ||
954 | } __attribute__ ((packed)) ld_strip; | ||
955 | |||
956 | struct megasas_evtarg_pd pd; | ||
957 | |||
958 | struct { | ||
959 | struct megasas_evtarg_pd pd; | ||
960 | u32 err; | ||
961 | } __attribute__ ((packed)) pd_err; | ||
962 | |||
963 | struct { | ||
964 | u64 lba; | ||
965 | struct megasas_evtarg_pd pd; | ||
966 | } __attribute__ ((packed)) pd_lba; | ||
967 | |||
968 | struct { | ||
969 | u64 lba; | ||
970 | struct megasas_evtarg_pd pd; | ||
971 | struct megasas_evtarg_ld ld; | ||
972 | } __attribute__ ((packed)) pd_lba_ld; | ||
973 | |||
974 | struct { | ||
975 | struct megasas_evtarg_pd pd; | ||
976 | struct megasas_progress prog; | ||
977 | } __attribute__ ((packed)) pd_prog; | ||
978 | |||
979 | struct { | ||
980 | struct megasas_evtarg_pd pd; | ||
981 | u32 prevState; | ||
982 | u32 newState; | ||
983 | } __attribute__ ((packed)) pd_state; | ||
984 | |||
985 | struct { | ||
986 | u16 vendorId; | ||
987 | u16 deviceId; | ||
988 | u16 subVendorId; | ||
989 | u16 subDeviceId; | ||
990 | } __attribute__ ((packed)) pci; | ||
991 | |||
992 | u32 rate; | ||
993 | char str[96]; | ||
994 | |||
995 | struct { | ||
996 | u32 rtc; | ||
997 | u32 elapsedSeconds; | ||
998 | } __attribute__ ((packed)) time; | ||
999 | |||
1000 | struct { | ||
1001 | u32 ecar; | ||
1002 | u32 elog; | ||
1003 | char str[64]; | ||
1004 | } __attribute__ ((packed)) ecc; | ||
1005 | |||
1006 | u8 b[96]; | ||
1007 | u16 s[48]; | ||
1008 | u32 w[24]; | ||
1009 | u64 d[12]; | ||
1010 | } args; | ||
1011 | |||
1012 | char description[128]; | ||
1013 | |||
1014 | } __attribute__ ((packed)); | ||
1015 | |||
1016 | struct megasas_instance { | ||
1017 | |||
1018 | u32 *producer; | ||
1019 | dma_addr_t producer_h; | ||
1020 | u32 *consumer; | ||
1021 | dma_addr_t consumer_h; | ||
1022 | |||
1023 | u32 *reply_queue; | ||
1024 | dma_addr_t reply_queue_h; | ||
1025 | |||
1026 | unsigned long base_addr; | ||
1027 | struct megasas_register_set __iomem *reg_set; | ||
1028 | |||
1029 | s8 init_id; | ||
1030 | u8 reserved[3]; | ||
1031 | |||
1032 | u16 max_num_sge; | ||
1033 | u16 max_fw_cmds; | ||
1034 | u32 max_sectors_per_req; | ||
1035 | |||
1036 | struct megasas_cmd **cmd_list; | ||
1037 | struct list_head cmd_pool; | ||
1038 | spinlock_t cmd_pool_lock; | ||
1039 | struct dma_pool *frame_dma_pool; | ||
1040 | struct dma_pool *sense_dma_pool; | ||
1041 | |||
1042 | struct megasas_evt_detail *evt_detail; | ||
1043 | dma_addr_t evt_detail_h; | ||
1044 | struct megasas_cmd *aen_cmd; | ||
1045 | struct semaphore aen_mutex; | ||
1046 | struct semaphore ioctl_sem; | ||
1047 | |||
1048 | struct Scsi_Host *host; | ||
1049 | |||
1050 | wait_queue_head_t int_cmd_wait_q; | ||
1051 | wait_queue_head_t abort_cmd_wait_q; | ||
1052 | |||
1053 | struct pci_dev *pdev; | ||
1054 | u32 unique_id; | ||
1055 | |||
1056 | u32 fw_outstanding; | ||
1057 | u32 hw_crit_error; | ||
1058 | spinlock_t instance_lock; | ||
1059 | }; | ||
1060 | |||
1061 | #define MEGASAS_IS_LOGICAL(scp) \ | ||
1062 | (scp->device->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1 | ||
1063 | |||
1064 | #define MEGASAS_DEV_INDEX(inst, scp) \ | ||
1065 | ((scp->device->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) + \ | ||
1066 | scp->device->id | ||
1067 | |||
1068 | struct megasas_cmd { | ||
1069 | |||
1070 | union megasas_frame *frame; | ||
1071 | dma_addr_t frame_phys_addr; | ||
1072 | u8 *sense; | ||
1073 | dma_addr_t sense_phys_addr; | ||
1074 | |||
1075 | u32 index; | ||
1076 | u8 sync_cmd; | ||
1077 | u8 cmd_status; | ||
1078 | u16 abort_aen; | ||
1079 | |||
1080 | struct list_head list; | ||
1081 | struct scsi_cmnd *scmd; | ||
1082 | struct megasas_instance *instance; | ||
1083 | u32 frame_count; | ||
1084 | }; | ||
1085 | |||
1086 | #define MAX_MGMT_ADAPTERS 1024 | ||
1087 | #define MAX_IOCTL_SGE 16 | ||
1088 | |||
1089 | struct megasas_iocpacket { | ||
1090 | |||
1091 | u16 host_no; | ||
1092 | u16 __pad1; | ||
1093 | u32 sgl_off; | ||
1094 | u32 sge_count; | ||
1095 | u32 sense_off; | ||
1096 | u32 sense_len; | ||
1097 | union { | ||
1098 | u8 raw[128]; | ||
1099 | struct megasas_header hdr; | ||
1100 | } frame; | ||
1101 | |||
1102 | struct iovec sgl[MAX_IOCTL_SGE]; | ||
1103 | |||
1104 | } __attribute__ ((packed)); | ||
1105 | |||
1106 | struct megasas_aen { | ||
1107 | u16 host_no; | ||
1108 | u16 __pad1; | ||
1109 | u32 seq_num; | ||
1110 | u32 class_locale_word; | ||
1111 | } __attribute__ ((packed)); | ||
1112 | |||
1113 | #ifdef CONFIG_COMPAT | ||
1114 | struct compat_megasas_iocpacket { | ||
1115 | u16 host_no; | ||
1116 | u16 __pad1; | ||
1117 | u32 sgl_off; | ||
1118 | u32 sge_count; | ||
1119 | u32 sense_off; | ||
1120 | u32 sense_len; | ||
1121 | union { | ||
1122 | u8 raw[128]; | ||
1123 | struct megasas_header hdr; | ||
1124 | } frame; | ||
1125 | struct compat_iovec sgl[MAX_IOCTL_SGE]; | ||
1126 | } __attribute__ ((packed)); | ||
1127 | |||
1128 | #define MEGASAS_IOC_FIRMWARE _IOWR('M', 1, struct compat_megasas_iocpacket) | ||
1129 | #else | ||
1130 | #define MEGASAS_IOC_FIRMWARE _IOWR('M', 1, struct megasas_iocpacket) | ||
1131 | #endif | ||
1132 | |||
1133 | #define MEGASAS_IOC_GET_AEN _IOW('M', 3, struct megasas_aen) | ||
1134 | |||
1135 | struct megasas_mgmt_info { | ||
1136 | |||
1137 | u16 count; | ||
1138 | struct megasas_instance *instance[MAX_MGMT_ADAPTERS]; | ||
1139 | int max_index; | ||
1140 | }; | ||
1141 | |||
1142 | #endif /*LSI_MEGARAID_SAS_H */ | ||
diff --git a/drivers/scsi/qla2xxx/qla_rscn.c b/drivers/scsi/qla2xxx/qla_rscn.c index bdc3bc74bbe1..1eba98828636 100644 --- a/drivers/scsi/qla2xxx/qla_rscn.c +++ b/drivers/scsi/qla2xxx/qla_rscn.c | |||
@@ -330,6 +330,8 @@ qla2x00_update_login_fcport(scsi_qla_host_t *ha, struct mbx_entry *mbxstat, | |||
330 | fcport->flags &= ~FCF_FAILOVER_NEEDED; | 330 | fcport->flags &= ~FCF_FAILOVER_NEEDED; |
331 | fcport->iodesc_idx_sent = IODESC_INVALID_INDEX; | 331 | fcport->iodesc_idx_sent = IODESC_INVALID_INDEX; |
332 | atomic_set(&fcport->state, FCS_ONLINE); | 332 | atomic_set(&fcport->state, FCS_ONLINE); |
333 | if (fcport->rport) | ||
334 | fc_remote_port_unblock(fcport->rport); | ||
333 | } | 335 | } |
334 | 336 | ||
335 | 337 | ||
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index fcf9f6cbb142..327c5d7e5bd2 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c | |||
@@ -587,6 +587,7 @@ static int scsi_probe_lun(struct scsi_device *sdev, char *inq_result, | |||
587 | if (sdev->scsi_level >= 2 || | 587 | if (sdev->scsi_level >= 2 || |
588 | (sdev->scsi_level == 1 && (inq_result[3] & 0x0f) == 1)) | 588 | (sdev->scsi_level == 1 && (inq_result[3] & 0x0f) == 1)) |
589 | sdev->scsi_level++; | 589 | sdev->scsi_level++; |
590 | sdev->sdev_target->scsi_level = sdev->scsi_level; | ||
590 | 591 | ||
591 | return 0; | 592 | return 0; |
592 | } | 593 | } |
@@ -771,6 +772,15 @@ static int scsi_add_lun(struct scsi_device *sdev, char *inq_result, int *bflags) | |||
771 | return SCSI_SCAN_LUN_PRESENT; | 772 | return SCSI_SCAN_LUN_PRESENT; |
772 | } | 773 | } |
773 | 774 | ||
775 | static inline void scsi_destroy_sdev(struct scsi_device *sdev) | ||
776 | { | ||
777 | if (sdev->host->hostt->slave_destroy) | ||
778 | sdev->host->hostt->slave_destroy(sdev); | ||
779 | transport_destroy_device(&sdev->sdev_gendev); | ||
780 | put_device(&sdev->sdev_gendev); | ||
781 | } | ||
782 | |||
783 | |||
774 | /** | 784 | /** |
775 | * scsi_probe_and_add_lun - probe a LUN, if a LUN is found add it | 785 | * scsi_probe_and_add_lun - probe a LUN, if a LUN is found add it |
776 | * @starget: pointer to target device structure | 786 | * @starget: pointer to target device structure |
@@ -803,9 +813,9 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget, | |||
803 | * The rescan flag is used as an optimization, the first scan of a | 813 | * The rescan flag is used as an optimization, the first scan of a |
804 | * host adapter calls into here with rescan == 0. | 814 | * host adapter calls into here with rescan == 0. |
805 | */ | 815 | */ |
806 | if (rescan) { | 816 | sdev = scsi_device_lookup_by_target(starget, lun); |
807 | sdev = scsi_device_lookup_by_target(starget, lun); | 817 | if (sdev) { |
808 | if (sdev) { | 818 | if (rescan || sdev->sdev_state != SDEV_CREATED) { |
809 | SCSI_LOG_SCAN_BUS(3, printk(KERN_INFO | 819 | SCSI_LOG_SCAN_BUS(3, printk(KERN_INFO |
810 | "scsi scan: device exists on %s\n", | 820 | "scsi scan: device exists on %s\n", |
811 | sdev->sdev_gendev.bus_id)); | 821 | sdev->sdev_gendev.bus_id)); |
@@ -820,9 +830,9 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget, | |||
820 | sdev->model); | 830 | sdev->model); |
821 | return SCSI_SCAN_LUN_PRESENT; | 831 | return SCSI_SCAN_LUN_PRESENT; |
822 | } | 832 | } |
823 | } | 833 | scsi_device_put(sdev); |
824 | 834 | } else | |
825 | sdev = scsi_alloc_sdev(starget, lun, hostdata); | 835 | sdev = scsi_alloc_sdev(starget, lun, hostdata); |
826 | if (!sdev) | 836 | if (!sdev) |
827 | goto out; | 837 | goto out; |
828 | 838 | ||
@@ -877,12 +887,8 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget, | |||
877 | res = SCSI_SCAN_NO_RESPONSE; | 887 | res = SCSI_SCAN_NO_RESPONSE; |
878 | } | 888 | } |
879 | } | 889 | } |
880 | } else { | 890 | } else |
881 | if (sdev->host->hostt->slave_destroy) | 891 | scsi_destroy_sdev(sdev); |
882 | sdev->host->hostt->slave_destroy(sdev); | ||
883 | transport_destroy_device(&sdev->sdev_gendev); | ||
884 | put_device(&sdev->sdev_gendev); | ||
885 | } | ||
886 | out: | 892 | out: |
887 | return res; | 893 | return res; |
888 | } | 894 | } |
@@ -1054,7 +1060,7 @@ EXPORT_SYMBOL(int_to_scsilun); | |||
1054 | * 0: scan completed (or no memory, so further scanning is futile) | 1060 | * 0: scan completed (or no memory, so further scanning is futile) |
1055 | * 1: no report lun scan, or not configured | 1061 | * 1: no report lun scan, or not configured |
1056 | **/ | 1062 | **/ |
1057 | static int scsi_report_lun_scan(struct scsi_device *sdev, int bflags, | 1063 | static int scsi_report_lun_scan(struct scsi_target *starget, int bflags, |
1058 | int rescan) | 1064 | int rescan) |
1059 | { | 1065 | { |
1060 | char devname[64]; | 1066 | char devname[64]; |
@@ -1067,7 +1073,8 @@ static int scsi_report_lun_scan(struct scsi_device *sdev, int bflags, | |||
1067 | struct scsi_lun *lunp, *lun_data; | 1073 | struct scsi_lun *lunp, *lun_data; |
1068 | u8 *data; | 1074 | u8 *data; |
1069 | struct scsi_sense_hdr sshdr; | 1075 | struct scsi_sense_hdr sshdr; |
1070 | struct scsi_target *starget = scsi_target(sdev); | 1076 | struct scsi_device *sdev; |
1077 | struct Scsi_Host *shost = dev_to_shost(&starget->dev); | ||
1071 | 1078 | ||
1072 | /* | 1079 | /* |
1073 | * Only support SCSI-3 and up devices if BLIST_NOREPORTLUN is not set. | 1080 | * Only support SCSI-3 and up devices if BLIST_NOREPORTLUN is not set. |
@@ -1075,15 +1082,23 @@ static int scsi_report_lun_scan(struct scsi_device *sdev, int bflags, | |||
1075 | * support more than 8 LUNs. | 1082 | * support more than 8 LUNs. |
1076 | */ | 1083 | */ |
1077 | if ((bflags & BLIST_NOREPORTLUN) || | 1084 | if ((bflags & BLIST_NOREPORTLUN) || |
1078 | sdev->scsi_level < SCSI_2 || | 1085 | starget->scsi_level < SCSI_2 || |
1079 | (sdev->scsi_level < SCSI_3 && | 1086 | (starget->scsi_level < SCSI_3 && |
1080 | (!(bflags & BLIST_REPORTLUN2) || sdev->host->max_lun <= 8)) ) | 1087 | (!(bflags & BLIST_REPORTLUN2) || shost->max_lun <= 8)) ) |
1081 | return 1; | 1088 | return 1; |
1082 | if (bflags & BLIST_NOLUN) | 1089 | if (bflags & BLIST_NOLUN) |
1083 | return 0; | 1090 | return 0; |
1084 | 1091 | ||
1092 | if (!(sdev = scsi_device_lookup_by_target(starget, 0))) { | ||
1093 | sdev = scsi_alloc_sdev(starget, 0, NULL); | ||
1094 | if (!sdev) | ||
1095 | return 0; | ||
1096 | if (scsi_device_get(sdev)) | ||
1097 | return 0; | ||
1098 | } | ||
1099 | |||
1085 | sprintf(devname, "host %d channel %d id %d", | 1100 | sprintf(devname, "host %d channel %d id %d", |
1086 | sdev->host->host_no, sdev->channel, sdev->id); | 1101 | shost->host_no, sdev->channel, sdev->id); |
1087 | 1102 | ||
1088 | /* | 1103 | /* |
1089 | * Allocate enough to hold the header (the same size as one scsi_lun) | 1104 | * Allocate enough to hold the header (the same size as one scsi_lun) |
@@ -1098,8 +1113,10 @@ static int scsi_report_lun_scan(struct scsi_device *sdev, int bflags, | |||
1098 | length = (max_scsi_report_luns + 1) * sizeof(struct scsi_lun); | 1113 | length = (max_scsi_report_luns + 1) * sizeof(struct scsi_lun); |
1099 | lun_data = kmalloc(length, GFP_ATOMIC | | 1114 | lun_data = kmalloc(length, GFP_ATOMIC | |
1100 | (sdev->host->unchecked_isa_dma ? __GFP_DMA : 0)); | 1115 | (sdev->host->unchecked_isa_dma ? __GFP_DMA : 0)); |
1101 | if (!lun_data) | 1116 | if (!lun_data) { |
1117 | printk(ALLOC_FAILURE_MSG, __FUNCTION__); | ||
1102 | goto out; | 1118 | goto out; |
1119 | } | ||
1103 | 1120 | ||
1104 | scsi_cmd[0] = REPORT_LUNS; | 1121 | scsi_cmd[0] = REPORT_LUNS; |
1105 | 1122 | ||
@@ -1201,10 +1218,6 @@ static int scsi_report_lun_scan(struct scsi_device *sdev, int bflags, | |||
1201 | for (i = 0; i < sizeof(struct scsi_lun); i++) | 1218 | for (i = 0; i < sizeof(struct scsi_lun); i++) |
1202 | printk("%02x", data[i]); | 1219 | printk("%02x", data[i]); |
1203 | printk(" has a LUN larger than currently supported.\n"); | 1220 | printk(" has a LUN larger than currently supported.\n"); |
1204 | } else if (lun == 0) { | ||
1205 | /* | ||
1206 | * LUN 0 has already been scanned. | ||
1207 | */ | ||
1208 | } else if (lun > sdev->host->max_lun) { | 1221 | } else if (lun > sdev->host->max_lun) { |
1209 | printk(KERN_WARNING "scsi: %s lun%d has a LUN larger" | 1222 | printk(KERN_WARNING "scsi: %s lun%d has a LUN larger" |
1210 | " than allowed by the host adapter\n", | 1223 | " than allowed by the host adapter\n", |
@@ -1227,13 +1240,13 @@ static int scsi_report_lun_scan(struct scsi_device *sdev, int bflags, | |||
1227 | } | 1240 | } |
1228 | 1241 | ||
1229 | kfree(lun_data); | 1242 | kfree(lun_data); |
1230 | return 0; | ||
1231 | |||
1232 | out: | 1243 | out: |
1233 | /* | 1244 | scsi_device_put(sdev); |
1234 | * We are out of memory, don't try scanning any further. | 1245 | if (sdev->sdev_state == SDEV_CREATED) |
1235 | */ | 1246 | /* |
1236 | printk(ALLOC_FAILURE_MSG, __FUNCTION__); | 1247 | * the sdev we used didn't appear in the report luns scan |
1248 | */ | ||
1249 | scsi_destroy_sdev(sdev); | ||
1237 | return 0; | 1250 | return 0; |
1238 | } | 1251 | } |
1239 | 1252 | ||
@@ -1299,7 +1312,6 @@ static void __scsi_scan_target(struct device *parent, unsigned int channel, | |||
1299 | struct Scsi_Host *shost = dev_to_shost(parent); | 1312 | struct Scsi_Host *shost = dev_to_shost(parent); |
1300 | int bflags = 0; | 1313 | int bflags = 0; |
1301 | int res; | 1314 | int res; |
1302 | struct scsi_device *sdev = NULL; | ||
1303 | struct scsi_target *starget; | 1315 | struct scsi_target *starget; |
1304 | 1316 | ||
1305 | if (shost->this_id == id) | 1317 | if (shost->this_id == id) |
@@ -1325,27 +1337,16 @@ static void __scsi_scan_target(struct device *parent, unsigned int channel, | |||
1325 | * Scan LUN 0, if there is some response, scan further. Ideally, we | 1337 | * Scan LUN 0, if there is some response, scan further. Ideally, we |
1326 | * would not configure LUN 0 until all LUNs are scanned. | 1338 | * would not configure LUN 0 until all LUNs are scanned. |
1327 | */ | 1339 | */ |
1328 | res = scsi_probe_and_add_lun(starget, 0, &bflags, &sdev, rescan, NULL); | 1340 | res = scsi_probe_and_add_lun(starget, 0, &bflags, NULL, rescan, NULL); |
1329 | if (res == SCSI_SCAN_LUN_PRESENT) { | 1341 | if (res == SCSI_SCAN_LUN_PRESENT || res == SCSI_SCAN_TARGET_PRESENT) { |
1330 | if (scsi_report_lun_scan(sdev, bflags, rescan) != 0) | 1342 | if (scsi_report_lun_scan(starget, bflags, rescan) != 0) |
1331 | /* | 1343 | /* |
1332 | * The REPORT LUN did not scan the target, | 1344 | * The REPORT LUN did not scan the target, |
1333 | * do a sequential scan. | 1345 | * do a sequential scan. |
1334 | */ | 1346 | */ |
1335 | scsi_sequential_lun_scan(starget, bflags, | 1347 | scsi_sequential_lun_scan(starget, bflags, |
1336 | res, sdev->scsi_level, rescan); | 1348 | res, starget->scsi_level, rescan); |
1337 | } else if (res == SCSI_SCAN_TARGET_PRESENT) { | ||
1338 | /* | ||
1339 | * There's a target here, but lun 0 is offline so we | ||
1340 | * can't use the report_lun scan. Fall back to a | ||
1341 | * sequential lun scan with a bflags of SPARSELUN and | ||
1342 | * a default scsi level of SCSI_2 | ||
1343 | */ | ||
1344 | scsi_sequential_lun_scan(starget, BLIST_SPARSELUN, | ||
1345 | SCSI_SCAN_TARGET_PRESENT, SCSI_2, rescan); | ||
1346 | } | 1349 | } |
1347 | if (sdev) | ||
1348 | scsi_device_put(sdev); | ||
1349 | 1350 | ||
1350 | out_reap: | 1351 | out_reap: |
1351 | /* now determine if the target has any children at all | 1352 | /* now determine if the target has any children at all |
@@ -1542,10 +1543,7 @@ void scsi_free_host_dev(struct scsi_device *sdev) | |||
1542 | { | 1543 | { |
1543 | BUG_ON(sdev->id != sdev->host->this_id); | 1544 | BUG_ON(sdev->id != sdev->host->this_id); |
1544 | 1545 | ||
1545 | if (sdev->host->hostt->slave_destroy) | 1546 | scsi_destroy_sdev(sdev); |
1546 | sdev->host->hostt->slave_destroy(sdev); | ||
1547 | transport_destroy_device(&sdev->sdev_gendev); | ||
1548 | put_device(&sdev->sdev_gendev); | ||
1549 | } | 1547 | } |
1550 | EXPORT_SYMBOL(scsi_free_host_dev); | 1548 | EXPORT_SYMBOL(scsi_free_host_dev); |
1551 | 1549 | ||
diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c index ff724bbe6611..1d145d2f9a38 100644 --- a/drivers/scsi/scsi_transport_sas.c +++ b/drivers/scsi/scsi_transport_sas.c | |||
@@ -628,17 +628,16 @@ sas_rphy_delete(struct sas_rphy *rphy) | |||
628 | struct Scsi_Host *shost = dev_to_shost(parent->dev.parent); | 628 | struct Scsi_Host *shost = dev_to_shost(parent->dev.parent); |
629 | struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); | 629 | struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); |
630 | 630 | ||
631 | transport_destroy_device(&rphy->dev); | 631 | scsi_remove_target(dev); |
632 | 632 | ||
633 | scsi_remove_target(&rphy->dev); | 633 | transport_remove_device(dev); |
634 | device_del(dev); | ||
635 | transport_destroy_device(dev); | ||
634 | 636 | ||
635 | spin_lock(&sas_host->lock); | 637 | spin_lock(&sas_host->lock); |
636 | list_del(&rphy->list); | 638 | list_del(&rphy->list); |
637 | spin_unlock(&sas_host->lock); | 639 | spin_unlock(&sas_host->lock); |
638 | 640 | ||
639 | transport_remove_device(dev); | ||
640 | device_del(dev); | ||
641 | transport_destroy_device(dev); | ||
642 | put_device(&parent->dev); | 641 | put_device(&parent->dev); |
643 | } | 642 | } |
644 | EXPORT_SYMBOL(sas_rphy_delete); | 643 | EXPORT_SYMBOL(sas_rphy_delete); |