aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/megaraid/megaraid_sas.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/megaraid/megaraid_sas.c')
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.c291
1 files changed, 141 insertions, 150 deletions
diff --git a/drivers/scsi/megaraid/megaraid_sas.c b/drivers/scsi/megaraid/megaraid_sas.c
index 511ed52a5807..a487f414960e 100644
--- a/drivers/scsi/megaraid/megaraid_sas.c
+++ b/drivers/scsi/megaraid/megaraid_sas.c
@@ -10,7 +10,7 @@
10 * 2 of the License, or (at your option) any later version. 10 * 2 of the License, or (at your option) any later version.
11 * 11 *
12 * FILE : megaraid_sas.c 12 * FILE : megaraid_sas.c
13 * Version : v00.00.02.00-rc4 13 * Version : v00.00.02.02
14 * 14 *
15 * Authors: 15 * Authors:
16 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsil.com> 16 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsil.com>
@@ -55,13 +55,13 @@ static struct pci_device_id megasas_pci_table[] = {
55 55
56 { 56 {
57 PCI_VENDOR_ID_LSI_LOGIC, 57 PCI_VENDOR_ID_LSI_LOGIC,
58 PCI_DEVICE_ID_LSI_SAS1064R, 58 PCI_DEVICE_ID_LSI_SAS1064R, // xscale IOP
59 PCI_ANY_ID, 59 PCI_ANY_ID,
60 PCI_ANY_ID, 60 PCI_ANY_ID,
61 }, 61 },
62 { 62 {
63 PCI_VENDOR_ID_DELL, 63 PCI_VENDOR_ID_DELL,
64 PCI_DEVICE_ID_DELL_PERC5, 64 PCI_DEVICE_ID_DELL_PERC5, // xscale IOP
65 PCI_ANY_ID, 65 PCI_ANY_ID,
66 PCI_ANY_ID, 66 PCI_ANY_ID,
67 }, 67 },
@@ -119,12 +119,18 @@ megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
119 spin_unlock_irqrestore(&instance->cmd_pool_lock, flags); 119 spin_unlock_irqrestore(&instance->cmd_pool_lock, flags);
120} 120}
121 121
122
123/**
124* The following functions are defined for xscale
125* (deviceid : 1064R, PERC5) controllers
126*/
127
122/** 128/**
123 * megasas_enable_intr - Enables interrupts 129 * megasas_enable_intr_xscale - Enables interrupts
124 * @regs: MFI register set 130 * @regs: MFI register set
125 */ 131 */
126static inline void 132static inline void
127megasas_enable_intr(struct megasas_register_set __iomem * regs) 133megasas_enable_intr_xscale(struct megasas_register_set __iomem * regs)
128{ 134{
129 writel(1, &(regs)->outbound_intr_mask); 135 writel(1, &(regs)->outbound_intr_mask);
130 136
@@ -133,13 +139,73 @@ megasas_enable_intr(struct megasas_register_set __iomem * regs)
133} 139}
134 140
135/** 141/**
142 * megasas_read_fw_status_reg_xscale - returns the current FW status value
143 * @regs: MFI register set
144 */
145static u32
146megasas_read_fw_status_reg_xscale(struct megasas_register_set __iomem * regs)
147{
148 return readl(&(regs)->outbound_msg_0);
149}
150/**
151 * megasas_clear_interrupt_xscale - Check & clear interrupt
152 * @regs: MFI register set
153 */
154static int
155megasas_clear_intr_xscale(struct megasas_register_set __iomem * regs)
156{
157 u32 status;
158 /*
159 * Check if it is our interrupt
160 */
161 status = readl(&regs->outbound_intr_status);
162
163 if (!(status & MFI_OB_INTR_STATUS_MASK)) {
164 return 1;
165 }
166
167 /*
168 * Clear the interrupt by writing back the same value
169 */
170 writel(status, &regs->outbound_intr_status);
171
172 return 0;
173}
174
175/**
176 * megasas_fire_cmd_xscale - Sends command to the FW
177 * @frame_phys_addr : Physical address of cmd
178 * @frame_count : Number of frames for the command
179 * @regs : MFI register set
180 */
181static inline void
182megasas_fire_cmd_xscale(dma_addr_t frame_phys_addr,u32 frame_count, struct megasas_register_set __iomem *regs)
183{
184 writel((frame_phys_addr >> 3)|(frame_count),
185 &(regs)->inbound_queue_port);
186}
187
188static struct megasas_instance_template megasas_instance_template_xscale = {
189
190 .fire_cmd = megasas_fire_cmd_xscale,
191 .enable_intr = megasas_enable_intr_xscale,
192 .clear_intr = megasas_clear_intr_xscale,
193 .read_fw_status_reg = megasas_read_fw_status_reg_xscale,
194};
195
196/**
197* This is the end of set of functions & definitions specific
198* to xscale (deviceid : 1064R, PERC5) controllers
199*/
200
201/**
136 * megasas_disable_intr - Disables interrupts 202 * megasas_disable_intr - Disables interrupts
137 * @regs: MFI register set 203 * @regs: MFI register set
138 */ 204 */
139static inline void 205static inline void
140megasas_disable_intr(struct megasas_register_set __iomem * regs) 206megasas_disable_intr(struct megasas_register_set __iomem * regs)
141{ 207{
142 u32 mask = readl(&regs->outbound_intr_mask) & (~0x00000001); 208 u32 mask = 0x1f;
143 writel(mask, &regs->outbound_intr_mask); 209 writel(mask, &regs->outbound_intr_mask);
144 210
145 /* Dummy readl to force pci flush */ 211 /* Dummy readl to force pci flush */
@@ -167,8 +233,7 @@ megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd)
167 /* 233 /*
168 * Issue the frame using inbound queue port 234 * Issue the frame using inbound queue port
169 */ 235 */
170 writel(cmd->frame_phys_addr >> 3, 236 instance->instancet->fire_cmd(cmd->frame_phys_addr ,0,instance->reg_set);
171 &instance->reg_set->inbound_queue_port);
172 237
173 /* 238 /*
174 * Wait for cmd_status to change 239 * Wait for cmd_status to change
@@ -198,8 +263,7 @@ megasas_issue_blocked_cmd(struct megasas_instance *instance,
198{ 263{
199 cmd->cmd_status = ENODATA; 264 cmd->cmd_status = ENODATA;
200 265
201 writel(cmd->frame_phys_addr >> 3, 266 instance->instancet->fire_cmd(cmd->frame_phys_addr ,0,instance->reg_set);
202 &instance->reg_set->inbound_queue_port);
203 267
204 wait_event(instance->int_cmd_wait_q, (cmd->cmd_status != ENODATA)); 268 wait_event(instance->int_cmd_wait_q, (cmd->cmd_status != ENODATA));
205 269
@@ -242,8 +306,7 @@ megasas_issue_blocked_abort_cmd(struct megasas_instance *instance,
242 cmd->sync_cmd = 1; 306 cmd->sync_cmd = 1;
243 cmd->cmd_status = 0xFF; 307 cmd->cmd_status = 0xFF;
244 308
245 writel(cmd->frame_phys_addr >> 3, 309 instance->instancet->fire_cmd(cmd->frame_phys_addr ,0,instance->reg_set);
246 &instance->reg_set->inbound_queue_port);
247 310
248 /* 311 /*
249 * Wait for this cmd to complete 312 * Wait for this cmd to complete
@@ -558,112 +621,29 @@ megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp,
558} 621}
559 622
560/** 623/**
561 * megasas_build_cmd - Prepares a command packet 624 * megasas_is_ldio - Checks if the cmd is for logical drive
562 * @instance: Adapter soft state 625 * @scmd: SCSI command
563 * @scp: SCSI command 626 *
564 * @frame_count: [OUT] Number of frames used to prepare this command 627 * Called by megasas_queue_command to find out if the command to be queued
628 * is a logical drive command
565 */ 629 */
566static struct megasas_cmd *megasas_build_cmd(struct megasas_instance 630static inline int megasas_is_ldio(struct scsi_cmnd *cmd)
567 *instance,
568 struct scsi_cmnd *scp,
569 int *frame_count)
570{ 631{
571 u32 logical_cmd; 632 if (!MEGASAS_IS_LOGICAL(cmd))
572 struct megasas_cmd *cmd; 633 return 0;
573 634 switch (cmd->cmnd[0]) {
574 /* 635 case READ_10:
575 * Find out if this is logical or physical drive command. 636 case WRITE_10:
576 */ 637 case READ_12:
577 logical_cmd = MEGASAS_IS_LOGICAL(scp); 638 case WRITE_12:
578 639 case READ_6:
579 /* 640 case WRITE_6:
580 * Logical drive command 641 case READ_16:
581 */ 642 case WRITE_16:
582 if (logical_cmd) { 643 return 1;
583 644 default:
584 if (scp->device->id >= MEGASAS_MAX_LD) { 645 return 0;
585 scp->result = DID_BAD_TARGET << 16;
586 return NULL;
587 }
588
589 switch (scp->cmnd[0]) {
590
591 case READ_10:
592 case WRITE_10:
593 case READ_12:
594 case WRITE_12:
595 case READ_6:
596 case WRITE_6:
597 case READ_16:
598 case WRITE_16:
599 /*
600 * Fail for LUN > 0
601 */
602 if (scp->device->lun) {
603 scp->result = DID_BAD_TARGET << 16;
604 return NULL;
605 }
606
607 cmd = megasas_get_cmd(instance);
608
609 if (!cmd) {
610 scp->result = DID_IMM_RETRY << 16;
611 return NULL;
612 }
613
614 *frame_count = megasas_build_ldio(instance, scp, cmd);
615
616 if (!(*frame_count)) {
617 megasas_return_cmd(instance, cmd);
618 return NULL;
619 }
620
621 return cmd;
622
623 default:
624 /*
625 * Fail for LUN > 0
626 */
627 if (scp->device->lun) {
628 scp->result = DID_BAD_TARGET << 16;
629 return NULL;
630 }
631
632 cmd = megasas_get_cmd(instance);
633
634 if (!cmd) {
635 scp->result = DID_IMM_RETRY << 16;
636 return NULL;
637 }
638
639 *frame_count = megasas_build_dcdb(instance, scp, cmd);
640
641 if (!(*frame_count)) {
642 megasas_return_cmd(instance, cmd);
643 return NULL;
644 }
645
646 return cmd;
647 }
648 } else {
649 cmd = megasas_get_cmd(instance);
650
651 if (!cmd) {
652 scp->result = DID_IMM_RETRY << 16;
653 return NULL;
654 }
655
656 *frame_count = megasas_build_dcdb(instance, scp, cmd);
657
658 if (!(*frame_count)) {
659 megasas_return_cmd(instance, cmd);
660 return NULL;
661 }
662
663 return cmd;
664 } 646 }
665
666 return NULL;
667} 647}
668 648
669/** 649/**
@@ -684,13 +664,27 @@ megasas_queue_command(struct scsi_cmnd *scmd, void (*done) (struct scsi_cmnd *))
684 scmd->scsi_done = done; 664 scmd->scsi_done = done;
685 scmd->result = 0; 665 scmd->result = 0;
686 666
687 cmd = megasas_build_cmd(instance, scmd, &frame_count); 667 if (MEGASAS_IS_LOGICAL(scmd) &&
688 668 (scmd->device->id >= MEGASAS_MAX_LD || scmd->device->lun)) {
689 if (!cmd) { 669 scmd->result = DID_BAD_TARGET << 16;
690 done(scmd); 670 goto out_done;
691 return 0;
692 } 671 }
693 672
673 cmd = megasas_get_cmd(instance);
674 if (!cmd)
675 return SCSI_MLQUEUE_HOST_BUSY;
676
677 /*
678 * Logical drive command
679 */
680 if (megasas_is_ldio(scmd))
681 frame_count = megasas_build_ldio(instance, scmd, cmd);
682 else
683 frame_count = megasas_build_dcdb(instance, scmd, cmd);
684
685 if (!frame_count)
686 goto out_return_cmd;
687
694 cmd->scmd = scmd; 688 cmd->scmd = scmd;
695 scmd->SCp.ptr = (char *)cmd; 689 scmd->SCp.ptr = (char *)cmd;
696 scmd->SCp.sent_command = jiffies; 690 scmd->SCp.sent_command = jiffies;
@@ -702,10 +696,15 @@ megasas_queue_command(struct scsi_cmnd *scmd, void (*done) (struct scsi_cmnd *))
702 instance->fw_outstanding++; 696 instance->fw_outstanding++;
703 spin_unlock_irqrestore(&instance->instance_lock, flags); 697 spin_unlock_irqrestore(&instance->instance_lock, flags);
704 698
705 writel(((cmd->frame_phys_addr >> 3) | (cmd->frame_count - 1)), 699 instance->instancet->fire_cmd(cmd->frame_phys_addr ,cmd->frame_count-1,instance->reg_set);
706 &instance->reg_set->inbound_queue_port);
707 700
708 return 0; 701 return 0;
702
703 out_return_cmd:
704 megasas_return_cmd(instance, cmd);
705 out_done:
706 done(scmd);
707 return 0;
709} 708}
710 709
711/** 710/**
@@ -1108,7 +1107,6 @@ megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd,
1108static int 1107static int
1109megasas_deplete_reply_queue(struct megasas_instance *instance, u8 alt_status) 1108megasas_deplete_reply_queue(struct megasas_instance *instance, u8 alt_status)
1110{ 1109{
1111 u32 status;
1112 u32 producer; 1110 u32 producer;
1113 u32 consumer; 1111 u32 consumer;
1114 u32 context; 1112 u32 context;
@@ -1116,17 +1114,10 @@ megasas_deplete_reply_queue(struct megasas_instance *instance, u8 alt_status)
1116 1114
1117 /* 1115 /*
1118 * Check if it is our interrupt 1116 * Check if it is our interrupt
1117 * Clear the interrupt
1119 */ 1118 */
1120 status = readl(&instance->reg_set->outbound_intr_status); 1119 if(instance->instancet->clear_intr(instance->reg_set))
1121
1122 if (!(status & MFI_OB_INTR_STATUS_MASK)) {
1123 return IRQ_NONE; 1120 return IRQ_NONE;
1124 }
1125
1126 /*
1127 * Clear the interrupt by writing back the same value
1128 */
1129 writel(status, &instance->reg_set->outbound_intr_status);
1130 1121
1131 producer = *instance->producer; 1122 producer = *instance->producer;
1132 consumer = *instance->consumer; 1123 consumer = *instance->consumer;
@@ -1160,7 +1151,7 @@ static irqreturn_t megasas_isr(int irq, void *devp, struct pt_regs *regs)
1160 1151
1161/** 1152/**
1162 * megasas_transition_to_ready - Move the FW to READY state 1153 * megasas_transition_to_ready - Move the FW to READY state
1163 * @reg_set: MFI register set 1154 * @instance: Adapter soft state
1164 * 1155 *
1165 * During the initialization, FW passes can potentially be in any one of 1156 * During the initialization, FW passes can potentially be in any one of
1166 * several possible states. If the FW in operational, waiting-for-handshake 1157 * several possible states. If the FW in operational, waiting-for-handshake
@@ -1168,14 +1159,14 @@ static irqreturn_t megasas_isr(int irq, void *devp, struct pt_regs *regs)
1168 * has to wait for the ready state. 1159 * has to wait for the ready state.
1169 */ 1160 */
1170static int 1161static int
1171megasas_transition_to_ready(struct megasas_register_set __iomem * reg_set) 1162megasas_transition_to_ready(struct megasas_instance* instance)
1172{ 1163{
1173 int i; 1164 int i;
1174 u8 max_wait; 1165 u8 max_wait;
1175 u32 fw_state; 1166 u32 fw_state;
1176 u32 cur_state; 1167 u32 cur_state;
1177 1168
1178 fw_state = readl(&reg_set->outbound_msg_0) & MFI_STATE_MASK; 1169 fw_state = instance->instancet->read_fw_status_reg(instance->reg_set) & MFI_STATE_MASK;
1179 1170
1180 while (fw_state != MFI_STATE_READY) { 1171 while (fw_state != MFI_STATE_READY) {
1181 1172
@@ -1193,7 +1184,7 @@ megasas_transition_to_ready(struct megasas_register_set __iomem * reg_set)
1193 * Set the CLR bit in inbound doorbell 1184 * Set the CLR bit in inbound doorbell
1194 */ 1185 */
1195 writel(MFI_INIT_CLEAR_HANDSHAKE, 1186 writel(MFI_INIT_CLEAR_HANDSHAKE,
1196 &reg_set->inbound_doorbell); 1187 &instance->reg_set->inbound_doorbell);
1197 1188
1198 max_wait = 2; 1189 max_wait = 2;
1199 cur_state = MFI_STATE_WAIT_HANDSHAKE; 1190 cur_state = MFI_STATE_WAIT_HANDSHAKE;
@@ -1203,8 +1194,8 @@ megasas_transition_to_ready(struct megasas_register_set __iomem * reg_set)
1203 /* 1194 /*
1204 * Bring it to READY state; assuming max wait 2 secs 1195 * Bring it to READY state; assuming max wait 2 secs
1205 */ 1196 */
1206 megasas_disable_intr(reg_set); 1197 megasas_disable_intr(instance->reg_set);
1207 writel(MFI_INIT_READY, &reg_set->inbound_doorbell); 1198 writel(MFI_INIT_READY, &instance->reg_set->inbound_doorbell);
1208 1199
1209 max_wait = 10; 1200 max_wait = 10;
1210 cur_state = MFI_STATE_OPERATIONAL; 1201 cur_state = MFI_STATE_OPERATIONAL;
@@ -1253,8 +1244,8 @@ megasas_transition_to_ready(struct megasas_register_set __iomem * reg_set)
1253 * The cur_state should not last for more than max_wait secs 1244 * The cur_state should not last for more than max_wait secs
1254 */ 1245 */
1255 for (i = 0; i < (max_wait * 1000); i++) { 1246 for (i = 0; i < (max_wait * 1000); i++) {
1256 fw_state = MFI_STATE_MASK & 1247 fw_state = instance->instancet->read_fw_status_reg(instance->reg_set) &
1257 readl(&reg_set->outbound_msg_0); 1248 MFI_STATE_MASK ;
1258 1249
1259 if (fw_state == cur_state) { 1250 if (fw_state == cur_state) {
1260 msleep(1); 1251 msleep(1);
@@ -1616,18 +1607,20 @@ static int megasas_init_mfi(struct megasas_instance *instance)
1616 1607
1617 reg_set = instance->reg_set; 1608 reg_set = instance->reg_set;
1618 1609
1610 instance->instancet = &megasas_instance_template_xscale;
1611
1619 /* 1612 /*
1620 * We expect the FW state to be READY 1613 * We expect the FW state to be READY
1621 */ 1614 */
1622 if (megasas_transition_to_ready(instance->reg_set)) 1615 if (megasas_transition_to_ready(instance))
1623 goto fail_ready_state; 1616 goto fail_ready_state;
1624 1617
1625 /* 1618 /*
1626 * Get various operational parameters from status register 1619 * Get various operational parameters from status register
1627 */ 1620 */
1628 instance->max_fw_cmds = readl(&reg_set->outbound_msg_0) & 0x00FFFF; 1621 instance->max_fw_cmds = instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF;
1629 instance->max_num_sge = (readl(&reg_set->outbound_msg_0) & 0xFF0000) >> 1622 instance->max_num_sge = (instance->instancet->read_fw_status_reg(reg_set) & 0xFF0000) >>
1630 0x10; 1623 0x10;
1631 /* 1624 /*
1632 * Create a pool of commands 1625 * Create a pool of commands
1633 */ 1626 */
@@ -1936,8 +1929,7 @@ megasas_register_aen(struct megasas_instance *instance, u32 seq_num,
1936 /* 1929 /*
1937 * Issue the aen registration frame 1930 * Issue the aen registration frame
1938 */ 1931 */
1939 writel(cmd->frame_phys_addr >> 3, 1932 instance->instancet->fire_cmd(cmd->frame_phys_addr ,0,instance->reg_set);
1940 &instance->reg_set->inbound_queue_port);
1941 1933
1942 return 0; 1934 return 0;
1943} 1935}
@@ -2126,7 +2118,7 @@ megasas_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2126 goto fail_irq; 2118 goto fail_irq;
2127 } 2119 }
2128 2120
2129 megasas_enable_intr(instance->reg_set); 2121 instance->instancet->enable_intr(instance->reg_set);
2130 2122
2131 /* 2123 /*
2132 * Store instance in PCI softstate 2124 * Store instance in PCI softstate
@@ -2681,9 +2673,8 @@ megasas_mgmt_compat_ioctl(struct file *file, unsigned int cmd,
2681 unsigned long arg) 2673 unsigned long arg)
2682{ 2674{
2683 switch (cmd) { 2675 switch (cmd) {
2684 case MEGASAS_IOC_FIRMWARE:{ 2676 case MEGASAS_IOC_FIRMWARE32:
2685 return megasas_mgmt_compat_ioctl_fw(file, arg); 2677 return megasas_mgmt_compat_ioctl_fw(file, arg);
2686 }
2687 case MEGASAS_IOC_GET_AEN: 2678 case MEGASAS_IOC_GET_AEN:
2688 return megasas_mgmt_ioctl_aen(file, arg); 2679 return megasas_mgmt_ioctl_aen(file, arg);
2689 } 2680 }