aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firewire/sbp2.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-03-22 23:31:15 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-22 23:31:15 -0400
commit34699403e9916060af8ae23f5e4705a6c078e79d (patch)
treee149ca6354171caf61132d80508ad878b00878c9 /drivers/firewire/sbp2.c
parent7fc86a7908a4e9eb2da4b6498f86193d113842d3 (diff)
parentd1bbd20972936b9b178fda3eb1ec417cb27fdc01 (diff)
Merge tag 'firewire-updates' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394
Pull IEEE 1394 (FireWire) subsystem updates post v3.3 from Stefan Richter: - Some SBP-2 initiator fixes, side product from ongoing work on a target. - Reintroduction of an isochronous I/O feature of the older ieee1394 driver stack (flush buffer completions); it was evidently rarely used but not actually unused. Matching libraw1394 code is already available. - Be sure to prefix all kernel log messages with device name or card name, and other logging related cleanups. - Misc other small cleanups, among them a small API change that affects sound/firewire/ too. Clemens Ladisch is aware of it. * tag 'firewire-updates' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394: (26 commits) firewire: allow explicit flushing of iso packet completions firewire: prevent dropping of completed iso packet header data firewire: ohci: factor out iso completion flushing code firewire: ohci: simplify iso header pointer arithmetic firewire: ohci: optimize control bit checks firewire: ohci: remove unused excess_bytes field firewire: ohci: copy_iso_headers(): make comment match the code firewire: cdev: fix IR multichannel event documentation firewire: ohci: fix too-early completion of IR multichannel buffers firewire: ohci: move runtime debug facility out of #ifdef firewire: tone down some diagnostic log messages firewire: sbp2: replace a GFP_ATOMIC allocation firewire: sbp2: Fix SCSI sense data mangling firewire: sbp2: Ignore SBP-2 targets on the local node firewire: sbp2: Take into account Unit_Unique_ID firewire: nosy: Use the macro DMA_BIT_MASK(). firewire: core: convert AR-req handler lock from _irqsave to _bh firewire: core: fix race at address_handler unregistration firewire: core: remove obsolete comment firewire: core: prefix log messages with card name ...
Diffstat (limited to 'drivers/firewire/sbp2.c')
-rw-r--r--drivers/firewire/sbp2.c130
1 files changed, 81 insertions, 49 deletions
diff --git a/drivers/firewire/sbp2.c b/drivers/firewire/sbp2.c
index 80e95aa3bf14..000a29ffedae 100644
--- a/drivers/firewire/sbp2.c
+++ b/drivers/firewire/sbp2.c
@@ -125,8 +125,6 @@ MODULE_PARM_DESC(workarounds, "Work around device bugs (default = 0"
125 ", override internal blacklist = " __stringify(SBP2_WORKAROUND_OVERRIDE) 125 ", override internal blacklist = " __stringify(SBP2_WORKAROUND_OVERRIDE)
126 ", or a combination)"); 126 ", or a combination)");
127 127
128static const char sbp2_driver_name[] = "sbp2";
129
130/* 128/*
131 * We create one struct sbp2_logical_unit per SBP-2 Logical Unit Number Entry 129 * We create one struct sbp2_logical_unit per SBP-2 Logical Unit Number Entry
132 * and one struct scsi_device per sbp2_logical_unit. 130 * and one struct scsi_device per sbp2_logical_unit.
@@ -165,7 +163,6 @@ static void sbp2_queue_work(struct sbp2_logical_unit *lu, unsigned long delay)
165 */ 163 */
166struct sbp2_target { 164struct sbp2_target {
167 struct fw_unit *unit; 165 struct fw_unit *unit;
168 const char *bus_id;
169 struct list_head lu_list; 166 struct list_head lu_list;
170 167
171 u64 management_agent_address; 168 u64 management_agent_address;
@@ -181,11 +178,21 @@ struct sbp2_target {
181 int blocked; /* ditto */ 178 int blocked; /* ditto */
182}; 179};
183 180
184static struct fw_device *target_device(struct sbp2_target *tgt) 181static struct fw_device *target_parent_device(struct sbp2_target *tgt)
185{ 182{
186 return fw_parent_device(tgt->unit); 183 return fw_parent_device(tgt->unit);
187} 184}
188 185
186static const struct device *tgt_dev(const struct sbp2_target *tgt)
187{
188 return &tgt->unit->device;
189}
190
191static const struct device *lu_dev(const struct sbp2_logical_unit *lu)
192{
193 return &lu->tgt->unit->device;
194}
195
189/* Impossible login_id, to detect logout attempt before successful login */ 196/* Impossible login_id, to detect logout attempt before successful login */
190#define INVALID_LOGIN_ID 0x10000 197#define INVALID_LOGIN_ID 0x10000
191 198
@@ -211,6 +218,7 @@ static struct fw_device *target_device(struct sbp2_target *tgt)
211#define SBP2_CSR_UNIT_CHARACTERISTICS 0x3a 218#define SBP2_CSR_UNIT_CHARACTERISTICS 0x3a
212#define SBP2_CSR_FIRMWARE_REVISION 0x3c 219#define SBP2_CSR_FIRMWARE_REVISION 0x3c
213#define SBP2_CSR_LOGICAL_UNIT_NUMBER 0x14 220#define SBP2_CSR_LOGICAL_UNIT_NUMBER 0x14
221#define SBP2_CSR_UNIT_UNIQUE_ID 0x8d
214#define SBP2_CSR_LOGICAL_UNIT_DIRECTORY 0xd4 222#define SBP2_CSR_LOGICAL_UNIT_DIRECTORY 0xd4
215 223
216/* Management orb opcodes */ 224/* Management orb opcodes */
@@ -430,7 +438,8 @@ static void sbp2_status_write(struct fw_card *card, struct fw_request *request,
430 memcpy(status.data, payload + 8, length - 8); 438 memcpy(status.data, payload + 8, length - 8);
431 439
432 if (STATUS_GET_SOURCE(status) == 2 || STATUS_GET_SOURCE(status) == 3) { 440 if (STATUS_GET_SOURCE(status) == 2 || STATUS_GET_SOURCE(status) == 3) {
433 fw_notify("non-orb related status write, not handled\n"); 441 dev_notice(lu_dev(lu),
442 "non-ORB related status write, not handled\n");
434 fw_send_response(card, request, RCODE_COMPLETE); 443 fw_send_response(card, request, RCODE_COMPLETE);
435 return; 444 return;
436 } 445 }
@@ -451,7 +460,7 @@ static void sbp2_status_write(struct fw_card *card, struct fw_request *request,
451 orb->callback(orb, &status); 460 orb->callback(orb, &status);
452 kref_put(&orb->kref, free_orb); /* orb callback reference */ 461 kref_put(&orb->kref, free_orb); /* orb callback reference */
453 } else { 462 } else {
454 fw_error("status write for unknown orb\n"); 463 dev_err(lu_dev(lu), "status write for unknown ORB\n");
455 } 464 }
456 465
457 fw_send_response(card, request, RCODE_COMPLETE); 466 fw_send_response(card, request, RCODE_COMPLETE);
@@ -492,7 +501,7 @@ static void complete_transaction(struct fw_card *card, int rcode,
492static void sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu, 501static void sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu,
493 int node_id, int generation, u64 offset) 502 int node_id, int generation, u64 offset)
494{ 503{
495 struct fw_device *device = target_device(lu->tgt); 504 struct fw_device *device = target_parent_device(lu->tgt);
496 struct sbp2_pointer orb_pointer; 505 struct sbp2_pointer orb_pointer;
497 unsigned long flags; 506 unsigned long flags;
498 507
@@ -513,7 +522,7 @@ static void sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu,
513 522
514static int sbp2_cancel_orbs(struct sbp2_logical_unit *lu) 523static int sbp2_cancel_orbs(struct sbp2_logical_unit *lu)
515{ 524{
516 struct fw_device *device = target_device(lu->tgt); 525 struct fw_device *device = target_parent_device(lu->tgt);
517 struct sbp2_orb *orb, *next; 526 struct sbp2_orb *orb, *next;
518 struct list_head list; 527 struct list_head list;
519 unsigned long flags; 528 unsigned long flags;
@@ -552,7 +561,7 @@ static int sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id,
552 int generation, int function, 561 int generation, int function,
553 int lun_or_login_id, void *response) 562 int lun_or_login_id, void *response)
554{ 563{
555 struct fw_device *device = target_device(lu->tgt); 564 struct fw_device *device = target_parent_device(lu->tgt);
556 struct sbp2_management_orb *orb; 565 struct sbp2_management_orb *orb;
557 unsigned int timeout; 566 unsigned int timeout;
558 int retval = -ENOMEM; 567 int retval = -ENOMEM;
@@ -560,7 +569,7 @@ static int sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id,
560 if (function == SBP2_LOGOUT_REQUEST && fw_device_is_shutdown(device)) 569 if (function == SBP2_LOGOUT_REQUEST && fw_device_is_shutdown(device))
561 return 0; 570 return 0;
562 571
563 orb = kzalloc(sizeof(*orb), GFP_ATOMIC); 572 orb = kzalloc(sizeof(*orb), GFP_NOIO);
564 if (orb == NULL) 573 if (orb == NULL)
565 return -ENOMEM; 574 return -ENOMEM;
566 575
@@ -612,20 +621,20 @@ static int sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id,
612 621
613 retval = -EIO; 622 retval = -EIO;
614 if (sbp2_cancel_orbs(lu) == 0) { 623 if (sbp2_cancel_orbs(lu) == 0) {
615 fw_error("%s: orb reply timed out, rcode=0x%02x\n", 624 dev_err(lu_dev(lu), "ORB reply timed out, rcode 0x%02x\n",
616 lu->tgt->bus_id, orb->base.rcode); 625 orb->base.rcode);
617 goto out; 626 goto out;
618 } 627 }
619 628
620 if (orb->base.rcode != RCODE_COMPLETE) { 629 if (orb->base.rcode != RCODE_COMPLETE) {
621 fw_error("%s: management write failed, rcode 0x%02x\n", 630 dev_err(lu_dev(lu), "management write failed, rcode 0x%02x\n",
622 lu->tgt->bus_id, orb->base.rcode); 631 orb->base.rcode);
623 goto out; 632 goto out;
624 } 633 }
625 634
626 if (STATUS_GET_RESPONSE(orb->status) != 0 || 635 if (STATUS_GET_RESPONSE(orb->status) != 0 ||
627 STATUS_GET_SBP_STATUS(orb->status) != 0) { 636 STATUS_GET_SBP_STATUS(orb->status) != 0) {
628 fw_error("%s: error status: %d:%d\n", lu->tgt->bus_id, 637 dev_err(lu_dev(lu), "error status: %d:%d\n",
629 STATUS_GET_RESPONSE(orb->status), 638 STATUS_GET_RESPONSE(orb->status),
630 STATUS_GET_SBP_STATUS(orb->status)); 639 STATUS_GET_SBP_STATUS(orb->status));
631 goto out; 640 goto out;
@@ -648,7 +657,7 @@ static int sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id,
648 657
649static void sbp2_agent_reset(struct sbp2_logical_unit *lu) 658static void sbp2_agent_reset(struct sbp2_logical_unit *lu)
650{ 659{
651 struct fw_device *device = target_device(lu->tgt); 660 struct fw_device *device = target_parent_device(lu->tgt);
652 __be32 d = 0; 661 __be32 d = 0;
653 662
654 fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST, 663 fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST,
@@ -665,7 +674,7 @@ static void complete_agent_reset_write_no_wait(struct fw_card *card,
665 674
666static void sbp2_agent_reset_no_wait(struct sbp2_logical_unit *lu) 675static void sbp2_agent_reset_no_wait(struct sbp2_logical_unit *lu)
667{ 676{
668 struct fw_device *device = target_device(lu->tgt); 677 struct fw_device *device = target_parent_device(lu->tgt);
669 struct fw_transaction *t; 678 struct fw_transaction *t;
670 static __be32 d; 679 static __be32 d;
671 680
@@ -704,7 +713,7 @@ static inline void sbp2_allow_block(struct sbp2_logical_unit *lu)
704static void sbp2_conditionally_block(struct sbp2_logical_unit *lu) 713static void sbp2_conditionally_block(struct sbp2_logical_unit *lu)
705{ 714{
706 struct sbp2_target *tgt = lu->tgt; 715 struct sbp2_target *tgt = lu->tgt;
707 struct fw_card *card = target_device(tgt)->card; 716 struct fw_card *card = target_parent_device(tgt)->card;
708 struct Scsi_Host *shost = 717 struct Scsi_Host *shost =
709 container_of((void *)tgt, struct Scsi_Host, hostdata[0]); 718 container_of((void *)tgt, struct Scsi_Host, hostdata[0]);
710 unsigned long flags; 719 unsigned long flags;
@@ -728,7 +737,7 @@ static void sbp2_conditionally_block(struct sbp2_logical_unit *lu)
728static void sbp2_conditionally_unblock(struct sbp2_logical_unit *lu) 737static void sbp2_conditionally_unblock(struct sbp2_logical_unit *lu)
729{ 738{
730 struct sbp2_target *tgt = lu->tgt; 739 struct sbp2_target *tgt = lu->tgt;
731 struct fw_card *card = target_device(tgt)->card; 740 struct fw_card *card = target_parent_device(tgt)->card;
732 struct Scsi_Host *shost = 741 struct Scsi_Host *shost =
733 container_of((void *)tgt, struct Scsi_Host, hostdata[0]); 742 container_of((void *)tgt, struct Scsi_Host, hostdata[0]);
734 unsigned long flags; 743 unsigned long flags;
@@ -753,7 +762,7 @@ static void sbp2_conditionally_unblock(struct sbp2_logical_unit *lu)
753 */ 762 */
754static void sbp2_unblock(struct sbp2_target *tgt) 763static void sbp2_unblock(struct sbp2_target *tgt)
755{ 764{
756 struct fw_card *card = target_device(tgt)->card; 765 struct fw_card *card = target_parent_device(tgt)->card;
757 struct Scsi_Host *shost = 766 struct Scsi_Host *shost =
758 container_of((void *)tgt, struct Scsi_Host, hostdata[0]); 767 container_of((void *)tgt, struct Scsi_Host, hostdata[0]);
759 unsigned long flags; 768 unsigned long flags;
@@ -794,7 +803,7 @@ static int sbp2_lun2int(u16 lun)
794 */ 803 */
795static void sbp2_set_busy_timeout(struct sbp2_logical_unit *lu) 804static void sbp2_set_busy_timeout(struct sbp2_logical_unit *lu)
796{ 805{
797 struct fw_device *device = target_device(lu->tgt); 806 struct fw_device *device = target_parent_device(lu->tgt);
798 __be32 d = cpu_to_be32(SBP2_CYCLE_LIMIT | SBP2_RETRY_LIMIT); 807 __be32 d = cpu_to_be32(SBP2_CYCLE_LIMIT | SBP2_RETRY_LIMIT);
799 808
800 fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST, 809 fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST,
@@ -809,7 +818,7 @@ static void sbp2_login(struct work_struct *work)
809 struct sbp2_logical_unit *lu = 818 struct sbp2_logical_unit *lu =
810 container_of(work, struct sbp2_logical_unit, work.work); 819 container_of(work, struct sbp2_logical_unit, work.work);
811 struct sbp2_target *tgt = lu->tgt; 820 struct sbp2_target *tgt = lu->tgt;
812 struct fw_device *device = target_device(tgt); 821 struct fw_device *device = target_parent_device(tgt);
813 struct Scsi_Host *shost; 822 struct Scsi_Host *shost;
814 struct scsi_device *sdev; 823 struct scsi_device *sdev;
815 struct sbp2_login_response response; 824 struct sbp2_login_response response;
@@ -833,8 +842,8 @@ static void sbp2_login(struct work_struct *work)
833 if (lu->retries++ < 5) { 842 if (lu->retries++ < 5) {
834 sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5)); 843 sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5));
835 } else { 844 } else {
836 fw_error("%s: failed to login to LUN %04x\n", 845 dev_err(tgt_dev(tgt), "failed to login to LUN %04x\n",
837 tgt->bus_id, lu->lun); 846 lu->lun);
838 /* Let any waiting I/O fail from now on. */ 847 /* Let any waiting I/O fail from now on. */
839 sbp2_unblock(lu->tgt); 848 sbp2_unblock(lu->tgt);
840 } 849 }
@@ -851,8 +860,8 @@ static void sbp2_login(struct work_struct *work)
851 << 32) | be32_to_cpu(response.command_block_agent.low); 860 << 32) | be32_to_cpu(response.command_block_agent.low);
852 lu->login_id = be32_to_cpu(response.misc) & 0xffff; 861 lu->login_id = be32_to_cpu(response.misc) & 0xffff;
853 862
854 fw_notify("%s: logged in to LUN %04x (%d retries)\n", 863 dev_notice(tgt_dev(tgt), "logged in to LUN %04x (%d retries)\n",
855 tgt->bus_id, lu->lun, lu->retries); 864 lu->lun, lu->retries);
856 865
857 /* set appropriate retry limit(s) in BUSY_TIMEOUT register */ 866 /* set appropriate retry limit(s) in BUSY_TIMEOUT register */
858 sbp2_set_busy_timeout(lu); 867 sbp2_set_busy_timeout(lu);
@@ -919,7 +928,7 @@ static void sbp2_reconnect(struct work_struct *work)
919 struct sbp2_logical_unit *lu = 928 struct sbp2_logical_unit *lu =
920 container_of(work, struct sbp2_logical_unit, work.work); 929 container_of(work, struct sbp2_logical_unit, work.work);
921 struct sbp2_target *tgt = lu->tgt; 930 struct sbp2_target *tgt = lu->tgt;
922 struct fw_device *device = target_device(tgt); 931 struct fw_device *device = target_parent_device(tgt);
923 int generation, node_id, local_node_id; 932 int generation, node_id, local_node_id;
924 933
925 if (fw_device_is_shutdown(device)) 934 if (fw_device_is_shutdown(device))
@@ -943,7 +952,7 @@ static void sbp2_reconnect(struct work_struct *work)
943 smp_rmb(); /* get current card generation */ 952 smp_rmb(); /* get current card generation */
944 if (generation == device->card->generation || 953 if (generation == device->card->generation ||
945 lu->retries++ >= 5) { 954 lu->retries++ >= 5) {
946 fw_error("%s: failed to reconnect\n", tgt->bus_id); 955 dev_err(tgt_dev(tgt), "failed to reconnect\n");
947 lu->retries = 0; 956 lu->retries = 0;
948 PREPARE_DELAYED_WORK(&lu->work, sbp2_login); 957 PREPARE_DELAYED_WORK(&lu->work, sbp2_login);
949 } 958 }
@@ -957,8 +966,8 @@ static void sbp2_reconnect(struct work_struct *work)
957 smp_wmb(); /* node IDs must not be older than generation */ 966 smp_wmb(); /* node IDs must not be older than generation */
958 lu->generation = generation; 967 lu->generation = generation;
959 968
960 fw_notify("%s: reconnected to LUN %04x (%d retries)\n", 969 dev_notice(tgt_dev(tgt), "reconnected to LUN %04x (%d retries)\n",
961 tgt->bus_id, lu->lun, lu->retries); 970 lu->lun, lu->retries);
962 971
963 sbp2_agent_reset(lu); 972 sbp2_agent_reset(lu);
964 sbp2_cancel_orbs(lu); 973 sbp2_cancel_orbs(lu);
@@ -997,6 +1006,13 @@ static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry)
997 return 0; 1006 return 0;
998} 1007}
999 1008
1009static void sbp2_get_unit_unique_id(struct sbp2_target *tgt,
1010 const u32 *leaf)
1011{
1012 if ((leaf[0] & 0xffff0000) == 0x00020000)
1013 tgt->guid = (u64)leaf[1] << 32 | leaf[2];
1014}
1015
1000static int sbp2_scan_logical_unit_dir(struct sbp2_target *tgt, 1016static int sbp2_scan_logical_unit_dir(struct sbp2_target *tgt,
1001 const u32 *directory) 1017 const u32 *directory)
1002{ 1018{
@@ -1048,6 +1064,10 @@ static int sbp2_scan_unit_dir(struct sbp2_target *tgt, const u32 *directory,
1048 return -ENOMEM; 1064 return -ENOMEM;
1049 break; 1065 break;
1050 1066
1067 case SBP2_CSR_UNIT_UNIQUE_ID:
1068 sbp2_get_unit_unique_id(tgt, ci.p - 1 + value);
1069 break;
1070
1051 case SBP2_CSR_LOGICAL_UNIT_DIRECTORY: 1071 case SBP2_CSR_LOGICAL_UNIT_DIRECTORY:
1052 /* Adjust for the increment in the iterator */ 1072 /* Adjust for the increment in the iterator */
1053 if (sbp2_scan_logical_unit_dir(tgt, ci.p - 1 + value) < 0) 1073 if (sbp2_scan_logical_unit_dir(tgt, ci.p - 1 + value) < 0)
@@ -1068,8 +1088,8 @@ static void sbp2_clamp_management_orb_timeout(struct sbp2_target *tgt)
1068 unsigned int timeout = tgt->mgt_orb_timeout; 1088 unsigned int timeout = tgt->mgt_orb_timeout;
1069 1089
1070 if (timeout > 40000) 1090 if (timeout > 40000)
1071 fw_notify("%s: %ds mgt_ORB_timeout limited to 40s\n", 1091 dev_notice(tgt_dev(tgt), "%ds mgt_ORB_timeout limited to 40s\n",
1072 tgt->bus_id, timeout / 1000); 1092 timeout / 1000);
1073 1093
1074 tgt->mgt_orb_timeout = clamp_val(timeout, 5000, 40000); 1094 tgt->mgt_orb_timeout = clamp_val(timeout, 5000, 40000);
1075} 1095}
@@ -1081,9 +1101,9 @@ static void sbp2_init_workarounds(struct sbp2_target *tgt, u32 model,
1081 unsigned int w = sbp2_param_workarounds; 1101 unsigned int w = sbp2_param_workarounds;
1082 1102
1083 if (w) 1103 if (w)
1084 fw_notify("Please notify linux1394-devel@lists.sourceforge.net " 1104 dev_notice(tgt_dev(tgt),
1085 "if you need the workarounds parameter for %s\n", 1105 "Please notify linux1394-devel@lists.sf.net "
1086 tgt->bus_id); 1106 "if you need the workarounds parameter\n");
1087 1107
1088 if (w & SBP2_WORKAROUND_OVERRIDE) 1108 if (w & SBP2_WORKAROUND_OVERRIDE)
1089 goto out; 1109 goto out;
@@ -1103,9 +1123,9 @@ static void sbp2_init_workarounds(struct sbp2_target *tgt, u32 model,
1103 } 1123 }
1104 out: 1124 out:
1105 if (w) 1125 if (w)
1106 fw_notify("Workarounds for %s: 0x%x " 1126 dev_notice(tgt_dev(tgt), "workarounds 0x%x "
1107 "(firmware_revision 0x%06x, model_id 0x%06x)\n", 1127 "(firmware_revision 0x%06x, model_id 0x%06x)\n",
1108 tgt->bus_id, w, firmware_revision, model); 1128 w, firmware_revision, model);
1109 tgt->workarounds = w; 1129 tgt->workarounds = w;
1110} 1130}
1111 1131
@@ -1121,6 +1141,10 @@ static int sbp2_probe(struct device *dev)
1121 struct Scsi_Host *shost; 1141 struct Scsi_Host *shost;
1122 u32 model, firmware_revision; 1142 u32 model, firmware_revision;
1123 1143
1144 /* cannot (or should not) handle targets on the local node */
1145 if (device->is_local)
1146 return -ENODEV;
1147
1124 if (dma_get_max_seg_size(device->card->device) > SBP2_MAX_SEG_SIZE) 1148 if (dma_get_max_seg_size(device->card->device) > SBP2_MAX_SEG_SIZE)
1125 BUG_ON(dma_set_max_seg_size(device->card->device, 1149 BUG_ON(dma_set_max_seg_size(device->card->device,
1126 SBP2_MAX_SEG_SIZE)); 1150 SBP2_MAX_SEG_SIZE));
@@ -1133,7 +1157,6 @@ static int sbp2_probe(struct device *dev)
1133 dev_set_drvdata(&unit->device, tgt); 1157 dev_set_drvdata(&unit->device, tgt);
1134 tgt->unit = unit; 1158 tgt->unit = unit;
1135 INIT_LIST_HEAD(&tgt->lu_list); 1159 INIT_LIST_HEAD(&tgt->lu_list);
1136 tgt->bus_id = dev_name(&unit->device);
1137 tgt->guid = (u64)device->config_rom[3] << 32 | device->config_rom[4]; 1160 tgt->guid = (u64)device->config_rom[3] << 32 | device->config_rom[4];
1138 1161
1139 if (fw_device_enable_phys_dma(device) < 0) 1162 if (fw_device_enable_phys_dma(device) < 0)
@@ -1239,7 +1262,7 @@ static int sbp2_remove(struct device *dev)
1239 kfree(lu); 1262 kfree(lu);
1240 } 1263 }
1241 scsi_remove_host(shost); 1264 scsi_remove_host(shost);
1242 fw_notify("released %s, target %d:0:0\n", tgt->bus_id, shost->host_no); 1265 dev_notice(dev, "released target %d:0:0\n", shost->host_no);
1243 1266
1244 scsi_host_put(shost); 1267 scsi_host_put(shost);
1245 return 0; 1268 return 0;
@@ -1261,7 +1284,7 @@ static const struct ieee1394_device_id sbp2_id_table[] = {
1261static struct fw_driver sbp2_driver = { 1284static struct fw_driver sbp2_driver = {
1262 .driver = { 1285 .driver = {
1263 .owner = THIS_MODULE, 1286 .owner = THIS_MODULE,
1264 .name = sbp2_driver_name, 1287 .name = KBUILD_MODNAME,
1265 .bus = &fw_bus_type, 1288 .bus = &fw_bus_type,
1266 .probe = sbp2_probe, 1289 .probe = sbp2_probe,
1267 .remove = sbp2_remove, 1290 .remove = sbp2_remove,
@@ -1286,10 +1309,19 @@ static void sbp2_unmap_scatterlist(struct device *card_device,
1286static unsigned int sbp2_status_to_sense_data(u8 *sbp2_status, u8 *sense_data) 1309static unsigned int sbp2_status_to_sense_data(u8 *sbp2_status, u8 *sense_data)
1287{ 1310{
1288 int sam_status; 1311 int sam_status;
1312 int sfmt = (sbp2_status[0] >> 6) & 0x03;
1313
1314 if (sfmt == 2 || sfmt == 3) {
1315 /*
1316 * Reserved for future standardization (2) or
1317 * Status block format vendor-dependent (3)
1318 */
1319 return DID_ERROR << 16;
1320 }
1289 1321
1290 sense_data[0] = 0x70; 1322 sense_data[0] = 0x70 | sfmt | (sbp2_status[1] & 0x80);
1291 sense_data[1] = 0x0; 1323 sense_data[1] = 0x0;
1292 sense_data[2] = sbp2_status[1]; 1324 sense_data[2] = ((sbp2_status[1] << 1) & 0xe0) | (sbp2_status[1] & 0x0f);
1293 sense_data[3] = sbp2_status[4]; 1325 sense_data[3] = sbp2_status[4];
1294 sense_data[4] = sbp2_status[5]; 1326 sense_data[4] = sbp2_status[5];
1295 sense_data[5] = sbp2_status[6]; 1327 sense_data[5] = sbp2_status[6];
@@ -1325,7 +1357,7 @@ static void complete_command_orb(struct sbp2_orb *base_orb,
1325{ 1357{
1326 struct sbp2_command_orb *orb = 1358 struct sbp2_command_orb *orb =
1327 container_of(base_orb, struct sbp2_command_orb, base); 1359 container_of(base_orb, struct sbp2_command_orb, base);
1328 struct fw_device *device = target_device(orb->lu->tgt); 1360 struct fw_device *device = target_parent_device(orb->lu->tgt);
1329 int result; 1361 int result;
1330 1362
1331 if (status != NULL) { 1363 if (status != NULL) {
@@ -1433,7 +1465,7 @@ static int sbp2_scsi_queuecommand(struct Scsi_Host *shost,
1433 struct scsi_cmnd *cmd) 1465 struct scsi_cmnd *cmd)
1434{ 1466{
1435 struct sbp2_logical_unit *lu = cmd->device->hostdata; 1467 struct sbp2_logical_unit *lu = cmd->device->hostdata;
1436 struct fw_device *device = target_device(lu->tgt); 1468 struct fw_device *device = target_parent_device(lu->tgt);
1437 struct sbp2_command_orb *orb; 1469 struct sbp2_command_orb *orb;
1438 int generation, retval = SCSI_MLQUEUE_HOST_BUSY; 1470 int generation, retval = SCSI_MLQUEUE_HOST_BUSY;
1439 1471
@@ -1442,7 +1474,7 @@ static int sbp2_scsi_queuecommand(struct Scsi_Host *shost,
1442 * transfer direction not handled. 1474 * transfer direction not handled.
1443 */ 1475 */
1444 if (cmd->sc_data_direction == DMA_BIDIRECTIONAL) { 1476 if (cmd->sc_data_direction == DMA_BIDIRECTIONAL) {
1445 fw_error("Can't handle DMA_BIDIRECTIONAL, rejecting command\n"); 1477 dev_err(lu_dev(lu), "cannot handle bidirectional command\n");
1446 cmd->result = DID_ERROR << 16; 1478 cmd->result = DID_ERROR << 16;
1447 cmd->scsi_done(cmd); 1479 cmd->scsi_done(cmd);
1448 return 0; 1480 return 0;
@@ -1450,7 +1482,7 @@ static int sbp2_scsi_queuecommand(struct Scsi_Host *shost,
1450 1482
1451 orb = kzalloc(sizeof(*orb), GFP_ATOMIC); 1483 orb = kzalloc(sizeof(*orb), GFP_ATOMIC);
1452 if (orb == NULL) { 1484 if (orb == NULL) {
1453 fw_notify("failed to alloc orb\n"); 1485 dev_notice(lu_dev(lu), "failed to alloc ORB\n");
1454 return SCSI_MLQUEUE_HOST_BUSY; 1486 return SCSI_MLQUEUE_HOST_BUSY;
1455 } 1487 }
1456 1488
@@ -1550,7 +1582,7 @@ static int sbp2_scsi_abort(struct scsi_cmnd *cmd)
1550{ 1582{
1551 struct sbp2_logical_unit *lu = cmd->device->hostdata; 1583 struct sbp2_logical_unit *lu = cmd->device->hostdata;
1552 1584
1553 fw_notify("%s: sbp2_scsi_abort\n", lu->tgt->bus_id); 1585 dev_notice(lu_dev(lu), "sbp2_scsi_abort\n");
1554 sbp2_agent_reset(lu); 1586 sbp2_agent_reset(lu);
1555 sbp2_cancel_orbs(lu); 1587 sbp2_cancel_orbs(lu);
1556 1588
@@ -1590,7 +1622,7 @@ static struct device_attribute *sbp2_scsi_sysfs_attrs[] = {
1590static struct scsi_host_template scsi_driver_template = { 1622static struct scsi_host_template scsi_driver_template = {
1591 .module = THIS_MODULE, 1623 .module = THIS_MODULE,
1592 .name = "SBP-2 IEEE-1394", 1624 .name = "SBP-2 IEEE-1394",
1593 .proc_name = sbp2_driver_name, 1625 .proc_name = "sbp2",
1594 .queuecommand = sbp2_scsi_queuecommand, 1626 .queuecommand = sbp2_scsi_queuecommand,
1595 .slave_alloc = sbp2_scsi_slave_alloc, 1627 .slave_alloc = sbp2_scsi_slave_alloc,
1596 .slave_configure = sbp2_scsi_slave_configure, 1628 .slave_configure = sbp2_scsi_slave_configure,