aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firewire/fw-sbp2.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/firewire/fw-sbp2.c')
-rw-r--r--drivers/firewire/fw-sbp2.c117
1 files changed, 58 insertions, 59 deletions
diff --git a/drivers/firewire/fw-sbp2.c b/drivers/firewire/fw-sbp2.c
index a98d3915e26f..7c53be0387fb 100644
--- a/drivers/firewire/fw-sbp2.c
+++ b/drivers/firewire/fw-sbp2.c
@@ -30,10 +30,13 @@
30 30
31#include <linux/kernel.h> 31#include <linux/kernel.h>
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/moduleparam.h>
33#include <linux/mod_devicetable.h> 34#include <linux/mod_devicetable.h>
34#include <linux/device.h> 35#include <linux/device.h>
35#include <linux/scatterlist.h> 36#include <linux/scatterlist.h>
36#include <linux/dma-mapping.h> 37#include <linux/dma-mapping.h>
38#include <linux/blkdev.h>
39#include <linux/string.h>
37#include <linux/timer.h> 40#include <linux/timer.h>
38 41
39#include <scsi/scsi.h> 42#include <scsi/scsi.h>
@@ -46,6 +49,18 @@
46#include "fw-topology.h" 49#include "fw-topology.h"
47#include "fw-device.h" 50#include "fw-device.h"
48 51
52/*
53 * So far only bridges from Oxford Semiconductor are known to support
54 * concurrent logins. Depending on firmware, four or two concurrent logins
55 * are possible on OXFW911 and newer Oxsemi bridges.
56 *
57 * Concurrent logins are useful together with cluster filesystems.
58 */
59static int sbp2_param_exclusive_login = 1;
60module_param_named(exclusive_login, sbp2_param_exclusive_login, bool, 0644);
61MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device "
62 "(default = Y, use N for concurrent initiators)");
63
49/* I don't know why the SCSI stack doesn't define something like this... */ 64/* I don't know why the SCSI stack doesn't define something like this... */
50typedef void (*scsi_done_fn_t)(struct scsi_cmnd *); 65typedef void (*scsi_done_fn_t)(struct scsi_cmnd *);
51 66
@@ -154,7 +169,7 @@ struct sbp2_orb {
154#define MANAGEMENT_ORB_LUN(v) ((v)) 169#define MANAGEMENT_ORB_LUN(v) ((v))
155#define MANAGEMENT_ORB_FUNCTION(v) ((v) << 16) 170#define MANAGEMENT_ORB_FUNCTION(v) ((v) << 16)
156#define MANAGEMENT_ORB_RECONNECT(v) ((v) << 20) 171#define MANAGEMENT_ORB_RECONNECT(v) ((v) << 20)
157#define MANAGEMENT_ORB_EXCLUSIVE ((1) << 28) 172#define MANAGEMENT_ORB_EXCLUSIVE(v) ((v) ? 1 << 28 : 0)
158#define MANAGEMENT_ORB_REQUEST_FORMAT(v) ((v) << 29) 173#define MANAGEMENT_ORB_REQUEST_FORMAT(v) ((v) << 29)
159#define MANAGEMENT_ORB_NOTIFY ((1) << 31) 174#define MANAGEMENT_ORB_NOTIFY ((1) << 31)
160 175
@@ -205,9 +220,8 @@ struct sbp2_command_orb {
205 scsi_done_fn_t done; 220 scsi_done_fn_t done;
206 struct fw_unit *unit; 221 struct fw_unit *unit;
207 222
208 struct sbp2_pointer page_table[SG_ALL]; 223 struct sbp2_pointer page_table[SG_ALL] __attribute__((aligned(8)));
209 dma_addr_t page_table_bus; 224 dma_addr_t page_table_bus;
210 dma_addr_t request_buffer_bus;
211}; 225};
212 226
213/* 227/*
@@ -347,8 +361,7 @@ sbp2_send_orb(struct sbp2_orb *orb, struct fw_unit *unit,
347 spin_unlock_irqrestore(&device->card->lock, flags); 361 spin_unlock_irqrestore(&device->card->lock, flags);
348 362
349 fw_send_request(device->card, &orb->t, TCODE_WRITE_BLOCK_REQUEST, 363 fw_send_request(device->card, &orb->t, TCODE_WRITE_BLOCK_REQUEST,
350 node_id, generation, 364 node_id, generation, device->max_speed, offset,
351 device->node->max_speed, offset,
352 &orb->pointer, sizeof(orb->pointer), 365 &orb->pointer, sizeof(orb->pointer),
353 complete_transaction, orb); 366 complete_transaction, orb);
354} 367}
@@ -383,7 +396,7 @@ static void
383complete_management_orb(struct sbp2_orb *base_orb, struct sbp2_status *status) 396complete_management_orb(struct sbp2_orb *base_orb, struct sbp2_status *status)
384{ 397{
385 struct sbp2_management_orb *orb = 398 struct sbp2_management_orb *orb =
386 (struct sbp2_management_orb *)base_orb; 399 container_of(base_orb, struct sbp2_management_orb, base);
387 400
388 if (status) 401 if (status)
389 memcpy(&orb->status, status, sizeof(*status)); 402 memcpy(&orb->status, status, sizeof(*status));
@@ -403,21 +416,11 @@ sbp2_send_management_orb(struct fw_unit *unit, int node_id, int generation,
403 if (orb == NULL) 416 if (orb == NULL)
404 return -ENOMEM; 417 return -ENOMEM;
405 418
406 /*
407 * The sbp2 device is going to send a block read request to
408 * read out the request from host memory, so map it for dma.
409 */
410 orb->base.request_bus =
411 dma_map_single(device->card->device, &orb->request,
412 sizeof(orb->request), DMA_TO_DEVICE);
413 if (dma_mapping_error(orb->base.request_bus))
414 goto out;
415
416 orb->response_bus = 419 orb->response_bus =
417 dma_map_single(device->card->device, &orb->response, 420 dma_map_single(device->card->device, &orb->response,
418 sizeof(orb->response), DMA_FROM_DEVICE); 421 sizeof(orb->response), DMA_FROM_DEVICE);
419 if (dma_mapping_error(orb->response_bus)) 422 if (dma_mapping_error(orb->response_bus))
420 goto out; 423 goto fail_mapping_response;
421 424
422 orb->request.response.high = 0; 425 orb->request.response.high = 0;
423 orb->request.response.low = orb->response_bus; 426 orb->request.response.low = orb->response_bus;
@@ -432,14 +435,9 @@ sbp2_send_management_orb(struct fw_unit *unit, int node_id, int generation,
432 orb->request.status_fifo.high = sd->address_handler.offset >> 32; 435 orb->request.status_fifo.high = sd->address_handler.offset >> 32;
433 orb->request.status_fifo.low = sd->address_handler.offset; 436 orb->request.status_fifo.low = sd->address_handler.offset;
434 437
435 /*
436 * FIXME: Yeah, ok this isn't elegant, we hardwire exclusive
437 * login and 1 second reconnect time. The reconnect setting
438 * is probably fine, but the exclusive login should be an option.
439 */
440 if (function == SBP2_LOGIN_REQUEST) { 438 if (function == SBP2_LOGIN_REQUEST) {
441 orb->request.misc |= 439 orb->request.misc |=
442 MANAGEMENT_ORB_EXCLUSIVE | 440 MANAGEMENT_ORB_EXCLUSIVE(sbp2_param_exclusive_login) |
443 MANAGEMENT_ORB_RECONNECT(0); 441 MANAGEMENT_ORB_RECONNECT(0);
444 } 442 }
445 443
@@ -448,6 +446,12 @@ sbp2_send_management_orb(struct fw_unit *unit, int node_id, int generation,
448 init_completion(&orb->done); 446 init_completion(&orb->done);
449 orb->base.callback = complete_management_orb; 447 orb->base.callback = complete_management_orb;
450 448
449 orb->base.request_bus =
450 dma_map_single(device->card->device, &orb->request,
451 sizeof(orb->request), DMA_TO_DEVICE);
452 if (dma_mapping_error(orb->base.request_bus))
453 goto fail_mapping_request;
454
451 sbp2_send_orb(&orb->base, unit, 455 sbp2_send_orb(&orb->base, unit,
452 node_id, generation, sd->management_agent_address); 456 node_id, generation, sd->management_agent_address);
453 457
@@ -479,9 +483,10 @@ sbp2_send_management_orb(struct fw_unit *unit, int node_id, int generation,
479 out: 483 out:
480 dma_unmap_single(device->card->device, orb->base.request_bus, 484 dma_unmap_single(device->card->device, orb->base.request_bus,
481 sizeof(orb->request), DMA_TO_DEVICE); 485 sizeof(orb->request), DMA_TO_DEVICE);
486 fail_mapping_request:
482 dma_unmap_single(device->card->device, orb->response_bus, 487 dma_unmap_single(device->card->device, orb->response_bus,
483 sizeof(orb->response), DMA_FROM_DEVICE); 488 sizeof(orb->response), DMA_FROM_DEVICE);
484 489 fail_mapping_response:
485 if (response) 490 if (response)
486 fw_memcpy_from_be32(response, 491 fw_memcpy_from_be32(response,
487 orb->response, sizeof(orb->response)); 492 orb->response, sizeof(orb->response));
@@ -511,7 +516,7 @@ static int sbp2_agent_reset(struct fw_unit *unit)
511 return -ENOMEM; 516 return -ENOMEM;
512 517
513 fw_send_request(device->card, t, TCODE_WRITE_QUADLET_REQUEST, 518 fw_send_request(device->card, t, TCODE_WRITE_QUADLET_REQUEST,
514 sd->node_id, sd->generation, SCODE_400, 519 sd->node_id, sd->generation, device->max_speed,
515 sd->command_block_agent_address + SBP2_AGENT_RESET, 520 sd->command_block_agent_address + SBP2_AGENT_RESET,
516 &zero, sizeof(zero), complete_agent_reset_write, t); 521 &zero, sizeof(zero), complete_agent_reset_write, t);
517 522
@@ -521,17 +526,15 @@ static int sbp2_agent_reset(struct fw_unit *unit)
521static void sbp2_reconnect(struct work_struct *work); 526static void sbp2_reconnect(struct work_struct *work);
522static struct scsi_host_template scsi_driver_template; 527static struct scsi_host_template scsi_driver_template;
523 528
524static void 529static void release_sbp2_device(struct kref *kref)
525release_sbp2_device(struct kref *kref)
526{ 530{
527 struct sbp2_device *sd = container_of(kref, struct sbp2_device, kref); 531 struct sbp2_device *sd = container_of(kref, struct sbp2_device, kref);
528 struct Scsi_Host *host = 532 struct Scsi_Host *host =
529 container_of((void *)sd, struct Scsi_Host, hostdata[0]); 533 container_of((void *)sd, struct Scsi_Host, hostdata[0]);
530 534
535 scsi_remove_host(host);
531 sbp2_send_management_orb(sd->unit, sd->node_id, sd->generation, 536 sbp2_send_management_orb(sd->unit, sd->node_id, sd->generation,
532 SBP2_LOGOUT_REQUEST, sd->login_id, NULL); 537 SBP2_LOGOUT_REQUEST, sd->login_id, NULL);
533
534 scsi_remove_host(host);
535 fw_core_remove_address_handler(&sd->address_handler); 538 fw_core_remove_address_handler(&sd->address_handler);
536 fw_notify("removed sbp2 unit %s\n", sd->unit->device.bus_id); 539 fw_notify("removed sbp2 unit %s\n", sd->unit->device.bus_id);
537 put_device(&sd->unit->device); 540 put_device(&sd->unit->device);
@@ -833,7 +836,8 @@ sbp2_status_to_sense_data(u8 *sbp2_status, u8 *sense_data)
833static void 836static void
834complete_command_orb(struct sbp2_orb *base_orb, struct sbp2_status *status) 837complete_command_orb(struct sbp2_orb *base_orb, struct sbp2_status *status)
835{ 838{
836 struct sbp2_command_orb *orb = (struct sbp2_command_orb *)base_orb; 839 struct sbp2_command_orb *orb =
840 container_of(base_orb, struct sbp2_command_orb, base);
837 struct fw_unit *unit = orb->unit; 841 struct fw_unit *unit = orb->unit;
838 struct fw_device *device = fw_device(unit->device.parent); 842 struct fw_device *device = fw_device(unit->device.parent);
839 struct scatterlist *sg; 843 struct scatterlist *sg;
@@ -880,12 +884,7 @@ complete_command_orb(struct sbp2_orb *base_orb, struct sbp2_status *status)
880 884
881 if (orb->page_table_bus != 0) 885 if (orb->page_table_bus != 0)
882 dma_unmap_single(device->card->device, orb->page_table_bus, 886 dma_unmap_single(device->card->device, orb->page_table_bus,
883 sizeof(orb->page_table_bus), DMA_TO_DEVICE); 887 sizeof(orb->page_table), DMA_TO_DEVICE);
884
885 if (orb->request_buffer_bus != 0)
886 dma_unmap_single(device->card->device, orb->request_buffer_bus,
887 sizeof(orb->request_buffer_bus),
888 DMA_FROM_DEVICE);
889 888
890 orb->cmd->result = result; 889 orb->cmd->result = result;
891 orb->done(orb->cmd); 890 orb->done(orb->cmd);
@@ -900,7 +899,6 @@ static int sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb)
900 struct fw_device *device = fw_device(unit->device.parent); 899 struct fw_device *device = fw_device(unit->device.parent);
901 struct scatterlist *sg; 900 struct scatterlist *sg;
902 int sg_len, l, i, j, count; 901 int sg_len, l, i, j, count;
903 size_t size;
904 dma_addr_t sg_addr; 902 dma_addr_t sg_addr;
905 903
906 sg = (struct scatterlist *)orb->cmd->request_buffer; 904 sg = (struct scatterlist *)orb->cmd->request_buffer;
@@ -935,6 +933,11 @@ static int sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb)
935 sg_len = sg_dma_len(sg + i); 933 sg_len = sg_dma_len(sg + i);
936 sg_addr = sg_dma_address(sg + i); 934 sg_addr = sg_dma_address(sg + i);
937 while (sg_len) { 935 while (sg_len) {
936 /* FIXME: This won't get us out of the pinch. */
937 if (unlikely(j >= ARRAY_SIZE(orb->page_table))) {
938 fw_error("page table overflow\n");
939 goto fail_page_table;
940 }
938 l = min(sg_len, SBP2_MAX_SG_ELEMENT_LENGTH); 941 l = min(sg_len, SBP2_MAX_SG_ELEMENT_LENGTH);
939 orb->page_table[j].low = sg_addr; 942 orb->page_table[j].low = sg_addr;
940 orb->page_table[j].high = (l << 16); 943 orb->page_table[j].high = (l << 16);
@@ -944,7 +947,13 @@ static int sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb)
944 } 947 }
945 } 948 }
946 949
947 size = sizeof(orb->page_table[0]) * j; 950 fw_memcpy_to_be32(orb->page_table, orb->page_table,
951 sizeof(orb->page_table[0]) * j);
952 orb->page_table_bus =
953 dma_map_single(device->card->device, orb->page_table,
954 sizeof(orb->page_table), DMA_TO_DEVICE);
955 if (dma_mapping_error(orb->page_table_bus))
956 goto fail_page_table;
948 957
949 /* 958 /*
950 * The data_descriptor pointer is the one case where we need 959 * The data_descriptor pointer is the one case where we need
@@ -953,20 +962,12 @@ static int sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb)
953 * initiator (i.e. us), but data_descriptor can refer to data 962 * initiator (i.e. us), but data_descriptor can refer to data
954 * on other nodes so we need to put our ID in descriptor.high. 963 * on other nodes so we need to put our ID in descriptor.high.
955 */ 964 */
956
957 orb->page_table_bus =
958 dma_map_single(device->card->device, orb->page_table,
959 size, DMA_TO_DEVICE);
960 if (dma_mapping_error(orb->page_table_bus))
961 goto fail_page_table;
962 orb->request.data_descriptor.high = sd->address_high; 965 orb->request.data_descriptor.high = sd->address_high;
963 orb->request.data_descriptor.low = orb->page_table_bus; 966 orb->request.data_descriptor.low = orb->page_table_bus;
964 orb->request.misc |= 967 orb->request.misc |=
965 COMMAND_ORB_PAGE_TABLE_PRESENT | 968 COMMAND_ORB_PAGE_TABLE_PRESENT |
966 COMMAND_ORB_DATA_SIZE(j); 969 COMMAND_ORB_DATA_SIZE(j);
967 970
968 fw_memcpy_to_be32(orb->page_table, orb->page_table, size);
969
970 return 0; 971 return 0;
971 972
972 fail_page_table: 973 fail_page_table:
@@ -991,7 +992,7 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
991 * transfer direction not handled. 992 * transfer direction not handled.
992 */ 993 */
993 if (cmd->sc_data_direction == DMA_BIDIRECTIONAL) { 994 if (cmd->sc_data_direction == DMA_BIDIRECTIONAL) {
994 fw_error("Cannot handle DMA_BIDIRECTIONAL - rejecting command"); 995 fw_error("Can't handle DMA_BIDIRECTIONAL, rejecting command\n");
995 cmd->result = DID_ERROR << 16; 996 cmd->result = DID_ERROR << 16;
996 done(cmd); 997 done(cmd);
997 return 0; 998 return 0;
@@ -1005,11 +1006,6 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1005 1006
1006 /* Initialize rcode to something not RCODE_COMPLETE. */ 1007 /* Initialize rcode to something not RCODE_COMPLETE. */
1007 orb->base.rcode = -1; 1008 orb->base.rcode = -1;
1008 orb->base.request_bus =
1009 dma_map_single(device->card->device, &orb->request,
1010 sizeof(orb->request), DMA_TO_DEVICE);
1011 if (dma_mapping_error(orb->base.request_bus))
1012 goto fail_mapping;
1013 1009
1014 orb->unit = unit; 1010 orb->unit = unit;
1015 orb->done = done; 1011 orb->done = done;
@@ -1024,8 +1020,8 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1024 * if we set this to max_speed + 7, we get the right value. 1020 * if we set this to max_speed + 7, we get the right value.
1025 */ 1021 */
1026 orb->request.misc = 1022 orb->request.misc =
1027 COMMAND_ORB_MAX_PAYLOAD(device->node->max_speed + 7) | 1023 COMMAND_ORB_MAX_PAYLOAD(device->max_speed + 7) |
1028 COMMAND_ORB_SPEED(device->node->max_speed) | 1024 COMMAND_ORB_SPEED(device->max_speed) |
1029 COMMAND_ORB_NOTIFY; 1025 COMMAND_ORB_NOTIFY;
1030 1026
1031 if (cmd->sc_data_direction == DMA_FROM_DEVICE) 1027 if (cmd->sc_data_direction == DMA_FROM_DEVICE)
@@ -1036,7 +1032,7 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1036 COMMAND_ORB_DIRECTION(SBP2_DIRECTION_TO_MEDIA); 1032 COMMAND_ORB_DIRECTION(SBP2_DIRECTION_TO_MEDIA);
1037 1033
1038 if (cmd->use_sg && sbp2_command_orb_map_scatterlist(orb) < 0) 1034 if (cmd->use_sg && sbp2_command_orb_map_scatterlist(orb) < 0)
1039 goto fail_map_payload; 1035 goto fail_mapping;
1040 1036
1041 fw_memcpy_to_be32(&orb->request, &orb->request, sizeof(orb->request)); 1037 fw_memcpy_to_be32(&orb->request, &orb->request, sizeof(orb->request));
1042 1038
@@ -1045,15 +1041,17 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1045 memcpy(orb->request.command_block, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd)); 1041 memcpy(orb->request.command_block, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
1046 1042
1047 orb->base.callback = complete_command_orb; 1043 orb->base.callback = complete_command_orb;
1044 orb->base.request_bus =
1045 dma_map_single(device->card->device, &orb->request,
1046 sizeof(orb->request), DMA_TO_DEVICE);
1047 if (dma_mapping_error(orb->base.request_bus))
1048 goto fail_mapping;
1048 1049
1049 sbp2_send_orb(&orb->base, unit, sd->node_id, sd->generation, 1050 sbp2_send_orb(&orb->base, unit, sd->node_id, sd->generation,
1050 sd->command_block_agent_address + SBP2_ORB_POINTER); 1051 sd->command_block_agent_address + SBP2_ORB_POINTER);
1051 1052
1052 return 0; 1053 return 0;
1053 1054
1054 fail_map_payload:
1055 dma_unmap_single(device->card->device, orb->base.request_bus,
1056 sizeof(orb->request), DMA_TO_DEVICE);
1057 fail_mapping: 1055 fail_mapping:
1058 kfree(orb); 1056 kfree(orb);
1059 fail_alloc: 1057 fail_alloc:
@@ -1087,7 +1085,8 @@ static int sbp2_scsi_slave_configure(struct scsi_device *sdev)
1087 fw_notify("setting fix_capacity for %s\n", unit->device.bus_id); 1085 fw_notify("setting fix_capacity for %s\n", unit->device.bus_id);
1088 sdev->fix_capacity = 1; 1086 sdev->fix_capacity = 1;
1089 } 1087 }
1090 1088 if (sd->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS)
1089 blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512);
1091 return 0; 1090 return 0;
1092} 1091}
1093 1092