73 #include <linux/slab.h>
74 #include <linux/module.h>
77 static int megaraid_init(
void);
78 static void megaraid_exit(
void);
81 static void megaraid_detach_one(
struct pci_dev *);
82 static void megaraid_mbox_shutdown(
struct pci_dev *);
84 static int megaraid_io_attach(
adapter_t *);
85 static void megaraid_io_detach(
adapter_t *);
87 static int megaraid_init_mbox(
adapter_t *);
88 static void megaraid_fini_mbox(
adapter_t *);
90 static int megaraid_alloc_cmd_packets(
adapter_t *);
91 static void megaraid_free_cmd_packets(
adapter_t *);
93 static int megaraid_mbox_setup_dma_pools(
adapter_t *);
94 static void megaraid_mbox_teardown_dma_pools(
adapter_t *);
96 static int megaraid_sysfs_alloc_resources(
adapter_t *);
97 static void megaraid_sysfs_free_resources(
adapter_t *);
99 static int megaraid_abort_handler(
struct scsi_cmnd *);
100 static int megaraid_reset_handler(
struct scsi_cmnd *);
105 static int megaraid_mbox_product_info(
adapter_t *);
106 static int megaraid_mbox_extended_cdb(
adapter_t *);
108 static int megaraid_mbox_support_random_del(
adapter_t *);
109 static int megaraid_mbox_get_max_sg(
adapter_t *);
110 static void megaraid_mbox_enum_raid_scsi(
adapter_t *);
111 static void megaraid_mbox_flush_cache(
adapter_t *);
112 static int megaraid_mbox_fire_sync_cmd(
adapter_t *);
115 static void megaraid_mbox_setup_device_map(
adapter_t *);
127 static void megaraid_mbox_dpc(
unsigned long);
132 static int megaraid_cmm_register(
adapter_t *);
133 static int megaraid_cmm_unregister(
adapter_t *);
134 static int megaraid_mbox_mm_handler(
unsigned long, uioc_t *,
uint32_t);
135 static int megaraid_mbox_mm_command(
adapter_t *, uioc_t *);
137 static int gather_hbainfo(
adapter_t *, mraid_hba_info_t *);
138 static int wait_till_fw_empty(
adapter_t *);
154 static int megaraid_expose_unconf_disks = 0;
157 "Set to expose unconfigured disks to kernel (default=0)");
165 "Max wait for mailbox in microseconds if busy (default=10)");
173 "Maximum number of sectors per IO command (default=128)");
181 "Maximum number of commands per logical unit (default=64)");
189 static unsigned int megaraid_fast_load = 0;
192 "Faster loading of the driver, skips physical devices! (default=0)");
207 static uint8_t megaraid_mbox_version[8] =
208 { 0x02, 0x20, 0x04, 0x06, 3, 7, 20, 5 };
304 static struct pci_driver megaraid_pci_driver = {
306 .id_table = pci_id_table_g,
307 .probe = megaraid_probe_one,
309 .shutdown = megaraid_mbox_shutdown,
322 &dev_attr_megaraid_mbox_app_hndl,
331 &dev_attr_megaraid_mbox_ld,
344 static int megaraid_change_queue_depth(
struct scsi_device *sdev,
int qdepth,
361 .name =
"LSI Logic MegaRAID driver",
362 .proc_name =
"megaraid",
363 .queuecommand = megaraid_queue_command,
364 .eh_abort_handler = megaraid_abort_handler,
365 .eh_device_reset_handler = megaraid_reset_handler,
366 .eh_bus_reset_handler = megaraid_reset_handler,
367 .eh_host_reset_handler = megaraid_reset_handler,
368 .change_queue_depth = megaraid_change_queue_depth,
370 .sdev_attrs = megaraid_sdev_attrs,
371 .shost_attrs = megaraid_shost_attrs,
394 "megaraid mailbox: max commands per lun reset to %d\n",
402 rval = pci_register_driver(&megaraid_pci_driver);
405 "megaraid: could not register hotplug support.\n"));
445 "megaraid: probe new device %#4.04x:%#4.04x:%#4.04x:%#4.04x: ",
454 "megaraid: pci_enable_device failed\n"));
465 if (adapter ==
NULL) {
467 "megaraid: out of memory, %s %d.\n", __func__, __LINE__));
476 adapter->
pdev = pdev;
485 "megaraid: pci_set_dma_mask failed:%d\n", __LINE__));
487 goto out_free_adapter;
507 if (megaraid_init_mbox(adapter) != 0) {
509 "megaraid: maibox adapter did not initialize\n"));
511 goto out_free_adapter;
515 if (megaraid_cmm_register(adapter) != 0) {
518 "megaraid: could not register with management module\n"));
524 pci_set_drvdata(pdev, adapter);
527 if (megaraid_io_attach(adapter) != 0) {
537 pci_set_drvdata(pdev,
NULL);
538 megaraid_cmm_unregister(adapter);
540 megaraid_fini_mbox(adapter);
561 megaraid_detach_one(
struct pci_dev *pdev)
568 adapter = pci_get_drvdata(pdev);
572 "megaraid: Invalid detach on %#4.04x:%#4.04x:%#4.04x:%#4.04x\n",
580 "megaraid: detaching device %#4.04x:%#4.04x:%#4.04x:%#4.04x\n",
586 host = adapter->
host;
595 megaraid_io_detach(adapter);
600 pci_set_drvdata(pdev,
NULL);
606 megaraid_cmm_unregister(adapter);
609 megaraid_fini_mbox(adapter);
628 megaraid_mbox_shutdown(
struct pci_dev *pdev)
630 adapter_t *adapter = pci_get_drvdata(pdev);
635 "megaraid: null device in shutdown\n"));
643 megaraid_mbox_flush_cache(adapter);
664 "megaraid mbox: scsi_register failed\n"));
670 adapter->
host = host;
685 if (scsi_add_host(host, &adapter->
pdev->dev)) {
688 "megaraid mbox: scsi_add_host failed\n"));
714 host = adapter->
host;
748 pdev = adapter->
pdev;
755 if (raid_dev ==
NULL)
return -1;
762 raid_dev->
fast_load = megaraid_fast_load;
771 "megaraid: mem region busy\n"));
773 goto out_free_raid_dev;
781 "megaraid: could not map hba memory\n") );
783 goto out_release_regions;
790 if (megaraid_alloc_cmd_packets(adapter) != 0)
798 if (megaraid_mbox_fire_sync_cmd(adapter))
811 "megaraid: Couldn't register IRQ %d!\n", adapter->
irq));
817 if (megaraid_mbox_product_info(adapter) != 0)
822 if (megaraid_mbox_extended_cdb(adapter) == 0) {
834 if (megaraid_mbox_support_ha(adapter, &adapter->
init_id) == 0) {
844 megaraid_mbox_setup_device_map(adapter);
847 if (megaraid_mbox_support_random_del(adapter)) {
865 adapter->
sglen = megaraid_mbox_get_max_sg(adapter);
869 megaraid_mbox_enum_raid_scsi(adapter);
887 if (megaraid_sysfs_alloc_resources(adapter) != 0)
895 ((adapter->
pdev->subsystem_device !=
897 (adapter->
pdev->subsystem_device !=
911 "megaraid: DMA mask for 64-bit failed\n"));
915 "megaraid: 32-bit DMA mask failed\n"));
916 goto out_free_sysfs_res;
923 (
unsigned long)adapter);
926 "megaraid mbox hba successfully initialized\n"));
931 megaraid_sysfs_free_resources(adapter);
935 megaraid_free_cmd_packets(adapter);
957 megaraid_mbox_flush_cache(adapter);
961 megaraid_sysfs_free_resources(adapter);
963 megaraid_free_cmd_packets(adapter);
987 megaraid_alloc_cmd_packets(
adapter_t *adapter)
999 pdev = adapter->
pdev;
1011 "megaraid: out of memory, %s %d\n", __func__,
1022 raid_dev->
mbox = (mbox_t *)((((
unsigned long)raid_dev->
mbox) + 15) &
1025 raid_dev->
mbox64 = (mbox64_t *)(((
unsigned long)raid_dev->
mbox) - 8);
1027 align = ((
void *)raid_dev->
mbox -
1036 if (!adapter->
ibuf) {
1039 "megaraid: out of memory, %s %d\n", __func__,
1042 goto out_free_common_mbox;
1061 "megaraid: out of memory, %s %d\n", __func__,
1067 if (megaraid_mbox_setup_dma_pools(adapter) != 0) {
1069 "megaraid: out of memory, %s %d\n", __func__,
1071 goto out_free_scb_list;
1076 sg_pci_blk = raid_dev->
sg_pool;
1083 ccb->
mbox = (mbox_t *)(mbox_pci_blk[i].
vaddr + 16);
1091 "megaraid mbox: not aligned on 16-bytes\n"));
1093 goto out_teardown_dma_pools;
1096 ccb->
epthru = (mraid_epassthru_t *)
1097 epthru_pci_blk[i].
vaddr;
1125 out_teardown_dma_pools:
1126 megaraid_mbox_teardown_dma_pools(adapter);
1132 out_free_common_mbox:
1147 megaraid_free_cmd_packets(
adapter_t *adapter)
1151 megaraid_mbox_teardown_dma_pools(adapter);
1172 megaraid_mbox_setup_dma_pools(
adapter_t *adapter)
1185 sizeof(mbox64_t) + 16,
1189 goto fail_setup_dma_pool;
1194 mbox_pci_blk[
i].
vaddr = pci_pool_alloc(
1198 if (!mbox_pci_blk[i].
vaddr) {
1199 goto fail_setup_dma_pool;
1212 adapter->
pdev,
sizeof(mraid_epassthru_t), 128, 0);
1215 goto fail_setup_dma_pool;
1220 epthru_pci_blk[
i].
vaddr = pci_pool_alloc(
1224 if (!epthru_pci_blk[i].
vaddr) {
1225 goto fail_setup_dma_pool;
1238 goto fail_setup_dma_pool;
1241 sg_pci_blk = raid_dev->
sg_pool;
1243 sg_pci_blk[
i].
vaddr = pci_pool_alloc(
1247 if (!sg_pci_blk[i].
vaddr) {
1248 goto fail_setup_dma_pool;
1254 fail_setup_dma_pool:
1255 megaraid_mbox_teardown_dma_pools(adapter);
1268 megaraid_mbox_teardown_dma_pools(
adapter_t *adapter)
1277 sg_pci_blk = raid_dev->
sg_pool;
1278 for (i = 0; i < MBOX_MAX_SCSI_CMDS && sg_pci_blk[
i].
vaddr; i++) {
1287 for (i = 0; i < MBOX_MAX_SCSI_CMDS && epthru_pci_blk[
i].
vaddr; i++) {
1296 for (i = 0; i < MBOX_MAX_SCSI_CMDS && mbox_pci_blk[
i].
vaddr; i++) {
1320 unsigned long flags;
1325 if (list_empty(head)) {
1331 list_del_init(&scb->
list);
1356 unsigned long flags;
1424 unsigned long flags;
1429 mbox = raid_dev->
mbox;
1430 mbox64 = raid_dev->
mbox64;
1443 }
while(mbox->busy && (i < max_mbox_busy_wait));
1456 mbox->cmdid = scb->
sno;
1461 pci_dma_sync_sg_for_device(adapter->
pdev,
1462 scsi_sglist(scb->
scp),
1463 scsi_sg_count(scb->
scp),
1506 scb = megaraid_mbox_build_cmd(adapter, scp, &if_busy);
1512 megaraid_mbox_runpendq(adapter, scb);
1537 mraid_passthru_t *
pthru;
1541 char skip[] =
"skipping";
1542 char scan[] =
"scanning";
1556 switch (scp->cmnd[0]) {
1563 scp->result = (
DID_OK << 16);
1567 if (!(scb = megaraid_alloc_scb(adapter, scp))) {
1593 sgl = scsi_sglist(scp);
1601 "megaraid mailbox: invalid sg:%d\n",
1605 scp->result = (
DID_OK << 16);
1616 "scsi[%d]: scanning scsi channel %d",
1617 adapter->host->host_no,
1621 " [virtual] for logical drives\n"));
1627 scp->sense_buffer[0] = 0x70;
1652 if (!(scb = megaraid_alloc_scb(adapter, scp))) {
1667 pthru->reqsenselen = 14;
1668 pthru->islogical = 1;
1669 pthru->logdrv = target;
1670 pthru->cdblen = scp->cmd_len;
1671 memcpy(pthru->cdb, scp->cmnd, scp->cmd_len);
1676 pthru->dataxferlen = scsi_bufflen(scp);
1678 pthru->numsge = megaraid_mbox_mksgl(adapter,
1681 mbox->xferaddr = 0xFFFFFFFF;
1683 mbox64->xferaddr_hi = 0;
1697 if (!(scb = megaraid_alloc_scb(adapter, scp))) {
1707 mbox->logdrv = target;
1719 if (scp->cmd_len == 6) {
1720 mbox->numsectors = (
uint32_t)scp->cmnd[4];
1726 mbox->lba &= 0x1FFFFF;
1732 else if (scp->cmd_len == 10) {
1746 else if (scp->cmd_len == 12) {
1761 "megaraid: unsupported CDB length\n"));
1763 megaraid_dealloc_scb(adapter, scb);
1773 mbox->numsge = megaraid_mbox_mksgl(adapter,
1775 mbox->xferaddr = 0xFFFFFFFF;
1776 mbox64->xferaddr_hi = 0;
1793 if (!(scb = megaraid_alloc_scb(adapter, scp))) {
1819 if (target > 15 ||
SCP2LUN(scp) > 7) {
1827 if (rdev->
fast_load && (target == 15) &&
1831 "megaraid[%d]: physical device scan re-enabled\n",
1832 adapter->host->host_no));
1844 "scsi[%d]: %s scsi channel %d [Phy %d]",
1849 " for non-raid devices\n"));
1861 if (!(scb = megaraid_alloc_scb(adapter, scp))) {
1875 if (adapter->max_cdb_sz == 16) {
1878 megaraid_mbox_prepare_epthru(adapter, scb, scp);
1881 mbox64->xferaddr_hi = 0;
1882 mbox->xferaddr = 0xFFFFFFFF;
1887 megaraid_mbox_prepare_pthru(adapter, scb, scp);
1890 mbox64->xferaddr_hi = 0;
1891 mbox->xferaddr = 0xFFFFFFFF;
1917 unsigned long flags;
1932 while (!list_empty(&adapter->
pend_list)) {
1942 list_del_init(&scb->
list);
1952 if (mbox_post_cmd(adapter, scb) != 0) {
1989 mraid_passthru_t *
pthru;
2001 pthru->islogical = 0;
2003 pthru->target = (channel << 4) |
target;
2005 pthru->reqsenselen = 14;
2010 if (scsi_bufflen(scp)) {
2011 pthru->dataxferlen = scsi_bufflen(scp);
2013 pthru->numsge = megaraid_mbox_mksgl(adapter, scb);
2016 pthru->dataxferaddr = 0;
2017 pthru->dataxferlen = 0;
2038 mraid_epassthru_t *epthru;
2048 epthru->timeout = 4;
2050 epthru->islogical = 0;
2051 epthru->channel = 0;
2052 epthru->target = (channel << 4) |
target;
2053 epthru->logdrv =
SCP2LUN(scp);
2054 epthru->reqsenselen = 14;
2055 epthru->cdblen = scp->
cmd_len;
2059 if (scsi_bufflen(scp)) {
2060 epthru->dataxferlen = scsi_bufflen(scp);
2062 epthru->numsge = megaraid_mbox_mksgl(adapter, scb);
2065 epthru->dataxferaddr = 0;
2066 epthru->dataxferlen = 0;
2083 megaraid_ack_sequence(
adapter_t *adapter)
2093 unsigned long flags;
2097 mbox = raid_dev->
mbox;
2100 INIT_LIST_HEAD(&clist);
2111 if (dword != 0x10001234)
break;
2119 for (i = 0; i < 0xFFFFF; i++) {
2120 if (mbox->numstatus != 0xFF) {
2121 nstatus = mbox->numstatus;
2126 mbox->numstatus = 0xFF;
2130 for (i = 0; i < nstatus; i++) {
2133 for (j = 0; j < 0xFFFFF; j++) {
2134 if (mbox->completed[i] != 0xFF)
break;
2137 completed[
i] = mbox->completed[
i];
2138 mbox->completed[
i] = 0xFF;
2140 if (completed[i] == 0xFF) {
2142 "megaraid: command posting timed out\n"));
2149 if (completed[i] >= MBOX_MAX_SCSI_CMDS) {
2159 scb->
status = mbox->status;
2182 tasklet_schedule(&adapter->
dpc_h);
2196 megaraid_isr(
int irq,
void *devp)
2201 handled = megaraid_ack_sequence(adapter);
2205 megaraid_mbox_runpendq(adapter,
NULL);
2227 pci_dma_sync_sg_for_cpu(adapter->
pdev,
2228 scsi_sglist(scb->
scp),
2229 scsi_sg_count(scb->
scp),
2246 megaraid_mbox_dpc(
unsigned long devp)
2255 mraid_passthru_t *
pthru;
2256 mraid_epassthru_t *epthru;
2262 unsigned long flags;
2268 if (!adapter)
return;
2273 INIT_LIST_HEAD(&clist);
2294 "megaraid critical err: invalid command %d:%d:%p\n",
2301 if (scb->
sno >= MBOX_MAX_SCSI_CMDS) {
2306 list_del_init(&scb->
list);
2308 kioc = (uioc_t *)scb->
gp;
2311 megaraid_mbox_mm_done(adapter, scb);
2319 "megaraid: aborted cmd [%x] completed\n",
2332 if (scp->
cmnd[0] ==
INQUIRY && status == 0 && islogical == 0
2335 sgl = scsi_sglist(scp);
2337 c = *(
unsigned char *) sg_virt(&sgl[0]);
2340 "megaraid mailbox: invalid sg:%d\n",
2355 megaraid_expose_unconf_disks == 0) {
2386 epthru->reqsensearea, 14);
2432 megaraid_mbox_display_scb(adapter, scb);
2437 megaraid_mbox_sync_scb(adapter, scb);
2440 list_del_init(&scb->
list);
2443 megaraid_dealloc_scb(adapter, scb);
2461 megaraid_abort_handler(
struct scsi_cmnd *scp)
2468 unsigned long flags;
2476 "megaraid: aborting cmd=%x <c=%d t=%d l=%d>\n",
2483 "megaraid: hw error, not aborting\n"));
2495 if (scb->
scp == scp) {
2497 list_del_init(&scb->
list);
2500 "megaraid: %d[%d:%d], abort from completed list\n",
2506 megaraid_dealloc_scb(adapter, scb);
2523 if (scb->
scp == scp) {
2525 list_del_init(&scb->
list);
2530 "megaraid abort: [%d:%d], driver owner\n",
2536 megaraid_dealloc_scb(adapter, scb);
2552 spin_lock_irq(&adapter->
lock);
2556 if (scb->
scp == scp) {
2562 "megaraid abort: %d[%d:%d], invalid state\n",
2568 "megaraid abort: %d[%d:%d], fw owner\n",
2573 spin_unlock_irq(&adapter->
lock);
2599 megaraid_reset_handler(
struct scsi_cmnd *scp)
2605 unsigned long flags;
2606 uint8_t raw_mbox[
sizeof(mbox_t)];
2608 int recovery_window;
2619 "megaraid: hw error, cannot reset\n"));
2631 list_del_init(&scb->
list);
2633 if (scb->
sno >= MBOX_MAX_SCSI_CMDS) {
2635 "megaraid: IOCTL packet with %d[%d:%d] being reset\n",
2640 kioc = (uioc_t *)scb->
gp;
2643 megaraid_mbox_mm_done(adapter, scb);
2645 if (scb->
scp == scp) {
2647 "megaraid: %d[%d:%d], reset from pending list\n",
2651 "megaraid: IO packet with %d[%d:%d] being reset\n",
2656 scb->
scp->scsi_done(scb->
scp);
2658 megaraid_dealloc_scb(adapter, scb);
2665 "megaraid: %d outstanding commands. Max wait %d sec\n",
2674 for (i = 0; i < recovery_window; i++) {
2676 megaraid_ack_sequence(adapter);
2681 "megaraid mbox: Wait for %d commands to complete:%d\n",
2694 spin_lock(&adapter->
lock);
2699 "megaraid mbox: critical hardware error!\n"));
2708 "megaraid mbox: reset sequence completed successfully\n"));
2723 if (mbox_post_sync_cmd_fast(adapter, raw_mbox) == 0) {
2725 (
KERN_INFO "megaraid: reservation reset\n"));
2730 "megaraid: reservation reset failed\n"));
2734 spin_unlock(&adapter->
lock);
2763 mbox64 = raid_dev->
mbox64;
2764 mbox = raid_dev->
mbox;
2769 if (megaraid_busywait_mbox(raid_dev) != 0)
2770 goto blocked_mailbox;
2780 mbox->numstatus = 0xFF;
2781 mbox->status = 0xFF;
2789 if (mbox->numstatus == 0xFF) {
2792 for (i = 0; mbox->numstatus == 0xFF && i < 1000; i++) {
2800 "megaraid mailbox: wait for FW to boot "));
2802 for (i = 0; (mbox->numstatus == 0xFF) &&
2813 "\nmegaraid mailbox: status not available\n"));
2822 if (mbox->poll != 0x77) {
2825 for (i = 0; (mbox->poll != 0x77) && (i < 1000); i++) {
2832 "megaraid mailbox: could not get poll semaphore\n"));
2844 for (i = 0; (
RDINDOOR(raid_dev) & 0x2) && (i < 1000); i++) {
2851 "megaraid mailbox: could not acknowledge\n"));
2858 status = mbox->status;
2862 mbox->numstatus = 0xFF;
2863 mbox->status = 0xFF;
2865 mbox->completed[
i] = 0xFF;
2894 mbox = raid_dev->
mbox;
2897 if (mbox->busy)
return -1;
2905 mbox->numstatus = 0xFF;
2906 mbox->status = 0xFF;
2912 if (mbox->numstatus != 0xFF)
break;
2917 if (i == MBOX_SYNC_WAIT_CNT) {
2920 "megaraid: fast sync command timed out\n"));
2926 return mbox->status;
2940 mbox_t *mbox = raid_dev->
mbox;
2945 for (i = 0; mbox->busy && i < 1000; i++)
2949 if (i < 1000)
return 0;
2962 megaraid_mbox_product_info(
adapter_t *adapter)
2966 uint8_t raw_mbox[
sizeof(mbox_t)];
2967 mraid_pinfo_t *
pinfo;
2969 mraid_inquiry3_t *mraid_inq3;
2974 mbox = (mbox_t *)raw_mbox;
2983 if (pinfo ==
NULL) {
2985 "megaraid: out of memory, %s %d\n", __func__,
2990 memset(pinfo, 0,
sizeof(mraid_pinfo_t));
3000 if (mbox_post_sync_cmd(adapter, raw_mbox) != 0) {
3005 pinfo, pinfo_dma_h);
3015 mraid_inq3 = (mraid_inquiry3_t *)adapter->
ibuf;
3025 mbox->xferaddr = (
uint32_t)pinfo_dma_h;
3030 if (mbox_post_sync_cmd(adapter, raw_mbox) != 0) {
3033 "megaraid: product info failed\n"));
3036 pinfo, pinfo_dma_h);
3068 "megaraid: fw version:[%s] bios version:[%s]\n",
3087 megaraid_mbox_extended_cdb(
adapter_t *adapter)
3090 uint8_t raw_mbox[
sizeof(mbox_t)];
3093 mbox = (mbox_t *)raw_mbox;
3107 if (mbox_post_sync_cmd(adapter, raw_mbox) != 0) {
3126 uint8_t raw_mbox[
sizeof(mbox_t)];
3130 mbox = (mbox_t *)raw_mbox;
3143 if (mbox_post_sync_cmd(adapter, raw_mbox) == 0) {
3148 "megaraid: cluster firmware, initiator ID: %d\n",
3166 megaraid_mbox_support_random_del(
adapter_t *adapter)
3169 uint8_t raw_mbox[
sizeof(mbox_t)];
3190 mbox = (mbox_t *)raw_mbox;
3199 if (mbox_post_sync_cmd(adapter, raw_mbox) == 0) {
3218 megaraid_mbox_get_max_sg(
adapter_t *adapter)
3221 uint8_t raw_mbox[
sizeof(mbox_t)];
3225 mbox = (mbox_t *)raw_mbox;
3237 if (mbox_post_sync_cmd(adapter, raw_mbox) == 0) {
3258 megaraid_mbox_enum_raid_scsi(
adapter_t *adapter)
3262 uint8_t raw_mbox[
sizeof(mbox_t)];
3265 mbox = (mbox_t *)raw_mbox;
3279 if (mbox_post_sync_cmd(adapter, raw_mbox) == 0) {
3294 megaraid_mbox_flush_cache(
adapter_t *adapter)
3297 uint8_t raw_mbox[
sizeof(mbox_t)];
3300 mbox = (mbox_t *)raw_mbox;
3306 if (mbox_post_sync_cmd(adapter, raw_mbox) != 0) {
3312 if (mbox_post_sync_cmd(adapter, raw_mbox) != 0) {
3327 megaraid_mbox_fire_sync_cmd(
adapter_t *adapter)
3330 uint8_t raw_mbox[
sizeof(mbox_t)];
3337 mbox = (mbox_t *)raw_mbox;
3343 mbox64 = raid_dev->mbox64;
3344 mbox = raid_dev->mbox;
3347 if (megaraid_busywait_mbox(raid_dev) != 0) {
3349 goto blocked_mailbox;
3358 mbox->numstatus = 0;
3362 WRINDOOR(raid_dev, raid_dev->mbox_dma | 0x1);
3374 while (!mbox->numstatus && mbox->cmd == 0xFF) {
3378 if (i > 1000 * 60) {
3383 if (mbox->numstatus == 1)
3424 "megaraid mailbox: status:%#x cmd:%#x id:%#x ", scb->
status,
3425 mbox->cmd, scb->
sno));
3427 con_log(level, (
"sec:%#x lba:%#x addr:%#x ld:%d sg:%d\n",
3428 mbox->numsectors, mbox->lba, mbox->xferaddr, mbox->logdrv,
3435 for (i = 0; i < scp->
cmd_len; i++) {
3455 megaraid_mbox_setup_device_map(
adapter_t *adapter)
3465 (t < adapter->init_id) ? t : t - 1;
3498 megaraid_cmm_register(
adapter_t *adapter)
3512 "megaraid: out of memory, %s %d\n", __func__,
3544 scb->
sno = i + MBOX_MAX_SCSI_CMDS;
3568 "megaraid mbox: did not register with CMM\n"));
3586 megaraid_cmm_unregister(
adapter_t *adapter)
3605 megaraid_mbox_mm_handler(
unsigned long drvr_data, uioc_t *kioc,
uint32_t action)
3611 "megaraid: unsupported management action:%#2x\n",
3621 "megaraid: reject management request, detaching\n"));
3625 switch (kioc->opcode) {
3629 kioc->status = gather_hbainfo(adapter, (mraid_hba_info_t *)
3630 (
unsigned long)kioc->buf_vaddr);
3634 return kioc->status;
3638 return megaraid_mbox_mm_command(adapter, kioc);
3641 kioc->status = (-
EINVAL);
3657 megaraid_mbox_mm_command(
adapter_t *adapter, uioc_t *kioc)
3664 unsigned long flags;
3669 if (list_empty(head)) {
3672 "megaraid mbox: bug in cmm handler, lost resources\n"));
3680 list_del_init(&scb->
list);
3689 mbox64 = (mbox64_t *)(
unsigned long)kioc->cmdbuf;
3690 raw_mbox = (
uint8_t *)&mbox64->mbox32;
3694 scb->
gp = (
unsigned long)kioc;
3702 if (wait_till_fw_empty(adapter)) {
3704 "megaraid mbox: LD delete, timed out\n"));
3706 kioc->status = -
ETIME;
3710 megaraid_mbox_mm_done(adapter, scb);
3715 INIT_LIST_HEAD(&scb->
list);
3718 if (mbox_post_cmd(adapter, scb) != 0) {
3721 "megaraid mbox: LD delete, mailbox busy\n"));
3723 kioc->status = -
EBUSY;
3727 megaraid_mbox_mm_done(adapter, scb);
3736 megaraid_mbox_runpendq(adapter, scb);
3745 unsigned long flags = 0;
3754 spin_unlock_irqrestore(&adapter->
lock, flags);
3762 "megaraid: FW has %d pending commands\n",
3786 unsigned long flags;
3788 kioc = (uioc_t *)scb->
gp;
3789 mbox64 = (mbox64_t *)(
unsigned long)kioc->cmdbuf;
3790 mbox64->mbox32.status = scb->
status;
3791 raw_mbox = (
uint8_t *)&mbox64->mbox32;
3810 megaraid_mbox_runpendq(adapter,
NULL);
3825 gather_hbainfo(
adapter_t *adapter, mraid_hba_info_t *hinfo)
3829 dmajor = megaraid_mbox_version[0];
3831 hinfo->pci_vendor_id = adapter->
pdev->vendor;
3832 hinfo->pci_device_id = adapter->
pdev->device;
3833 hinfo->subsys_vendor_id = adapter->
pdev->subsystem_vendor;
3834 hinfo->subsys_device_id = adapter->
pdev->subsystem_device;
3836 hinfo->pci_bus = adapter->
pdev->bus->number;
3837 hinfo->pci_dev_fn = adapter->
pdev->devfn;
3839 hinfo->irq = adapter->
host->irq;
3842 hinfo->unique_id = (hinfo->pci_bus << 8) | adapter->
pdev->devfn;
3843 hinfo->host_no = adapter->
host->host_no;
3867 megaraid_sysfs_alloc_resources(
adapter_t *adapter)
3883 "megaraid: out of memory, %s %d\n", __func__,
3888 megaraid_sysfs_free_resources(adapter);
3906 megaraid_sysfs_free_resources(
adapter_t *adapter)
3927 megaraid_sysfs_get_ldmap_done(uioc_t *
uioc)
3947 megaraid_sysfs_get_ldmap_timeout(
unsigned long data)
3949 uioc_t *uioc = (uioc_t *)data;
3953 uioc->status = -
ETIME;
3977 megaraid_sysfs_get_ldmap(
adapter_t *adapter)
3998 memset(uioc, 0,
sizeof(uioc_t));
3999 memset(mbox64, 0,
sizeof(mbox64_t));
4002 mbox = &mbox64->mbox32;
4003 raw_mbox = (
char *)mbox;
4004 uioc->cmdbuf = (
uint64_t)(
unsigned long)mbox64;
4005 uioc->buf_vaddr = (
caddr_t)adapter;
4007 uioc->done = megaraid_sysfs_get_ldmap_done;
4021 timerp = &sysfs_timer;
4024 timerp->
function = megaraid_sysfs_get_ldmap_timeout;
4025 timerp->
data = (
unsigned long)uioc;
4033 rval = megaraid_mbox_mm_command(adapter, uioc);
4041 if (uioc->status == -
ETIME) {
4043 "megaraid: sysfs get ld map timed out\n"));
4048 rval = mbox->status;
4057 "megaraid: get ld map failed with %x\n", rval));
4062 "megaraid: could not issue ldmap command:%x\n", rval));
4093 return snprintf(buf, 8,
"%u\n", app_hndl);
4119 int logical_drv = -1;
4129 rval = megaraid_sysfs_get_ldmap(adapter);
4134 mapped_sdev_id = sdev->
id;
4137 mapped_sdev_id -= 1;
4140 if (raid_dev->
curr_ldmap[i] == mapped_sdev_id) {
4157 "megaraid: sysfs get ld map failed: %x\n",
4162 return snprintf(buf, 36,
"%d %d %d %d\n", scsi_id, logical_drv,
4163 ldid_map, app_hndl);