aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ieee1394/sbp2.c384
-rw-r--r--drivers/ieee1394/sbp2.h80
2 files changed, 109 insertions, 355 deletions
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
index 5156b88b0f2a..625f1eb80698 100644
--- a/drivers/ieee1394/sbp2.c
+++ b/drivers/ieee1394/sbp2.c
@@ -404,15 +404,15 @@ static int sbp2util_access_timeout(struct scsi_id_instance_data *scsi_id,
404 return leftover <= 0; 404 return leftover <= 0;
405} 405}
406 406
407/* Frees an allocated packet */
408static void sbp2_free_packet(struct hpsb_packet *packet) 407static void sbp2_free_packet(struct hpsb_packet *packet)
409{ 408{
410 hpsb_free_tlabel(packet); 409 hpsb_free_tlabel(packet);
411 hpsb_free_packet(packet); 410 hpsb_free_packet(packet);
412} 411}
413 412
414/* This is much like hpsb_node_write(), except it ignores the response 413/*
415 * subaction and returns immediately. Can be used from interrupts. 414 * This is much like hpsb_node_write(), except it ignores the response
415 * subaction and returns immediately. Can be used from atomic context.
416 */ 416 */
417static int sbp2util_node_write_no_wait(struct node_entry *ne, u64 addr, 417static int sbp2util_node_write_no_wait(struct node_entry *ne, u64 addr,
418 quadlet_t *buffer, size_t length) 418 quadlet_t *buffer, size_t length)
@@ -476,10 +476,6 @@ static void sbp2util_write_doorbell(struct work_struct *work)
476 sbp2util_notify_fetch_agent(container_of(work, struct scsi_id_instance_data, protocol_work), SBP2_DOORBELL_OFFSET, NULL, 4); 476 sbp2util_notify_fetch_agent(container_of(work, struct scsi_id_instance_data, protocol_work), SBP2_DOORBELL_OFFSET, NULL, 4);
477} 477}
478 478
479/*
480 * This function is called to create a pool of command orbs used for
481 * command processing. It is called when a new sbp2 device is detected.
482 */
483static int sbp2util_create_command_orb_pool(struct scsi_id_instance_data *scsi_id) 479static int sbp2util_create_command_orb_pool(struct scsi_id_instance_data *scsi_id)
484{ 480{
485 struct sbp2scsi_host_info *hi = scsi_id->hi; 481 struct sbp2scsi_host_info *hi = scsi_id->hi;
@@ -513,9 +509,6 @@ static int sbp2util_create_command_orb_pool(struct scsi_id_instance_data *scsi_i
513 return 0; 509 return 0;
514} 510}
515 511
516/*
517 * This function is called to delete a pool of command orbs.
518 */
519static void sbp2util_remove_command_orb_pool(struct scsi_id_instance_data *scsi_id) 512static void sbp2util_remove_command_orb_pool(struct scsi_id_instance_data *scsi_id)
520{ 513{
521 struct hpsb_host *host = scsi_id->hi->host; 514 struct hpsb_host *host = scsi_id->hi->host;
@@ -527,8 +520,6 @@ static void sbp2util_remove_command_orb_pool(struct scsi_id_instance_data *scsi_
527 if (!list_empty(&scsi_id->sbp2_command_orb_completed)) { 520 if (!list_empty(&scsi_id->sbp2_command_orb_completed)) {
528 list_for_each_safe(lh, next, &scsi_id->sbp2_command_orb_completed) { 521 list_for_each_safe(lh, next, &scsi_id->sbp2_command_orb_completed) {
529 command = list_entry(lh, struct sbp2_command_info, list); 522 command = list_entry(lh, struct sbp2_command_info, list);
530
531 /* Release our generic DMA's */
532 pci_unmap_single(host->pdev, command->command_orb_dma, 523 pci_unmap_single(host->pdev, command->command_orb_dma,
533 sizeof(struct sbp2_command_orb), 524 sizeof(struct sbp2_command_orb),
534 PCI_DMA_TODEVICE); 525 PCI_DMA_TODEVICE);
@@ -543,8 +534,8 @@ static void sbp2util_remove_command_orb_pool(struct scsi_id_instance_data *scsi_
543} 534}
544 535
545/* 536/*
546 * This function finds the sbp2_command for a given outstanding command 537 * Finds the sbp2_command for a given outstanding command ORB.
547 * orb.Only looks at the inuse list. 538 * Only looks at the in-use list.
548 */ 539 */
549static struct sbp2_command_info *sbp2util_find_command_for_orb( 540static struct sbp2_command_info *sbp2util_find_command_for_orb(
550 struct scsi_id_instance_data *scsi_id, dma_addr_t orb) 541 struct scsi_id_instance_data *scsi_id, dma_addr_t orb)
@@ -566,8 +557,8 @@ static struct sbp2_command_info *sbp2util_find_command_for_orb(
566} 557}
567 558
568/* 559/*
569 * This function finds the sbp2_command for a given outstanding SCpnt. 560 * Finds the sbp2_command for a given outstanding SCpnt.
570 * Only looks at the inuse list. 561 * Only looks at the in-use list.
571 * Must be called with scsi_id->sbp2_command_orb_lock held. 562 * Must be called with scsi_id->sbp2_command_orb_lock held.
572 */ 563 */
573static struct sbp2_command_info *sbp2util_find_command_for_SCpnt( 564static struct sbp2_command_info *sbp2util_find_command_for_SCpnt(
@@ -582,9 +573,6 @@ static struct sbp2_command_info *sbp2util_find_command_for_SCpnt(
582 return NULL; 573 return NULL;
583} 574}
584 575
585/*
586 * This function allocates a command orb used to send a scsi command.
587 */
588static struct sbp2_command_info *sbp2util_allocate_command_orb( 576static struct sbp2_command_info *sbp2util_allocate_command_orb(
589 struct scsi_id_instance_data *scsi_id, 577 struct scsi_id_instance_data *scsi_id,
590 struct scsi_cmnd *Current_SCpnt, 578 struct scsi_cmnd *Current_SCpnt,
@@ -609,7 +597,6 @@ static struct sbp2_command_info *sbp2util_allocate_command_orb(
609 return command; 597 return command;
610} 598}
611 599
612/* Free our DMA's */
613static void sbp2util_free_command_dma(struct sbp2_command_info *command) 600static void sbp2util_free_command_dma(struct sbp2_command_info *command)
614{ 601{
615 struct scsi_id_instance_data *scsi_id = 602 struct scsi_id_instance_data *scsi_id =
@@ -705,7 +692,7 @@ static int sbp2_remove(struct device *dev)
705 * send them. */ 692 * send them. */
706 if (!sbp2util_node_is_available(scsi_id)) 693 if (!sbp2util_node_is_available(scsi_id))
707 sbp2scsi_complete_all_commands(scsi_id, DID_NO_CONNECT); 694 sbp2scsi_complete_all_commands(scsi_id, DID_NO_CONNECT);
708 /* scsi_remove_device() will trigger shutdown functions of SCSI 695 /* scsi_remove_device() may trigger shutdown functions of SCSI
709 * highlevel drivers which would deadlock if blocked. */ 696 * highlevel drivers which would deadlock if blocked. */
710 atomic_set(&scsi_id->state, SBP2LU_STATE_IN_SHUTDOWN); 697 atomic_set(&scsi_id->state, SBP2LU_STATE_IN_SHUTDOWN);
711 scsi_unblock_requests(scsi_id->scsi_host); 698 scsi_unblock_requests(scsi_id->scsi_host);
@@ -727,12 +714,9 @@ static int sbp2_update(struct unit_directory *ud)
727 struct scsi_id_instance_data *scsi_id = ud->device.driver_data; 714 struct scsi_id_instance_data *scsi_id = ud->device.driver_data;
728 715
729 if (sbp2_reconnect_device(scsi_id)) { 716 if (sbp2_reconnect_device(scsi_id)) {
730 717 /* Reconnect has failed. Perhaps we didn't reconnect fast
731 /* 718 * enough. Try a regular login, but first log out just in
732 * Ok, reconnect has failed. Perhaps we didn't 719 * case of any weirdness. */
733 * reconnect fast enough. Try doing a regular login, but
734 * first do a logout just in case of any weirdness.
735 */
736 sbp2_logout_device(scsi_id); 720 sbp2_logout_device(scsi_id);
737 721
738 if (sbp2_login_device(scsi_id)) { 722 if (sbp2_login_device(scsi_id)) {
@@ -743,18 +727,12 @@ static int sbp2_update(struct unit_directory *ud)
743 } 727 }
744 } 728 }
745 729
746 /* Set max retries to something large on the device. */
747 sbp2_set_busy_timeout(scsi_id); 730 sbp2_set_busy_timeout(scsi_id);
748
749 /* Do a SBP-2 fetch agent reset. */
750 sbp2_agent_reset(scsi_id, 1); 731 sbp2_agent_reset(scsi_id, 1);
751
752 /* Get the max speed and packet size that we can use. */
753 sbp2_max_speed_and_size(scsi_id); 732 sbp2_max_speed_and_size(scsi_id);
754 733
755 /* Complete any pending commands with busy (so they get 734 /* Complete any pending commands with busy (so they get retried)
756 * retried) and remove them from our queue 735 * and remove them from our queue. */
757 */
758 sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY); 736 sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY);
759 737
760 /* Accept new commands unless there was another bus reset in the 738 /* Accept new commands unless there was another bus reset in the
@@ -766,8 +744,6 @@ static int sbp2_update(struct unit_directory *ud)
766 return 0; 744 return 0;
767} 745}
768 746
769/* This functions is called by the sbp2_probe, for each new device. We now
770 * allocate one scsi host for each scsi_id (unit directory). */
771static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud) 747static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud)
772{ 748{
773 struct sbp2scsi_host_info *hi; 749 struct sbp2scsi_host_info *hi;
@@ -843,7 +819,6 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud
843 goto failed_alloc; 819 goto failed_alloc;
844 } 820 }
845 821
846 /* Register our host with the SCSI stack. */
847 scsi_host = scsi_host_alloc(&scsi_driver_template, 822 scsi_host = scsi_host_alloc(&scsi_driver_template,
848 sizeof(unsigned long)); 823 sizeof(unsigned long));
849 if (!scsi_host) { 824 if (!scsi_host) {
@@ -882,16 +857,11 @@ static void sbp2_host_reset(struct hpsb_host *host)
882 } 857 }
883} 858}
884 859
885/*
886 * This function is where we first pull the node unique ids, and then
887 * allocate memory and register a SBP-2 device.
888 */
889static int sbp2_start_device(struct scsi_id_instance_data *scsi_id) 860static int sbp2_start_device(struct scsi_id_instance_data *scsi_id)
890{ 861{
891 struct sbp2scsi_host_info *hi = scsi_id->hi; 862 struct sbp2scsi_host_info *hi = scsi_id->hi;
892 int error; 863 int error;
893 864
894 /* Login FIFO DMA */
895 scsi_id->login_response = 865 scsi_id->login_response =
896 pci_alloc_consistent(hi->host->pdev, 866 pci_alloc_consistent(hi->host->pdev,
897 sizeof(struct sbp2_login_response), 867 sizeof(struct sbp2_login_response),
@@ -899,7 +869,6 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id)
899 if (!scsi_id->login_response) 869 if (!scsi_id->login_response)
900 goto alloc_fail; 870 goto alloc_fail;
901 871
902 /* Query logins ORB DMA */
903 scsi_id->query_logins_orb = 872 scsi_id->query_logins_orb =
904 pci_alloc_consistent(hi->host->pdev, 873 pci_alloc_consistent(hi->host->pdev,
905 sizeof(struct sbp2_query_logins_orb), 874 sizeof(struct sbp2_query_logins_orb),
@@ -907,7 +876,6 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id)
907 if (!scsi_id->query_logins_orb) 876 if (!scsi_id->query_logins_orb)
908 goto alloc_fail; 877 goto alloc_fail;
909 878
910 /* Query logins response DMA */
911 scsi_id->query_logins_response = 879 scsi_id->query_logins_response =
912 pci_alloc_consistent(hi->host->pdev, 880 pci_alloc_consistent(hi->host->pdev,
913 sizeof(struct sbp2_query_logins_response), 881 sizeof(struct sbp2_query_logins_response),
@@ -915,7 +883,6 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id)
915 if (!scsi_id->query_logins_response) 883 if (!scsi_id->query_logins_response)
916 goto alloc_fail; 884 goto alloc_fail;
917 885
918 /* Reconnect ORB DMA */
919 scsi_id->reconnect_orb = 886 scsi_id->reconnect_orb =
920 pci_alloc_consistent(hi->host->pdev, 887 pci_alloc_consistent(hi->host->pdev,
921 sizeof(struct sbp2_reconnect_orb), 888 sizeof(struct sbp2_reconnect_orb),
@@ -923,7 +890,6 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id)
923 if (!scsi_id->reconnect_orb) 890 if (!scsi_id->reconnect_orb)
924 goto alloc_fail; 891 goto alloc_fail;
925 892
926 /* Logout ORB DMA */
927 scsi_id->logout_orb = 893 scsi_id->logout_orb =
928 pci_alloc_consistent(hi->host->pdev, 894 pci_alloc_consistent(hi->host->pdev,
929 sizeof(struct sbp2_logout_orb), 895 sizeof(struct sbp2_logout_orb),
@@ -931,7 +897,6 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id)
931 if (!scsi_id->logout_orb) 897 if (!scsi_id->logout_orb)
932 goto alloc_fail; 898 goto alloc_fail;
933 899
934 /* Login ORB DMA */
935 scsi_id->login_orb = 900 scsi_id->login_orb =
936 pci_alloc_consistent(hi->host->pdev, 901 pci_alloc_consistent(hi->host->pdev,
937 sizeof(struct sbp2_login_orb), 902 sizeof(struct sbp2_login_orb),
@@ -939,51 +904,28 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id)
939 if (!scsi_id->login_orb) 904 if (!scsi_id->login_orb)
940 goto alloc_fail; 905 goto alloc_fail;
941 906
942 /*
943 * Create our command orb pool
944 */
945 if (sbp2util_create_command_orb_pool(scsi_id)) { 907 if (sbp2util_create_command_orb_pool(scsi_id)) {
946 SBP2_ERR("sbp2util_create_command_orb_pool failed!"); 908 SBP2_ERR("sbp2util_create_command_orb_pool failed!");
947 sbp2_remove_device(scsi_id); 909 sbp2_remove_device(scsi_id);
948 return -ENOMEM; 910 return -ENOMEM;
949 } 911 }
950 912
951 /* Schedule a timeout here. The reason is that we may be so close 913 /* Wait a second before trying to log in. Previously logged in
952 * to a bus reset, that the device is not available for logins. 914 * initiators need a chance to reconnect. */
953 * This can happen when the bus reset is caused by the host
954 * connected to the sbp2 device being removed. That host would
955 * have a certain amount of time to relogin before the sbp2 device
956 * allows someone else to login instead. One second makes sense. */
957 if (msleep_interruptible(1000)) { 915 if (msleep_interruptible(1000)) {
958 sbp2_remove_device(scsi_id); 916 sbp2_remove_device(scsi_id);
959 return -EINTR; 917 return -EINTR;
960 } 918 }
961 919
962 /*
963 * Login to the sbp-2 device
964 */
965 if (sbp2_login_device(scsi_id)) { 920 if (sbp2_login_device(scsi_id)) {
966 /* Login failed, just remove the device. */
967 sbp2_remove_device(scsi_id); 921 sbp2_remove_device(scsi_id);
968 return -EBUSY; 922 return -EBUSY;
969 } 923 }
970 924
971 /*
972 * Set max retries to something large on the device
973 */
974 sbp2_set_busy_timeout(scsi_id); 925 sbp2_set_busy_timeout(scsi_id);
975
976 /*
977 * Do a SBP-2 fetch agent reset
978 */
979 sbp2_agent_reset(scsi_id, 1); 926 sbp2_agent_reset(scsi_id, 1);
980
981 /*
982 * Get the max speed and packet size that we can use
983 */
984 sbp2_max_speed_and_size(scsi_id); 927 sbp2_max_speed_and_size(scsi_id);
985 928
986 /* Add this device to the scsi layer now */
987 error = scsi_add_device(scsi_id->scsi_host, 0, scsi_id->ud->id, 0); 929 error = scsi_add_device(scsi_id->scsi_host, 0, scsi_id->ud->id, 0);
988 if (error) { 930 if (error) {
989 SBP2_ERR("scsi_add_device failed"); 931 SBP2_ERR("scsi_add_device failed");
@@ -1000,9 +942,6 @@ alloc_fail:
1000 return -ENOMEM; 942 return -ENOMEM;
1001} 943}
1002 944
1003/*
1004 * This function removes an sbp2 device from the sbp2scsi_host_info struct.
1005 */
1006static void sbp2_remove_device(struct scsi_id_instance_data *scsi_id) 945static void sbp2_remove_device(struct scsi_id_instance_data *scsi_id)
1007{ 946{
1008 struct sbp2scsi_host_info *hi; 947 struct sbp2scsi_host_info *hi;
@@ -1012,7 +951,6 @@ static void sbp2_remove_device(struct scsi_id_instance_data *scsi_id)
1012 951
1013 hi = scsi_id->hi; 952 hi = scsi_id->hi;
1014 953
1015 /* This will remove our scsi device aswell */
1016 if (scsi_id->scsi_host) { 954 if (scsi_id->scsi_host) {
1017 scsi_remove_host(scsi_id->scsi_host); 955 scsi_remove_host(scsi_id->scsi_host);
1018 scsi_host_put(scsi_id->scsi_host); 956 scsi_host_put(scsi_id->scsi_host);
@@ -1067,33 +1005,25 @@ static void sbp2_remove_device(struct scsi_id_instance_data *scsi_id)
1067 1005
1068#ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA 1006#ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
1069/* 1007/*
1070 * This function deals with physical dma write requests (for adapters that do not support 1008 * Deal with write requests on adapters which do not support physical DMA or
1071 * physical dma in hardware). Mostly just here for debugging... 1009 * have it switched off.
1072 */ 1010 */
1073static int sbp2_handle_physdma_write(struct hpsb_host *host, int nodeid, 1011static int sbp2_handle_physdma_write(struct hpsb_host *host, int nodeid,
1074 int destid, quadlet_t *data, u64 addr, 1012 int destid, quadlet_t *data, u64 addr,
1075 size_t length, u16 flags) 1013 size_t length, u16 flags)
1076{ 1014{
1077
1078 /*
1079 * Manually put the data in the right place.
1080 */
1081 memcpy(bus_to_virt((u32) addr), data, length); 1015 memcpy(bus_to_virt((u32) addr), data, length);
1082 return RCODE_COMPLETE; 1016 return RCODE_COMPLETE;
1083} 1017}
1084 1018
1085/* 1019/*
1086 * This function deals with physical dma read requests (for adapters that do not support 1020 * Deal with read requests on adapters which do not support physical DMA or
1087 * physical dma in hardware). Mostly just here for debugging... 1021 * have it switched off.
1088 */ 1022 */
1089static int sbp2_handle_physdma_read(struct hpsb_host *host, int nodeid, 1023static int sbp2_handle_physdma_read(struct hpsb_host *host, int nodeid,
1090 quadlet_t *data, u64 addr, size_t length, 1024 quadlet_t *data, u64 addr, size_t length,
1091 u16 flags) 1025 u16 flags)
1092{ 1026{
1093
1094 /*
1095 * Grab data from memory and send a read response.
1096 */
1097 memcpy(data, bus_to_virt((u32) addr), length); 1027 memcpy(data, bus_to_virt((u32) addr), length);
1098 return RCODE_COMPLETE; 1028 return RCODE_COMPLETE;
1099} 1029}
@@ -1103,10 +1033,6 @@ static int sbp2_handle_physdma_read(struct hpsb_host *host, int nodeid,
1103 * SBP-2 protocol related section 1033 * SBP-2 protocol related section
1104 **************************************/ 1034 **************************************/
1105 1035
1106/*
1107 * This function queries the device for the maximum concurrent logins it
1108 * supports.
1109 */
1110static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id) 1036static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id)
1111{ 1037{
1112 struct sbp2scsi_host_info *hi = scsi_id->hi; 1038 struct sbp2scsi_host_info *hi = scsi_id->hi;
@@ -1172,10 +1098,6 @@ static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id)
1172 return 0; 1098 return 0;
1173} 1099}
1174 1100
1175/*
1176 * This function is called in order to login to a particular SBP-2 device,
1177 * after a bus reset.
1178 */
1179static int sbp2_login_device(struct scsi_id_instance_data *scsi_id) 1101static int sbp2_login_device(struct scsi_id_instance_data *scsi_id)
1180{ 1102{
1181 struct sbp2scsi_host_info *hi = scsi_id->hi; 1103 struct sbp2scsi_host_info *hi = scsi_id->hi;
@@ -1191,17 +1113,18 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id)
1191 } 1113 }
1192 } 1114 }
1193 1115
1194 /* Set-up login ORB, assume no password */ 1116 /* assume no password */
1195 scsi_id->login_orb->password_hi = 0; 1117 scsi_id->login_orb->password_hi = 0;
1196 scsi_id->login_orb->password_lo = 0; 1118 scsi_id->login_orb->password_lo = 0;
1197 1119
1198 scsi_id->login_orb->login_response_lo = scsi_id->login_response_dma; 1120 scsi_id->login_orb->login_response_lo = scsi_id->login_response_dma;
1199 scsi_id->login_orb->login_response_hi = ORB_SET_NODE_ID(hi->host->node_id); 1121 scsi_id->login_orb->login_response_hi = ORB_SET_NODE_ID(hi->host->node_id);
1200
1201 scsi_id->login_orb->lun_misc = ORB_SET_FUNCTION(SBP2_LOGIN_REQUEST); 1122 scsi_id->login_orb->lun_misc = ORB_SET_FUNCTION(SBP2_LOGIN_REQUEST);
1202 scsi_id->login_orb->lun_misc |= ORB_SET_RECONNECT(0); /* One second reconnect time */ 1123
1203 scsi_id->login_orb->lun_misc |= ORB_SET_EXCLUSIVE(exclusive_login); /* Exclusive access to device */ 1124 /* one second reconnect time */
1204 scsi_id->login_orb->lun_misc |= ORB_SET_NOTIFY(1); /* Notify us of login complete */ 1125 scsi_id->login_orb->lun_misc |= ORB_SET_RECONNECT(0);
1126 scsi_id->login_orb->lun_misc |= ORB_SET_EXCLUSIVE(exclusive_login);
1127 scsi_id->login_orb->lun_misc |= ORB_SET_NOTIFY(1);
1205 scsi_id->login_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_lun); 1128 scsi_id->login_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_lun);
1206 1129
1207 scsi_id->login_orb->passwd_resp_lengths = 1130 scsi_id->login_orb->passwd_resp_lengths =
@@ -1222,17 +1145,13 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id)
1222 1145
1223 hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8); 1146 hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8);
1224 1147
1225 /* 1148 /* wait up to 20 seconds for login status */
1226 * Wait for login status (up to 20 seconds)...
1227 */
1228 if (sbp2util_access_timeout(scsi_id, 20*HZ)) { 1149 if (sbp2util_access_timeout(scsi_id, 20*HZ)) {
1229 SBP2_ERR("Error logging into SBP-2 device - timed out"); 1150 SBP2_ERR("Error logging into SBP-2 device - timed out");
1230 return -EIO; 1151 return -EIO;
1231 } 1152 }
1232 1153
1233 /* 1154 /* make sure that the returned status matches the login ORB */
1234 * Sanity. Make sure status returned matches login orb.
1235 */
1236 if (scsi_id->status_block.ORB_offset_lo != scsi_id->login_orb_dma) { 1155 if (scsi_id->status_block.ORB_offset_lo != scsi_id->login_orb_dma) {
1237 SBP2_ERR("Error logging into SBP-2 device - timed out"); 1156 SBP2_ERR("Error logging into SBP-2 device - timed out");
1238 return -EIO; 1157 return -EIO;
@@ -1243,15 +1162,7 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id)
1243 return -EIO; 1162 return -EIO;
1244 } 1163 }
1245 1164
1246 /*
1247 * Byte swap the login response, for use when reconnecting or
1248 * logging out.
1249 */
1250 sbp2util_cpu_to_be32_buffer(scsi_id->login_response, sizeof(struct sbp2_login_response)); 1165 sbp2util_cpu_to_be32_buffer(scsi_id->login_response, sizeof(struct sbp2_login_response));
1251
1252 /*
1253 * Grab our command block agent address from the login response.
1254 */
1255 scsi_id->sbp2_command_block_agent_addr = 1166 scsi_id->sbp2_command_block_agent_addr =
1256 ((u64)scsi_id->login_response->command_block_agent_hi) << 32; 1167 ((u64)scsi_id->login_response->command_block_agent_hi) << 32;
1257 scsi_id->sbp2_command_block_agent_addr |= ((u64)scsi_id->login_response->command_block_agent_lo); 1168 scsi_id->sbp2_command_block_agent_addr |= ((u64)scsi_id->login_response->command_block_agent_lo);
@@ -1261,19 +1172,12 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id)
1261 return 0; 1172 return 0;
1262} 1173}
1263 1174
1264/*
1265 * This function is called in order to logout from a particular SBP-2
1266 * device, usually called during driver unload.
1267 */
1268static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id) 1175static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id)
1269{ 1176{
1270 struct sbp2scsi_host_info *hi = scsi_id->hi; 1177 struct sbp2scsi_host_info *hi = scsi_id->hi;
1271 quadlet_t data[2]; 1178 quadlet_t data[2];
1272 int error; 1179 int error;
1273 1180
1274 /*
1275 * Set-up logout ORB
1276 */
1277 scsi_id->logout_orb->reserved1 = 0x0; 1181 scsi_id->logout_orb->reserved1 = 0x0;
1278 scsi_id->logout_orb->reserved2 = 0x0; 1182 scsi_id->logout_orb->reserved2 = 0x0;
1279 scsi_id->logout_orb->reserved3 = 0x0; 1183 scsi_id->logout_orb->reserved3 = 0x0;
@@ -1281,8 +1185,6 @@ static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id)
1281 1185
1282 scsi_id->logout_orb->login_ID_misc = ORB_SET_FUNCTION(SBP2_LOGOUT_REQUEST); 1186 scsi_id->logout_orb->login_ID_misc = ORB_SET_FUNCTION(SBP2_LOGOUT_REQUEST);
1283 scsi_id->logout_orb->login_ID_misc |= ORB_SET_LOGIN_ID(scsi_id->login_response->length_login_ID); 1187 scsi_id->logout_orb->login_ID_misc |= ORB_SET_LOGIN_ID(scsi_id->login_response->length_login_ID);
1284
1285 /* Notify us when complete */
1286 scsi_id->logout_orb->login_ID_misc |= ORB_SET_NOTIFY(1); 1188 scsi_id->logout_orb->login_ID_misc |= ORB_SET_NOTIFY(1);
1287 1189
1288 scsi_id->logout_orb->reserved5 = 0x0; 1190 scsi_id->logout_orb->reserved5 = 0x0;
@@ -1291,14 +1193,8 @@ static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id)
1291 scsi_id->logout_orb->status_fifo_lo = 1193 scsi_id->logout_orb->status_fifo_lo =
1292 ORB_SET_STATUS_FIFO_LO(scsi_id->status_fifo_addr); 1194 ORB_SET_STATUS_FIFO_LO(scsi_id->status_fifo_addr);
1293 1195
1294 /*
1295 * Byte swap ORB if necessary
1296 */
1297 sbp2util_cpu_to_be32_buffer(scsi_id->logout_orb, sizeof(struct sbp2_logout_orb)); 1196 sbp2util_cpu_to_be32_buffer(scsi_id->logout_orb, sizeof(struct sbp2_logout_orb));
1298 1197
1299 /*
1300 * Ok, let's write to the target's management agent register
1301 */
1302 data[0] = ORB_SET_NODE_ID(hi->host->node_id); 1198 data[0] = ORB_SET_NODE_ID(hi->host->node_id);
1303 data[1] = scsi_id->logout_orb_dma; 1199 data[1] = scsi_id->logout_orb_dma;
1304 sbp2util_cpu_to_be32_buffer(data, 8); 1200 sbp2util_cpu_to_be32_buffer(data, 8);
@@ -1308,7 +1204,7 @@ static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id)
1308 if (error) 1204 if (error)
1309 return error; 1205 return error;
1310 1206
1311 /* Wait for device to logout...1 second. */ 1207 /* wait up to 1 second for the device to complete logout */
1312 if (sbp2util_access_timeout(scsi_id, HZ)) 1208 if (sbp2util_access_timeout(scsi_id, HZ))
1313 return -EIO; 1209 return -EIO;
1314 1210
@@ -1316,19 +1212,12 @@ static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id)
1316 return 0; 1212 return 0;
1317} 1213}
1318 1214
1319/*
1320 * This function is called in order to reconnect to a particular SBP-2
1321 * device, after a bus reset.
1322 */
1323static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id) 1215static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id)
1324{ 1216{
1325 struct sbp2scsi_host_info *hi = scsi_id->hi; 1217 struct sbp2scsi_host_info *hi = scsi_id->hi;
1326 quadlet_t data[2]; 1218 quadlet_t data[2];
1327 int error; 1219 int error;
1328 1220
1329 /*
1330 * Set-up reconnect ORB
1331 */
1332 scsi_id->reconnect_orb->reserved1 = 0x0; 1221 scsi_id->reconnect_orb->reserved1 = 0x0;
1333 scsi_id->reconnect_orb->reserved2 = 0x0; 1222 scsi_id->reconnect_orb->reserved2 = 0x0;
1334 scsi_id->reconnect_orb->reserved3 = 0x0; 1223 scsi_id->reconnect_orb->reserved3 = 0x0;
@@ -1337,8 +1226,6 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id)
1337 scsi_id->reconnect_orb->login_ID_misc = ORB_SET_FUNCTION(SBP2_RECONNECT_REQUEST); 1226 scsi_id->reconnect_orb->login_ID_misc = ORB_SET_FUNCTION(SBP2_RECONNECT_REQUEST);
1338 scsi_id->reconnect_orb->login_ID_misc |= 1227 scsi_id->reconnect_orb->login_ID_misc |=
1339 ORB_SET_LOGIN_ID(scsi_id->login_response->length_login_ID); 1228 ORB_SET_LOGIN_ID(scsi_id->login_response->length_login_ID);
1340
1341 /* Notify us when complete */
1342 scsi_id->reconnect_orb->login_ID_misc |= ORB_SET_NOTIFY(1); 1229 scsi_id->reconnect_orb->login_ID_misc |= ORB_SET_NOTIFY(1);
1343 1230
1344 scsi_id->reconnect_orb->reserved5 = 0x0; 1231 scsi_id->reconnect_orb->reserved5 = 0x0;
@@ -1347,9 +1234,6 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id)
1347 scsi_id->reconnect_orb->status_fifo_lo = 1234 scsi_id->reconnect_orb->status_fifo_lo =
1348 ORB_SET_STATUS_FIFO_LO(scsi_id->status_fifo_addr); 1235 ORB_SET_STATUS_FIFO_LO(scsi_id->status_fifo_addr);
1349 1236
1350 /*
1351 * Byte swap ORB if necessary
1352 */
1353 sbp2util_cpu_to_be32_buffer(scsi_id->reconnect_orb, sizeof(struct sbp2_reconnect_orb)); 1237 sbp2util_cpu_to_be32_buffer(scsi_id->reconnect_orb, sizeof(struct sbp2_reconnect_orb));
1354 1238
1355 data[0] = ORB_SET_NODE_ID(hi->host->node_id); 1239 data[0] = ORB_SET_NODE_ID(hi->host->node_id);
@@ -1361,17 +1245,13 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id)
1361 if (error) 1245 if (error)
1362 return error; 1246 return error;
1363 1247
1364 /* 1248 /* wait up to 1 second for reconnect status */
1365 * Wait for reconnect status (up to 1 second)...
1366 */
1367 if (sbp2util_access_timeout(scsi_id, HZ)) { 1249 if (sbp2util_access_timeout(scsi_id, HZ)) {
1368 SBP2_ERR("Error reconnecting to SBP-2 device - timed out"); 1250 SBP2_ERR("Error reconnecting to SBP-2 device - timed out");
1369 return -EIO; 1251 return -EIO;
1370 } 1252 }
1371 1253
1372 /* 1254 /* make sure that the returned status matches the reconnect ORB */
1373 * Sanity. Make sure status returned matches reconnect orb.
1374 */
1375 if (scsi_id->status_block.ORB_offset_lo != scsi_id->reconnect_orb_dma) { 1255 if (scsi_id->status_block.ORB_offset_lo != scsi_id->reconnect_orb_dma) {
1376 SBP2_ERR("Error reconnecting to SBP-2 device - timed out"); 1256 SBP2_ERR("Error reconnecting to SBP-2 device - timed out");
1377 return -EIO; 1257 return -EIO;
@@ -1387,8 +1267,8 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id)
1387} 1267}
1388 1268
1389/* 1269/*
1390 * This function is called in order to set the busy timeout (number of 1270 * Set the target node's Single Phase Retry limit. Affects the target's retry
1391 * retries to attempt) on the sbp2 device. 1271 * behaviour if our node is too busy to accept requests.
1392 */ 1272 */
1393static int sbp2_set_busy_timeout(struct scsi_id_instance_data *scsi_id) 1273static int sbp2_set_busy_timeout(struct scsi_id_instance_data *scsi_id)
1394{ 1274{
@@ -1400,11 +1280,6 @@ static int sbp2_set_busy_timeout(struct scsi_id_instance_data *scsi_id)
1400 return 0; 1280 return 0;
1401} 1281}
1402 1282
1403/*
1404 * This function is called to parse sbp2 device's config rom unit
1405 * directory. Used to determine things like sbp2 management agent offset,
1406 * and command set used (SCSI or RBC).
1407 */
1408static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id, 1283static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id,
1409 struct unit_directory *ud) 1284 struct unit_directory *ud)
1410{ 1285{
@@ -1422,12 +1297,10 @@ static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id,
1422 unit_characteristics = 0x0; 1297 unit_characteristics = 0x0;
1423 firmware_revision = 0x0; 1298 firmware_revision = 0x0;
1424 1299
1425 /* Handle different fields in the unit directory, based on keys */
1426 csr1212_for_each_dir_entry(ud->ne->csr, kv, ud->ud_kv, dentry) { 1300 csr1212_for_each_dir_entry(ud->ne->csr, kv, ud->ud_kv, dentry) {
1427 switch (kv->key.id) { 1301 switch (kv->key.id) {
1428 case CSR1212_KV_ID_DEPENDENT_INFO: 1302 case CSR1212_KV_ID_DEPENDENT_INFO:
1429 if (kv->key.type == CSR1212_KV_TYPE_CSR_OFFSET) 1303 if (kv->key.type == CSR1212_KV_TYPE_CSR_OFFSET)
1430 /* Save off the management agent address */
1431 management_agent_addr = 1304 management_agent_addr =
1432 CSR1212_REGISTER_SPACE_BASE + 1305 CSR1212_REGISTER_SPACE_BASE +
1433 (kv->value.csr_offset << 2); 1306 (kv->value.csr_offset << 2);
@@ -1438,29 +1311,27 @@ static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id,
1438 break; 1311 break;
1439 1312
1440 case SBP2_COMMAND_SET_SPEC_ID_KEY: 1313 case SBP2_COMMAND_SET_SPEC_ID_KEY:
1441 /* Command spec organization */
1442 command_set_spec_id = kv->value.immediate; 1314 command_set_spec_id = kv->value.immediate;
1443 break; 1315 break;
1444 1316
1445 case SBP2_COMMAND_SET_KEY: 1317 case SBP2_COMMAND_SET_KEY:
1446 /* Command set used by sbp2 device */
1447 command_set = kv->value.immediate; 1318 command_set = kv->value.immediate;
1448 break; 1319 break;
1449 1320
1450 case SBP2_UNIT_CHARACTERISTICS_KEY: 1321 case SBP2_UNIT_CHARACTERISTICS_KEY:
1451 /* 1322 /* FIXME: This is ignored so far.
1452 * Unit characterisitcs (orb related stuff 1323 * See SBP-2 clause 7.4.8. */
1453 * that I'm not yet paying attention to)
1454 */
1455 unit_characteristics = kv->value.immediate; 1324 unit_characteristics = kv->value.immediate;
1456 break; 1325 break;
1457 1326
1458 case SBP2_FIRMWARE_REVISION_KEY: 1327 case SBP2_FIRMWARE_REVISION_KEY:
1459 /* Firmware revision */
1460 firmware_revision = kv->value.immediate; 1328 firmware_revision = kv->value.immediate;
1461 break; 1329 break;
1462 1330
1463 default: 1331 default:
1332 /* FIXME: Check for SBP2_DEVICE_TYPE_AND_LUN_KEY.
1333 * Its "ordered" bit has consequences for command ORB
1334 * list handling. See SBP-2 clauses 4.6, 7.4.11, 10.2 */
1464 break; 1335 break;
1465 } 1336 }
1466 } 1337 }
@@ -1536,7 +1407,6 @@ static int sbp2_max_speed_and_size(struct scsi_id_instance_data *scsi_id)
1536 scsi_id->speed_code = 1407 scsi_id->speed_code =
1537 hi->host->speed[NODEID_TO_NODE(scsi_id->ne->nodeid)]; 1408 hi->host->speed[NODEID_TO_NODE(scsi_id->ne->nodeid)];
1538 1409
1539 /* Bump down our speed if the user requested it */
1540 if (scsi_id->speed_code > max_speed) { 1410 if (scsi_id->speed_code > max_speed) {
1541 scsi_id->speed_code = max_speed; 1411 scsi_id->speed_code = max_speed;
1542 SBP2_INFO("Reducing speed to %s", hpsb_speedto_str[max_speed]); 1412 SBP2_INFO("Reducing speed to %s", hpsb_speedto_str[max_speed]);
@@ -1563,9 +1433,6 @@ static int sbp2_max_speed_and_size(struct scsi_id_instance_data *scsi_id)
1563 return 0; 1433 return 0;
1564} 1434}
1565 1435
1566/*
1567 * This function is called in order to perform a SBP-2 agent reset.
1568 */
1569static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait) 1436static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait)
1570{ 1437{
1571 quadlet_t data; 1438 quadlet_t data;
@@ -1590,9 +1457,7 @@ static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait)
1590 return -EIO; 1457 return -EIO;
1591 } 1458 }
1592 1459
1593 /* 1460 /* make sure that the ORB_POINTER is written on next command */
1594 * Need to make sure orb pointer is written on next command
1595 */
1596 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); 1461 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
1597 scsi_id->last_orb = NULL; 1462 scsi_id->last_orb = NULL;
1598 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); 1463 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
@@ -1612,7 +1477,7 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
1612 orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); 1477 orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
1613 orb->misc |= ORB_SET_DIRECTION(orb_direction); 1478 orb->misc |= ORB_SET_DIRECTION(orb_direction);
1614 1479
1615 /* Special case if only one element (and less than 64KB in size) */ 1480 /* special case if only one element (and less than 64KB in size) */
1616 if ((scsi_use_sg == 1) && 1481 if ((scsi_use_sg == 1) &&
1617 (sgpnt[0].length <= SBP2_MAX_SG_ELEMENT_LENGTH)) { 1482 (sgpnt[0].length <= SBP2_MAX_SG_ELEMENT_LENGTH)) {
1618 1483
@@ -1642,10 +1507,8 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
1642 orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); 1507 orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1);
1643 orb->data_descriptor_lo = command->sge_dma; 1508 orb->data_descriptor_lo = command->sge_dma;
1644 1509
1645 /* 1510 /* loop through and fill out our SBP-2 page tables
1646 * Loop through and fill out our sbp-2 page tables 1511 * (and split up anything too large) */
1647 * (and split up anything too large)
1648 */
1649 for (i = 0, sg_count = 0 ; i < count; i++, sgpnt++) { 1512 for (i = 0, sg_count = 0 ; i < count; i++, sgpnt++) {
1650 sg_len = sg_dma_len(sgpnt); 1513 sg_len = sg_dma_len(sgpnt);
1651 sg_addr = sg_dma_address(sgpnt); 1514 sg_addr = sg_dma_address(sgpnt);
@@ -1665,10 +1528,8 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
1665 } 1528 }
1666 } 1529 }
1667 1530
1668 /* Number of page table (s/g) elements */
1669 orb->misc |= ORB_SET_DATA_SIZE(sg_count); 1531 orb->misc |= ORB_SET_DATA_SIZE(sg_count);
1670 1532
1671 /* Byte swap page tables if necessary */
1672 sbp2util_cpu_to_be32_buffer(sg_element, 1533 sbp2util_cpu_to_be32_buffer(sg_element,
1673 (sizeof(struct sbp2_unrestricted_page_table)) * 1534 (sizeof(struct sbp2_unrestricted_page_table)) *
1674 sg_count); 1535 sg_count);
@@ -1692,34 +1553,25 @@ static void sbp2_prep_command_orb_no_sg(struct sbp2_command_orb *orb,
1692 orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); 1553 orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
1693 orb->misc |= ORB_SET_DIRECTION(orb_direction); 1554 orb->misc |= ORB_SET_DIRECTION(orb_direction);
1694 1555
1695 /* 1556 /* handle case where we get a command w/o s/g enabled
1696 * Handle case where we get a command w/o s/g enabled (but 1557 * (but check for transfers larger than 64K) */
1697 * check for transfers larger than 64K)
1698 */
1699 if (scsi_request_bufflen <= SBP2_MAX_SG_ELEMENT_LENGTH) { 1558 if (scsi_request_bufflen <= SBP2_MAX_SG_ELEMENT_LENGTH) {
1700 1559
1701 orb->data_descriptor_lo = command->cmd_dma; 1560 orb->data_descriptor_lo = command->cmd_dma;
1702 orb->misc |= ORB_SET_DATA_SIZE(scsi_request_bufflen); 1561 orb->misc |= ORB_SET_DATA_SIZE(scsi_request_bufflen);
1703 1562
1704 } else { 1563 } else {
1564 /* The buffer is too large. Turn this into page tables. */
1565
1705 struct sbp2_unrestricted_page_table *sg_element = 1566 struct sbp2_unrestricted_page_table *sg_element =
1706 &command->scatter_gather_element[0]; 1567 &command->scatter_gather_element[0];
1707 u32 sg_count, sg_len; 1568 u32 sg_count, sg_len;
1708 dma_addr_t sg_addr; 1569 dma_addr_t sg_addr;
1709 1570
1710 /*
1711 * Need to turn this into page tables, since the
1712 * buffer is too large.
1713 */
1714 orb->data_descriptor_lo = command->sge_dma; 1571 orb->data_descriptor_lo = command->sge_dma;
1715
1716 /* Use page tables (s/g) */
1717 orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); 1572 orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1);
1718 1573
1719 /* 1574 /* fill out our SBP-2 page tables; split up the large buffer */
1720 * fill out our sbp-2 page tables (and split up
1721 * the large buffer)
1722 */
1723 sg_count = 0; 1575 sg_count = 0;
1724 sg_len = scsi_request_bufflen; 1576 sg_len = scsi_request_bufflen;
1725 sg_addr = command->cmd_dma; 1577 sg_addr = command->cmd_dma;
@@ -1738,20 +1590,14 @@ static void sbp2_prep_command_orb_no_sg(struct sbp2_command_orb *orb,
1738 sg_count++; 1590 sg_count++;
1739 } 1591 }
1740 1592
1741 /* Number of page table (s/g) elements */
1742 orb->misc |= ORB_SET_DATA_SIZE(sg_count); 1593 orb->misc |= ORB_SET_DATA_SIZE(sg_count);
1743 1594
1744 /* Byte swap page tables if necessary */
1745 sbp2util_cpu_to_be32_buffer(sg_element, 1595 sbp2util_cpu_to_be32_buffer(sg_element,
1746 (sizeof(struct sbp2_unrestricted_page_table)) * 1596 (sizeof(struct sbp2_unrestricted_page_table)) *
1747 sg_count); 1597 sg_count);
1748 } 1598 }
1749} 1599}
1750 1600
1751/*
1752 * This function is called to create the actual command orb and s/g list
1753 * out of the scsi command itself.
1754 */
1755static void sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id, 1601static void sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id,
1756 struct sbp2_command_info *command, 1602 struct sbp2_command_info *command,
1757 unchar *scsi_cmd, 1603 unchar *scsi_cmd,
@@ -1766,7 +1612,7 @@ static void sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id,
1766 u32 orb_direction; 1612 u32 orb_direction;
1767 1613
1768 /* 1614 /*
1769 * Set-up our command ORB.. 1615 * Set-up our command ORB.
1770 * 1616 *
1771 * NOTE: We're doing unrestricted page tables (s/g), as this is 1617 * NOTE: We're doing unrestricted page tables (s/g), as this is
1772 * best performance (at least with the devices I have). This means 1618 * best performance (at least with the devices I have). This means
@@ -1777,7 +1623,7 @@ static void sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id,
1777 command_orb->next_ORB_lo = 0x0; 1623 command_orb->next_ORB_lo = 0x0;
1778 command_orb->misc = ORB_SET_MAX_PAYLOAD(scsi_id->max_payload_size); 1624 command_orb->misc = ORB_SET_MAX_PAYLOAD(scsi_id->max_payload_size);
1779 command_orb->misc |= ORB_SET_SPEED(scsi_id->speed_code); 1625 command_orb->misc |= ORB_SET_SPEED(scsi_id->speed_code);
1780 command_orb->misc |= ORB_SET_NOTIFY(1); /* Notify us when complete */ 1626 command_orb->misc |= ORB_SET_NOTIFY(1);
1781 1627
1782 if (dma_dir == DMA_NONE) 1628 if (dma_dir == DMA_NONE)
1783 orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER; 1629 orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER;
@@ -1790,7 +1636,7 @@ static void sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id,
1790 orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER; 1636 orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER;
1791 } 1637 }
1792 1638
1793 /* Set-up our pagetable stuff */ 1639 /* set up our page table stuff */
1794 if (orb_direction == ORB_DIRECTION_NO_DATA_TRANSFER) { 1640 if (orb_direction == ORB_DIRECTION_NO_DATA_TRANSFER) {
1795 command_orb->data_descriptor_hi = 0x0; 1641 command_orb->data_descriptor_hi = 0x0;
1796 command_orb->data_descriptor_lo = 0x0; 1642 command_orb->data_descriptor_lo = 0x0;
@@ -1803,17 +1649,12 @@ static void sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id,
1803 orb_direction, scsi_request_bufflen, 1649 orb_direction, scsi_request_bufflen,
1804 scsi_request_buffer, dma_dir); 1650 scsi_request_buffer, dma_dir);
1805 1651
1806 /* Byte swap command ORB if necessary */
1807 sbp2util_cpu_to_be32_buffer(command_orb, sizeof(struct sbp2_command_orb)); 1652 sbp2util_cpu_to_be32_buffer(command_orb, sizeof(struct sbp2_command_orb));
1808 1653
1809 /* Put our scsi command in the command ORB */
1810 memset(command_orb->cdb, 0, 12); 1654 memset(command_orb->cdb, 0, 12);
1811 memcpy(command_orb->cdb, scsi_cmd, COMMAND_SIZE(*scsi_cmd)); 1655 memcpy(command_orb->cdb, scsi_cmd, COMMAND_SIZE(*scsi_cmd));
1812} 1656}
1813 1657
1814/*
1815 * This function is called in order to begin a regular SBP-2 command.
1816 */
1817static void sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, 1658static void sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id,
1818 struct sbp2_command_info *command) 1659 struct sbp2_command_info *command)
1819{ 1660{
@@ -1832,9 +1673,8 @@ static void sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id,
1832 pci_dma_sync_single_for_device(hi->host->pdev, command->sge_dma, 1673 pci_dma_sync_single_for_device(hi->host->pdev, command->sge_dma,
1833 sizeof(command->scatter_gather_element), 1674 sizeof(command->scatter_gather_element),
1834 PCI_DMA_BIDIRECTIONAL); 1675 PCI_DMA_BIDIRECTIONAL);
1835 /* 1676
1836 * Check to see if there are any previous orbs to use 1677 /* check to see if there are any previous orbs to use */
1837 */
1838 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); 1678 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
1839 last_orb = scsi_id->last_orb; 1679 last_orb = scsi_id->last_orb;
1840 last_orb_dma = scsi_id->last_orb_dma; 1680 last_orb_dma = scsi_id->last_orb_dma;
@@ -1892,9 +1732,6 @@ static void sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id,
1892 } 1732 }
1893} 1733}
1894 1734
1895/*
1896 * This function is called in order to begin a regular SBP-2 command.
1897 */
1898static int sbp2_send_command(struct scsi_id_instance_data *scsi_id, 1735static int sbp2_send_command(struct scsi_id_instance_data *scsi_id,
1899 struct scsi_cmnd *SCpnt, 1736 struct scsi_cmnd *SCpnt,
1900 void (*done)(struct scsi_cmnd *)) 1737 void (*done)(struct scsi_cmnd *))
@@ -1903,23 +1740,13 @@ static int sbp2_send_command(struct scsi_id_instance_data *scsi_id,
1903 unsigned int request_bufflen = SCpnt->request_bufflen; 1740 unsigned int request_bufflen = SCpnt->request_bufflen;
1904 struct sbp2_command_info *command; 1741 struct sbp2_command_info *command;
1905 1742
1906 /*
1907 * Allocate a command orb and s/g structure
1908 */
1909 command = sbp2util_allocate_command_orb(scsi_id, SCpnt, done); 1743 command = sbp2util_allocate_command_orb(scsi_id, SCpnt, done);
1910 if (!command) 1744 if (!command)
1911 return -EIO; 1745 return -EIO;
1912 1746
1913 /*
1914 * Now actually fill in the comamnd orb and sbp2 s/g list
1915 */
1916 sbp2_create_command_orb(scsi_id, command, cmd, SCpnt->use_sg, 1747 sbp2_create_command_orb(scsi_id, command, cmd, SCpnt->use_sg,
1917 request_bufflen, SCpnt->request_buffer, 1748 request_bufflen, SCpnt->request_buffer,
1918 SCpnt->sc_data_direction); 1749 SCpnt->sc_data_direction);
1919
1920 /*
1921 * Link up the orb, and ring the doorbell if needed
1922 */
1923 sbp2_link_orb_command(scsi_id, command); 1750 sbp2_link_orb_command(scsi_id, command);
1924 1751
1925 return 0; 1752 return 0;
@@ -1930,9 +1757,7 @@ static int sbp2_send_command(struct scsi_id_instance_data *scsi_id,
1930 */ 1757 */
1931static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense_data) 1758static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense_data)
1932{ 1759{
1933 /* 1760 /* OK, it's pretty ugly... ;-) */
1934 * Ok, it's pretty ugly... ;-)
1935 */
1936 sense_data[0] = 0x70; 1761 sense_data[0] = 0x70;
1937 sense_data[1] = 0x0; 1762 sense_data[1] = 0x0;
1938 sense_data[2] = sbp2_status[9]; 1763 sense_data[2] = sbp2_status[9];
@@ -1950,12 +1775,9 @@ static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense
1950 sense_data[14] = sbp2_status[20]; 1775 sense_data[14] = sbp2_status[20];
1951 sense_data[15] = sbp2_status[21]; 1776 sense_data[15] = sbp2_status[21];
1952 1777
1953 return sbp2_status[8] & 0x3f; /* return scsi status */ 1778 return sbp2_status[8] & 0x3f;
1954} 1779}
1955 1780
1956/*
1957 * This function deals with status writes from the SBP-2 device
1958 */
1959static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, 1781static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
1960 int destid, quadlet_t *data, u64 addr, 1782 int destid, quadlet_t *data, u64 addr,
1961 size_t length, u16 fl) 1783 size_t length, u16 fl)
@@ -1981,10 +1803,8 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
1981 SBP2_ERR("host info is NULL - this is bad!"); 1803 SBP2_ERR("host info is NULL - this is bad!");
1982 return RCODE_ADDRESS_ERROR; 1804 return RCODE_ADDRESS_ERROR;
1983 } 1805 }
1984 /* 1806
1985 * Find our scsi_id structure by looking at the status fifo address 1807 /* Find the unit which wrote the status. */
1986 * written to by the sbp2 device.
1987 */
1988 list_for_each_entry(scsi_id_tmp, &hi->scsi_ids, scsi_list) { 1808 list_for_each_entry(scsi_id_tmp, &hi->scsi_ids, scsi_list) {
1989 if (scsi_id_tmp->ne->nodeid == nodeid && 1809 if (scsi_id_tmp->ne->nodeid == nodeid &&
1990 scsi_id_tmp->status_fifo_addr == addr) { 1810 scsi_id_tmp->status_fifo_addr == addr) {
@@ -1997,20 +1817,16 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
1997 return RCODE_ADDRESS_ERROR; 1817 return RCODE_ADDRESS_ERROR;
1998 } 1818 }
1999 1819
2000 /* 1820 /* Put response into scsi_id status fifo buffer. The first two bytes
2001 * Put response into scsi_id status fifo buffer. The first two bytes
2002 * come in big endian bit order. Often the target writes only a 1821 * come in big endian bit order. Often the target writes only a
2003 * truncated status block, minimally the first two quadlets. The rest 1822 * truncated status block, minimally the first two quadlets. The rest
2004 * is implied to be zeros. 1823 * is implied to be zeros. */
2005 */
2006 sb = &scsi_id->status_block; 1824 sb = &scsi_id->status_block;
2007 memset(sb->command_set_dependent, 0, sizeof(sb->command_set_dependent)); 1825 memset(sb->command_set_dependent, 0, sizeof(sb->command_set_dependent));
2008 memcpy(sb, data, length); 1826 memcpy(sb, data, length);
2009 sbp2util_be32_to_cpu_buffer(sb, 8); 1827 sbp2util_be32_to_cpu_buffer(sb, 8);
2010 1828
2011 /* 1829 /* Ignore unsolicited status. Handle command ORB status. */
2012 * Ignore unsolicited status. Handle command ORB status.
2013 */
2014 if (unlikely(STATUS_GET_SRC(sb->ORB_offset_hi_misc) == 2)) 1830 if (unlikely(STATUS_GET_SRC(sb->ORB_offset_hi_misc) == 2))
2015 command = NULL; 1831 command = NULL;
2016 else 1832 else
@@ -2023,10 +1839,7 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
2023 pci_dma_sync_single_for_cpu(hi->host->pdev, command->sge_dma, 1839 pci_dma_sync_single_for_cpu(hi->host->pdev, command->sge_dma,
2024 sizeof(command->scatter_gather_element), 1840 sizeof(command->scatter_gather_element),
2025 PCI_DMA_BIDIRECTIONAL); 1841 PCI_DMA_BIDIRECTIONAL);
2026 /* 1842 /* Grab SCSI command pointers and check status. */
2027 * Matched status with command, now grab scsi command pointers
2028 * and check status.
2029 */
2030 /* 1843 /*
2031 * FIXME: If the src field in the status is 1, the ORB DMA must 1844 * FIXME: If the src field in the status is 1, the ORB DMA must
2032 * not be reused until status for a subsequent ORB is received. 1845 * not be reused until status for a subsequent ORB is received.
@@ -2048,37 +1861,28 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
2048 SBP2_SCSI_STATUS_BUSY : 1861 SBP2_SCSI_STATUS_BUSY :
2049 SBP2_SCSI_STATUS_COMMAND_TERMINATED; 1862 SBP2_SCSI_STATUS_COMMAND_TERMINATED;
2050 } 1863 }
2051 /* 1864
2052 * See if the target stored any scsi status information.
2053 */
2054 if (STATUS_GET_LEN(h) > 1) 1865 if (STATUS_GET_LEN(h) > 1)
2055 scsi_status = sbp2_status_to_sense_data( 1866 scsi_status = sbp2_status_to_sense_data(
2056 (unchar *)sb, SCpnt->sense_buffer); 1867 (unchar *)sb, SCpnt->sense_buffer);
2057 /* 1868
2058 * Check to see if the dead bit is set. If so, we'll
2059 * have to initiate a fetch agent reset.
2060 */
2061 if (STATUS_TEST_DEAD(h)) 1869 if (STATUS_TEST_DEAD(h))
2062 sbp2_agent_reset(scsi_id, 0); 1870 sbp2_agent_reset(scsi_id, 0);
2063 } 1871 }
2064 1872
2065 /* 1873 /* Check here to see if there are no commands in-use. If there
2066 * Check here to see if there are no commands in-use. If there
2067 * are none, we know that the fetch agent left the active state 1874 * are none, we know that the fetch agent left the active state
2068 * _and_ that we did not reactivate it yet. Therefore clear 1875 * _and_ that we did not reactivate it yet. Therefore clear
2069 * last_orb so that next time we write directly to the 1876 * last_orb so that next time we write directly to the
2070 * ORB_POINTER register. That way the fetch agent does not need 1877 * ORB_POINTER register. That way the fetch agent does not need
2071 * to refetch the next_ORB. 1878 * to refetch the next_ORB. */
2072 */
2073 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); 1879 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
2074 if (list_empty(&scsi_id->sbp2_command_orb_inuse)) 1880 if (list_empty(&scsi_id->sbp2_command_orb_inuse))
2075 scsi_id->last_orb = NULL; 1881 scsi_id->last_orb = NULL;
2076 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); 1882 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
2077 1883
2078 } else { 1884 } else {
2079 /* 1885 /* It's probably status after a management request. */
2080 * It's probably a login/logout/reconnect status.
2081 */
2082 if ((sb->ORB_offset_lo == scsi_id->reconnect_orb_dma) || 1886 if ((sb->ORB_offset_lo == scsi_id->reconnect_orb_dma) ||
2083 (sb->ORB_offset_lo == scsi_id->login_orb_dma) || 1887 (sb->ORB_offset_lo == scsi_id->login_orb_dma) ||
2084 (sb->ORB_offset_lo == scsi_id->query_logins_orb_dma) || 1888 (sb->ORB_offset_lo == scsi_id->query_logins_orb_dma) ||
@@ -2098,10 +1902,6 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
2098 * SCSI interface related section 1902 * SCSI interface related section
2099 **************************************/ 1903 **************************************/
2100 1904
2101/*
2102 * This routine is the main request entry routine for doing I/O. It is
2103 * called from the scsi stack directly.
2104 */
2105static int sbp2scsi_queuecommand(struct scsi_cmnd *SCpnt, 1905static int sbp2scsi_queuecommand(struct scsi_cmnd *SCpnt,
2106 void (*done)(struct scsi_cmnd *)) 1906 void (*done)(struct scsi_cmnd *))
2107{ 1907{
@@ -2120,17 +1920,13 @@ static int sbp2scsi_queuecommand(struct scsi_cmnd *SCpnt,
2120 goto done; 1920 goto done;
2121 } 1921 }
2122 1922
2123 /* 1923 /* Multiple units are currently represented to the SCSI core as separate
2124 * Until we handle multiple luns, just return selection time-out 1924 * targets, not as one target with multiple LUs. Therefore return
2125 * to any IO directed at non-zero LUNs 1925 * selection time-out to any IO directed at non-zero LUNs. */
2126 */
2127 if (SCpnt->device->lun) 1926 if (SCpnt->device->lun)
2128 goto done; 1927 goto done;
2129 1928
2130 /* 1929 /* handle the request sense command here (auto-request sense) */
2131 * Check for request sense command, and handle it here
2132 * (autorequest sense)
2133 */
2134 if (SCpnt->cmnd[0] == REQUEST_SENSE) { 1930 if (SCpnt->cmnd[0] == REQUEST_SENSE) {
2135 memcpy(SCpnt->request_buffer, SCpnt->sense_buffer, SCpnt->request_bufflen); 1931 memcpy(SCpnt->request_buffer, SCpnt->sense_buffer, SCpnt->request_bufflen);
2136 memset(SCpnt->sense_buffer, 0, sizeof(SCpnt->sense_buffer)); 1932 memset(SCpnt->sense_buffer, 0, sizeof(SCpnt->sense_buffer));
@@ -2138,28 +1934,20 @@ static int sbp2scsi_queuecommand(struct scsi_cmnd *SCpnt,
2138 return 0; 1934 return 0;
2139 } 1935 }
2140 1936
2141 /*
2142 * Check to see if we are in the middle of a bus reset.
2143 */
2144 if (!hpsb_node_entry_valid(scsi_id->ne)) { 1937 if (!hpsb_node_entry_valid(scsi_id->ne)) {
2145 SBP2_ERR("Bus reset in progress - rejecting command"); 1938 SBP2_ERR("Bus reset in progress - rejecting command");
2146 result = DID_BUS_BUSY << 16; 1939 result = DID_BUS_BUSY << 16;
2147 goto done; 1940 goto done;
2148 } 1941 }
2149 1942
2150 /* 1943 /* Bidirectional commands are not yet implemented,
2151 * Bidirectional commands are not yet implemented, 1944 * and unknown transfer direction not handled. */
2152 * and unknown transfer direction not handled.
2153 */
2154 if (SCpnt->sc_data_direction == DMA_BIDIRECTIONAL) { 1945 if (SCpnt->sc_data_direction == DMA_BIDIRECTIONAL) {
2155 SBP2_ERR("Cannot handle DMA_BIDIRECTIONAL - rejecting command"); 1946 SBP2_ERR("Cannot handle DMA_BIDIRECTIONAL - rejecting command");
2156 result = DID_ERROR << 16; 1947 result = DID_ERROR << 16;
2157 goto done; 1948 goto done;
2158 } 1949 }
2159 1950
2160 /*
2161 * Try and send our SCSI command
2162 */
2163 if (sbp2_send_command(scsi_id, SCpnt, done)) { 1951 if (sbp2_send_command(scsi_id, SCpnt, done)) {
2164 SBP2_ERR("Error sending SCSI command"); 1952 SBP2_ERR("Error sending SCSI command");
2165 sbp2scsi_complete_command(scsi_id, SBP2_SCSI_STATUS_SELECTION_TIMEOUT, 1953 sbp2scsi_complete_command(scsi_id, SBP2_SCSI_STATUS_SELECTION_TIMEOUT,
@@ -2173,10 +1961,6 @@ done:
2173 return 0; 1961 return 0;
2174} 1962}
2175 1963
2176/*
2177 * This function is called in order to complete all outstanding SBP-2
2178 * commands (in case of resets, etc.).
2179 */
2180static void sbp2scsi_complete_all_commands(struct scsi_id_instance_data *scsi_id, 1964static void sbp2scsi_complete_all_commands(struct scsi_id_instance_data *scsi_id,
2181 u32 status) 1965 u32 status)
2182{ 1966{
@@ -2207,25 +1991,17 @@ static void sbp2scsi_complete_all_commands(struct scsi_id_instance_data *scsi_id
2207} 1991}
2208 1992
2209/* 1993/*
2210 * This function is called in order to complete a regular SBP-2 command. 1994 * Complete a regular SCSI command. Can be called in atomic context.
2211 *
2212 * This can be called in interrupt context.
2213 */ 1995 */
2214static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id, 1996static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id,
2215 u32 scsi_status, struct scsi_cmnd *SCpnt, 1997 u32 scsi_status, struct scsi_cmnd *SCpnt,
2216 void (*done)(struct scsi_cmnd *)) 1998 void (*done)(struct scsi_cmnd *))
2217{ 1999{
2218 /*
2219 * Sanity
2220 */
2221 if (!SCpnt) { 2000 if (!SCpnt) {
2222 SBP2_ERR("SCpnt is NULL"); 2001 SBP2_ERR("SCpnt is NULL");
2223 return; 2002 return;
2224 } 2003 }
2225 2004
2226 /*
2227 * Switch on scsi status
2228 */
2229 switch (scsi_status) { 2005 switch (scsi_status) {
2230 case SBP2_SCSI_STATUS_GOOD: 2006 case SBP2_SCSI_STATUS_GOOD:
2231 SCpnt->result = DID_OK << 16; 2007 SCpnt->result = DID_OK << 16;
@@ -2259,19 +2035,15 @@ static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id,
2259 SCpnt->result = DID_ERROR << 16; 2035 SCpnt->result = DID_ERROR << 16;
2260 } 2036 }
2261 2037
2262 /* 2038 /* If a bus reset is in progress and there was an error, complete
2263 * If a bus reset is in progress and there was an error, complete 2039 * the command as busy so that it will get retried. */
2264 * the command as busy so that it will get retried.
2265 */
2266 if (!hpsb_node_entry_valid(scsi_id->ne) 2040 if (!hpsb_node_entry_valid(scsi_id->ne)
2267 && (scsi_status != SBP2_SCSI_STATUS_GOOD)) { 2041 && (scsi_status != SBP2_SCSI_STATUS_GOOD)) {
2268 SBP2_ERR("Completing command with busy (bus reset)"); 2042 SBP2_ERR("Completing command with busy (bus reset)");
2269 SCpnt->result = DID_BUS_BUSY << 16; 2043 SCpnt->result = DID_BUS_BUSY << 16;
2270 } 2044 }
2271 2045
2272 /* 2046 /* Tell the SCSI stack that we're done with this command. */
2273 * Tell scsi stack that we're done with this command
2274 */
2275 done(SCpnt); 2047 done(SCpnt);
2276} 2048}
2277 2049
@@ -2311,8 +2083,8 @@ static void sbp2scsi_slave_destroy(struct scsi_device *sdev)
2311} 2083}
2312 2084
2313/* 2085/*
2314 * Called by scsi stack when something has really gone wrong. Usually 2086 * Called by scsi stack when something has really gone wrong.
2315 * called when a command has timed-out for some reason. 2087 * Usually called when a command has timed-out for some reason.
2316 */ 2088 */
2317static int sbp2scsi_abort(struct scsi_cmnd *SCpnt) 2089static int sbp2scsi_abort(struct scsi_cmnd *SCpnt)
2318{ 2090{
@@ -2401,7 +2173,6 @@ static int sbp2_module_init(void)
2401{ 2173{
2402 int ret; 2174 int ret;
2403 2175
2404 /* Module load debug option to force one command at a time (serializing I/O) */
2405 if (serialize_io) { 2176 if (serialize_io) {
2406 scsi_driver_template.can_queue = 1; 2177 scsi_driver_template.can_queue = 1;
2407 scsi_driver_template.cmd_per_lun = 1; 2178 scsi_driver_template.cmd_per_lun = 1;
@@ -2412,16 +2183,13 @@ static int sbp2_module_init(void)
2412 max_sectors = 128 * 1024 / 512; 2183 max_sectors = 128 * 1024 / 512;
2413 scsi_driver_template.max_sectors = max_sectors; 2184 scsi_driver_template.max_sectors = max_sectors;
2414 2185
2415 /* Register our high level driver with 1394 stack */
2416 hpsb_register_highlevel(&sbp2_highlevel); 2186 hpsb_register_highlevel(&sbp2_highlevel);
2417
2418 ret = hpsb_register_protocol(&sbp2_driver); 2187 ret = hpsb_register_protocol(&sbp2_driver);
2419 if (ret) { 2188 if (ret) {
2420 SBP2_ERR("Failed to register protocol"); 2189 SBP2_ERR("Failed to register protocol");
2421 hpsb_unregister_highlevel(&sbp2_highlevel); 2190 hpsb_unregister_highlevel(&sbp2_highlevel);
2422 return ret; 2191 return ret;
2423 } 2192 }
2424
2425 return 0; 2193 return 0;
2426} 2194}
2427 2195
diff --git a/drivers/ieee1394/sbp2.h b/drivers/ieee1394/sbp2.h
index 5483b458bd77..d1dbc0d63177 100644
--- a/drivers/ieee1394/sbp2.h
+++ b/drivers/ieee1394/sbp2.h
@@ -25,7 +25,7 @@
25#define SBP2_DEVICE_NAME "sbp2" 25#define SBP2_DEVICE_NAME "sbp2"
26 26
27/* 27/*
28 * SBP2 specific structures and defines 28 * SBP-2 specific definitions
29 */ 29 */
30 30
31#define ORB_DIRECTION_WRITE_TO_MEDIA 0x0 31#define ORB_DIRECTION_WRITE_TO_MEDIA 0x0
@@ -185,8 +185,9 @@ struct sbp2_status_block {
185 u8 command_set_dependent[24]; 185 u8 command_set_dependent[24];
186} __attribute__((packed)); 186} __attribute__((packed));
187 187
188
188/* 189/*
189 * Miscellaneous SBP2 related config rom defines 190 * SBP2 related configuration ROM definitions
190 */ 191 */
191 192
192#define SBP2_UNIT_DIRECTORY_OFFSET_KEY 0xd1 193#define SBP2_UNIT_DIRECTORY_OFFSET_KEY 0xd1
@@ -207,19 +208,17 @@ struct sbp2_status_block {
207#define SBP2_UNSOLICITED_STATUS_VALUE 0xf 208#define SBP2_UNSOLICITED_STATUS_VALUE 0xf
208 209
209#define SBP2_BUSY_TIMEOUT_ADDRESS 0xfffff0000210ULL 210#define SBP2_BUSY_TIMEOUT_ADDRESS 0xfffff0000210ULL
211/* biggest possible value for Single Phase Retry count is 0xf */
210#define SBP2_BUSY_TIMEOUT_VALUE 0xf 212#define SBP2_BUSY_TIMEOUT_VALUE 0xf
211 213
212#define SBP2_AGENT_RESET_DATA 0xf 214#define SBP2_AGENT_RESET_DATA 0xf
213 215
214/*
215 * Unit spec id and sw version entry for SBP-2 devices
216 */
217
218#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e 216#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e
219#define SBP2_SW_VERSION_ENTRY 0x00010483 217#define SBP2_SW_VERSION_ENTRY 0x00010483
220 218
219
221/* 220/*
222 * SCSI specific stuff 221 * SCSI specific definitions
223 */ 222 */
224 223
225#define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000 224#define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000
@@ -237,18 +236,19 @@ struct sbp2_status_block {
237#define SBP2_SCSI_STATUS_COMMAND_TERMINATED 0x22 236#define SBP2_SCSI_STATUS_COMMAND_TERMINATED 0x22
238#define SBP2_SCSI_STATUS_SELECTION_TIMEOUT 0xff 237#define SBP2_SCSI_STATUS_SELECTION_TIMEOUT 0xff
239 238
240/* This is the two dma types we use for cmd_dma below */ 239
240/*
241 * Representations of commands and devices
242 */
243
241enum cmd_dma_types { 244enum cmd_dma_types {
242 CMD_DMA_NONE, 245 CMD_DMA_NONE,
243 CMD_DMA_PAGE, 246 CMD_DMA_PAGE,
244 CMD_DMA_SINGLE 247 CMD_DMA_SINGLE
245}; 248};
246 249
247/* 250/* Per SCSI command */
248 * Encapsulates all the info necessary for an outstanding command.
249 */
250struct sbp2_command_info { 251struct sbp2_command_info {
251
252 struct list_head list; 252 struct list_head list;
253 struct sbp2_command_orb command_orb ____cacheline_aligned; 253 struct sbp2_command_orb command_orb ____cacheline_aligned;
254 dma_addr_t command_orb_dma ____cacheline_aligned; 254 dma_addr_t command_orb_dma ____cacheline_aligned;
@@ -263,18 +263,17 @@ struct sbp2_command_info {
263 enum cmd_dma_types dma_type; 263 enum cmd_dma_types dma_type;
264 unsigned long dma_size; 264 unsigned long dma_size;
265 int dma_dir; 265 int dma_dir;
266
267}; 266};
268 267
269struct sbp2scsi_host_info; 268/* Per FireWire host */
269struct sbp2scsi_host_info {
270 struct hpsb_host *host;
271 struct list_head scsi_ids;
272};
270 273
271/* 274/* Per logical unit */
272 * Information needed on a per scsi id basis (one for each sbp2 device)
273 */
274struct scsi_id_instance_data { 275struct scsi_id_instance_data {
275 /* 276 /* Operation request blocks */
276 * Various sbp2 specific structures
277 */
278 struct sbp2_command_orb *last_orb; 277 struct sbp2_command_orb *last_orb;
279 dma_addr_t last_orb_dma; 278 dma_addr_t last_orb_dma;
280 struct sbp2_login_orb *login_orb; 279 struct sbp2_login_orb *login_orb;
@@ -291,57 +290,49 @@ struct scsi_id_instance_data {
291 dma_addr_t logout_orb_dma; 290 dma_addr_t logout_orb_dma;
292 struct sbp2_status_block status_block; 291 struct sbp2_status_block status_block;
293 292
294 /* 293 /* How to talk to the unit */
295 * Stuff we need to know about the sbp2 device itself
296 */
297 u64 sbp2_management_agent_addr; 294 u64 sbp2_management_agent_addr;
298 u64 sbp2_command_block_agent_addr; 295 u64 sbp2_command_block_agent_addr;
299 u32 speed_code; 296 u32 speed_code;
300 u32 max_payload_size; 297 u32 max_payload_size;
301 298
302 /* 299 /* Pulled from the device's unit directory */
303 * Values pulled from the device's unit directory
304 */
305 u32 sbp2_command_set_spec_id; 300 u32 sbp2_command_set_spec_id;
306 u32 sbp2_command_set; 301 u32 sbp2_command_set;
307 u32 sbp2_unit_characteristics; 302 u32 sbp2_unit_characteristics;
308 u32 sbp2_lun; 303 u32 sbp2_lun;
309 u32 sbp2_firmware_revision; 304 u32 sbp2_firmware_revision;
310 305
311 /* 306 /* Address for the unit to write status blocks to */
312 * Address for the device to write status blocks to
313 */
314 u64 status_fifo_addr; 307 u64 status_fifo_addr;
315 308
316 /* 309 /* Waitqueue flag for logins, reconnects, logouts, query logins */
317 * Waitqueue flag for logins, reconnects, logouts, query logins
318 */
319 int access_complete:1; 310 int access_complete:1;
320 311
321 /* 312 /* Pool of command ORBs for this logical unit */
322 * Pool of command orbs, so we can have more than overlapped command per id
323 */
324 spinlock_t sbp2_command_orb_lock; 313 spinlock_t sbp2_command_orb_lock;
325 struct list_head sbp2_command_orb_inuse; 314 struct list_head sbp2_command_orb_inuse;
326 struct list_head sbp2_command_orb_completed; 315 struct list_head sbp2_command_orb_completed;
327 316
317 /* Backlink to FireWire host; list of units attached to the host */
318 struct sbp2scsi_host_info *hi;
328 struct list_head scsi_list; 319 struct list_head scsi_list;
329 320
330 /* Node entry, as retrieved from NodeMgr entries */ 321 /* IEEE 1394 core's device representations */
331 struct node_entry *ne; 322 struct node_entry *ne;
332 struct unit_directory *ud; 323 struct unit_directory *ud;
333 324
334 /* A backlink to our host_info */ 325 /* SCSI core's device representations */
335 struct sbp2scsi_host_info *hi;
336
337 /* SCSI related pointers */
338 struct scsi_device *sdev; 326 struct scsi_device *sdev;
339 struct Scsi_Host *scsi_host; 327 struct Scsi_Host *scsi_host;
340 328
341 /* Device specific workarounds/brokeness */ 329 /* Device specific workarounds/brokeness */
342 unsigned workarounds; 330 unsigned workarounds;
343 331
332 /* Connection state */
344 atomic_t state; 333 atomic_t state;
334
335 /* For deferred requests to the fetch agent */
345 struct work_struct protocol_work; 336 struct work_struct protocol_work;
346}; 337};
347 338
@@ -352,13 +343,8 @@ enum sbp2lu_state_types {
352 SBP2LU_STATE_IN_SHUTDOWN /* when sbp2_remove was called */ 343 SBP2LU_STATE_IN_SHUTDOWN /* when sbp2_remove was called */
353}; 344};
354 345
355/* Sbp2 host data structure (one per IEEE1394 host) */ 346/* For use in scsi_id_instance_data.workarounds and in the corresponding
356struct sbp2scsi_host_info { 347 * module load parameter */
357 struct hpsb_host *host; /* IEEE1394 host */
358 struct list_head scsi_ids; /* List of scsi ids on this host */
359};
360
361/* Flags for detected oddities and brokeness */
362#define SBP2_WORKAROUND_128K_MAX_TRANS 0x1 348#define SBP2_WORKAROUND_128K_MAX_TRANS 0x1
363#define SBP2_WORKAROUND_INQUIRY_36 0x2 349#define SBP2_WORKAROUND_INQUIRY_36 0x2
364#define SBP2_WORKAROUND_MODE_SENSE_8 0x4 350#define SBP2_WORKAROUND_MODE_SENSE_8 0x4