diff options
Diffstat (limited to 'drivers/firewire/fw-sbp2.c')
-rw-r--r-- | drivers/firewire/fw-sbp2.c | 116 |
1 files changed, 44 insertions, 72 deletions
diff --git a/drivers/firewire/fw-sbp2.c b/drivers/firewire/fw-sbp2.c index aaff50ebba1d..ef0b9b419c27 100644 --- a/drivers/firewire/fw-sbp2.c +++ b/drivers/firewire/fw-sbp2.c | |||
@@ -29,6 +29,7 @@ | |||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <linux/blkdev.h> | 31 | #include <linux/blkdev.h> |
32 | #include <linux/bug.h> | ||
32 | #include <linux/delay.h> | 33 | #include <linux/delay.h> |
33 | #include <linux/device.h> | 34 | #include <linux/device.h> |
34 | #include <linux/dma-mapping.h> | 35 | #include <linux/dma-mapping.h> |
@@ -181,10 +182,16 @@ struct sbp2_target { | |||
181 | #define SBP2_MAX_LOGIN_ORB_TIMEOUT 40000U /* Timeout in ms */ | 182 | #define SBP2_MAX_LOGIN_ORB_TIMEOUT 40000U /* Timeout in ms */ |
182 | #define SBP2_ORB_TIMEOUT 2000U /* Timeout in ms */ | 183 | #define SBP2_ORB_TIMEOUT 2000U /* Timeout in ms */ |
183 | #define SBP2_ORB_NULL 0x80000000 | 184 | #define SBP2_ORB_NULL 0x80000000 |
184 | #define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000 | ||
185 | #define SBP2_RETRY_LIMIT 0xf /* 15 retries */ | 185 | #define SBP2_RETRY_LIMIT 0xf /* 15 retries */ |
186 | #define SBP2_CYCLE_LIMIT (0xc8 << 12) /* 200 125us cycles */ | 186 | #define SBP2_CYCLE_LIMIT (0xc8 << 12) /* 200 125us cycles */ |
187 | 187 | ||
188 | /* | ||
189 | * The default maximum s/g segment size of a FireWire controller is | ||
190 | * usually 0x10000, but SBP-2 only allows 0xffff. Since buffers have to | ||
191 | * be quadlet-aligned, we set the length limit to 0xffff & ~3. | ||
192 | */ | ||
193 | #define SBP2_MAX_SEG_SIZE 0xfffc | ||
194 | |||
188 | /* Unit directory keys */ | 195 | /* Unit directory keys */ |
189 | #define SBP2_CSR_UNIT_CHARACTERISTICS 0x3a | 196 | #define SBP2_CSR_UNIT_CHARACTERISTICS 0x3a |
190 | #define SBP2_CSR_FIRMWARE_REVISION 0x3c | 197 | #define SBP2_CSR_FIRMWARE_REVISION 0x3c |
@@ -621,25 +628,15 @@ sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id, | |||
621 | return retval; | 628 | return retval; |
622 | } | 629 | } |
623 | 630 | ||
624 | static void | ||
625 | complete_agent_reset_write(struct fw_card *card, int rcode, | ||
626 | void *payload, size_t length, void *done) | ||
627 | { | ||
628 | complete(done); | ||
629 | } | ||
630 | |||
631 | static void sbp2_agent_reset(struct sbp2_logical_unit *lu) | 631 | static void sbp2_agent_reset(struct sbp2_logical_unit *lu) |
632 | { | 632 | { |
633 | struct fw_device *device = fw_device(lu->tgt->unit->device.parent); | 633 | struct fw_device *device = fw_device(lu->tgt->unit->device.parent); |
634 | DECLARE_COMPLETION_ONSTACK(done); | 634 | __be32 d = 0; |
635 | struct fw_transaction t; | ||
636 | static u32 z; | ||
637 | 635 | ||
638 | fw_send_request(device->card, &t, TCODE_WRITE_QUADLET_REQUEST, | 636 | fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST, |
639 | lu->tgt->node_id, lu->generation, device->max_speed, | 637 | lu->tgt->node_id, lu->generation, device->max_speed, |
640 | lu->command_block_agent_address + SBP2_AGENT_RESET, | 638 | lu->command_block_agent_address + SBP2_AGENT_RESET, |
641 | &z, sizeof(z), complete_agent_reset_write, &done); | 639 | &d, sizeof(d)); |
642 | wait_for_completion(&done); | ||
643 | } | 640 | } |
644 | 641 | ||
645 | static void | 642 | static void |
@@ -653,7 +650,7 @@ static void sbp2_agent_reset_no_wait(struct sbp2_logical_unit *lu) | |||
653 | { | 650 | { |
654 | struct fw_device *device = fw_device(lu->tgt->unit->device.parent); | 651 | struct fw_device *device = fw_device(lu->tgt->unit->device.parent); |
655 | struct fw_transaction *t; | 652 | struct fw_transaction *t; |
656 | static u32 z; | 653 | static __be32 d; |
657 | 654 | ||
658 | t = kmalloc(sizeof(*t), GFP_ATOMIC); | 655 | t = kmalloc(sizeof(*t), GFP_ATOMIC); |
659 | if (t == NULL) | 656 | if (t == NULL) |
@@ -662,7 +659,7 @@ static void sbp2_agent_reset_no_wait(struct sbp2_logical_unit *lu) | |||
662 | fw_send_request(device->card, t, TCODE_WRITE_QUADLET_REQUEST, | 659 | fw_send_request(device->card, t, TCODE_WRITE_QUADLET_REQUEST, |
663 | lu->tgt->node_id, lu->generation, device->max_speed, | 660 | lu->tgt->node_id, lu->generation, device->max_speed, |
664 | lu->command_block_agent_address + SBP2_AGENT_RESET, | 661 | lu->command_block_agent_address + SBP2_AGENT_RESET, |
665 | &z, sizeof(z), complete_agent_reset_write_no_wait, t); | 662 | &d, sizeof(d), complete_agent_reset_write_no_wait, t); |
666 | } | 663 | } |
667 | 664 | ||
668 | static void sbp2_set_generation(struct sbp2_logical_unit *lu, int generation) | 665 | static void sbp2_set_generation(struct sbp2_logical_unit *lu, int generation) |
@@ -823,13 +820,6 @@ static void sbp2_target_put(struct sbp2_target *tgt) | |||
823 | kref_put(&tgt->kref, sbp2_release_target); | 820 | kref_put(&tgt->kref, sbp2_release_target); |
824 | } | 821 | } |
825 | 822 | ||
826 | static void | ||
827 | complete_set_busy_timeout(struct fw_card *card, int rcode, | ||
828 | void *payload, size_t length, void *done) | ||
829 | { | ||
830 | complete(done); | ||
831 | } | ||
832 | |||
833 | /* | 823 | /* |
834 | * Write retransmit retry values into the BUSY_TIMEOUT register. | 824 | * Write retransmit retry values into the BUSY_TIMEOUT register. |
835 | * - The single-phase retry protocol is supported by all SBP-2 devices, but the | 825 | * - The single-phase retry protocol is supported by all SBP-2 devices, but the |
@@ -849,17 +839,12 @@ complete_set_busy_timeout(struct fw_card *card, int rcode, | |||
849 | static void sbp2_set_busy_timeout(struct sbp2_logical_unit *lu) | 839 | static void sbp2_set_busy_timeout(struct sbp2_logical_unit *lu) |
850 | { | 840 | { |
851 | struct fw_device *device = fw_device(lu->tgt->unit->device.parent); | 841 | struct fw_device *device = fw_device(lu->tgt->unit->device.parent); |
852 | DECLARE_COMPLETION_ONSTACK(done); | 842 | __be32 d = cpu_to_be32(SBP2_CYCLE_LIMIT | SBP2_RETRY_LIMIT); |
853 | struct fw_transaction t; | ||
854 | static __be32 busy_timeout; | ||
855 | |||
856 | busy_timeout = cpu_to_be32(SBP2_CYCLE_LIMIT | SBP2_RETRY_LIMIT); | ||
857 | 843 | ||
858 | fw_send_request(device->card, &t, TCODE_WRITE_QUADLET_REQUEST, | 844 | fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST, |
859 | lu->tgt->node_id, lu->generation, device->max_speed, | 845 | lu->tgt->node_id, lu->generation, device->max_speed, |
860 | CSR_REGISTER_BASE + CSR_BUSY_TIMEOUT, &busy_timeout, | 846 | CSR_REGISTER_BASE + CSR_BUSY_TIMEOUT, |
861 | sizeof(busy_timeout), complete_set_busy_timeout, &done); | 847 | &d, sizeof(d)); |
862 | wait_for_completion(&done); | ||
863 | } | 848 | } |
864 | 849 | ||
865 | static void sbp2_reconnect(struct work_struct *work); | 850 | static void sbp2_reconnect(struct work_struct *work); |
@@ -1121,6 +1106,10 @@ static int sbp2_probe(struct device *dev) | |||
1121 | struct Scsi_Host *shost; | 1106 | struct Scsi_Host *shost; |
1122 | u32 model, firmware_revision; | 1107 | u32 model, firmware_revision; |
1123 | 1108 | ||
1109 | if (dma_get_max_seg_size(device->card->device) > SBP2_MAX_SEG_SIZE) | ||
1110 | BUG_ON(dma_set_max_seg_size(device->card->device, | ||
1111 | SBP2_MAX_SEG_SIZE)); | ||
1112 | |||
1124 | shost = scsi_host_alloc(&scsi_driver_template, sizeof(*tgt)); | 1113 | shost = scsi_host_alloc(&scsi_driver_template, sizeof(*tgt)); |
1125 | if (shost == NULL) | 1114 | if (shost == NULL) |
1126 | return -ENOMEM; | 1115 | return -ENOMEM; |
@@ -1369,14 +1358,12 @@ static int | |||
1369 | sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device, | 1358 | sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device, |
1370 | struct sbp2_logical_unit *lu) | 1359 | struct sbp2_logical_unit *lu) |
1371 | { | 1360 | { |
1372 | struct scatterlist *sg; | 1361 | struct scatterlist *sg = scsi_sglist(orb->cmd); |
1373 | int sg_len, l, i, j, count; | 1362 | int i, n; |
1374 | dma_addr_t sg_addr; | 1363 | |
1375 | 1364 | n = dma_map_sg(device->card->device, sg, scsi_sg_count(orb->cmd), | |
1376 | sg = scsi_sglist(orb->cmd); | 1365 | orb->cmd->sc_data_direction); |
1377 | count = dma_map_sg(device->card->device, sg, scsi_sg_count(orb->cmd), | 1366 | if (n == 0) |
1378 | orb->cmd->sc_data_direction); | ||
1379 | if (count == 0) | ||
1380 | goto fail; | 1367 | goto fail; |
1381 | 1368 | ||
1382 | /* | 1369 | /* |
@@ -1386,7 +1373,7 @@ sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device, | |||
1386 | * as the second generation iPod which doesn't support page | 1373 | * as the second generation iPod which doesn't support page |
1387 | * tables. | 1374 | * tables. |
1388 | */ | 1375 | */ |
1389 | if (count == 1 && sg_dma_len(sg) < SBP2_MAX_SG_ELEMENT_LENGTH) { | 1376 | if (n == 1) { |
1390 | orb->request.data_descriptor.high = | 1377 | orb->request.data_descriptor.high = |
1391 | cpu_to_be32(lu->tgt->address_high); | 1378 | cpu_to_be32(lu->tgt->address_high); |
1392 | orb->request.data_descriptor.low = | 1379 | orb->request.data_descriptor.low = |
@@ -1396,29 +1383,9 @@ sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device, | |||
1396 | return 0; | 1383 | return 0; |
1397 | } | 1384 | } |
1398 | 1385 | ||
1399 | /* | 1386 | for_each_sg(sg, sg, n, i) { |
1400 | * Convert the scatterlist to an sbp2 page table. If any | 1387 | orb->page_table[i].high = cpu_to_be32(sg_dma_len(sg) << 16); |
1401 | * scatterlist entries are too big for sbp2, we split them as we | 1388 | orb->page_table[i].low = cpu_to_be32(sg_dma_address(sg)); |
1402 | * go. Even if we ask the block I/O layer to not give us sg | ||
1403 | * elements larger than 65535 bytes, some IOMMUs may merge sg elements | ||
1404 | * during DMA mapping, and Linux currently doesn't prevent this. | ||
1405 | */ | ||
1406 | for (i = 0, j = 0; i < count; i++, sg = sg_next(sg)) { | ||
1407 | sg_len = sg_dma_len(sg); | ||
1408 | sg_addr = sg_dma_address(sg); | ||
1409 | while (sg_len) { | ||
1410 | /* FIXME: This won't get us out of the pinch. */ | ||
1411 | if (unlikely(j >= ARRAY_SIZE(orb->page_table))) { | ||
1412 | fw_error("page table overflow\n"); | ||
1413 | goto fail_page_table; | ||
1414 | } | ||
1415 | l = min(sg_len, SBP2_MAX_SG_ELEMENT_LENGTH); | ||
1416 | orb->page_table[j].low = cpu_to_be32(sg_addr); | ||
1417 | orb->page_table[j].high = cpu_to_be32(l << 16); | ||
1418 | sg_addr += l; | ||
1419 | sg_len -= l; | ||
1420 | j++; | ||
1421 | } | ||
1422 | } | 1389 | } |
1423 | 1390 | ||
1424 | orb->page_table_bus = | 1391 | orb->page_table_bus = |
@@ -1437,13 +1404,13 @@ sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device, | |||
1437 | orb->request.data_descriptor.high = cpu_to_be32(lu->tgt->address_high); | 1404 | orb->request.data_descriptor.high = cpu_to_be32(lu->tgt->address_high); |
1438 | orb->request.data_descriptor.low = cpu_to_be32(orb->page_table_bus); | 1405 | orb->request.data_descriptor.low = cpu_to_be32(orb->page_table_bus); |
1439 | orb->request.misc |= cpu_to_be32(COMMAND_ORB_PAGE_TABLE_PRESENT | | 1406 | orb->request.misc |= cpu_to_be32(COMMAND_ORB_PAGE_TABLE_PRESENT | |
1440 | COMMAND_ORB_DATA_SIZE(j)); | 1407 | COMMAND_ORB_DATA_SIZE(n)); |
1441 | 1408 | ||
1442 | return 0; | 1409 | return 0; |
1443 | 1410 | ||
1444 | fail_page_table: | 1411 | fail_page_table: |
1445 | dma_unmap_sg(device->card->device, sg, scsi_sg_count(orb->cmd), | 1412 | dma_unmap_sg(device->card->device, scsi_sglist(orb->cmd), |
1446 | orb->cmd->sc_data_direction); | 1413 | scsi_sg_count(orb->cmd), orb->cmd->sc_data_direction); |
1447 | fail: | 1414 | fail: |
1448 | return -ENOMEM; | 1415 | return -ENOMEM; |
1449 | } | 1416 | } |
@@ -1456,7 +1423,7 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done) | |||
1456 | struct fw_device *device = fw_device(lu->tgt->unit->device.parent); | 1423 | struct fw_device *device = fw_device(lu->tgt->unit->device.parent); |
1457 | struct sbp2_command_orb *orb; | 1424 | struct sbp2_command_orb *orb; |
1458 | unsigned int max_payload; | 1425 | unsigned int max_payload; |
1459 | int retval = SCSI_MLQUEUE_HOST_BUSY; | 1426 | int generation, retval = SCSI_MLQUEUE_HOST_BUSY; |
1460 | 1427 | ||
1461 | /* | 1428 | /* |
1462 | * Bidirectional commands are not yet implemented, and unknown | 1429 | * Bidirectional commands are not yet implemented, and unknown |
@@ -1500,6 +1467,9 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done) | |||
1500 | if (cmd->sc_data_direction == DMA_FROM_DEVICE) | 1467 | if (cmd->sc_data_direction == DMA_FROM_DEVICE) |
1501 | orb->request.misc |= cpu_to_be32(COMMAND_ORB_DIRECTION); | 1468 | orb->request.misc |= cpu_to_be32(COMMAND_ORB_DIRECTION); |
1502 | 1469 | ||
1470 | generation = device->generation; | ||
1471 | smp_rmb(); /* sbp2_map_scatterlist looks at tgt->address_high */ | ||
1472 | |||
1503 | if (scsi_sg_count(cmd) && sbp2_map_scatterlist(orb, device, lu) < 0) | 1473 | if (scsi_sg_count(cmd) && sbp2_map_scatterlist(orb, device, lu) < 0) |
1504 | goto out; | 1474 | goto out; |
1505 | 1475 | ||
@@ -1512,7 +1482,7 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done) | |||
1512 | if (dma_mapping_error(device->card->device, orb->base.request_bus)) | 1482 | if (dma_mapping_error(device->card->device, orb->base.request_bus)) |
1513 | goto out; | 1483 | goto out; |
1514 | 1484 | ||
1515 | sbp2_send_orb(&orb->base, lu, lu->tgt->node_id, lu->generation, | 1485 | sbp2_send_orb(&orb->base, lu, lu->tgt->node_id, generation, |
1516 | lu->command_block_agent_address + SBP2_ORB_POINTER); | 1486 | lu->command_block_agent_address + SBP2_ORB_POINTER); |
1517 | retval = 0; | 1487 | retval = 0; |
1518 | out: | 1488 | out: |
@@ -1564,6 +1534,8 @@ static int sbp2_scsi_slave_configure(struct scsi_device *sdev) | |||
1564 | if (lu->tgt->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS) | 1534 | if (lu->tgt->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS) |
1565 | blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512); | 1535 | blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512); |
1566 | 1536 | ||
1537 | blk_queue_max_segment_size(sdev->request_queue, SBP2_MAX_SEG_SIZE); | ||
1538 | |||
1567 | return 0; | 1539 | return 0; |
1568 | } | 1540 | } |
1569 | 1541 | ||