32 #include <linux/kernel.h>
33 #include <linux/types.h>
34 #include <linux/pci.h>
35 #include <linux/list.h>
37 #include <linux/module.h>
41 #include <linux/uio.h>
47 #include <linux/poll.h>
49 #include <scsi/scsi.h>
107 writel(~0, ®s->outbound_intr_status);
108 readl(®s->outbound_intr_status);
113 readl(®s->outbound_intr_mask);
126 writel(mask, ®s->outbound_intr_mask);
128 status =
readl(®s->outbound_intr_mask);
138 status =
readl(®s->outbound_intr_status);
141 writel(status, ®s->outbound_intr_status);
142 readl(®s->outbound_intr_status);
167 if (!list_empty(&fusion->
cmd_pool)) {
170 list_del_init(&
cmd->list);
205 static void megasas_teardown_frame_pool_fusion(
225 for (i = 0; i < max_cmd; i++) {
288 megasas_teardown_frame_pool_fusion(instance);
306 static int megasas_create_frame_pool_fusion(
struct megasas_instance *instance)
312 u32 total_sz_chain_frame;
323 fusion->
sg_dma_pool = pci_pool_create(
"megasas sg pool fusion",
325 total_sz_chain_frame, 4,
332 fusion->
sense_dma_pool = pci_pool_create(
"megasas sense pool fusion",
347 for (i = 0; i < max_cmd; i++) {
363 megasas_teardown_frame_pool_fusion(instance);
390 u32 max_cmd, io_frames_sz;
415 pci_pool_create(
"reply_frames pool", instance->
pdev,
420 "reply_frame pool\n");
421 goto fail_reply_desc;
429 "reply_frame pool\n");
431 goto fail_reply_desc;
441 pci_pool_create(
"io_request_frames pool", instance->
pdev,
446 "io_request_frame pool\n");
455 "io_request_frames frames\n");
470 "memory for cmd_list_fusion\n");
475 for (i = 0; i < max_cmd; i++) {
481 for (j = 0; j <
i; j++)
501 for (i = 0; i < max_cmd; i++) {
511 (io_req_base + offset);
522 if (megasas_create_frame_pool_fusion(instance)) {
569 for (i = 0; (i < msecs) && (frame_hdr->
cmd_status == 0xff); i += 20) {
614 if (!IOCInitMessage) {
653 req_desc->
MFAIo.RequestFlags =
662 for (i = 0; i < (10 * 1000); i += 20) {
669 instance->
instancet->fire_cmd(instance, req_desc->
u.low,
670 req_desc->
u.high, instance->
reg_set);
688 IOCInitMessage, ioc_init_handle);
740 memset(ci, 0,
sizeof(*ci));
751 dcmd->
sgl.
sge32[0].phys_addr = ci_h;
752 dcmd->
sgl.
sge32[0].length = size_map_info;
772 if (!megasas_get_ld_map_info(instance)) {
796 u32 size_sync_info, num_lds;
822 num_lds = map->
raidMap.ldCount;
838 for (i = 0; i < num_lds; i++, ld_sync++) {
854 dcmd->
mbox.
b[0] = num_lds;
857 dcmd->
sgl.
sge32[0].phys_addr = ci_h;
858 dcmd->
sgl.
sge32[0].length = size_map_info;
862 instance->
instancet->issue_dcmd(instance, cmd);
889 instance->
instancet->read_fw_status_reg(reg_set) & 0x00FFFF;
932 for (i = 0 ; i <
count; i++)
940 goto fail_alloc_mfi_cmds;
942 goto fail_alloc_cmds;
954 for (i = 0; i < 2; i++) {
1002 spin_unlock_irqrestore(&instance->
hba_lock, flags);
1029 cmd->
scmd->result = (
DID_OK << 16) | ext_status;
1077 sgl_ptr_end->
Flags = 0;
1084 if (sge_count > instance->
max_num_sge || !sge_count)
1092 if (i == sge_count - 1)
1097 sg_processed = i + 1;
1103 if (instance->
pdev->device ==
1110 chain_offset_io_request;
1120 if (instance->
pdev->device ==
1128 *(sge_count - sg_processed));
1174 cdb[12] = (
u8)((start_blk >> 56) & 0xff);
1175 cdb[13] = (
u8)((start_blk >> 48) & 0xff);
1176 cdb[14] = (
u8)((start_blk >> 40) & 0xff);
1177 cdb[15] = (
u8)((start_blk >> 32) & 0xff);
1178 cdb[16] = (
u8)((start_blk >> 24) & 0xff);
1179 cdb[17] = (
u8)((start_blk >> 16) & 0xff);
1180 cdb[18] = (
u8)((start_blk >> 8) & 0xff);
1181 cdb[19] = (
u8)(start_blk & 0xff);
1184 io_request->
CDB.
EEDP32.PrimaryReferenceTag =
1186 io_request->
CDB.
EEDP32.PrimaryApplicationTagMask = 0xffff;
1190 cdb[28] = (
u8)((num_blocks >> 24) & 0xff);
1191 cdb[29] = (
u8)((num_blocks >> 16) & 0xff);
1192 cdb[30] = (
u8)((num_blocks >> 8) & 0xff);
1193 cdb[31] = (
u8)(num_blocks & 0xff);
1208 io_request->
Control |= (0x4 << 26);
1212 if (((cdb_len == 12) || (cdb_len == 16)) &&
1213 (start_blk <= 0xffffffff)) {
1214 if (cdb_len == 16) {
1234 cdb[8] = (
u8)(num_blocks & 0xff);
1235 cdb[7] = (
u8)((num_blocks >> 8) & 0xff);
1239 }
else if ((cdb_len < 16) && (start_blk > 0xffffffff)) {
1270 cdb[13] = (
u8)(num_blocks & 0xff);
1271 cdb[12] = (
u8)((num_blocks >> 8) & 0xff);
1272 cdb[11] = (
u8)((num_blocks >> 16) & 0xff);
1273 cdb[10] = (
u8)((num_blocks >> 24) & 0xff);
1283 u8 val = cdb[1] & 0xE0;
1284 cdb[3] = (
u8)(start_blk & 0xff);
1285 cdb[2] = (
u8)((start_blk >> 8) & 0xff);
1286 cdb[1] = val | ((
u8)(start_blk >> 16) & 0x1f);
1290 cdb[5] = (
u8)(start_blk & 0xff);
1291 cdb[4] = (
u8)((start_blk >> 8) & 0xff);
1292 cdb[3] = (
u8)((start_blk >> 16) & 0xff);
1293 cdb[2] = (
u8)((start_blk >> 24) & 0xff);
1296 cdb[5] = (
u8)(start_blk & 0xff);
1297 cdb[4] = (
u8)((start_blk >> 8) & 0xff);
1298 cdb[3] = (
u8)((start_blk >> 16) & 0xff);
1299 cdb[2] = (
u8)((start_blk >> 24) & 0xff);
1302 cdb[9] = (
u8)(start_blk & 0xff);
1303 cdb[8] = (
u8)((start_blk >> 8) & 0xff);
1304 cdb[7] = (
u8)((start_blk >> 16) & 0xff);
1305 cdb[6] = (
u8)((start_blk >> 24) & 0xff);
1306 cdb[5] = (
u8)((start_blk >> 32) & 0xff);
1307 cdb[4] = (
u8)((start_blk >> 40) & 0xff);
1308 cdb[3] = (
u8)((start_blk >> 48) & 0xff);
1309 cdb[2] = (
u8)((start_blk >> 56) & 0xff);
1356 datalength = (
u32) scp->
cmnd[4];
1357 start_lba_lo = ((
u32) scp->
cmnd[1] << 16) |
1360 start_lba_lo &= 0x1FFFFF;
1366 else if (scp->
cmd_len == 10) {
1367 datalength = (
u32) scp->
cmnd[8] |
1369 start_lba_lo = ((
u32) scp->
cmnd[2] << 24) |
1377 else if (scp->
cmd_len == 12) {
1378 datalength = ((
u32) scp->
cmnd[6] << 24) |
1381 start_lba_lo = ((
u32) scp->
cmnd[2] << 24) |
1389 else if (scp->
cmd_len == 16) {
1390 datalength = ((
u32) scp->
cmnd[10] << 24) |
1393 start_lba_lo = ((
u32) scp->
cmnd[6] << 24) |
1397 start_lba_hi = ((
u32) scp->
cmnd[2] << 24) |
1411 local_map_ptr = fusion->
ld_map[(instance->
map_id & 1)];
1432 local_map_ptr, start_lba_lo);
1464 local_map_ptr->
raidMap.fpPdIoTimeoutSec;
1508 local_map_ptr = fusion->
ld_map[(instance->
map_id & 1)];
1517 local_map_ptr->
raidMap.fpPdIoTimeoutSec;
1561 io_request->
LUN[1] = 0;
1562 io_request->
CDB.
EEDP32.PrimaryReferenceTag = 0;
1563 io_request->
CDB.
EEDP32.PrimaryApplicationTagMask = 0;
1582 megasas_build_dcdb_fusion(instance, scp, cmd);
1589 megasas_make_sgl_fusion(instance, scp,
1591 &io_request->
SGL, cmd);
1595 "max (0x%x) allowed\n", sge_count,
1616 scp->
SCp.ptr = (
char *)cmd;
1629 "descriptor\n", index);
1666 req_desc->
Words = 0;
1670 megasas_return_cmd_fusion(instance, cmd);
1682 "correct : %x\n", cmd->
io_request->ChainOffset);
1690 req_desc->
u.low, req_desc->
u.high,
1710 u16 smid, num_completed;
1711 u8 reply_descript_type,
arm;
1730 reply_descript_type = reply_desc->
ReplyFlags &
1739 smid = reply_desc->
SMID;
1741 cmd_fusion = fusion->
cmd_list[smid - 1];
1759 if (cmd_fusion->
scmd->SCp.Status &
1765 cmd_fusion->
scmd->SCp.Status &=
1768 if (reply_descript_type ==
1779 cmd_fusion->
scmd->scsi_done(cmd_fusion->
scmd);
1782 megasas_return_cmd_fusion(instance, cmd_fusion);
1789 cmd_fusion->
flags = 0;
1790 megasas_return_cmd_fusion(instance, cmd_fusion);
1816 reply_descript_type = reply_desc->
ReplyFlags &
1828 &instance->
reg_set->reply_post_host_index);
1844 unsigned long flags;
1852 spin_unlock_irqrestore(&instance->
hba_lock, flags);
1855 spin_unlock_irqrestore(&instance->
hba_lock, flags);
1857 for (MSIxIndex = 0 ; MSIxIndex <
count; MSIxIndex++)
1885 fw_state = instance->
instancet->read_fw_status_reg(
1935 sgl_ptr_end->
Flags = 0;
1980 req_desc->
Words = 0;
2006 instance->
instancet->fire_cmd(instance, req_desc->
u.low,
2007 req_desc->
u.high, instance->
reg_set);
2060 int i, outstanding,
retval = 0;
2065 fw_state = instance->
instancet->read_fw_status_reg(
2069 " will reset adapter.\n");
2080 "commands to complete\n", i, outstanding);
2082 (
unsigned long)instance);
2088 printk(
"megaraid_sas: pending commands remain after waiting, "
2089 "will reset adapter.\n");
2104 for (i = 0 ; i <
count ; i++)
2127 "returning FAILED.\n");
2144 if (cmd_fusion->
scmd) {
2147 cmd_fusion->
scmd->scsi_done(cmd_fusion->
scmd);
2148 megasas_return_cmd_fusion(instance, cmd_fusion);
2153 status_reg = instance->
instancet->read_fw_status_reg(
2161 ", killing adapter.\n");
2171 &instance->
reg_set->fusion_seq_offset);
2173 &instance->
reg_set->fusion_seq_offset);
2175 &instance->
reg_set->fusion_seq_offset);
2177 &instance->
reg_set->fusion_seq_offset);
2179 &instance->
reg_set->fusion_seq_offset);
2181 &instance->
reg_set->fusion_seq_offset);
2183 &instance->
reg_set->fusion_seq_offset);
2186 host_diag =
readl(&instance->
reg_set->fusion_host_diag);
2192 if (retry++ == 100) {
2194 "Host diag unlock failed!\n");
2198 if (!(host_diag & HOST_DIAG_WRITE_ENABLE))
2203 &instance->
reg_set->fusion_host_diag);
2207 host_diag =
readl(&instance->
reg_set->fusion_host_diag);
2213 if (retry++ == 1000) {
2215 "Diag reset adapter never "
2220 if (host_diag & HOST_DIAG_RESET_ADAPTER)
2224 instance->
instancet->read_fw_status_reg(
2232 instance->
instancet->read_fw_status_reg(
2237 "state < MFI_STATE_FW_INIT, state = "
2238 "0x%x\n", abs_state);
2245 "transition controller to ready.\n");
2252 "megasas_ioc_init_fusion() failed!\n");
2273 megasas_return_cmd_fusion(
2274 instance, cmd_fusion);
2343 .read_fw_status_reg = megasas_read_fw_status_reg_fusion,
2344 .adp_reset = megasas_adp_reset_fusion,
2345 .check_reset = megasas_check_reset_fusion,
2349 .build_and_issue_cmd = megasas_build_and_issue_cmd_fusion,