35 #include <linux/kernel.h>
36 #include <linux/types.h>
37 #include <linux/pci.h>
38 #include <linux/list.h>
40 #include <linux/module.h>
44 #include <linux/uio.h>
45 #include <linux/slab.h>
46 #include <asm/uaccess.h>
51 #include <linux/poll.h>
53 #include <scsi/scsi.h>
65 static unsigned int max_sectors;
68 "Maximum number of sectors per IO command");
70 static int msix_disable;
72 MODULE_PARM_DESC(msix_disable,
"Disable MSI-X interrupt handling. Default: 0");
81 "Adapter queue depth when throttled due to I/O timeout. Default: 16");
86 "before resetting adapter. Default: 180");
130 static int megasas_mgmt_majorno;
135 static int megasas_poll_wait_aen;
137 static u32 support_poll_for_event;
139 static u32 support_device_change;
152 static irqreturn_t megasas_isr(
int irq,
void *devp);
158 static void megasas_complete_cmd_dpc(
unsigned long instance_addr);
198 if (!list_empty(&instance->
cmd_pool)) {
201 list_del_init(&cmd->
list);
249 readl(®s->outbound_intr_mask);
260 writel(mask, ®s->outbound_intr_mask);
262 readl(®s->outbound_intr_mask);
286 status =
readl(®s->outbound_intr_status);
297 writel(status, ®s->outbound_intr_status);
300 readl(®s->outbound_intr_status);
319 writel((frame_phys_addr >> 3)|(frame_count),
321 spin_unlock_irqrestore(&instance->
hba_lock, flags);
336 for (i = 0; i < 3; i++)
344 pci_write_config_dword(instance->
pdev,
347 for (i = 0; i < 2; i++)
351 pci_read_config_dword(instance->
pdev,
357 pci_write_config_dword(instance->
pdev,
384 .fire_cmd = megasas_fire_cmd_xscale,
385 .enable_intr = megasas_enable_intr_xscale,
386 .disable_intr = megasas_disable_intr_xscale,
387 .clear_intr = megasas_clear_intr_xscale,
388 .read_fw_status_reg = megasas_read_fw_status_reg_xscale,
389 .adp_reset = megasas_adp_reset_xscale,
390 .check_reset = megasas_check_reset_xscale,
391 .service_isr = megasas_isr,
392 .tasklet = megasas_complete_cmd_dpc,
393 .init_adapter = megasas_init_adapter_mfi,
420 readl(®s->outbound_intr_mask);
431 writel(mask, ®s->outbound_intr_mask);
433 readl(®s->outbound_intr_mask);
458 status =
readl(®s->outbound_intr_status);
469 writel(status, ®s->outbound_doorbell_clear);
472 readl(®s->outbound_doorbell_clear);
491 writel((frame_phys_addr | (frame_count<<1))|1,
493 spin_unlock_irqrestore(&instance->
hba_lock, flags);
512 .fire_cmd = megasas_fire_cmd_ppc,
513 .enable_intr = megasas_enable_intr_ppc,
514 .disable_intr = megasas_disable_intr_ppc,
515 .clear_intr = megasas_clear_intr_ppc,
516 .read_fw_status_reg = megasas_read_fw_status_reg_ppc,
517 .adp_reset = megasas_adp_reset_xscale,
518 .check_reset = megasas_check_reset_ppc,
519 .service_isr = megasas_isr,
520 .tasklet = megasas_complete_cmd_dpc,
521 .init_adapter = megasas_init_adapter_mfi,
538 readl(®s->outbound_intr_mask);
549 writel(mask, ®s->outbound_intr_mask);
551 readl(®s->outbound_intr_mask);
577 status =
readl(®s->outbound_intr_status);
595 writel(status, ®s->outbound_intr_status);
600 readl(®s->outbound_intr_status);
620 writel((frame_phys_addr | (frame_count<<1))|1,
622 spin_unlock_irqrestore(&instance->
hba_lock, flags);
641 .fire_cmd = megasas_fire_cmd_skinny,
642 .enable_intr = megasas_enable_intr_skinny,
643 .disable_intr = megasas_disable_intr_skinny,
644 .clear_intr = megasas_clear_intr_skinny,
645 .read_fw_status_reg = megasas_read_fw_status_reg_skinny,
646 .adp_reset = megasas_adp_reset_gen2,
647 .check_reset = megasas_check_reset_skinny,
648 .service_isr = megasas_isr,
649 .tasklet = megasas_complete_cmd_dpc,
650 .init_adapter = megasas_init_adapter_mfi,
674 readl(®s->outbound_intr_mask);
685 writel(mask, ®s->outbound_intr_mask);
687 readl(®s->outbound_intr_mask);
712 status =
readl(®s->outbound_intr_status);
725 writel(status, ®s->outbound_doorbell_clear);
728 readl(®s->outbound_intr_status);
746 writel((frame_phys_addr | (frame_count<<1))|1,
748 spin_unlock_irqrestore(&instance->
hba_lock, flags);
762 u32 *hostdiag_offset = ®_set->host_diag;
764 if (instance->
instancet == &megasas_instance_template_skinny) {
765 seq_offset = ®_set->fusion_seq_offset;
766 hostdiag_offset = ®_set->fusion_host_diag;
778 HostDiag = (
u32)
readl(hostdiag_offset);
782 HostDiag = (
u32)
readl(hostdiag_offset);
797 HostDiag = (
u32)
readl(hostdiag_offset);
800 HostDiag = (
u32)
readl(hostdiag_offset);
828 .fire_cmd = megasas_fire_cmd_gen2,
829 .enable_intr = megasas_enable_intr_gen2,
830 .disable_intr = megasas_disable_intr_gen2,
831 .clear_intr = megasas_clear_intr_gen2,
832 .read_fw_status_reg = megasas_read_fw_status_reg_gen2,
833 .adp_reset = megasas_adp_reset_gen2,
834 .check_reset = megasas_check_reset_gen2,
835 .service_isr = megasas_isr,
836 .tasklet = megasas_complete_cmd_dpc,
837 .init_adapter = megasas_init_adapter_mfi,
871 instance->
instancet->issue_dcmd(instance, cmd);
894 instance->
instancet->issue_dcmd(instance, cmd);
938 instance->
instancet->issue_dcmd(instance, cmd);
1069 num_cnt = sge_count - 1;
1071 num_cnt = sge_count - 1;
1073 num_cnt = sge_count - 2;
1076 num_cnt = sge_count - 1;
1078 num_cnt = sge_count - 2;
1080 num_cnt = sge_count - 3;
1084 sge_bytes = sge_sz * num_cnt;
1092 if (frame_count > 7)
1151 if ((scp->
request->timeout /
HZ) > 0xFFFF)
1162 pthru->
sge_count = megasas_make_sgl_skinny(instance, scp,
1166 pthru->
sge_count = megasas_make_sgl64(instance, scp,
1169 pthru->
sge_count = megasas_make_sgl32(instance, scp,
1252 else if (scp->
cmd_len == 10) {
1263 else if (scp->
cmd_len == 12) {
1276 else if (scp->
cmd_len == 16) {
1296 ldio->
sge_count = megasas_make_sgl_skinny(instance, scp,
1300 ldio->
sge_count = megasas_make_sgl64(instance, scp, &ldio->
sgl);
1302 ldio->
sge_count = megasas_make_sgl32(instance, scp, &ldio->
sgl);
1321 cmd->
frame_count = megasas_get_frame_count(instance,
1338 switch (cmd->
cmnd[0]) {
1369 printk(
KERN_ERR "\nmegasas[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->
host->host_no);
1372 printk(
KERN_ERR "\nmegasas[%d]: 64 bit SGLs were sent to FW\n",instance->
host->host_no);
1374 printk(
KERN_ERR "\nmegasas[%d]: 32 bit SGLs were sent to FW\n",instance->
host->host_no);
1377 for (i = 0; i < max_cmd; i++) {
1384 mfi_sgl = &ldio->
sgl;
1386 printk(
KERN_ERR "megasas[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x, lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n",instance->
host->host_no, cmd->
frame_count,ldio->
cmd,ldio->
target_id, ldio->
start_lba_lo,ldio->
start_lba_hi,ldio->
sense_buf_phys_addr_lo,sgcount);
1390 mfi_sgl = &pthru->
sgl;
1392 printk(
KERN_ERR "megasas[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x, lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n",instance->
host->host_no,cmd->
frame_count,pthru->
cmd,pthru->
target_id,pthru->
lun,pthru->
cdb_len , pthru->
data_xfer_len,pthru->
sense_buf_phys_addr_lo,sgcount);
1395 for (n = 0; n < sgcount; n++){
1397 printk(
KERN_ERR "megasas: sgl len : 0x%x, sgl addr : 0x%08lx ",mfi_sgl->
sge64[n].length , (
unsigned long)mfi_sgl->
sge64[n].phys_addr) ;
1399 printk(
KERN_ERR "megasas: sgl len : 0x%x, sgl addr : 0x%x ",mfi_sgl->
sge32[n].length , mfi_sgl->
sge32[n].phys_addr) ;
1404 printk(
KERN_ERR "\nmegasas[%d]: Pending Internal cmds in FW : \n",instance->
host->host_no);
1405 for (i = 0; i < max_cmd; i++) {
1431 frame_count = megasas_build_ldio(instance, scmd, cmd);
1433 frame_count = megasas_build_dcdb(instance, scmd, cmd);
1436 goto out_return_cmd;
1439 scmd->
SCp.ptr = (
char *)cmd;
1465 unsigned long flags;
1468 scmd->
device->host->hostdata;
1475 spin_unlock_irqrestore(&instance->
hba_lock, flags);
1479 spin_unlock_irqrestore(&instance->
hba_lock, flags);
1490 switch (scmd->
cmnd[0]) {
1502 if (instance->
instancet->build_and_issue_cmd(instance, scmd)) {
1503 printk(
KERN_ERR "megasas: Err returned from build_and_issue_cmd\n");
1530 static int megasas_slave_configure(
struct scsi_device *sdev)
1535 instance = megasas_lookup_instance(sdev->
host->host_no);
1548 if (instance->
pd_list[pd_index].driveState ==
1565 static int megasas_slave_alloc(
struct scsi_device *sdev)
1569 instance = megasas_lookup_instance(sdev->
host->host_no);
1578 if ((instance->
pd_list[pd_index].driveState ==
1580 (instance->
pd_list[pd_index].driveType ==
1610 unsigned long flags;
1618 if ((instance->
pdev->device ==
1620 (instance->
pdev->device ==
1622 instance->
host->can_queue =
1625 instance->
host->can_queue =
1628 spin_unlock_irqrestore(instance->
host->host_lock, flags);
1638 static void megasas_complete_cmd_dpc(
unsigned long instance_addr)
1646 unsigned long flags;
1657 while (consumer != producer) {
1703 megasas_internal_reset_defer_cmds(instance);
1704 process_fw_state_change_wq(&instance->
work_init);
1721 unsigned long flags;
1725 u8 kill_adapter_flag;
1729 spin_unlock_irqrestore(&instance->
hba_lock, flags);
1733 INIT_LIST_HEAD(&clist_local);
1737 spin_unlock_irqrestore(&instance->
hba_lock, flags);
1744 spin_unlock_irqrestore(&instance->
hba_lock, flags);
1753 spin_unlock_irqrestore(&instance->
hba_lock, flags);
1758 while (!list_empty(&clist_local)) {
1761 list_del_init(&reset_cmd->
list);
1762 if (reset_cmd->
scmd) {
1765 reset_index, reset_cmd,
1766 reset_cmd->
scmd->cmnd[0]);
1768 reset_cmd->
scmd->scsi_done(reset_cmd->
scmd);
1799 "commands to complete\n",i,outstanding);
1804 megasas_complete_cmd_dpc((
unsigned long)instance);
1811 kill_adapter_flag = 0;
1813 fw_state = instance->
instancet->read_fw_status_reg(
1818 kill_adapter_flag = 2;
1822 kill_adapter_flag = 1;
1831 !kill_adapter_flag) {
1848 (kill_adapter_flag == 2)) {
1854 if ((instance->
pdev->device ==
1856 (instance->
pdev->device ==
1859 &instance->
reg_set->doorbell);
1862 &instance->
reg_set->inbound_doorbell);
1864 megasas_dump_pending_frames(instance);
1867 spin_unlock_irqrestore(&instance->
hba_lock, flags);
1884 static int megasas_generic_reset(
struct scsi_cmnd *scmd)
1900 ret_val = megasas_wait_for_outstanding(instance);
1917 blk_eh_timer_return megasas_reset_timer(
struct scsi_cmnd *scmd)
1920 unsigned long flags;
1924 return BLK_EH_NOT_HANDLED;
1936 spin_unlock_irqrestore(instance->
host->host_lock, flags);
1938 return BLK_EH_RESET_TIMER;
1944 static int megasas_reset_device(
struct scsi_cmnd *scmd)
1951 ret = megasas_generic_reset(scmd);
1959 static int megasas_reset_bus_host(
struct scsi_cmnd *scmd)
1972 ret = megasas_generic_reset(scmd);
2005 if (capacity >= 0x200000) {
2037 unsigned long flags;
2043 megasas_poll_wait_aen = 1;
2044 spin_unlock_irqrestore(&poll_aen_lock, flags);
2054 if ((instance->
unload == 0) &&
2064 megasas_aen_polling);
2070 static int megasas_change_queue_depth(
struct scsi_device *sdev,
2076 if (queue_depth > sdev->
host->can_queue)
2077 queue_depth = sdev->
host->can_queue;
2090 .name =
"LSI SAS based MegaRAID driver",
2091 .proc_name =
"megaraid_sas",
2092 .slave_configure = megasas_slave_configure,
2093 .slave_alloc = megasas_slave_alloc,
2094 .queuecommand = megasas_queue_command,
2095 .eh_device_reset_handler = megasas_reset_device,
2096 .eh_bus_reset_handler = megasas_reset_bus_host,
2097 .eh_host_reset_handler = megasas_reset_bus_host,
2098 .eh_timed_out = megasas_reset_timer,
2099 .bios_param = megasas_bios_param,
2101 .change_queue_depth = megasas_change_queue_depth,
2163 unsigned long flags;
2181 "other than PERC5, please upgrade your firmware.\n");
2193 megasas_complete_int_cmd(instance, cmd);
2201 cmd->
scmd->result = alt_status << 16;
2270 if (cmd->
frame->
hdr.cmd_status != 0) {
2274 "failed, status = 0x%x.\n",
2278 spin_unlock_irqrestore(
2279 instance->
host->host_lock,
2293 spin_unlock_irqrestore(instance->
host->host_lock,
2300 megasas_poll_wait_aen = 0;
2301 spin_unlock_irqrestore(&poll_aen_lock, flags);
2308 megasas_service_aen(instance, cmd);
2310 megasas_complete_int_cmd(instance, cmd);
2318 megasas_complete_abort(instance, cmd);
2322 printk(
"megasas: Unknown command completed! [0x%X]\n",
2339 unsigned long flags;
2342 INIT_LIST_HEAD(&clist_local);
2345 spin_unlock_irqrestore(&instance->
hba_lock, flags);
2347 while (!list_empty(&clist_local)) {
2350 list_del_init(&cmd->
list);
2354 "detected to be pending while HBA reset.\n",
2361 "was tried multiple times during reset."
2362 "Shutting down the HBA\n",
2375 "cmd attached to internal command!\n");
2378 "on the internal reset queue,"
2379 "issue it again.\n", cmd);
2384 }
else if (cmd->
scmd) {
2386 "detected on the internal queue, issue again.\n",
2387 cmd, cmd->
scmd->cmnd[0]);
2395 "internal reset defer list while re-issue!!\n",
2411 class_locale.members.reserved = 0;
2415 megasas_register_aen(instance, seq_num, class_locale.word);
2434 unsigned long flags;
2438 for (i = 0; i < max_cmd; i++) {
2442 "on the defer queue as internal\n",
2445 if (!list_empty(&cmd->
list)) {
2447 " moving this cmd:%p, %d %p, it was"
2448 "discovered on some list?\n",
2451 list_del_init(&cmd->
list);
2468 unsigned long flags;
2478 "state, restarting it...\n");
2488 "initiating next stage...\n");
2491 "state 2 starting...\n");
2494 for (wait = 0; wait < 30; wait++) {
2516 megasas_issue_init_mfi(instance);
2520 spin_unlock_irqrestore(&instance->
hba_lock, flags);
2523 megasas_issue_pending_cmds_again(instance);
2544 if ((mfiStatus = instance->
instancet->check_reset(instance,
2549 if ((mfiStatus = instance->
instancet->clear_intr(
2560 fw_state = instance->
instancet->read_fw_status_reg(
2572 if ((instance->
pdev->device ==
2574 (instance->
pdev->device ==
2576 (instance->
pdev->device ==
2589 megasas_internal_reset_defer_cmds(instance);
2609 static irqreturn_t megasas_isr(
int irq,
void *devp)
2613 unsigned long flags;
2620 rc = megasas_deplete_reply_queue(instance,
DID_OK);
2621 spin_unlock_irqrestore(&instance->
hba_lock, flags);
2642 u32 abs_state, curr_abs_state;
2670 if ((instance->
pdev->device ==
2672 (instance->
pdev->device ==
2674 (instance->
pdev->device ==
2676 (instance->
pdev->device ==
2680 &instance->
reg_set->doorbell);
2684 &instance->
reg_set->inbound_doorbell);
2692 if ((instance->
pdev->device ==
2694 (instance->
pdev->device ==
2696 (instance->
pdev->device ==
2698 (instance->
pdev->device ==
2701 &instance->
reg_set->doorbell);
2704 &instance->
reg_set->inbound_doorbell);
2715 if ((instance->
pdev->device ==
2717 (instance->
pdev->device ==
2719 (instance->
pdev->device
2721 (instance->
pdev->device
2724 &instance->
reg_set->doorbell);
2725 if ((instance->
pdev->device ==
2727 (instance->
pdev->device ==
2729 for (i = 0; i < (10 * 1000); i += 20) {
2741 &instance->
reg_set->inbound_doorbell);
2789 for (i = 0; i < (max_wait * 1000); i++) {
2795 if (abs_state == curr_abs_state) {
2804 if (curr_abs_state == abs_state) {
2806 "in %d secs\n", fw_state, max_wait);
2831 for (i = 0; i < max_cmd; i++) {
2903 instance->
pdev, total_sz, 64,
2912 instance->
pdev, 128, 4, 0);
2928 for (i = 0; i < max_cmd; i++) {
2944 megasas_teardown_frame_pool(instance);
2968 megasas_teardown_frame_pool(instance);
2979 INIT_LIST_HEAD(&instance->
cmd_pool);
3023 for (i = 0; i < max_cmd; i++) {
3029 for (j = 0; j <
i; j++)
3042 for (i = 0; i < max_cmd; i++) {
3055 if (megasas_create_frame_pool(instance)) {
3075 int ret = 0, pd_index = 0;
3100 memset(ci, 0,
sizeof(*ci));
3104 dcmd->
mbox.
b[1] = 0;
3113 dcmd->
sgl.
sge32[0].phys_addr = ci_h;
3135 for (pd_index = 0; pd_index < ci->
count; pd_index++) {
3167 int ret = 0,
ld_index = 0, ids = 0;
3192 memset(ci, 0,
sizeof(*ci));
3202 dcmd->
sgl.
sge32[0].phys_addr = ci_h;
3272 memset(ci, 0,
sizeof(*ci));
3283 dcmd->
sgl.
sge32[0].phys_addr = ci_h;
3330 ((
unsigned long)init_frame + 64);
3333 initq_info_h = init_frame_h + 64;
3335 context = init_frame->
context;
3401 goto fail_alloc_cmds;
3412 context_sz =
sizeof(
u32);
3413 reply_q_sz = context_sz * (instance->
max_fw_cmds + 1);
3421 goto fail_reply_queue;
3424 if (megasas_issue_init_mfi(instance))
3429 (instance->
instancet->read_fw_status_reg(reg_set) &
3462 u32 tmp_sectors, msix_enable;
3465 unsigned long bar_list;
3487 switch (instance->
pdev->device) {
3494 instance->
instancet = &megasas_instance_template_ppc;
3498 instance->
instancet = &megasas_instance_template_gen2;
3502 instance->
instancet = &megasas_instance_template_skinny;
3507 instance->
instancet = &megasas_instance_template_xscale;
3515 goto fail_ready_state;
3518 msix_enable = (instance->
instancet->read_fw_status_reg(reg_set) &
3520 if (msix_enable && !msix_disable) {
3553 if (instance->
instancet->init_adapter(instance))
3554 goto fail_init_adapter;
3564 megasas_get_pd_list(instance);
3567 megasas_get_ld_list(instance);
3581 if (ctrl_info && !megasas_get_ctrl_info(instance, ctrl_info)) {
3583 max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.
min) *
3587 tmp_sectors =
min_t(
u32, max_sectors_1 , max_sectors_2);
3589 ctrl_info->
properties.OnOffProperties.disableOnlineCtrlReset;
3622 (
unsigned long)instance);
3692 memset(el_info, 0,
sizeof(*el_info));
3703 dcmd->
sgl.
sge32[0].phys_addr = el_info_h;
3706 megasas_issue_blocked_cmd(instance, cmd);
3714 el_info, el_info_h);
3757 prev_aen.word = instance->
aen_cmd->frame->dcmd.mbox.w[1];
3769 if ((prev_aen.members.class <= curr_aen.members.class) &&
3770 !((prev_aen.members.locale & curr_aen.members.locale) ^
3771 curr_aen.members.locale)) {
3778 curr_aen.members.locale |= prev_aen.members.locale;
3780 if (prev_aen.members.class < curr_aen.members.class)
3781 curr_aen.members.class = prev_aen.members.class;
3783 instance->
aen_cmd->abort_aen = 1;
3784 ret_val = megasas_issue_blocked_abort_cmd(instance,
3790 "previous AEN command\n");
3820 dcmd->
mbox.
w[1] = curr_aen.word;
3839 instance->
instancet->issue_dcmd(instance, cmd);
3856 memset(&eli, 0,
sizeof(eli));
3858 if (megasas_get_seq_num(instance, &eli))
3864 class_locale.members.reserved = 0;
3883 host->
irq = instance->
pdev->irq;
3901 if (
max_sectors && max_sectors < instance->max_sectors_per_req)
3905 if (((instance->
pdev->device ==
3907 (instance->
pdev->device ==
3913 "and <= %d (or < 1MB for GEN2 controller)\n",
3929 host->
hostt->eh_device_reset_handler =
NULL;
3930 host->
hostt->eh_bus_reset_handler =
NULL;
3936 if (scsi_add_host(host, &instance->
pdev->dev)) {
3949 megasas_set_dma_mask(
struct pci_dev *pdev)
3958 goto fail_set_dma_mask;
3962 goto fail_set_dma_mask;
3978 int rval,
pos,
i,
j;
3991 pci_write_config_word(pdev,
3994 ~PCI_MSIX_FLAGS_ENABLE);
4006 printk(
"bus %d:slot %d:func %d\n",
4020 if (megasas_set_dma_mask(pdev))
4021 goto fail_set_dma_mask;
4028 goto fail_alloc_instance;
4032 memset(instance, 0,
sizeof(*instance));
4036 switch (instance->
pdev->device) {
4046 "memory for Fusion context info\n");
4047 goto fail_alloc_dma_buf;
4065 "memory for producer, consumer\n");
4066 goto fail_alloc_dma_buf;
4074 megasas_poll_wait_aen = 0;
4079 megasas_poll_wait_aen = 0;
4088 "event detail structure\n");
4089 goto fail_alloc_dma_buf;
4095 INIT_LIST_HEAD(&instance->
cmd_pool);
4113 instance->
host = host;
4139 if (megasas_init_fw(instance))
4154 "register IRQ for vector %d.\n", i);
4155 for (j = 0 ; j <
i ; j++)
4178 pci_set_drvdata(pdev, instance);
4191 if (megasas_io_attach(instance))
4192 goto fail_io_attach;
4199 if (megasas_start_aen(instance)) {
4201 goto fail_start_aen;
4212 pci_set_drvdata(pdev,
NULL);
4225 megasas_release_mfi(instance);
4243 fail_alloc_instance:
4281 megasas_issue_blocked_cmd(instance, cmd);
4308 megasas_issue_blocked_abort_cmd(instance, instance->
aen_cmd);
4310 megasas_issue_blocked_abort_cmd(instance,
4325 megasas_issue_blocked_cmd(instance, cmd);
4345 instance = pci_get_drvdata(pdev);
4346 host = instance->
host;
4349 megasas_flush_cache(instance);
4353 if (instance->
ev !=
NULL) {
4361 pci_set_drvdata(instance->
pdev, instance);
4392 instance = pci_get_drvdata(pdev);
4393 host = instance->
host;
4395 pci_enable_wake(pdev,
PCI_D0, 0);
4410 if (megasas_set_dma_mask(pdev))
4411 goto fail_set_dma_mask;
4423 goto fail_ready_state;
4430 switch (instance->
pdev->device) {
4447 if (megasas_issue_init_mfi(instance))
4453 (
unsigned long)instance);
4467 "register IRQ for vector %d.\n", i);
4468 for (j = 0 ; j <
i ; j++)
4492 if (megasas_start_aen(instance))
4520 #define megasas_suspend NULL
4521 #define megasas_resume NULL
4535 instance = pci_get_drvdata(pdev);
4537 host = instance->
host;
4541 megasas_flush_cache(instance);
4545 if (instance->
ev !=
NULL) {
4566 pci_set_drvdata(instance->
pdev,
NULL);
4579 switch (instance->
pdev->device) {
4583 for (i = 0; i < 2 ; i++)
4593 megasas_release_mfi(instance);
4609 pci_set_drvdata(pdev,
NULL);
4620 static void megasas_shutdown(
struct pci_dev *pdev)
4626 megasas_flush_cache(instance);
4642 static int megasas_mgmt_open(
struct inode *
inode,
struct file *filep)
4659 static int megasas_mgmt_fasync(
int fd,
struct file *filep,
int mode)
4686 unsigned long flags;
4687 poll_wait(file, &megasas_poll_wait, wait);
4689 if (megasas_poll_wait_aen)
4693 spin_unlock_irqrestore(&poll_aen_lock, flags);
4714 unsigned long *sense_ptr;
4716 memset(kbuff_arr, 0,
sizeof(kbuff_arr));
4757 if (!ioc->
sgl[i].iov_len)
4761 ioc->
sgl[i].iov_len,
4763 if (!kbuff_arr[i]) {
4765 "kernel SGL buffer for IOCTL \n");
4782 (
u32) (ioc->
sgl[i].iov_len))) {
4798 *sense_ptr = sense_handle;
4806 megasas_issue_blocked_cmd(instance, cmd);
4814 ioc->
sgl[i].iov_len)) {
4828 sense_ptr = (
unsigned long *) ((
unsigned long)ioc->
frame.
raw +
4831 if (
copy_to_user((
void __user *)((
unsigned long)(*sense_ptr)),
4852 sense, sense_handle);
4855 for (i = 0; i < ioc->
sge_count && kbuff_arr[
i]; i++) {
4865 static int megasas_mgmt_ioctl_fw(
struct file *file,
unsigned long arg)
4873 unsigned long flags;
4885 instance = megasas_lookup_instance(ioc->
host_no);
4897 if (instance->
unload == 1) {
4914 spin_unlock_irqrestore(&instance->
hba_lock, flags);
4917 spin_unlock_irqrestore(&instance->
hba_lock, flags);
4919 if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
4921 "for controller reset to finish\n");
4929 spin_unlock_irqrestore(&instance->
hba_lock, flags);
4932 "waiting for HBA to recover\n");
4936 spin_unlock_irqrestore(&instance->
hba_lock, flags);
4938 error = megasas_mgmt_fw_ioctl(instance, user_ioc, ioc);
4946 static int megasas_mgmt_ioctl_aen(
struct file *file,
unsigned long arg)
4952 unsigned long flags;
4964 instance = megasas_lookup_instance(
aen.host_no);
4973 if (instance->
unload == 1) {
4981 spin_unlock_irqrestore(&instance->
hba_lock,
4986 spin_unlock_irqrestore(&instance->
hba_lock, flags);
4988 if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
4990 "controller reset to finish\n");
4998 spin_unlock_irqrestore(&instance->
hba_lock, flags);
5000 "for HBA to recover.\n");
5003 spin_unlock_irqrestore(&instance->
hba_lock, flags);
5006 error = megasas_register_aen(instance,
aen.seq_num,
5007 aen.class_locale_word);
5016 megasas_mgmt_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
5020 return megasas_mgmt_ioctl_fw(file, arg);
5023 return megasas_mgmt_ioctl_aen(file, arg);
5029 #ifdef CONFIG_COMPAT
5030 static int megasas_mgmt_compat_ioctl_fw(
struct file *file,
unsigned long arg)
5032 struct compat_megasas_iocpacket
__user *cioc =
5033 (
struct compat_megasas_iocpacket
__user *)arg;
5057 void __user **sense_ioc_ptr =
5061 if (
get_user(ptr, sense_cioc_ptr) ||
5062 put_user(compat_ptr(ptr), sense_ioc_ptr))
5067 if (
get_user(ptr, &cioc->sgl[i].iov_base) ||
5068 put_user(compat_ptr(ptr), &ioc->
sgl[i].iov_base) ||
5074 error = megasas_mgmt_ioctl_fw(file, (
unsigned long)ioc);
5085 megasas_mgmt_compat_ioctl(
struct file *file,
unsigned int cmd,
5089 case MEGASAS_IOC_FIRMWARE32:
5090 return megasas_mgmt_compat_ioctl_fw(file, arg);
5092 return megasas_mgmt_ioctl_aen(file, arg);
5104 .open = megasas_mgmt_open,
5105 .fasync = megasas_mgmt_fasync,
5106 .unlocked_ioctl = megasas_mgmt_ioctl,
5107 .poll = megasas_mgmt_poll,
5108 #ifdef CONFIG_COMPAT
5109 .compat_ioctl = megasas_mgmt_compat_ioctl,
5117 static struct pci_driver megasas_pci_driver = {
5119 .name =
"megaraid_sas",
5120 .id_table = megasas_pci_table,
5121 .probe = megasas_probe_one,
5125 .shutdown = megasas_shutdown,
5140 megasas_sysfs_show_release_date(
struct device_driver *dd,
char *buf)
5150 megasas_sysfs_show_support_poll_for_event(
struct device_driver *dd,
char *buf)
5152 return sprintf(buf,
"%u\n", support_poll_for_event);
5156 megasas_sysfs_show_support_poll_for_event,
NULL);
5159 megasas_sysfs_show_support_device_change(
struct device_driver *dd,
char *buf)
5161 return sprintf(buf,
"%u\n", support_device_change);
5165 megasas_sysfs_show_support_device_change,
NULL);
5168 megasas_sysfs_show_dbg_lvl(
struct device_driver *dd,
char *buf)
5185 megasas_sysfs_set_dbg_lvl);
5198 int i,
j, doscan = 0;
5208 host = instance->
host;
5213 if (megasas_get_pd_list(instance) == 0) {
5225 if (instance->
pd_list[pd_index].driveState
5241 if (megasas_get_pd_list(instance) == 0) {
5253 if (instance->
pd_list[pd_index].driveState
5273 megasas_get_ld_list(instance);
5283 i + MEGASAS_MAX_LD_CHANNELS,
5287 if (instance->
ld_ids[ld_index] != 0xff) {
5302 megasas_get_ld_list(instance);
5311 i+MEGASAS_MAX_LD_CHANNELS,
5314 if (instance->
ld_ids[ld_index] !=
5346 megasas_get_pd_list(instance);
5349 pd_index = i*MEGASAS_MAX_DEV_PER_CHANNEL +
j;
5351 if (instance->
pd_list[pd_index].driveState ==
5367 megasas_get_ld_list(instance);
5374 i+MEGASAS_MAX_LD_CHANNELS, j, 0);
5375 if (instance->
ld_ids[ld_index] != 0xff) {
5401 class_locale.members.reserved = 0;
5405 error = megasas_register_aen(instance, seq_num,
5418 static int __init megasas_init(
void)
5430 support_poll_for_event = 2;
5431 support_device_change = 1;
5438 rval = register_chrdev(0,
"megaraid_sas_ioctl", &megasas_mgmt_fops);
5445 megasas_mgmt_majorno = rval;
5450 rval = pci_register_driver(&megasas_pci_driver);
5458 &driver_attr_version);
5460 goto err_dcf_attr_ver;
5462 &driver_attr_release_date);
5464 goto err_dcf_rel_date;
5467 &driver_attr_support_poll_for_event);
5469 goto err_dcf_support_poll_for_event;
5472 &driver_attr_dbg_lvl);
5474 goto err_dcf_dbg_lvl;
5476 &driver_attr_support_device_change);
5478 goto err_dcf_support_device_change;
5482 err_dcf_support_device_change:
5484 &driver_attr_dbg_lvl);
5487 &driver_attr_support_poll_for_event);
5489 err_dcf_support_poll_for_event:
5491 &driver_attr_release_date);
5498 unregister_chrdev(megasas_mgmt_majorno,
"megaraid_sas_ioctl");
5505 static void __exit megasas_exit(
void)
5508 &driver_attr_dbg_lvl);
5510 &driver_attr_support_poll_for_event);
5512 &driver_attr_support_device_change);
5514 &driver_attr_release_date);
5518 unregister_chrdev(megasas_mgmt_majorno,
"megaraid_sas_ioctl");