aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/pmcraid.c
diff options
context:
space:
mode:
authorBrian Norris <computersforpeace@gmail.com>2017-05-15 14:19:19 -0400
committerBrian Norris <computersforpeace@gmail.com>2017-05-15 14:19:19 -0400
commitc316cf670491def52a396d3bdc5a63ad01f7fefa (patch)
treebf22299ce777088d190b532629b1bd647d28fab6 /drivers/scsi/pmcraid.c
parent6c51a52eeb58befd2e9be2ed7ee2c4c04139b336 (diff)
parent2ea659a9ef488125eb46da6eb571de5eae5c43f6 (diff)
Merge 'v4.12-rc1' into MTD
Bring a few queued patches in sync for -next development.
Diffstat (limited to 'drivers/scsi/pmcraid.c')
-rw-r--r--drivers/scsi/pmcraid.c234
1 files changed, 96 insertions, 138 deletions
diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index 49e70a383afa..a4aadf5f4dc6 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -77,7 +77,7 @@ static atomic_t pmcraid_adapter_count = ATOMIC_INIT(0);
77 */ 77 */
78static unsigned int pmcraid_major; 78static unsigned int pmcraid_major;
79static struct class *pmcraid_class; 79static struct class *pmcraid_class;
80DECLARE_BITMAP(pmcraid_minor, PMCRAID_MAX_ADAPTERS); 80static DECLARE_BITMAP(pmcraid_minor, PMCRAID_MAX_ADAPTERS);
81 81
82/* 82/*
83 * Module parameters 83 * Module parameters
@@ -175,7 +175,7 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
175 if (fw_version <= PMCRAID_FW_VERSION_1) 175 if (fw_version <= PMCRAID_FW_VERSION_1)
176 target = temp->cfg_entry.unique_flags1; 176 target = temp->cfg_entry.unique_flags1;
177 else 177 else
178 target = temp->cfg_entry.array_id & 0xFF; 178 target = le16_to_cpu(temp->cfg_entry.array_id) & 0xFF;
179 179
180 if (target > PMCRAID_MAX_VSET_TARGETS) 180 if (target > PMCRAID_MAX_VSET_TARGETS)
181 continue; 181 continue;
@@ -330,7 +330,7 @@ static void pmcraid_init_cmdblk(struct pmcraid_cmd *cmd, int index)
330 ioarcb->request_flags0 = 0; 330 ioarcb->request_flags0 = 0;
331 ioarcb->request_flags1 = 0; 331 ioarcb->request_flags1 = 0;
332 ioarcb->cmd_timeout = 0; 332 ioarcb->cmd_timeout = 0;
333 ioarcb->ioarcb_bus_addr &= (~0x1FULL); 333 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~0x1FULL);
334 ioarcb->ioadl_bus_addr = 0; 334 ioarcb->ioadl_bus_addr = 0;
335 ioarcb->ioadl_length = 0; 335 ioarcb->ioadl_length = 0;
336 ioarcb->data_transfer_length = 0; 336 ioarcb->data_transfer_length = 0;
@@ -345,7 +345,7 @@ static void pmcraid_init_cmdblk(struct pmcraid_cmd *cmd, int index)
345 cmd->scsi_cmd = NULL; 345 cmd->scsi_cmd = NULL;
346 cmd->release = 0; 346 cmd->release = 0;
347 cmd->completion_req = 0; 347 cmd->completion_req = 0;
348 cmd->sense_buffer = 0; 348 cmd->sense_buffer = NULL;
349 cmd->sense_buffer_dma = 0; 349 cmd->sense_buffer_dma = 0;
350 cmd->dma_handle = 0; 350 cmd->dma_handle = 0;
351 init_timer(&cmd->timer); 351 init_timer(&cmd->timer);
@@ -898,8 +898,7 @@ static void _pmcraid_fire_command(struct pmcraid_cmd *cmd)
898 898
899 /* driver writes lower 32-bit value of IOARCB address only */ 899 /* driver writes lower 32-bit value of IOARCB address only */
900 mb(); 900 mb();
901 iowrite32(le32_to_cpu(cmd->ioa_cb->ioarcb.ioarcb_bus_addr), 901 iowrite32(le64_to_cpu(cmd->ioa_cb->ioarcb.ioarcb_bus_addr), pinstance->ioarrin);
902 pinstance->ioarrin);
903} 902}
904 903
905/** 904/**
@@ -1051,7 +1050,7 @@ static void pmcraid_get_fwversion(struct pmcraid_cmd *cmd)
1051 offsetof(struct pmcraid_ioarcb, 1050 offsetof(struct pmcraid_ioarcb,
1052 add_data.u.ioadl[0])); 1051 add_data.u.ioadl[0]));
1053 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); 1052 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc));
1054 ioarcb->ioarcb_bus_addr &= ~(0x1FULL); 1053 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~(0x1FULL));
1055 1054
1056 ioarcb->request_flags0 |= NO_LINK_DESCS; 1055 ioarcb->request_flags0 |= NO_LINK_DESCS;
1057 ioarcb->data_transfer_length = cpu_to_le32(data_size); 1056 ioarcb->data_transfer_length = cpu_to_le32(data_size);
@@ -1077,7 +1076,7 @@ static void pmcraid_identify_hrrq(struct pmcraid_cmd *cmd)
1077 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; 1076 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb;
1078 int index = cmd->hrrq_index; 1077 int index = cmd->hrrq_index;
1079 __be64 hrrq_addr = cpu_to_be64(pinstance->hrrq_start_bus_addr[index]); 1078 __be64 hrrq_addr = cpu_to_be64(pinstance->hrrq_start_bus_addr[index]);
1080 u32 hrrq_size = cpu_to_be32(sizeof(u32) * PMCRAID_MAX_CMD); 1079 __be32 hrrq_size = cpu_to_be32(sizeof(u32) * PMCRAID_MAX_CMD);
1081 void (*done_function)(struct pmcraid_cmd *); 1080 void (*done_function)(struct pmcraid_cmd *);
1082 1081
1083 pmcraid_reinit_cmdblk(cmd); 1082 pmcraid_reinit_cmdblk(cmd);
@@ -1202,7 +1201,7 @@ static struct pmcraid_cmd *pmcraid_init_hcam
1202 1201
1203 ioadl[0].flags |= IOADL_FLAGS_READ_LAST; 1202 ioadl[0].flags |= IOADL_FLAGS_READ_LAST;
1204 ioadl[0].data_len = cpu_to_le32(rcb_size); 1203 ioadl[0].data_len = cpu_to_le32(rcb_size);
1205 ioadl[0].address = cpu_to_le32(dma); 1204 ioadl[0].address = cpu_to_le64(dma);
1206 1205
1207 cmd->cmd_done = cmd_done; 1206 cmd->cmd_done = cmd_done;
1208 return cmd; 1207 return cmd;
@@ -1237,7 +1236,13 @@ static void pmcraid_prepare_cancel_cmd(
1237) 1236)
1238{ 1237{
1239 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; 1238 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb;
1240 __be64 ioarcb_addr = cmd_to_cancel->ioa_cb->ioarcb.ioarcb_bus_addr; 1239 __be64 ioarcb_addr;
1240
1241 /* IOARCB address of the command to be cancelled is given in
1242 * cdb[2]..cdb[9] is Big-Endian format. Note that length bits in
1243 * IOARCB address are not masked.
1244 */
1245 ioarcb_addr = cpu_to_be64(le64_to_cpu(cmd_to_cancel->ioa_cb->ioarcb.ioarcb_bus_addr));
1241 1246
1242 /* Get the resource handle to where the command to be aborted has been 1247 /* Get the resource handle to where the command to be aborted has been
1243 * sent. 1248 * sent.
@@ -1247,11 +1252,6 @@ static void pmcraid_prepare_cancel_cmd(
1247 memset(ioarcb->cdb, 0, PMCRAID_MAX_CDB_LEN); 1252 memset(ioarcb->cdb, 0, PMCRAID_MAX_CDB_LEN);
1248 ioarcb->cdb[0] = PMCRAID_ABORT_CMD; 1253 ioarcb->cdb[0] = PMCRAID_ABORT_CMD;
1249 1254
1250 /* IOARCB address of the command to be cancelled is given in
1251 * cdb[2]..cdb[9] is Big-Endian format. Note that length bits in
1252 * IOARCB address are not masked.
1253 */
1254 ioarcb_addr = cpu_to_be64(ioarcb_addr);
1255 memcpy(&(ioarcb->cdb[2]), &ioarcb_addr, sizeof(ioarcb_addr)); 1255 memcpy(&(ioarcb->cdb[2]), &ioarcb_addr, sizeof(ioarcb_addr));
1256} 1256}
1257 1257
@@ -1493,7 +1493,7 @@ static int pmcraid_notify_ccn(struct pmcraid_instance *pinstance)
1493{ 1493{
1494 return pmcraid_notify_aen(pinstance, 1494 return pmcraid_notify_aen(pinstance,
1495 pinstance->ccn.msg, 1495 pinstance->ccn.msg,
1496 pinstance->ccn.hcam->data_len + 1496 le32_to_cpu(pinstance->ccn.hcam->data_len) +
1497 sizeof(struct pmcraid_hcam_hdr)); 1497 sizeof(struct pmcraid_hcam_hdr));
1498} 1498}
1499 1499
@@ -1508,7 +1508,7 @@ static int pmcraid_notify_ldn(struct pmcraid_instance *pinstance)
1508{ 1508{
1509 return pmcraid_notify_aen(pinstance, 1509 return pmcraid_notify_aen(pinstance,
1510 pinstance->ldn.msg, 1510 pinstance->ldn.msg,
1511 pinstance->ldn.hcam->data_len + 1511 le32_to_cpu(pinstance->ldn.hcam->data_len) +
1512 sizeof(struct pmcraid_hcam_hdr)); 1512 sizeof(struct pmcraid_hcam_hdr));
1513} 1513}
1514 1514
@@ -1556,10 +1556,10 @@ static void pmcraid_handle_config_change(struct pmcraid_instance *pinstance)
1556 1556
1557 pmcraid_info("CCN(%x): %x timestamp: %llx type: %x lost: %x flags: %x \ 1557 pmcraid_info("CCN(%x): %x timestamp: %llx type: %x lost: %x flags: %x \
1558 res: %x:%x:%x:%x\n", 1558 res: %x:%x:%x:%x\n",
1559 pinstance->ccn.hcam->ilid, 1559 le32_to_cpu(pinstance->ccn.hcam->ilid),
1560 pinstance->ccn.hcam->op_code, 1560 pinstance->ccn.hcam->op_code,
1561 ((pinstance->ccn.hcam->timestamp1) | 1561 (le32_to_cpu(pinstance->ccn.hcam->timestamp1) |
1562 ((pinstance->ccn.hcam->timestamp2 & 0xffffffffLL) << 32)), 1562 ((le32_to_cpu(pinstance->ccn.hcam->timestamp2) & 0xffffffffLL) << 32)),
1563 pinstance->ccn.hcam->notification_type, 1563 pinstance->ccn.hcam->notification_type,
1564 pinstance->ccn.hcam->notification_lost, 1564 pinstance->ccn.hcam->notification_lost,
1565 pinstance->ccn.hcam->flags, 1565 pinstance->ccn.hcam->flags,
@@ -1570,7 +1570,7 @@ static void pmcraid_handle_config_change(struct pmcraid_instance *pinstance)
1570 RES_IS_VSET(*cfg_entry) ? 1570 RES_IS_VSET(*cfg_entry) ?
1571 (fw_version <= PMCRAID_FW_VERSION_1 ? 1571 (fw_version <= PMCRAID_FW_VERSION_1 ?
1572 cfg_entry->unique_flags1 : 1572 cfg_entry->unique_flags1 :
1573 cfg_entry->array_id & 0xFF) : 1573 le16_to_cpu(cfg_entry->array_id) & 0xFF) :
1574 RES_TARGET(cfg_entry->resource_address), 1574 RES_TARGET(cfg_entry->resource_address),
1575 RES_LUN(cfg_entry->resource_address)); 1575 RES_LUN(cfg_entry->resource_address));
1576 1576
@@ -1658,7 +1658,7 @@ static void pmcraid_handle_config_change(struct pmcraid_instance *pinstance)
1658 if (fw_version <= PMCRAID_FW_VERSION_1) 1658 if (fw_version <= PMCRAID_FW_VERSION_1)
1659 res->cfg_entry.unique_flags1 &= 0x7F; 1659 res->cfg_entry.unique_flags1 &= 0x7F;
1660 else 1660 else
1661 res->cfg_entry.array_id &= 0xFF; 1661 res->cfg_entry.array_id &= cpu_to_le16(0xFF);
1662 res->change_detected = RES_CHANGE_DEL; 1662 res->change_detected = RES_CHANGE_DEL;
1663 res->cfg_entry.resource_handle = 1663 res->cfg_entry.resource_handle =
1664 PMCRAID_INVALID_RES_HANDLE; 1664 PMCRAID_INVALID_RES_HANDLE;
@@ -1716,8 +1716,8 @@ static void pmcraid_ioasc_logger(u32 ioasc, struct pmcraid_cmd *cmd)
1716 /* log the error string */ 1716 /* log the error string */
1717 pmcraid_err("cmd [%x] for resource %x failed with %x(%s)\n", 1717 pmcraid_err("cmd [%x] for resource %x failed with %x(%s)\n",
1718 cmd->ioa_cb->ioarcb.cdb[0], 1718 cmd->ioa_cb->ioarcb.cdb[0],
1719 cmd->ioa_cb->ioarcb.resource_handle, 1719 le32_to_cpu(cmd->ioa_cb->ioarcb.resource_handle),
1720 le32_to_cpu(ioasc), error_info->error_string); 1720 ioasc, error_info->error_string);
1721} 1721}
1722 1722
1723/** 1723/**
@@ -2034,7 +2034,7 @@ static void pmcraid_fail_outstanding_cmds(struct pmcraid_instance *pinstance)
2034 cmd->ioa_cb->ioasa.ioasc = 2034 cmd->ioa_cb->ioasa.ioasc =
2035 cpu_to_le32(PMCRAID_IOASC_IOA_WAS_RESET); 2035 cpu_to_le32(PMCRAID_IOASC_IOA_WAS_RESET);
2036 cmd->ioa_cb->ioasa.ilid = 2036 cmd->ioa_cb->ioasa.ilid =
2037 cpu_to_be32(PMCRAID_DRIVER_ILID); 2037 cpu_to_le32(PMCRAID_DRIVER_ILID);
2038 2038
2039 /* In case the command timer is still running */ 2039 /* In case the command timer is still running */
2040 del_timer(&cmd->timer); 2040 del_timer(&cmd->timer);
@@ -2373,46 +2373,43 @@ static int pmcraid_reset_reload(
2373 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); 2373 spin_lock_irqsave(pinstance->host->host_lock, lock_flags);
2374 2374
2375 if (pinstance->ioa_state == IOA_STATE_DEAD) { 2375 if (pinstance->ioa_state == IOA_STATE_DEAD) {
2376 spin_unlock_irqrestore(pinstance->host->host_lock,
2377 lock_flags);
2378 pmcraid_info("reset_reload: IOA is dead\n"); 2376 pmcraid_info("reset_reload: IOA is dead\n");
2379 return reset; 2377 goto out_unlock;
2380 } else if (pinstance->ioa_state == target_state) { 2378 }
2379
2380 if (pinstance->ioa_state == target_state) {
2381 reset = 0; 2381 reset = 0;
2382 goto out_unlock;
2382 } 2383 }
2383 } 2384 }
2384 2385
2385 if (reset) { 2386 pmcraid_info("reset_reload: proceeding with reset\n");
2386 pmcraid_info("reset_reload: proceeding with reset\n"); 2387 scsi_block_requests(pinstance->host);
2387 scsi_block_requests(pinstance->host); 2388 reset_cmd = pmcraid_get_free_cmd(pinstance);
2388 reset_cmd = pmcraid_get_free_cmd(pinstance); 2389 if (reset_cmd == NULL) {
2389 2390 pmcraid_err("no free cmnd for reset_reload\n");
2390 if (reset_cmd == NULL) { 2391 goto out_unlock;
2391 pmcraid_err("no free cmnd for reset_reload\n"); 2392 }
2392 spin_unlock_irqrestore(pinstance->host->host_lock,
2393 lock_flags);
2394 return reset;
2395 }
2396 2393
2397 if (shutdown_type == SHUTDOWN_NORMAL) 2394 if (shutdown_type == SHUTDOWN_NORMAL)
2398 pinstance->ioa_bringdown = 1; 2395 pinstance->ioa_bringdown = 1;
2399 2396
2400 pinstance->ioa_shutdown_type = shutdown_type; 2397 pinstance->ioa_shutdown_type = shutdown_type;
2401 pinstance->reset_cmd = reset_cmd; 2398 pinstance->reset_cmd = reset_cmd;
2402 pinstance->force_ioa_reset = reset; 2399 pinstance->force_ioa_reset = reset;
2403 pmcraid_info("reset_reload: initiating reset\n"); 2400 pmcraid_info("reset_reload: initiating reset\n");
2404 pmcraid_ioa_reset(reset_cmd); 2401 pmcraid_ioa_reset(reset_cmd);
2405 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); 2402 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags);
2406 pmcraid_info("reset_reload: waiting for reset to complete\n"); 2403 pmcraid_info("reset_reload: waiting for reset to complete\n");
2407 wait_event(pinstance->reset_wait_q, 2404 wait_event(pinstance->reset_wait_q,
2408 !pinstance->ioa_reset_in_progress); 2405 !pinstance->ioa_reset_in_progress);
2409 2406
2410 pmcraid_info("reset_reload: reset is complete !!\n"); 2407 pmcraid_info("reset_reload: reset is complete !!\n");
2411 scsi_unblock_requests(pinstance->host); 2408 scsi_unblock_requests(pinstance->host);
2412 if (pinstance->ioa_state == target_state) 2409 return pinstance->ioa_state != target_state;
2413 reset = 0;
2414 }
2415 2410
2411out_unlock:
2412 spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags);
2416 return reset; 2413 return reset;
2417} 2414}
2418 2415
@@ -2529,7 +2526,7 @@ static void pmcraid_cancel_all(struct pmcraid_cmd *cmd, u32 sense)
2529 ioarcb->ioadl_bus_addr = 0; 2526 ioarcb->ioadl_bus_addr = 0;
2530 ioarcb->ioadl_length = 0; 2527 ioarcb->ioadl_length = 0;
2531 ioarcb->data_transfer_length = 0; 2528 ioarcb->data_transfer_length = 0;
2532 ioarcb->ioarcb_bus_addr &= (~0x1FULL); 2529 ioarcb->ioarcb_bus_addr &= cpu_to_le64((~0x1FULL));
2533 2530
2534 /* writing to IOARRIN must be protected by host_lock, as mid-layer 2531 /* writing to IOARRIN must be protected by host_lock, as mid-layer
2535 * schedule queuecommand while we are doing this 2532 * schedule queuecommand while we are doing this
@@ -2692,8 +2689,8 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
2692 * mid-layer 2689 * mid-layer
2693 */ 2690 */
2694 if (ioasa->auto_sense_length != 0) { 2691 if (ioasa->auto_sense_length != 0) {
2695 short sense_len = ioasa->auto_sense_length; 2692 short sense_len = le16_to_cpu(ioasa->auto_sense_length);
2696 int data_size = min_t(u16, le16_to_cpu(sense_len), 2693 int data_size = min_t(u16, sense_len,
2697 SCSI_SENSE_BUFFERSIZE); 2694 SCSI_SENSE_BUFFERSIZE);
2698 2695
2699 memcpy(scsi_cmd->sense_buffer, 2696 memcpy(scsi_cmd->sense_buffer,
@@ -2915,7 +2912,7 @@ static struct pmcraid_cmd *pmcraid_abort_cmd(struct pmcraid_cmd *cmd)
2915 2912
2916 pmcraid_info("aborting command CDB[0]= %x with index = %d\n", 2913 pmcraid_info("aborting command CDB[0]= %x with index = %d\n",
2917 cmd->ioa_cb->ioarcb.cdb[0], 2914 cmd->ioa_cb->ioarcb.cdb[0],
2918 cmd->ioa_cb->ioarcb.response_handle >> 2); 2915 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle) >> 2);
2919 2916
2920 init_completion(&cancel_cmd->wait_for_completion); 2917 init_completion(&cancel_cmd->wait_for_completion);
2921 cancel_cmd->completion_req = 1; 2918 cancel_cmd->completion_req = 1;
@@ -3140,9 +3137,8 @@ pmcraid_init_ioadls(struct pmcraid_cmd *cmd, int sgcount)
3140 int ioadl_count = 0; 3137 int ioadl_count = 0;
3141 3138
3142 if (ioarcb->add_cmd_param_length) 3139 if (ioarcb->add_cmd_param_length)
3143 ioadl_count = DIV_ROUND_UP(ioarcb->add_cmd_param_length, 16); 3140 ioadl_count = DIV_ROUND_UP(le16_to_cpu(ioarcb->add_cmd_param_length), 16);
3144 ioarcb->ioadl_length = 3141 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc) * sgcount);
3145 sizeof(struct pmcraid_ioadl_desc) * sgcount;
3146 3142
3147 if ((sgcount + ioadl_count) > (ARRAY_SIZE(ioarcb->add_data.u.ioadl))) { 3143 if ((sgcount + ioadl_count) > (ARRAY_SIZE(ioarcb->add_data.u.ioadl))) {
3148 /* external ioadls start at offset 0x80 from control_block 3144 /* external ioadls start at offset 0x80 from control_block
@@ -3150,7 +3146,7 @@ pmcraid_init_ioadls(struct pmcraid_cmd *cmd, int sgcount)
3150 * It is necessary to indicate to firmware that driver is 3146 * It is necessary to indicate to firmware that driver is
3151 * using ioadls to be treated as external to IOARCB. 3147 * using ioadls to be treated as external to IOARCB.
3152 */ 3148 */
3153 ioarcb->ioarcb_bus_addr &= ~(0x1FULL); 3149 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~(0x1FULL));
3154 ioarcb->ioadl_bus_addr = 3150 ioarcb->ioadl_bus_addr =
3155 cpu_to_le64((cmd->ioa_cb_bus_addr) + 3151 cpu_to_le64((cmd->ioa_cb_bus_addr) +
3156 offsetof(struct pmcraid_ioarcb, 3152 offsetof(struct pmcraid_ioarcb,
@@ -3164,7 +3160,7 @@ pmcraid_init_ioadls(struct pmcraid_cmd *cmd, int sgcount)
3164 3160
3165 ioadl = &ioarcb->add_data.u.ioadl[ioadl_count]; 3161 ioadl = &ioarcb->add_data.u.ioadl[ioadl_count];
3166 ioarcb->ioarcb_bus_addr |= 3162 ioarcb->ioarcb_bus_addr |=
3167 DIV_ROUND_CLOSEST(sgcount + ioadl_count, 8); 3163 cpu_to_le64(DIV_ROUND_CLOSEST(sgcount + ioadl_count, 8));
3168 } 3164 }
3169 3165
3170 return ioadl; 3166 return ioadl;
@@ -3325,7 +3321,7 @@ static struct pmcraid_sglist *pmcraid_alloc_sglist(int buflen)
3325 */ 3321 */
3326static int pmcraid_copy_sglist( 3322static int pmcraid_copy_sglist(
3327 struct pmcraid_sglist *sglist, 3323 struct pmcraid_sglist *sglist,
3328 unsigned long buffer, 3324 void __user *buffer,
3329 u32 len, 3325 u32 len,
3330 int direction 3326 int direction
3331) 3327)
@@ -3346,11 +3342,9 @@ static int pmcraid_copy_sglist(
3346 3342
3347 kaddr = kmap(page); 3343 kaddr = kmap(page);
3348 if (direction == DMA_TO_DEVICE) 3344 if (direction == DMA_TO_DEVICE)
3349 rc = __copy_from_user(kaddr, 3345 rc = copy_from_user(kaddr, buffer, bsize_elem);
3350 (void *)buffer,
3351 bsize_elem);
3352 else 3346 else
3353 rc = __copy_to_user((void *)buffer, kaddr, bsize_elem); 3347 rc = copy_to_user(buffer, kaddr, bsize_elem);
3354 3348
3355 kunmap(page); 3349 kunmap(page);
3356 3350
@@ -3368,13 +3362,9 @@ static int pmcraid_copy_sglist(
3368 kaddr = kmap(page); 3362 kaddr = kmap(page);
3369 3363
3370 if (direction == DMA_TO_DEVICE) 3364 if (direction == DMA_TO_DEVICE)
3371 rc = __copy_from_user(kaddr, 3365 rc = copy_from_user(kaddr, buffer, len % bsize_elem);
3372 (void *)buffer,
3373 len % bsize_elem);
3374 else 3366 else
3375 rc = __copy_to_user((void *)buffer, 3367 rc = copy_to_user(buffer, kaddr, len % bsize_elem);
3376 kaddr,
3377 len % bsize_elem);
3378 3368
3379 kunmap(page); 3369 kunmap(page);
3380 3370
@@ -3496,7 +3486,7 @@ static int pmcraid_queuecommand_lck(
3496 RES_IS_VSET(res->cfg_entry) ? 3486 RES_IS_VSET(res->cfg_entry) ?
3497 (fw_version <= PMCRAID_FW_VERSION_1 ? 3487 (fw_version <= PMCRAID_FW_VERSION_1 ?
3498 res->cfg_entry.unique_flags1 : 3488 res->cfg_entry.unique_flags1 :
3499 res->cfg_entry.array_id & 0xFF) : 3489 le16_to_cpu(res->cfg_entry.array_id) & 0xFF) :
3500 RES_TARGET(res->cfg_entry.resource_address), 3490 RES_TARGET(res->cfg_entry.resource_address),
3501 RES_LUN(res->cfg_entry.resource_address)); 3491 RES_LUN(res->cfg_entry.resource_address));
3502 3492
@@ -3652,17 +3642,17 @@ static long pmcraid_ioctl_passthrough(
3652 struct pmcraid_instance *pinstance, 3642 struct pmcraid_instance *pinstance,
3653 unsigned int ioctl_cmd, 3643 unsigned int ioctl_cmd,
3654 unsigned int buflen, 3644 unsigned int buflen,
3655 unsigned long arg 3645 void __user *arg
3656) 3646)
3657{ 3647{
3658 struct pmcraid_passthrough_ioctl_buffer *buffer; 3648 struct pmcraid_passthrough_ioctl_buffer *buffer;
3659 struct pmcraid_ioarcb *ioarcb; 3649 struct pmcraid_ioarcb *ioarcb;
3660 struct pmcraid_cmd *cmd; 3650 struct pmcraid_cmd *cmd;
3661 struct pmcraid_cmd *cancel_cmd; 3651 struct pmcraid_cmd *cancel_cmd;
3662 unsigned long request_buffer; 3652 void __user *request_buffer;
3663 unsigned long request_offset; 3653 unsigned long request_offset;
3664 unsigned long lock_flags; 3654 unsigned long lock_flags;
3665 void *ioasa; 3655 void __user *ioasa;
3666 u32 ioasc; 3656 u32 ioasc;
3667 int request_size; 3657 int request_size;
3668 int buffer_size; 3658 int buffer_size;
@@ -3701,13 +3691,10 @@ static long pmcraid_ioctl_passthrough(
3701 3691
3702 request_buffer = arg + request_offset; 3692 request_buffer = arg + request_offset;
3703 3693
3704 rc = __copy_from_user(buffer, 3694 rc = copy_from_user(buffer, arg,
3705 (struct pmcraid_passthrough_ioctl_buffer *) arg,
3706 sizeof(struct pmcraid_passthrough_ioctl_buffer)); 3695 sizeof(struct pmcraid_passthrough_ioctl_buffer));
3707 3696
3708 ioasa = 3697 ioasa = arg + offsetof(struct pmcraid_passthrough_ioctl_buffer, ioasa);
3709 (void *)(arg +
3710 offsetof(struct pmcraid_passthrough_ioctl_buffer, ioasa));
3711 3698
3712 if (rc) { 3699 if (rc) {
3713 pmcraid_err("ioctl: can't copy passthrough buffer\n"); 3700 pmcraid_err("ioctl: can't copy passthrough buffer\n");
@@ -3715,7 +3702,7 @@ static long pmcraid_ioctl_passthrough(
3715 goto out_free_buffer; 3702 goto out_free_buffer;
3716 } 3703 }
3717 3704
3718 request_size = buffer->ioarcb.data_transfer_length; 3705 request_size = le32_to_cpu(buffer->ioarcb.data_transfer_length);
3719 3706
3720 if (buffer->ioarcb.request_flags0 & TRANSFER_DIR_WRITE) { 3707 if (buffer->ioarcb.request_flags0 & TRANSFER_DIR_WRITE) {
3721 access = VERIFY_READ; 3708 access = VERIFY_READ;
@@ -3725,20 +3712,14 @@ static long pmcraid_ioctl_passthrough(
3725 direction = DMA_FROM_DEVICE; 3712 direction = DMA_FROM_DEVICE;
3726 } 3713 }
3727 3714
3728 if (request_size > 0) { 3715 if (request_size < 0) {
3729 rc = access_ok(access, arg, request_offset + request_size);
3730
3731 if (!rc) {
3732 rc = -EFAULT;
3733 goto out_free_buffer;
3734 }
3735 } else if (request_size < 0) {
3736 rc = -EINVAL; 3716 rc = -EINVAL;
3737 goto out_free_buffer; 3717 goto out_free_buffer;
3738 } 3718 }
3739 3719
3740 /* check if we have any additional command parameters */ 3720 /* check if we have any additional command parameters */
3741 if (buffer->ioarcb.add_cmd_param_length > PMCRAID_ADD_CMD_PARAM_LEN) { 3721 if (le16_to_cpu(buffer->ioarcb.add_cmd_param_length)
3722 > PMCRAID_ADD_CMD_PARAM_LEN) {
3742 rc = -EINVAL; 3723 rc = -EINVAL;
3743 goto out_free_buffer; 3724 goto out_free_buffer;
3744 } 3725 }
@@ -3770,7 +3751,7 @@ static long pmcraid_ioctl_passthrough(
3770 buffer->ioarcb.add_cmd_param_offset; 3751 buffer->ioarcb.add_cmd_param_offset;
3771 memcpy(ioarcb->add_data.u.add_cmd_params, 3752 memcpy(ioarcb->add_data.u.add_cmd_params,
3772 buffer->ioarcb.add_data.u.add_cmd_params, 3753 buffer->ioarcb.add_data.u.add_cmd_params,
3773 buffer->ioarcb.add_cmd_param_length); 3754 le16_to_cpu(buffer->ioarcb.add_cmd_param_length));
3774 } 3755 }
3775 3756
3776 /* set hrrq number where the IOA should respond to. Note that all cmds 3757 /* set hrrq number where the IOA should respond to. Note that all cmds
@@ -3840,10 +3821,10 @@ static long pmcraid_ioctl_passthrough(
3840 wait_for_completion(&cmd->wait_for_completion); 3821 wait_for_completion(&cmd->wait_for_completion);
3841 } else if (!wait_for_completion_timeout( 3822 } else if (!wait_for_completion_timeout(
3842 &cmd->wait_for_completion, 3823 &cmd->wait_for_completion,
3843 msecs_to_jiffies(buffer->ioarcb.cmd_timeout * 1000))) { 3824 msecs_to_jiffies(le16_to_cpu(buffer->ioarcb.cmd_timeout) * 1000))) {
3844 3825
3845 pmcraid_info("aborting cmd %d (CDB[0] = %x) due to timeout\n", 3826 pmcraid_info("aborting cmd %d (CDB[0] = %x) due to timeout\n",
3846 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle >> 2), 3827 le32_to_cpu(cmd->ioa_cb->ioarcb.response_handle) >> 2,
3847 cmd->ioa_cb->ioarcb.cdb[0]); 3828 cmd->ioa_cb->ioarcb.cdb[0]);
3848 3829
3849 spin_lock_irqsave(pinstance->host->host_lock, lock_flags); 3830 spin_lock_irqsave(pinstance->host->host_lock, lock_flags);
@@ -3852,7 +3833,7 @@ static long pmcraid_ioctl_passthrough(
3852 3833
3853 if (cancel_cmd) { 3834 if (cancel_cmd) {
3854 wait_for_completion(&cancel_cmd->wait_for_completion); 3835 wait_for_completion(&cancel_cmd->wait_for_completion);
3855 ioasc = cancel_cmd->ioa_cb->ioasa.ioasc; 3836 ioasc = le32_to_cpu(cancel_cmd->ioa_cb->ioasa.ioasc);
3856 pmcraid_return_cmd(cancel_cmd); 3837 pmcraid_return_cmd(cancel_cmd);
3857 3838
3858 /* if abort task couldn't find the command i.e it got 3839 /* if abort task couldn't find the command i.e it got
@@ -3941,11 +3922,6 @@ static long pmcraid_ioctl_driver(
3941{ 3922{
3942 int rc = -ENOSYS; 3923 int rc = -ENOSYS;
3943 3924
3944 if (!access_ok(VERIFY_READ, user_buffer, _IOC_SIZE(cmd))) {
3945 pmcraid_err("ioctl_driver: access fault in request buffer\n");
3946 return -EFAULT;
3947 }
3948
3949 switch (cmd) { 3925 switch (cmd) {
3950 case PMCRAID_IOCTL_RESET_ADAPTER: 3926 case PMCRAID_IOCTL_RESET_ADAPTER:
3951 pmcraid_reset_bringup(pinstance); 3927 pmcraid_reset_bringup(pinstance);
@@ -3977,8 +3953,7 @@ static int pmcraid_check_ioctl_buffer(
3977 struct pmcraid_ioctl_header *hdr 3953 struct pmcraid_ioctl_header *hdr
3978) 3954)
3979{ 3955{
3980 int rc = 0; 3956 int rc;
3981 int access = VERIFY_READ;
3982 3957
3983 if (copy_from_user(hdr, arg, sizeof(struct pmcraid_ioctl_header))) { 3958 if (copy_from_user(hdr, arg, sizeof(struct pmcraid_ioctl_header))) {
3984 pmcraid_err("couldn't copy ioctl header from user buffer\n"); 3959 pmcraid_err("couldn't copy ioctl header from user buffer\n");
@@ -3994,19 +3969,6 @@ static int pmcraid_check_ioctl_buffer(
3994 return -EINVAL; 3969 return -EINVAL;
3995 } 3970 }
3996 3971
3997 /* check for appropriate buffer access */
3998 if ((_IOC_DIR(cmd) & _IOC_READ) == _IOC_READ)
3999 access = VERIFY_WRITE;
4000
4001 rc = access_ok(access,
4002 (arg + sizeof(struct pmcraid_ioctl_header)),
4003 hdr->buffer_length);
4004 if (!rc) {
4005 pmcraid_err("access failed for user buffer of size %d\n",
4006 hdr->buffer_length);
4007 return -EFAULT;
4008 }
4009
4010 return 0; 3972 return 0;
4011} 3973}
4012 3974
@@ -4021,6 +3983,7 @@ static long pmcraid_chr_ioctl(
4021{ 3983{
4022 struct pmcraid_instance *pinstance = NULL; 3984 struct pmcraid_instance *pinstance = NULL;
4023 struct pmcraid_ioctl_header *hdr = NULL; 3985 struct pmcraid_ioctl_header *hdr = NULL;
3986 void __user *argp = (void __user *)arg;
4024 int retval = -ENOTTY; 3987 int retval = -ENOTTY;
4025 3988
4026 hdr = kmalloc(sizeof(struct pmcraid_ioctl_header), GFP_KERNEL); 3989 hdr = kmalloc(sizeof(struct pmcraid_ioctl_header), GFP_KERNEL);
@@ -4030,7 +3993,7 @@ static long pmcraid_chr_ioctl(
4030 return -ENOMEM; 3993 return -ENOMEM;
4031 } 3994 }
4032 3995
4033 retval = pmcraid_check_ioctl_buffer(cmd, (void *)arg, hdr); 3996 retval = pmcraid_check_ioctl_buffer(cmd, argp, hdr);
4034 3997
4035 if (retval) { 3998 if (retval) {
4036 pmcraid_info("chr_ioctl: header check failed\n"); 3999 pmcraid_info("chr_ioctl: header check failed\n");
@@ -4055,10 +4018,8 @@ static long pmcraid_chr_ioctl(
4055 if (cmd == PMCRAID_IOCTL_DOWNLOAD_MICROCODE) 4018 if (cmd == PMCRAID_IOCTL_DOWNLOAD_MICROCODE)
4056 scsi_block_requests(pinstance->host); 4019 scsi_block_requests(pinstance->host);
4057 4020
4058 retval = pmcraid_ioctl_passthrough(pinstance, 4021 retval = pmcraid_ioctl_passthrough(pinstance, cmd,
4059 cmd, 4022 hdr->buffer_length, argp);
4060 hdr->buffer_length,
4061 arg);
4062 4023
4063 if (cmd == PMCRAID_IOCTL_DOWNLOAD_MICROCODE) 4024 if (cmd == PMCRAID_IOCTL_DOWNLOAD_MICROCODE)
4064 scsi_unblock_requests(pinstance->host); 4025 scsi_unblock_requests(pinstance->host);
@@ -4066,10 +4027,8 @@ static long pmcraid_chr_ioctl(
4066 4027
4067 case PMCRAID_DRIVER_IOCTL: 4028 case PMCRAID_DRIVER_IOCTL:
4068 arg += sizeof(struct pmcraid_ioctl_header); 4029 arg += sizeof(struct pmcraid_ioctl_header);
4069 retval = pmcraid_ioctl_driver(pinstance, 4030 retval = pmcraid_ioctl_driver(pinstance, cmd,
4070 cmd, 4031 hdr->buffer_length, argp);
4071 hdr->buffer_length,
4072 (void __user *)arg);
4073 break; 4032 break;
4074 4033
4075 default: 4034 default:
@@ -4470,7 +4429,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
4470 if (fw_version <= PMCRAID_FW_VERSION_1) 4429 if (fw_version <= PMCRAID_FW_VERSION_1)
4471 target = res->cfg_entry.unique_flags1; 4430 target = res->cfg_entry.unique_flags1;
4472 else 4431 else
4473 target = res->cfg_entry.array_id & 0xFF; 4432 target = le16_to_cpu(res->cfg_entry.array_id) & 0xFF;
4474 lun = PMCRAID_VSET_LUN_ID; 4433 lun = PMCRAID_VSET_LUN_ID;
4475 } else { 4434 } else {
4476 bus = PMCRAID_PHYS_BUS_ID; 4435 bus = PMCRAID_PHYS_BUS_ID;
@@ -4509,7 +4468,7 @@ static void pmcraid_tasklet_function(unsigned long instance)
4509 unsigned long host_lock_flags; 4468 unsigned long host_lock_flags;
4510 spinlock_t *lockp; /* hrrq buffer lock */ 4469 spinlock_t *lockp; /* hrrq buffer lock */
4511 int id; 4470 int id;
4512 __le32 resp; 4471 u32 resp;
4513 4472
4514 hrrq_vector = (struct pmcraid_isr_param *)instance; 4473 hrrq_vector = (struct pmcraid_isr_param *)instance;
4515 pinstance = hrrq_vector->drv_inst; 4474 pinstance = hrrq_vector->drv_inst;
@@ -4833,7 +4792,7 @@ static int pmcraid_allocate_host_rrqs(struct pmcraid_instance *pinstance)
4833 buffer_size, 4792 buffer_size,
4834 &(pinstance->hrrq_start_bus_addr[i])); 4793 &(pinstance->hrrq_start_bus_addr[i]));
4835 4794
4836 if (pinstance->hrrq_start[i] == 0) { 4795 if (!pinstance->hrrq_start[i]) {
4837 pmcraid_err("pci_alloc failed for hrrq vector : %d\n", 4796 pmcraid_err("pci_alloc failed for hrrq vector : %d\n",
4838 i); 4797 i);
4839 pmcraid_release_host_rrqs(pinstance, i); 4798 pmcraid_release_host_rrqs(pinstance, i);
@@ -5549,8 +5508,7 @@ static void pmcraid_set_timestamp(struct pmcraid_cmd *cmd)
5549 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; 5508 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb;
5550 __be32 time_stamp_len = cpu_to_be32(PMCRAID_TIMESTAMP_LEN); 5509 __be32 time_stamp_len = cpu_to_be32(PMCRAID_TIMESTAMP_LEN);
5551 struct pmcraid_ioadl_desc *ioadl = ioarcb->add_data.u.ioadl; 5510 struct pmcraid_ioadl_desc *ioadl = ioarcb->add_data.u.ioadl;
5552 5511 u64 timestamp;
5553 __le64 timestamp;
5554 5512
5555 timestamp = ktime_get_real_seconds() * 1000; 5513 timestamp = ktime_get_real_seconds() * 1000;
5556 5514
@@ -5572,7 +5530,7 @@ static void pmcraid_set_timestamp(struct pmcraid_cmd *cmd)
5572 offsetof(struct pmcraid_ioarcb, 5530 offsetof(struct pmcraid_ioarcb,
5573 add_data.u.ioadl[0])); 5531 add_data.u.ioadl[0]));
5574 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); 5532 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc));
5575 ioarcb->ioarcb_bus_addr &= ~(0x1FULL); 5533 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~(0x1FULL));
5576 5534
5577 ioarcb->request_flags0 |= NO_LINK_DESCS; 5535 ioarcb->request_flags0 |= NO_LINK_DESCS;
5578 ioarcb->request_flags0 |= TRANSFER_DIR_WRITE; 5536 ioarcb->request_flags0 |= TRANSFER_DIR_WRITE;
@@ -5631,7 +5589,7 @@ static void pmcraid_init_res_table(struct pmcraid_cmd *cmd)
5631 list_for_each_entry_safe(res, temp, &pinstance->used_res_q, queue) 5589 list_for_each_entry_safe(res, temp, &pinstance->used_res_q, queue)
5632 list_move_tail(&res->queue, &old_res); 5590 list_move_tail(&res->queue, &old_res);
5633 5591
5634 for (i = 0; i < pinstance->cfg_table->num_entries; i++) { 5592 for (i = 0; i < le16_to_cpu(pinstance->cfg_table->num_entries); i++) {
5635 if (be16_to_cpu(pinstance->inq_data->fw_version) <= 5593 if (be16_to_cpu(pinstance->inq_data->fw_version) <=
5636 PMCRAID_FW_VERSION_1) 5594 PMCRAID_FW_VERSION_1)
5637 cfgte = &pinstance->cfg_table->entries[i]; 5595 cfgte = &pinstance->cfg_table->entries[i];
@@ -5686,7 +5644,7 @@ static void pmcraid_init_res_table(struct pmcraid_cmd *cmd)
5686 res->cfg_entry.resource_type, 5644 res->cfg_entry.resource_type,
5687 (fw_version <= PMCRAID_FW_VERSION_1 ? 5645 (fw_version <= PMCRAID_FW_VERSION_1 ?
5688 res->cfg_entry.unique_flags1 : 5646 res->cfg_entry.unique_flags1 :
5689 res->cfg_entry.array_id & 0xFF), 5647 le16_to_cpu(res->cfg_entry.array_id) & 0xFF),
5690 le32_to_cpu(res->cfg_entry.resource_address)); 5648 le32_to_cpu(res->cfg_entry.resource_address));
5691 } 5649 }
5692 } 5650 }
@@ -5724,7 +5682,7 @@ static void pmcraid_querycfg(struct pmcraid_cmd *cmd)
5724 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb; 5682 struct pmcraid_ioarcb *ioarcb = &cmd->ioa_cb->ioarcb;
5725 struct pmcraid_ioadl_desc *ioadl = ioarcb->add_data.u.ioadl; 5683 struct pmcraid_ioadl_desc *ioadl = ioarcb->add_data.u.ioadl;
5726 struct pmcraid_instance *pinstance = cmd->drv_inst; 5684 struct pmcraid_instance *pinstance = cmd->drv_inst;
5727 int cfg_table_size = cpu_to_be32(sizeof(struct pmcraid_config_table)); 5685 __be32 cfg_table_size = cpu_to_be32(sizeof(struct pmcraid_config_table));
5728 5686
5729 if (be16_to_cpu(pinstance->inq_data->fw_version) <= 5687 if (be16_to_cpu(pinstance->inq_data->fw_version) <=
5730 PMCRAID_FW_VERSION_1) 5688 PMCRAID_FW_VERSION_1)
@@ -5749,7 +5707,7 @@ static void pmcraid_querycfg(struct pmcraid_cmd *cmd)
5749 offsetof(struct pmcraid_ioarcb, 5707 offsetof(struct pmcraid_ioarcb,
5750 add_data.u.ioadl[0])); 5708 add_data.u.ioadl[0]));
5751 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc)); 5709 ioarcb->ioadl_length = cpu_to_le32(sizeof(struct pmcraid_ioadl_desc));
5752 ioarcb->ioarcb_bus_addr &= ~(0x1FULL); 5710 ioarcb->ioarcb_bus_addr &= cpu_to_le64(~0x1FULL);
5753 5711
5754 ioarcb->request_flags0 |= NO_LINK_DESCS; 5712 ioarcb->request_flags0 |= NO_LINK_DESCS;
5755 ioarcb->data_transfer_length = 5713 ioarcb->data_transfer_length =