diff options
Diffstat (limited to 'drivers/ieee1394/sbp2.c')
-rw-r--r-- | drivers/ieee1394/sbp2.c | 1040 |
1 files changed, 400 insertions, 640 deletions
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index f7e18ccc5c0a..18d7eda38851 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c | |||
@@ -80,9 +80,6 @@ | |||
80 | #include "ieee1394_transactions.h" | 80 | #include "ieee1394_transactions.h" |
81 | #include "sbp2.h" | 81 | #include "sbp2.h" |
82 | 82 | ||
83 | static char version[] __devinitdata = | ||
84 | "$Rev: 1306 $ Ben Collins <bcollins@debian.org>"; | ||
85 | |||
86 | /* | 83 | /* |
87 | * Module load parameter definitions | 84 | * Module load parameter definitions |
88 | */ | 85 | */ |
@@ -151,18 +148,15 @@ static int force_inquiry_hack; | |||
151 | module_param(force_inquiry_hack, int, 0444); | 148 | module_param(force_inquiry_hack, int, 0444); |
152 | MODULE_PARM_DESC(force_inquiry_hack, "Force SCSI inquiry hack (default = 0)"); | 149 | MODULE_PARM_DESC(force_inquiry_hack, "Force SCSI inquiry hack (default = 0)"); |
153 | 150 | ||
154 | |||
155 | /* | 151 | /* |
156 | * Export information about protocols/devices supported by this driver. | 152 | * Export information about protocols/devices supported by this driver. |
157 | */ | 153 | */ |
158 | static struct ieee1394_device_id sbp2_id_table[] = { | 154 | static struct ieee1394_device_id sbp2_id_table[] = { |
159 | { | 155 | { |
160 | .match_flags =IEEE1394_MATCH_SPECIFIER_ID | | 156 | .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION, |
161 | IEEE1394_MATCH_VERSION, | 157 | .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff, |
162 | .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff, | 158 | .version = SBP2_SW_VERSION_ENTRY & 0xffffff}, |
163 | .version = SBP2_SW_VERSION_ENTRY & 0xffffff | 159 | {} |
164 | }, | ||
165 | { } | ||
166 | }; | 160 | }; |
167 | 161 | ||
168 | MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table); | 162 | MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table); |
@@ -221,7 +215,6 @@ static u32 global_outstanding_dmas = 0; | |||
221 | 215 | ||
222 | #define SBP2_ERR(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args) | 216 | #define SBP2_ERR(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args) |
223 | 217 | ||
224 | |||
225 | /* | 218 | /* |
226 | * Globals | 219 | * Globals |
227 | */ | 220 | */ |
@@ -254,8 +247,8 @@ static struct hpsb_address_ops sbp2_ops = { | |||
254 | 247 | ||
255 | #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA | 248 | #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA |
256 | static struct hpsb_address_ops sbp2_physdma_ops = { | 249 | static struct hpsb_address_ops sbp2_physdma_ops = { |
257 | .read = sbp2_handle_physdma_read, | 250 | .read = sbp2_handle_physdma_read, |
258 | .write = sbp2_handle_physdma_write, | 251 | .write = sbp2_handle_physdma_write, |
259 | }; | 252 | }; |
260 | #endif | 253 | #endif |
261 | 254 | ||
@@ -287,7 +280,6 @@ static u32 sbp2_broken_inquiry_list[] = { | |||
287 | * General utility functions | 280 | * General utility functions |
288 | **************************************/ | 281 | **************************************/ |
289 | 282 | ||
290 | |||
291 | #ifndef __BIG_ENDIAN | 283 | #ifndef __BIG_ENDIAN |
292 | /* | 284 | /* |
293 | * Converts a buffer from be32 to cpu byte ordering. Length is in bytes. | 285 | * Converts a buffer from be32 to cpu byte ordering. Length is in bytes. |
@@ -324,7 +316,8 @@ static __inline__ void sbp2util_cpu_to_be32_buffer(void *buffer, int length) | |||
324 | /* | 316 | /* |
325 | * Debug packet dump routine. Length is in bytes. | 317 | * Debug packet dump routine. Length is in bytes. |
326 | */ | 318 | */ |
327 | static void sbp2util_packet_dump(void *buffer, int length, char *dump_name, u32 dump_phys_addr) | 319 | static void sbp2util_packet_dump(void *buffer, int length, char *dump_name, |
320 | u32 dump_phys_addr) | ||
328 | { | 321 | { |
329 | int i; | 322 | int i; |
330 | unsigned char *dump = buffer; | 323 | unsigned char *dump = buffer; |
@@ -345,7 +338,7 @@ static void sbp2util_packet_dump(void *buffer, int length, char *dump_name, u32 | |||
345 | printk(" "); | 338 | printk(" "); |
346 | if ((i & 0xf) == 0) | 339 | if ((i & 0xf) == 0) |
347 | printk("\n "); | 340 | printk("\n "); |
348 | printk("%02x ", (int) dump[i]); | 341 | printk("%02x ", (int)dump[i]); |
349 | } | 342 | } |
350 | printk("\n"); | 343 | printk("\n"); |
351 | 344 | ||
@@ -364,9 +357,9 @@ static int sbp2util_down_timeout(atomic_t *done, int timeout) | |||
364 | 357 | ||
365 | for (i = timeout; (i > 0 && atomic_read(done) == 0); i-= HZ/10) { | 358 | for (i = timeout; (i > 0 && atomic_read(done) == 0); i-= HZ/10) { |
366 | if (msleep_interruptible(100)) /* 100ms */ | 359 | if (msleep_interruptible(100)) /* 100ms */ |
367 | return(1); | 360 | return 1; |
368 | } | 361 | } |
369 | return ((i > 0) ? 0:1); | 362 | return (i > 0) ? 0 : 1; |
370 | } | 363 | } |
371 | 364 | ||
372 | /* Free's an allocated packet */ | 365 | /* Free's an allocated packet */ |
@@ -380,21 +373,22 @@ static void sbp2_free_packet(struct hpsb_packet *packet) | |||
380 | * subaction and returns immediately. Can be used from interrupts. | 373 | * subaction and returns immediately. Can be used from interrupts. |
381 | */ | 374 | */ |
382 | static int sbp2util_node_write_no_wait(struct node_entry *ne, u64 addr, | 375 | static int sbp2util_node_write_no_wait(struct node_entry *ne, u64 addr, |
383 | quadlet_t *buffer, size_t length) | 376 | quadlet_t *buffer, size_t length) |
384 | { | 377 | { |
385 | struct hpsb_packet *packet; | 378 | struct hpsb_packet *packet; |
386 | 379 | ||
387 | packet = hpsb_make_writepacket(ne->host, ne->nodeid, | 380 | packet = hpsb_make_writepacket(ne->host, ne->nodeid, |
388 | addr, buffer, length); | 381 | addr, buffer, length); |
389 | if (!packet) | 382 | if (!packet) |
390 | return -ENOMEM; | 383 | return -ENOMEM; |
391 | 384 | ||
392 | hpsb_set_packet_complete_task(packet, (void (*)(void*))sbp2_free_packet, | 385 | hpsb_set_packet_complete_task(packet, |
386 | (void (*)(void *))sbp2_free_packet, | ||
393 | packet); | 387 | packet); |
394 | 388 | ||
395 | hpsb_node_fill_packet(ne, packet); | 389 | hpsb_node_fill_packet(ne, packet); |
396 | 390 | ||
397 | if (hpsb_send_packet(packet) < 0) { | 391 | if (hpsb_send_packet(packet) < 0) { |
398 | sbp2_free_packet(packet); | 392 | sbp2_free_packet(packet); |
399 | return -EIO; | 393 | return -EIO; |
400 | } | 394 | } |
@@ -417,22 +411,22 @@ static int sbp2util_create_command_orb_pool(struct scsi_id_instance_data *scsi_i | |||
417 | 411 | ||
418 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); | 412 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); |
419 | for (i = 0; i < orbs; i++) { | 413 | for (i = 0; i < orbs; i++) { |
420 | command = (struct sbp2_command_info *) | 414 | command = kzalloc(sizeof(*command), GFP_ATOMIC); |
421 | kmalloc(sizeof(struct sbp2_command_info), GFP_ATOMIC); | ||
422 | if (!command) { | 415 | if (!command) { |
423 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | 416 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, |
424 | return(-ENOMEM); | 417 | flags); |
418 | return -ENOMEM; | ||
425 | } | 419 | } |
426 | memset(command, '\0', sizeof(struct sbp2_command_info)); | ||
427 | command->command_orb_dma = | 420 | command->command_orb_dma = |
428 | pci_map_single (hi->host->pdev, &command->command_orb, | 421 | pci_map_single(hi->host->pdev, &command->command_orb, |
429 | sizeof(struct sbp2_command_orb), | 422 | sizeof(struct sbp2_command_orb), |
430 | PCI_DMA_BIDIRECTIONAL); | 423 | PCI_DMA_BIDIRECTIONAL); |
431 | SBP2_DMA_ALLOC("single command orb DMA"); | 424 | SBP2_DMA_ALLOC("single command orb DMA"); |
432 | command->sge_dma = | 425 | command->sge_dma = |
433 | pci_map_single (hi->host->pdev, &command->scatter_gather_element, | 426 | pci_map_single(hi->host->pdev, |
434 | sizeof(command->scatter_gather_element), | 427 | &command->scatter_gather_element, |
435 | PCI_DMA_BIDIRECTIONAL); | 428 | sizeof(command->scatter_gather_element), |
429 | PCI_DMA_BIDIRECTIONAL); | ||
436 | SBP2_DMA_ALLOC("scatter_gather_element"); | 430 | SBP2_DMA_ALLOC("scatter_gather_element"); |
437 | INIT_LIST_HEAD(&command->list); | 431 | INIT_LIST_HEAD(&command->list); |
438 | list_add_tail(&command->list, &scsi_id->sbp2_command_orb_completed); | 432 | list_add_tail(&command->list, &scsi_id->sbp2_command_orb_completed); |
@@ -488,7 +482,7 @@ static struct sbp2_command_info *sbp2util_find_command_for_orb( | |||
488 | list_for_each_entry(command, &scsi_id->sbp2_command_orb_inuse, list) { | 482 | list_for_each_entry(command, &scsi_id->sbp2_command_orb_inuse, list) { |
489 | if (command->command_orb_dma == orb) { | 483 | if (command->command_orb_dma == orb) { |
490 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | 484 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); |
491 | return (command); | 485 | return command; |
492 | } | 486 | } |
493 | } | 487 | } |
494 | } | 488 | } |
@@ -496,7 +490,7 @@ static struct sbp2_command_info *sbp2util_find_command_for_orb( | |||
496 | 490 | ||
497 | SBP2_ORB_DEBUG("could not match command orb %x", (unsigned int)orb); | 491 | SBP2_ORB_DEBUG("could not match command orb %x", (unsigned int)orb); |
498 | 492 | ||
499 | return(NULL); | 493 | return NULL; |
500 | } | 494 | } |
501 | 495 | ||
502 | /* | 496 | /* |
@@ -513,12 +507,12 @@ static struct sbp2_command_info *sbp2util_find_command_for_SCpnt(struct scsi_id_ | |||
513 | list_for_each_entry(command, &scsi_id->sbp2_command_orb_inuse, list) { | 507 | list_for_each_entry(command, &scsi_id->sbp2_command_orb_inuse, list) { |
514 | if (command->Current_SCpnt == SCpnt) { | 508 | if (command->Current_SCpnt == SCpnt) { |
515 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | 509 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); |
516 | return (command); | 510 | return command; |
517 | } | 511 | } |
518 | } | 512 | } |
519 | } | 513 | } |
520 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | 514 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); |
521 | return(NULL); | 515 | return NULL; |
522 | } | 516 | } |
523 | 517 | ||
524 | /* | 518 | /* |
@@ -545,7 +539,7 @@ static struct sbp2_command_info *sbp2util_allocate_command_orb( | |||
545 | SBP2_ERR("sbp2util_allocate_command_orb - No orbs available!"); | 539 | SBP2_ERR("sbp2util_allocate_command_orb - No orbs available!"); |
546 | } | 540 | } |
547 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); | 541 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); |
548 | return (command); | 542 | return command; |
549 | } | 543 | } |
550 | 544 | ||
551 | /* Free our DMA's */ | 545 | /* Free our DMA's */ |
@@ -587,7 +581,8 @@ static void sbp2util_free_command_dma(struct sbp2_command_info *command) | |||
587 | /* | 581 | /* |
588 | * This function moves a command to the completed orb list. | 582 | * This function moves a command to the completed orb list. |
589 | */ | 583 | */ |
590 | static void sbp2util_mark_command_completed(struct scsi_id_instance_data *scsi_id, struct sbp2_command_info *command) | 584 | static void sbp2util_mark_command_completed(struct scsi_id_instance_data *scsi_id, |
585 | struct sbp2_command_info *command) | ||
591 | { | 586 | { |
592 | unsigned long flags; | 587 | unsigned long flags; |
593 | 588 | ||
@@ -606,8 +601,6 @@ static inline int sbp2util_node_is_available(struct scsi_id_instance_data *scsi_ | |||
606 | return scsi_id && scsi_id->ne && !scsi_id->ne->in_limbo; | 601 | return scsi_id && scsi_id->ne && !scsi_id->ne->in_limbo; |
607 | } | 602 | } |
608 | 603 | ||
609 | |||
610 | |||
611 | /********************************************* | 604 | /********************************************* |
612 | * IEEE-1394 core driver stack related section | 605 | * IEEE-1394 core driver stack related section |
613 | *********************************************/ | 606 | *********************************************/ |
@@ -627,14 +620,14 @@ static int sbp2_probe(struct device *dev) | |||
627 | if (ud->flags & UNIT_DIRECTORY_HAS_LUN_DIRECTORY) | 620 | if (ud->flags & UNIT_DIRECTORY_HAS_LUN_DIRECTORY) |
628 | return -ENODEV; | 621 | return -ENODEV; |
629 | 622 | ||
630 | scsi_id = sbp2_alloc_device(ud); | 623 | scsi_id = sbp2_alloc_device(ud); |
631 | 624 | ||
632 | if (!scsi_id) | 625 | if (!scsi_id) |
633 | return -ENOMEM; | 626 | return -ENOMEM; |
634 | 627 | ||
635 | sbp2_parse_unit_directory(scsi_id, ud); | 628 | sbp2_parse_unit_directory(scsi_id, ud); |
636 | 629 | ||
637 | return sbp2_start_device(scsi_id); | 630 | return sbp2_start_device(scsi_id); |
638 | } | 631 | } |
639 | 632 | ||
640 | static int sbp2_remove(struct device *dev) | 633 | static int sbp2_remove(struct device *dev) |
@@ -719,12 +712,11 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud | |||
719 | 712 | ||
720 | SBP2_DEBUG("sbp2_alloc_device"); | 713 | SBP2_DEBUG("sbp2_alloc_device"); |
721 | 714 | ||
722 | scsi_id = kmalloc(sizeof(*scsi_id), GFP_KERNEL); | 715 | scsi_id = kzalloc(sizeof(*scsi_id), GFP_KERNEL); |
723 | if (!scsi_id) { | 716 | if (!scsi_id) { |
724 | SBP2_ERR("failed to create scsi_id"); | 717 | SBP2_ERR("failed to create scsi_id"); |
725 | goto failed_alloc; | 718 | goto failed_alloc; |
726 | } | 719 | } |
727 | memset(scsi_id, 0, sizeof(*scsi_id)); | ||
728 | 720 | ||
729 | scsi_id->ne = ud->ne; | 721 | scsi_id->ne = ud->ne; |
730 | scsi_id->ud = ud; | 722 | scsi_id->ud = ud; |
@@ -735,7 +727,7 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud | |||
735 | INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_completed); | 727 | INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_completed); |
736 | INIT_LIST_HEAD(&scsi_id->scsi_list); | 728 | INIT_LIST_HEAD(&scsi_id->scsi_list); |
737 | spin_lock_init(&scsi_id->sbp2_command_orb_lock); | 729 | spin_lock_init(&scsi_id->sbp2_command_orb_lock); |
738 | scsi_id->sbp2_device_type_and_lun = SBP2_DEVICE_TYPE_LUN_UNINITIALIZED; | 730 | scsi_id->sbp2_lun = 0; |
739 | 731 | ||
740 | ud->device.driver_data = scsi_id; | 732 | ud->device.driver_data = scsi_id; |
741 | 733 | ||
@@ -769,7 +761,7 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud | |||
769 | 761 | ||
770 | /* Register our host with the SCSI stack. */ | 762 | /* Register our host with the SCSI stack. */ |
771 | scsi_host = scsi_host_alloc(&scsi_driver_template, | 763 | scsi_host = scsi_host_alloc(&scsi_driver_template, |
772 | sizeof (unsigned long)); | 764 | sizeof(unsigned long)); |
773 | if (!scsi_host) { | 765 | if (!scsi_host) { |
774 | SBP2_ERR("failed to register scsi host"); | 766 | SBP2_ERR("failed to register scsi host"); |
775 | goto failed_alloc; | 767 | goto failed_alloc; |
@@ -790,7 +782,6 @@ failed_alloc: | |||
790 | return NULL; | 782 | return NULL; |
791 | } | 783 | } |
792 | 784 | ||
793 | |||
794 | static void sbp2_host_reset(struct hpsb_host *host) | 785 | static void sbp2_host_reset(struct hpsb_host *host) |
795 | { | 786 | { |
796 | struct sbp2scsi_host_info *hi; | 787 | struct sbp2scsi_host_info *hi; |
@@ -804,7 +795,6 @@ static void sbp2_host_reset(struct hpsb_host *host) | |||
804 | } | 795 | } |
805 | } | 796 | } |
806 | 797 | ||
807 | |||
808 | /* | 798 | /* |
809 | * This function is where we first pull the node unique ids, and then | 799 | * This function is where we first pull the node unique ids, and then |
810 | * allocate memory and register a SBP-2 device. | 800 | * allocate memory and register a SBP-2 device. |
@@ -818,7 +808,8 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id) | |||
818 | 808 | ||
819 | /* Login FIFO DMA */ | 809 | /* Login FIFO DMA */ |
820 | scsi_id->login_response = | 810 | scsi_id->login_response = |
821 | pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_login_response), | 811 | pci_alloc_consistent(hi->host->pdev, |
812 | sizeof(struct sbp2_login_response), | ||
822 | &scsi_id->login_response_dma); | 813 | &scsi_id->login_response_dma); |
823 | if (!scsi_id->login_response) | 814 | if (!scsi_id->login_response) |
824 | goto alloc_fail; | 815 | goto alloc_fail; |
@@ -826,7 +817,8 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id) | |||
826 | 817 | ||
827 | /* Query logins ORB DMA */ | 818 | /* Query logins ORB DMA */ |
828 | scsi_id->query_logins_orb = | 819 | scsi_id->query_logins_orb = |
829 | pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_query_logins_orb), | 820 | pci_alloc_consistent(hi->host->pdev, |
821 | sizeof(struct sbp2_query_logins_orb), | ||
830 | &scsi_id->query_logins_orb_dma); | 822 | &scsi_id->query_logins_orb_dma); |
831 | if (!scsi_id->query_logins_orb) | 823 | if (!scsi_id->query_logins_orb) |
832 | goto alloc_fail; | 824 | goto alloc_fail; |
@@ -834,7 +826,8 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id) | |||
834 | 826 | ||
835 | /* Query logins response DMA */ | 827 | /* Query logins response DMA */ |
836 | scsi_id->query_logins_response = | 828 | scsi_id->query_logins_response = |
837 | pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_query_logins_response), | 829 | pci_alloc_consistent(hi->host->pdev, |
830 | sizeof(struct sbp2_query_logins_response), | ||
838 | &scsi_id->query_logins_response_dma); | 831 | &scsi_id->query_logins_response_dma); |
839 | if (!scsi_id->query_logins_response) | 832 | if (!scsi_id->query_logins_response) |
840 | goto alloc_fail; | 833 | goto alloc_fail; |
@@ -842,7 +835,8 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id) | |||
842 | 835 | ||
843 | /* Reconnect ORB DMA */ | 836 | /* Reconnect ORB DMA */ |
844 | scsi_id->reconnect_orb = | 837 | scsi_id->reconnect_orb = |
845 | pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_reconnect_orb), | 838 | pci_alloc_consistent(hi->host->pdev, |
839 | sizeof(struct sbp2_reconnect_orb), | ||
846 | &scsi_id->reconnect_orb_dma); | 840 | &scsi_id->reconnect_orb_dma); |
847 | if (!scsi_id->reconnect_orb) | 841 | if (!scsi_id->reconnect_orb) |
848 | goto alloc_fail; | 842 | goto alloc_fail; |
@@ -850,7 +844,8 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id) | |||
850 | 844 | ||
851 | /* Logout ORB DMA */ | 845 | /* Logout ORB DMA */ |
852 | scsi_id->logout_orb = | 846 | scsi_id->logout_orb = |
853 | pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_logout_orb), | 847 | pci_alloc_consistent(hi->host->pdev, |
848 | sizeof(struct sbp2_logout_orb), | ||
854 | &scsi_id->logout_orb_dma); | 849 | &scsi_id->logout_orb_dma); |
855 | if (!scsi_id->logout_orb) | 850 | if (!scsi_id->logout_orb) |
856 | goto alloc_fail; | 851 | goto alloc_fail; |
@@ -858,58 +853,11 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id) | |||
858 | 853 | ||
859 | /* Login ORB DMA */ | 854 | /* Login ORB DMA */ |
860 | scsi_id->login_orb = | 855 | scsi_id->login_orb = |
861 | pci_alloc_consistent(hi->host->pdev, sizeof(struct sbp2_login_orb), | 856 | pci_alloc_consistent(hi->host->pdev, |
857 | sizeof(struct sbp2_login_orb), | ||
862 | &scsi_id->login_orb_dma); | 858 | &scsi_id->login_orb_dma); |
863 | if (!scsi_id->login_orb) { | 859 | if (!scsi_id->login_orb) |
864 | alloc_fail: | 860 | goto alloc_fail; |
865 | if (scsi_id->query_logins_response) { | ||
866 | pci_free_consistent(hi->host->pdev, | ||
867 | sizeof(struct sbp2_query_logins_response), | ||
868 | scsi_id->query_logins_response, | ||
869 | scsi_id->query_logins_response_dma); | ||
870 | SBP2_DMA_FREE("query logins response DMA"); | ||
871 | } | ||
872 | |||
873 | if (scsi_id->query_logins_orb) { | ||
874 | pci_free_consistent(hi->host->pdev, | ||
875 | sizeof(struct sbp2_query_logins_orb), | ||
876 | scsi_id->query_logins_orb, | ||
877 | scsi_id->query_logins_orb_dma); | ||
878 | SBP2_DMA_FREE("query logins ORB DMA"); | ||
879 | } | ||
880 | |||
881 | if (scsi_id->logout_orb) { | ||
882 | pci_free_consistent(hi->host->pdev, | ||
883 | sizeof(struct sbp2_logout_orb), | ||
884 | scsi_id->logout_orb, | ||
885 | scsi_id->logout_orb_dma); | ||
886 | SBP2_DMA_FREE("logout ORB DMA"); | ||
887 | } | ||
888 | |||
889 | if (scsi_id->reconnect_orb) { | ||
890 | pci_free_consistent(hi->host->pdev, | ||
891 | sizeof(struct sbp2_reconnect_orb), | ||
892 | scsi_id->reconnect_orb, | ||
893 | scsi_id->reconnect_orb_dma); | ||
894 | SBP2_DMA_FREE("reconnect ORB DMA"); | ||
895 | } | ||
896 | |||
897 | if (scsi_id->login_response) { | ||
898 | pci_free_consistent(hi->host->pdev, | ||
899 | sizeof(struct sbp2_login_response), | ||
900 | scsi_id->login_response, | ||
901 | scsi_id->login_response_dma); | ||
902 | SBP2_DMA_FREE("login FIFO DMA"); | ||
903 | } | ||
904 | |||
905 | list_del(&scsi_id->scsi_list); | ||
906 | |||
907 | kfree(scsi_id); | ||
908 | |||
909 | SBP2_ERR ("Could not allocate memory for scsi_id"); | ||
910 | |||
911 | return -ENOMEM; | ||
912 | } | ||
913 | SBP2_DMA_ALLOC("consistent DMA region for login ORB"); | 861 | SBP2_DMA_ALLOC("consistent DMA region for login ORB"); |
914 | 862 | ||
915 | SBP2_DEBUG("New SBP-2 device inserted, SCSI ID = %x", scsi_id->ud->id); | 863 | SBP2_DEBUG("New SBP-2 device inserted, SCSI ID = %x", scsi_id->ud->id); |
@@ -935,7 +883,7 @@ alloc_fail: | |||
935 | sbp2_remove_device(scsi_id); | 883 | sbp2_remove_device(scsi_id); |
936 | return -EINTR; | 884 | return -EINTR; |
937 | } | 885 | } |
938 | 886 | ||
939 | /* | 887 | /* |
940 | * Login to the sbp-2 device | 888 | * Login to the sbp-2 device |
941 | */ | 889 | */ |
@@ -964,10 +912,17 @@ alloc_fail: | |||
964 | error = scsi_add_device(scsi_id->scsi_host, 0, scsi_id->ud->id, 0); | 912 | error = scsi_add_device(scsi_id->scsi_host, 0, scsi_id->ud->id, 0); |
965 | if (error) { | 913 | if (error) { |
966 | SBP2_ERR("scsi_add_device failed"); | 914 | SBP2_ERR("scsi_add_device failed"); |
915 | sbp2_logout_device(scsi_id); | ||
916 | sbp2_remove_device(scsi_id); | ||
967 | return error; | 917 | return error; |
968 | } | 918 | } |
969 | 919 | ||
970 | return 0; | 920 | return 0; |
921 | |||
922 | alloc_fail: | ||
923 | SBP2_ERR("Could not allocate memory for scsi_id"); | ||
924 | sbp2_remove_device(scsi_id); | ||
925 | return -ENOMEM; | ||
971 | } | 926 | } |
972 | 927 | ||
973 | /* | 928 | /* |
@@ -1054,51 +1009,44 @@ static void sbp2_remove_device(struct scsi_id_instance_data *scsi_id) | |||
1054 | * This function deals with physical dma write requests (for adapters that do not support | 1009 | * This function deals with physical dma write requests (for adapters that do not support |
1055 | * physical dma in hardware). Mostly just here for debugging... | 1010 | * physical dma in hardware). Mostly just here for debugging... |
1056 | */ | 1011 | */ |
1057 | static int sbp2_handle_physdma_write(struct hpsb_host *host, int nodeid, int destid, quadlet_t *data, | 1012 | static int sbp2_handle_physdma_write(struct hpsb_host *host, int nodeid, |
1058 | u64 addr, size_t length, u16 flags) | 1013 | int destid, quadlet_t *data, u64 addr, |
1014 | size_t length, u16 flags) | ||
1059 | { | 1015 | { |
1060 | 1016 | ||
1061 | /* | 1017 | /* |
1062 | * Manually put the data in the right place. | 1018 | * Manually put the data in the right place. |
1063 | */ | 1019 | */ |
1064 | memcpy(bus_to_virt((u32)addr), data, length); | 1020 | memcpy(bus_to_virt((u32) addr), data, length); |
1065 | sbp2util_packet_dump(data, length, "sbp2 phys dma write by device", (u32)addr); | 1021 | sbp2util_packet_dump(data, length, "sbp2 phys dma write by device", |
1066 | return(RCODE_COMPLETE); | 1022 | (u32) addr); |
1023 | return RCODE_COMPLETE; | ||
1067 | } | 1024 | } |
1068 | 1025 | ||
1069 | /* | 1026 | /* |
1070 | * This function deals with physical dma read requests (for adapters that do not support | 1027 | * This function deals with physical dma read requests (for adapters that do not support |
1071 | * physical dma in hardware). Mostly just here for debugging... | 1028 | * physical dma in hardware). Mostly just here for debugging... |
1072 | */ | 1029 | */ |
1073 | static int sbp2_handle_physdma_read(struct hpsb_host *host, int nodeid, quadlet_t *data, | 1030 | static int sbp2_handle_physdma_read(struct hpsb_host *host, int nodeid, |
1074 | u64 addr, size_t length, u16 flags) | 1031 | quadlet_t *data, u64 addr, size_t length, |
1032 | u16 flags) | ||
1075 | { | 1033 | { |
1076 | 1034 | ||
1077 | /* | 1035 | /* |
1078 | * Grab data from memory and send a read response. | 1036 | * Grab data from memory and send a read response. |
1079 | */ | 1037 | */ |
1080 | memcpy(data, bus_to_virt((u32)addr), length); | 1038 | memcpy(data, bus_to_virt((u32) addr), length); |
1081 | sbp2util_packet_dump(data, length, "sbp2 phys dma read by device", (u32)addr); | 1039 | sbp2util_packet_dump(data, length, "sbp2 phys dma read by device", |
1082 | return(RCODE_COMPLETE); | 1040 | (u32) addr); |
1041 | return RCODE_COMPLETE; | ||
1083 | } | 1042 | } |
1084 | #endif | 1043 | #endif |
1085 | 1044 | ||
1086 | |||
1087 | /************************************** | 1045 | /************************************** |
1088 | * SBP-2 protocol related section | 1046 | * SBP-2 protocol related section |
1089 | **************************************/ | 1047 | **************************************/ |
1090 | 1048 | ||
1091 | /* | 1049 | /* |
1092 | * This function determines if we should convert scsi commands for a particular sbp2 device type | ||
1093 | */ | ||
1094 | static __inline__ int sbp2_command_conversion_device_type(u8 device_type) | ||
1095 | { | ||
1096 | return (((device_type == TYPE_DISK) || | ||
1097 | (device_type == TYPE_RBC) || | ||
1098 | (device_type == TYPE_ROM)) ? 1:0); | ||
1099 | } | ||
1100 | |||
1101 | /* | ||
1102 | * This function queries the device for the maximum concurrent logins it | 1050 | * This function queries the device for the maximum concurrent logins it |
1103 | * supports. | 1051 | * supports. |
1104 | */ | 1052 | */ |
@@ -1120,11 +1068,7 @@ static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id) | |||
1120 | 1068 | ||
1121 | scsi_id->query_logins_orb->lun_misc = ORB_SET_FUNCTION(SBP2_QUERY_LOGINS_REQUEST); | 1069 | scsi_id->query_logins_orb->lun_misc = ORB_SET_FUNCTION(SBP2_QUERY_LOGINS_REQUEST); |
1122 | scsi_id->query_logins_orb->lun_misc |= ORB_SET_NOTIFY(1); | 1070 | scsi_id->query_logins_orb->lun_misc |= ORB_SET_NOTIFY(1); |
1123 | if (scsi_id->sbp2_device_type_and_lun != SBP2_DEVICE_TYPE_LUN_UNINITIALIZED) { | 1071 | scsi_id->query_logins_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_lun); |
1124 | scsi_id->query_logins_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_device_type_and_lun); | ||
1125 | SBP2_DEBUG("sbp2_query_logins: set lun to %d", | ||
1126 | ORB_SET_LUN(scsi_id->sbp2_device_type_and_lun)); | ||
1127 | } | ||
1128 | SBP2_DEBUG("sbp2_query_logins: lun_misc initialized"); | 1072 | SBP2_DEBUG("sbp2_query_logins: lun_misc initialized"); |
1129 | 1073 | ||
1130 | scsi_id->query_logins_orb->reserved_resp_length = | 1074 | scsi_id->query_logins_orb->reserved_resp_length = |
@@ -1161,12 +1105,12 @@ static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id) | |||
1161 | 1105 | ||
1162 | if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, 2*HZ)) { | 1106 | if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, 2*HZ)) { |
1163 | SBP2_INFO("Error querying logins to SBP-2 device - timed out"); | 1107 | SBP2_INFO("Error querying logins to SBP-2 device - timed out"); |
1164 | return(-EIO); | 1108 | return -EIO; |
1165 | } | 1109 | } |
1166 | 1110 | ||
1167 | if (scsi_id->status_block.ORB_offset_lo != scsi_id->query_logins_orb_dma) { | 1111 | if (scsi_id->status_block.ORB_offset_lo != scsi_id->query_logins_orb_dma) { |
1168 | SBP2_INFO("Error querying logins to SBP-2 device - timed out"); | 1112 | SBP2_INFO("Error querying logins to SBP-2 device - timed out"); |
1169 | return(-EIO); | 1113 | return -EIO; |
1170 | } | 1114 | } |
1171 | 1115 | ||
1172 | if (STATUS_GET_RESP(scsi_id->status_block.ORB_offset_hi_misc) || | 1116 | if (STATUS_GET_RESP(scsi_id->status_block.ORB_offset_hi_misc) || |
@@ -1174,7 +1118,7 @@ static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id) | |||
1174 | STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) { | 1118 | STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) { |
1175 | 1119 | ||
1176 | SBP2_INFO("Error querying logins to SBP-2 device - timed out"); | 1120 | SBP2_INFO("Error querying logins to SBP-2 device - timed out"); |
1177 | return(-EIO); | 1121 | return -EIO; |
1178 | } | 1122 | } |
1179 | 1123 | ||
1180 | sbp2util_cpu_to_be32_buffer(scsi_id->query_logins_response, sizeof(struct sbp2_query_logins_response)); | 1124 | sbp2util_cpu_to_be32_buffer(scsi_id->query_logins_response, sizeof(struct sbp2_query_logins_response)); |
@@ -1191,7 +1135,7 @@ static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id) | |||
1191 | SBP2_DEBUG("Number of active logins: %d", active_logins); | 1135 | SBP2_DEBUG("Number of active logins: %d", active_logins); |
1192 | 1136 | ||
1193 | if (active_logins >= max_logins) { | 1137 | if (active_logins >= max_logins) { |
1194 | return(-EIO); | 1138 | return -EIO; |
1195 | } | 1139 | } |
1196 | 1140 | ||
1197 | return 0; | 1141 | return 0; |
@@ -1210,13 +1154,13 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id) | |||
1210 | 1154 | ||
1211 | if (!scsi_id->login_orb) { | 1155 | if (!scsi_id->login_orb) { |
1212 | SBP2_DEBUG("sbp2_login_device: login_orb not alloc'd!"); | 1156 | SBP2_DEBUG("sbp2_login_device: login_orb not alloc'd!"); |
1213 | return(-EIO); | 1157 | return -EIO; |
1214 | } | 1158 | } |
1215 | 1159 | ||
1216 | if (!exclusive_login) { | 1160 | if (!exclusive_login) { |
1217 | if (sbp2_query_logins(scsi_id)) { | 1161 | if (sbp2_query_logins(scsi_id)) { |
1218 | SBP2_INFO("Device does not support any more concurrent logins"); | 1162 | SBP2_INFO("Device does not support any more concurrent logins"); |
1219 | return(-EIO); | 1163 | return -EIO; |
1220 | } | 1164 | } |
1221 | } | 1165 | } |
1222 | 1166 | ||
@@ -1233,12 +1177,7 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id) | |||
1233 | scsi_id->login_orb->lun_misc |= ORB_SET_RECONNECT(0); /* One second reconnect time */ | 1177 | scsi_id->login_orb->lun_misc |= ORB_SET_RECONNECT(0); /* One second reconnect time */ |
1234 | scsi_id->login_orb->lun_misc |= ORB_SET_EXCLUSIVE(exclusive_login); /* Exclusive access to device */ | 1178 | scsi_id->login_orb->lun_misc |= ORB_SET_EXCLUSIVE(exclusive_login); /* Exclusive access to device */ |
1235 | scsi_id->login_orb->lun_misc |= ORB_SET_NOTIFY(1); /* Notify us of login complete */ | 1179 | scsi_id->login_orb->lun_misc |= ORB_SET_NOTIFY(1); /* Notify us of login complete */ |
1236 | /* Set the lun if we were able to pull it from the device's unit directory */ | 1180 | scsi_id->login_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_lun); |
1237 | if (scsi_id->sbp2_device_type_and_lun != SBP2_DEVICE_TYPE_LUN_UNINITIALIZED) { | ||
1238 | scsi_id->login_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_device_type_and_lun); | ||
1239 | SBP2_DEBUG("sbp2_query_logins: set lun to %d", | ||
1240 | ORB_SET_LUN(scsi_id->sbp2_device_type_and_lun)); | ||
1241 | } | ||
1242 | SBP2_DEBUG("sbp2_login_device: lun_misc initialized"); | 1181 | SBP2_DEBUG("sbp2_login_device: lun_misc initialized"); |
1243 | 1182 | ||
1244 | scsi_id->login_orb->passwd_resp_lengths = | 1183 | scsi_id->login_orb->passwd_resp_lengths = |
@@ -1288,7 +1227,7 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id) | |||
1288 | */ | 1227 | */ |
1289 | if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, 20*HZ)) { | 1228 | if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, 20*HZ)) { |
1290 | SBP2_ERR("Error logging into SBP-2 device - login timed-out"); | 1229 | SBP2_ERR("Error logging into SBP-2 device - login timed-out"); |
1291 | return(-EIO); | 1230 | return -EIO; |
1292 | } | 1231 | } |
1293 | 1232 | ||
1294 | /* | 1233 | /* |
@@ -1296,7 +1235,7 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id) | |||
1296 | */ | 1235 | */ |
1297 | if (scsi_id->status_block.ORB_offset_lo != scsi_id->login_orb_dma) { | 1236 | if (scsi_id->status_block.ORB_offset_lo != scsi_id->login_orb_dma) { |
1298 | SBP2_ERR("Error logging into SBP-2 device - login timed-out"); | 1237 | SBP2_ERR("Error logging into SBP-2 device - login timed-out"); |
1299 | return(-EIO); | 1238 | return -EIO; |
1300 | } | 1239 | } |
1301 | 1240 | ||
1302 | /* | 1241 | /* |
@@ -1307,7 +1246,7 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id) | |||
1307 | STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) { | 1246 | STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) { |
1308 | 1247 | ||
1309 | SBP2_ERR("Error logging into SBP-2 device - login failed"); | 1248 | SBP2_ERR("Error logging into SBP-2 device - login failed"); |
1310 | return(-EIO); | 1249 | return -EIO; |
1311 | } | 1250 | } |
1312 | 1251 | ||
1313 | /* | 1252 | /* |
@@ -1331,7 +1270,7 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id) | |||
1331 | 1270 | ||
1332 | SBP2_INFO("Logged into SBP-2 device"); | 1271 | SBP2_INFO("Logged into SBP-2 device"); |
1333 | 1272 | ||
1334 | return(0); | 1273 | return 0; |
1335 | 1274 | ||
1336 | } | 1275 | } |
1337 | 1276 | ||
@@ -1385,8 +1324,7 @@ static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id) | |||
1385 | atomic_set(&scsi_id->sbp2_login_complete, 0); | 1324 | atomic_set(&scsi_id->sbp2_login_complete, 0); |
1386 | 1325 | ||
1387 | error = hpsb_node_write(scsi_id->ne, | 1326 | error = hpsb_node_write(scsi_id->ne, |
1388 | scsi_id->sbp2_management_agent_addr, | 1327 | scsi_id->sbp2_management_agent_addr, data, 8); |
1389 | data, 8); | ||
1390 | if (error) | 1328 | if (error) |
1391 | return error; | 1329 | return error; |
1392 | 1330 | ||
@@ -1396,7 +1334,7 @@ static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id) | |||
1396 | 1334 | ||
1397 | SBP2_INFO("Logged out of SBP-2 device"); | 1335 | SBP2_INFO("Logged out of SBP-2 device"); |
1398 | 1336 | ||
1399 | return(0); | 1337 | return 0; |
1400 | 1338 | ||
1401 | } | 1339 | } |
1402 | 1340 | ||
@@ -1456,8 +1394,7 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id) | |||
1456 | atomic_set(&scsi_id->sbp2_login_complete, 0); | 1394 | atomic_set(&scsi_id->sbp2_login_complete, 0); |
1457 | 1395 | ||
1458 | error = hpsb_node_write(scsi_id->ne, | 1396 | error = hpsb_node_write(scsi_id->ne, |
1459 | scsi_id->sbp2_management_agent_addr, | 1397 | scsi_id->sbp2_management_agent_addr, data, 8); |
1460 | data, 8); | ||
1461 | if (error) | 1398 | if (error) |
1462 | return error; | 1399 | return error; |
1463 | 1400 | ||
@@ -1466,7 +1403,7 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id) | |||
1466 | */ | 1403 | */ |
1467 | if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, HZ)) { | 1404 | if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, HZ)) { |
1468 | SBP2_ERR("Error reconnecting to SBP-2 device - reconnect timed-out"); | 1405 | SBP2_ERR("Error reconnecting to SBP-2 device - reconnect timed-out"); |
1469 | return(-EIO); | 1406 | return -EIO; |
1470 | } | 1407 | } |
1471 | 1408 | ||
1472 | /* | 1409 | /* |
@@ -1474,7 +1411,7 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id) | |||
1474 | */ | 1411 | */ |
1475 | if (scsi_id->status_block.ORB_offset_lo != scsi_id->reconnect_orb_dma) { | 1412 | if (scsi_id->status_block.ORB_offset_lo != scsi_id->reconnect_orb_dma) { |
1476 | SBP2_ERR("Error reconnecting to SBP-2 device - reconnect timed-out"); | 1413 | SBP2_ERR("Error reconnecting to SBP-2 device - reconnect timed-out"); |
1477 | return(-EIO); | 1414 | return -EIO; |
1478 | } | 1415 | } |
1479 | 1416 | ||
1480 | /* | 1417 | /* |
@@ -1485,12 +1422,12 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id) | |||
1485 | STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) { | 1422 | STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) { |
1486 | 1423 | ||
1487 | SBP2_ERR("Error reconnecting to SBP-2 device - reconnect failed"); | 1424 | SBP2_ERR("Error reconnecting to SBP-2 device - reconnect failed"); |
1488 | return(-EIO); | 1425 | return -EIO; |
1489 | } | 1426 | } |
1490 | 1427 | ||
1491 | HPSB_DEBUG("Reconnected to SBP-2 device"); | 1428 | HPSB_DEBUG("Reconnected to SBP-2 device"); |
1492 | 1429 | ||
1493 | return(0); | 1430 | return 0; |
1494 | 1431 | ||
1495 | } | 1432 | } |
1496 | 1433 | ||
@@ -1513,10 +1450,9 @@ static int sbp2_set_busy_timeout(struct scsi_id_instance_data *scsi_id) | |||
1513 | SBP2_ERR("sbp2_set_busy_timeout error"); | 1450 | SBP2_ERR("sbp2_set_busy_timeout error"); |
1514 | } | 1451 | } |
1515 | 1452 | ||
1516 | return(0); | 1453 | return 0; |
1517 | } | 1454 | } |
1518 | 1455 | ||
1519 | |||
1520 | /* | 1456 | /* |
1521 | * This function is called to parse sbp2 device's config rom unit | 1457 | * This function is called to parse sbp2 device's config rom unit |
1522 | * directory. Used to determine things like sbp2 management agent offset, | 1458 | * directory. Used to determine things like sbp2 management agent offset, |
@@ -1529,7 +1465,7 @@ static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id, | |||
1529 | struct csr1212_dentry *dentry; | 1465 | struct csr1212_dentry *dentry; |
1530 | u64 management_agent_addr; | 1466 | u64 management_agent_addr; |
1531 | u32 command_set_spec_id, command_set, unit_characteristics, | 1467 | u32 command_set_spec_id, command_set, unit_characteristics, |
1532 | firmware_revision, workarounds; | 1468 | firmware_revision, workarounds; |
1533 | int i; | 1469 | int i; |
1534 | 1470 | ||
1535 | SBP2_DEBUG("sbp2_parse_unit_directory"); | 1471 | SBP2_DEBUG("sbp2_parse_unit_directory"); |
@@ -1547,13 +1483,14 @@ static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id, | |||
1547 | if (kv->key.type == CSR1212_KV_TYPE_CSR_OFFSET) { | 1483 | if (kv->key.type == CSR1212_KV_TYPE_CSR_OFFSET) { |
1548 | /* Save off the management agent address */ | 1484 | /* Save off the management agent address */ |
1549 | management_agent_addr = | 1485 | management_agent_addr = |
1550 | CSR1212_REGISTER_SPACE_BASE + | 1486 | CSR1212_REGISTER_SPACE_BASE + |
1551 | (kv->value.csr_offset << 2); | 1487 | (kv->value.csr_offset << 2); |
1552 | 1488 | ||
1553 | SBP2_DEBUG("sbp2_management_agent_addr = %x", | 1489 | SBP2_DEBUG("sbp2_management_agent_addr = %x", |
1554 | (unsigned int) management_agent_addr); | 1490 | (unsigned int)management_agent_addr); |
1555 | } else if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE) { | 1491 | } else if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE) { |
1556 | scsi_id->sbp2_device_type_and_lun = kv->value.immediate; | 1492 | scsi_id->sbp2_lun = |
1493 | ORB_SET_LUN(kv->value.immediate); | ||
1557 | } | 1494 | } |
1558 | break; | 1495 | break; |
1559 | 1496 | ||
@@ -1561,14 +1498,14 @@ static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id, | |||
1561 | /* Command spec organization */ | 1498 | /* Command spec organization */ |
1562 | command_set_spec_id = kv->value.immediate; | 1499 | command_set_spec_id = kv->value.immediate; |
1563 | SBP2_DEBUG("sbp2_command_set_spec_id = %x", | 1500 | SBP2_DEBUG("sbp2_command_set_spec_id = %x", |
1564 | (unsigned int) command_set_spec_id); | 1501 | (unsigned int)command_set_spec_id); |
1565 | break; | 1502 | break; |
1566 | 1503 | ||
1567 | case SBP2_COMMAND_SET_KEY: | 1504 | case SBP2_COMMAND_SET_KEY: |
1568 | /* Command set used by sbp2 device */ | 1505 | /* Command set used by sbp2 device */ |
1569 | command_set = kv->value.immediate; | 1506 | command_set = kv->value.immediate; |
1570 | SBP2_DEBUG("sbp2_command_set = %x", | 1507 | SBP2_DEBUG("sbp2_command_set = %x", |
1571 | (unsigned int) command_set); | 1508 | (unsigned int)command_set); |
1572 | break; | 1509 | break; |
1573 | 1510 | ||
1574 | case SBP2_UNIT_CHARACTERISTICS_KEY: | 1511 | case SBP2_UNIT_CHARACTERISTICS_KEY: |
@@ -1578,7 +1515,7 @@ static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id, | |||
1578 | */ | 1515 | */ |
1579 | unit_characteristics = kv->value.immediate; | 1516 | unit_characteristics = kv->value.immediate; |
1580 | SBP2_DEBUG("sbp2_unit_characteristics = %x", | 1517 | SBP2_DEBUG("sbp2_unit_characteristics = %x", |
1581 | (unsigned int) unit_characteristics); | 1518 | (unsigned int)unit_characteristics); |
1582 | break; | 1519 | break; |
1583 | 1520 | ||
1584 | case SBP2_FIRMWARE_REVISION_KEY: | 1521 | case SBP2_FIRMWARE_REVISION_KEY: |
@@ -1586,9 +1523,10 @@ static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id, | |||
1586 | firmware_revision = kv->value.immediate; | 1523 | firmware_revision = kv->value.immediate; |
1587 | if (force_inquiry_hack) | 1524 | if (force_inquiry_hack) |
1588 | SBP2_INFO("sbp2_firmware_revision = %x", | 1525 | SBP2_INFO("sbp2_firmware_revision = %x", |
1589 | (unsigned int) firmware_revision); | 1526 | (unsigned int)firmware_revision); |
1590 | else SBP2_DEBUG("sbp2_firmware_revision = %x", | 1527 | else |
1591 | (unsigned int) firmware_revision); | 1528 | SBP2_DEBUG("sbp2_firmware_revision = %x", |
1529 | (unsigned int)firmware_revision); | ||
1592 | break; | 1530 | break; |
1593 | 1531 | ||
1594 | default: | 1532 | default: |
@@ -1646,7 +1584,7 @@ static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id, | |||
1646 | scsi_id->sbp2_firmware_revision = firmware_revision; | 1584 | scsi_id->sbp2_firmware_revision = firmware_revision; |
1647 | scsi_id->workarounds = workarounds; | 1585 | scsi_id->workarounds = workarounds; |
1648 | if (ud->flags & UNIT_DIRECTORY_HAS_LUN) | 1586 | if (ud->flags & UNIT_DIRECTORY_HAS_LUN) |
1649 | scsi_id->sbp2_device_type_and_lun = ud->lun; | 1587 | scsi_id->sbp2_lun = ORB_SET_LUN(ud->lun); |
1650 | } | 1588 | } |
1651 | } | 1589 | } |
1652 | 1590 | ||
@@ -1666,8 +1604,9 @@ static int sbp2_max_speed_and_size(struct scsi_id_instance_data *scsi_id) | |||
1666 | SBP2_DEBUG("sbp2_max_speed_and_size"); | 1604 | SBP2_DEBUG("sbp2_max_speed_and_size"); |
1667 | 1605 | ||
1668 | /* Initial setting comes from the hosts speed map */ | 1606 | /* Initial setting comes from the hosts speed map */ |
1669 | scsi_id->speed_code = hi->host->speed_map[NODEID_TO_NODE(hi->host->node_id) * 64 | 1607 | scsi_id->speed_code = |
1670 | + NODEID_TO_NODE(scsi_id->ne->nodeid)]; | 1608 | hi->host->speed_map[NODEID_TO_NODE(hi->host->node_id) * 64 + |
1609 | NODEID_TO_NODE(scsi_id->ne->nodeid)]; | ||
1671 | 1610 | ||
1672 | /* Bump down our speed if the user requested it */ | 1611 | /* Bump down our speed if the user requested it */ |
1673 | if (scsi_id->speed_code > max_speed) { | 1612 | if (scsi_id->speed_code > max_speed) { |
@@ -1678,15 +1617,16 @@ static int sbp2_max_speed_and_size(struct scsi_id_instance_data *scsi_id) | |||
1678 | 1617 | ||
1679 | /* Payload size is the lesser of what our speed supports and what | 1618 | /* Payload size is the lesser of what our speed supports and what |
1680 | * our host supports. */ | 1619 | * our host supports. */ |
1681 | scsi_id->max_payload_size = min(sbp2_speedto_max_payload[scsi_id->speed_code], | 1620 | scsi_id->max_payload_size = |
1682 | (u8)(hi->host->csr.max_rec - 1)); | 1621 | min(sbp2_speedto_max_payload[scsi_id->speed_code], |
1622 | (u8) (hi->host->csr.max_rec - 1)); | ||
1683 | 1623 | ||
1684 | HPSB_DEBUG("Node " NODE_BUS_FMT ": Max speed [%s] - Max payload [%u]", | 1624 | HPSB_DEBUG("Node " NODE_BUS_FMT ": Max speed [%s] - Max payload [%u]", |
1685 | NODE_BUS_ARGS(hi->host, scsi_id->ne->nodeid), | 1625 | NODE_BUS_ARGS(hi->host, scsi_id->ne->nodeid), |
1686 | hpsb_speedto_str[scsi_id->speed_code], | 1626 | hpsb_speedto_str[scsi_id->speed_code], |
1687 | 1 << ((u32)scsi_id->max_payload_size + 2)); | 1627 | 1 << ((u32) scsi_id->max_payload_size + 2)); |
1688 | 1628 | ||
1689 | return(0); | 1629 | return 0; |
1690 | } | 1630 | } |
1691 | 1631 | ||
1692 | /* | 1632 | /* |
@@ -1721,30 +1661,187 @@ static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait) | |||
1721 | */ | 1661 | */ |
1722 | scsi_id->last_orb = NULL; | 1662 | scsi_id->last_orb = NULL; |
1723 | 1663 | ||
1724 | return(0); | 1664 | return 0; |
1665 | } | ||
1666 | |||
1667 | static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb, | ||
1668 | struct sbp2scsi_host_info *hi, | ||
1669 | struct sbp2_command_info *command, | ||
1670 | unsigned int scsi_use_sg, | ||
1671 | struct scatterlist *sgpnt, | ||
1672 | u32 orb_direction, | ||
1673 | enum dma_data_direction dma_dir) | ||
1674 | { | ||
1675 | command->dma_dir = dma_dir; | ||
1676 | orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); | ||
1677 | orb->misc |= ORB_SET_DIRECTION(orb_direction); | ||
1678 | |||
1679 | /* Special case if only one element (and less than 64KB in size) */ | ||
1680 | if ((scsi_use_sg == 1) && | ||
1681 | (sgpnt[0].length <= SBP2_MAX_SG_ELEMENT_LENGTH)) { | ||
1682 | |||
1683 | SBP2_DEBUG("Only one s/g element"); | ||
1684 | command->dma_size = sgpnt[0].length; | ||
1685 | command->dma_type = CMD_DMA_PAGE; | ||
1686 | command->cmd_dma = pci_map_page(hi->host->pdev, | ||
1687 | sgpnt[0].page, | ||
1688 | sgpnt[0].offset, | ||
1689 | command->dma_size, | ||
1690 | command->dma_dir); | ||
1691 | SBP2_DMA_ALLOC("single page scatter element"); | ||
1692 | |||
1693 | orb->data_descriptor_lo = command->cmd_dma; | ||
1694 | orb->misc |= ORB_SET_DATA_SIZE(command->dma_size); | ||
1695 | |||
1696 | } else { | ||
1697 | struct sbp2_unrestricted_page_table *sg_element = | ||
1698 | &command->scatter_gather_element[0]; | ||
1699 | u32 sg_count, sg_len; | ||
1700 | dma_addr_t sg_addr; | ||
1701 | int i, count = pci_map_sg(hi->host->pdev, sgpnt, scsi_use_sg, | ||
1702 | dma_dir); | ||
1703 | |||
1704 | SBP2_DMA_ALLOC("scatter list"); | ||
1705 | |||
1706 | command->dma_size = scsi_use_sg; | ||
1707 | command->sge_buffer = sgpnt; | ||
1708 | |||
1709 | /* use page tables (s/g) */ | ||
1710 | orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); | ||
1711 | orb->data_descriptor_lo = command->sge_dma; | ||
1712 | |||
1713 | /* | ||
1714 | * Loop through and fill out our sbp-2 page tables | ||
1715 | * (and split up anything too large) | ||
1716 | */ | ||
1717 | for (i = 0, sg_count = 0 ; i < count; i++, sgpnt++) { | ||
1718 | sg_len = sg_dma_len(sgpnt); | ||
1719 | sg_addr = sg_dma_address(sgpnt); | ||
1720 | while (sg_len) { | ||
1721 | sg_element[sg_count].segment_base_lo = sg_addr; | ||
1722 | if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) { | ||
1723 | sg_element[sg_count].length_segment_base_hi = | ||
1724 | PAGE_TABLE_SET_SEGMENT_LENGTH(SBP2_MAX_SG_ELEMENT_LENGTH); | ||
1725 | sg_addr += SBP2_MAX_SG_ELEMENT_LENGTH; | ||
1726 | sg_len -= SBP2_MAX_SG_ELEMENT_LENGTH; | ||
1727 | } else { | ||
1728 | sg_element[sg_count].length_segment_base_hi = | ||
1729 | PAGE_TABLE_SET_SEGMENT_LENGTH(sg_len); | ||
1730 | sg_len = 0; | ||
1731 | } | ||
1732 | sg_count++; | ||
1733 | } | ||
1734 | } | ||
1735 | |||
1736 | /* Number of page table (s/g) elements */ | ||
1737 | orb->misc |= ORB_SET_DATA_SIZE(sg_count); | ||
1738 | |||
1739 | sbp2util_packet_dump(sg_element, | ||
1740 | (sizeof(struct sbp2_unrestricted_page_table)) * sg_count, | ||
1741 | "sbp2 s/g list", command->sge_dma); | ||
1742 | |||
1743 | /* Byte swap page tables if necessary */ | ||
1744 | sbp2util_cpu_to_be32_buffer(sg_element, | ||
1745 | (sizeof(struct sbp2_unrestricted_page_table)) * | ||
1746 | sg_count); | ||
1747 | } | ||
1748 | } | ||
1749 | |||
1750 | static void sbp2_prep_command_orb_no_sg(struct sbp2_command_orb *orb, | ||
1751 | struct sbp2scsi_host_info *hi, | ||
1752 | struct sbp2_command_info *command, | ||
1753 | struct scatterlist *sgpnt, | ||
1754 | u32 orb_direction, | ||
1755 | unsigned int scsi_request_bufflen, | ||
1756 | void *scsi_request_buffer, | ||
1757 | enum dma_data_direction dma_dir) | ||
1758 | { | ||
1759 | command->dma_dir = dma_dir; | ||
1760 | command->dma_size = scsi_request_bufflen; | ||
1761 | command->dma_type = CMD_DMA_SINGLE; | ||
1762 | command->cmd_dma = pci_map_single(hi->host->pdev, scsi_request_buffer, | ||
1763 | command->dma_size, command->dma_dir); | ||
1764 | orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); | ||
1765 | orb->misc |= ORB_SET_DIRECTION(orb_direction); | ||
1766 | |||
1767 | SBP2_DMA_ALLOC("single bulk"); | ||
1768 | |||
1769 | /* | ||
1770 | * Handle case where we get a command w/o s/g enabled (but | ||
1771 | * check for transfers larger than 64K) | ||
1772 | */ | ||
1773 | if (scsi_request_bufflen <= SBP2_MAX_SG_ELEMENT_LENGTH) { | ||
1774 | |||
1775 | orb->data_descriptor_lo = command->cmd_dma; | ||
1776 | orb->misc |= ORB_SET_DATA_SIZE(scsi_request_bufflen); | ||
1777 | |||
1778 | } else { | ||
1779 | struct sbp2_unrestricted_page_table *sg_element = | ||
1780 | &command->scatter_gather_element[0]; | ||
1781 | u32 sg_count, sg_len; | ||
1782 | dma_addr_t sg_addr; | ||
1783 | |||
1784 | /* | ||
1785 | * Need to turn this into page tables, since the | ||
1786 | * buffer is too large. | ||
1787 | */ | ||
1788 | orb->data_descriptor_lo = command->sge_dma; | ||
1789 | |||
1790 | /* Use page tables (s/g) */ | ||
1791 | orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); | ||
1792 | |||
1793 | /* | ||
1794 | * fill out our sbp-2 page tables (and split up | ||
1795 | * the large buffer) | ||
1796 | */ | ||
1797 | sg_count = 0; | ||
1798 | sg_len = scsi_request_bufflen; | ||
1799 | sg_addr = command->cmd_dma; | ||
1800 | while (sg_len) { | ||
1801 | sg_element[sg_count].segment_base_lo = sg_addr; | ||
1802 | if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) { | ||
1803 | sg_element[sg_count].length_segment_base_hi = | ||
1804 | PAGE_TABLE_SET_SEGMENT_LENGTH(SBP2_MAX_SG_ELEMENT_LENGTH); | ||
1805 | sg_addr += SBP2_MAX_SG_ELEMENT_LENGTH; | ||
1806 | sg_len -= SBP2_MAX_SG_ELEMENT_LENGTH; | ||
1807 | } else { | ||
1808 | sg_element[sg_count].length_segment_base_hi = | ||
1809 | PAGE_TABLE_SET_SEGMENT_LENGTH(sg_len); | ||
1810 | sg_len = 0; | ||
1811 | } | ||
1812 | sg_count++; | ||
1813 | } | ||
1814 | |||
1815 | /* Number of page table (s/g) elements */ | ||
1816 | orb->misc |= ORB_SET_DATA_SIZE(sg_count); | ||
1817 | |||
1818 | sbp2util_packet_dump(sg_element, | ||
1819 | (sizeof(struct sbp2_unrestricted_page_table)) * sg_count, | ||
1820 | "sbp2 s/g list", command->sge_dma); | ||
1821 | |||
1822 | /* Byte swap page tables if necessary */ | ||
1823 | sbp2util_cpu_to_be32_buffer(sg_element, | ||
1824 | (sizeof(struct sbp2_unrestricted_page_table)) * | ||
1825 | sg_count); | ||
1826 | } | ||
1725 | } | 1827 | } |
1726 | 1828 | ||
1727 | /* | 1829 | /* |
1728 | * This function is called to create the actual command orb and s/g list | 1830 | * This function is called to create the actual command orb and s/g list |
1729 | * out of the scsi command itself. | 1831 | * out of the scsi command itself. |
1730 | */ | 1832 | */ |
1731 | static int sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id, | 1833 | static void sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id, |
1732 | struct sbp2_command_info *command, | 1834 | struct sbp2_command_info *command, |
1733 | unchar *scsi_cmd, | 1835 | unchar *scsi_cmd, |
1734 | unsigned int scsi_use_sg, | 1836 | unsigned int scsi_use_sg, |
1735 | unsigned int scsi_request_bufflen, | 1837 | unsigned int scsi_request_bufflen, |
1736 | void *scsi_request_buffer, | 1838 | void *scsi_request_buffer, |
1737 | enum dma_data_direction dma_dir) | 1839 | enum dma_data_direction dma_dir) |
1738 | |||
1739 | { | 1840 | { |
1740 | struct sbp2scsi_host_info *hi = scsi_id->hi; | 1841 | struct sbp2scsi_host_info *hi = scsi_id->hi; |
1741 | struct scatterlist *sgpnt = (struct scatterlist *) scsi_request_buffer; | 1842 | struct scatterlist *sgpnt = (struct scatterlist *)scsi_request_buffer; |
1742 | struct sbp2_command_orb *command_orb = &command->command_orb; | 1843 | struct sbp2_command_orb *command_orb = &command->command_orb; |
1743 | struct sbp2_unrestricted_page_table *scatter_gather_element = | 1844 | u32 orb_direction; |
1744 | &command->scatter_gather_element[0]; | ||
1745 | u32 sg_count, sg_len, orb_direction; | ||
1746 | dma_addr_t sg_addr; | ||
1747 | int i; | ||
1748 | 1845 | ||
1749 | /* | 1846 | /* |
1750 | * Set-up our command ORB.. | 1847 | * Set-up our command ORB.. |
@@ -1758,222 +1855,42 @@ static int sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id, | |||
1758 | command_orb->next_ORB_lo = 0x0; | 1855 | command_orb->next_ORB_lo = 0x0; |
1759 | command_orb->misc = ORB_SET_MAX_PAYLOAD(scsi_id->max_payload_size); | 1856 | command_orb->misc = ORB_SET_MAX_PAYLOAD(scsi_id->max_payload_size); |
1760 | command_orb->misc |= ORB_SET_SPEED(scsi_id->speed_code); | 1857 | command_orb->misc |= ORB_SET_SPEED(scsi_id->speed_code); |
1761 | command_orb->misc |= ORB_SET_NOTIFY(1); /* Notify us when complete */ | 1858 | command_orb->misc |= ORB_SET_NOTIFY(1); /* Notify us when complete */ |
1762 | 1859 | ||
1763 | /* | 1860 | if (dma_dir == DMA_NONE) |
1764 | * Get the direction of the transfer. If the direction is unknown, then use our | 1861 | orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER; |
1765 | * goofy table as a back-up. | 1862 | else if (dma_dir == DMA_TO_DEVICE && scsi_request_bufflen) |
1766 | */ | 1863 | orb_direction = ORB_DIRECTION_WRITE_TO_MEDIA; |
1767 | switch (dma_dir) { | 1864 | else if (dma_dir == DMA_FROM_DEVICE && scsi_request_bufflen) |
1768 | case DMA_NONE: | 1865 | orb_direction = ORB_DIRECTION_READ_FROM_MEDIA; |
1769 | orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER; | 1866 | else { |
1770 | break; | 1867 | SBP2_WARN("Falling back to DMA_NONE"); |
1771 | case DMA_TO_DEVICE: | 1868 | orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER; |
1772 | orb_direction = ORB_DIRECTION_WRITE_TO_MEDIA; | ||
1773 | break; | ||
1774 | case DMA_FROM_DEVICE: | ||
1775 | orb_direction = ORB_DIRECTION_READ_FROM_MEDIA; | ||
1776 | break; | ||
1777 | case DMA_BIDIRECTIONAL: | ||
1778 | default: | ||
1779 | SBP2_ERR("SCSI data transfer direction not specified. " | ||
1780 | "Update the SBP2 direction table in sbp2.h if " | ||
1781 | "necessary for your application"); | ||
1782 | __scsi_print_command(scsi_cmd); | ||
1783 | orb_direction = sbp2scsi_direction_table[*scsi_cmd]; | ||
1784 | break; | ||
1785 | } | 1869 | } |
1786 | 1870 | ||
1787 | /* | 1871 | /* Set-up our pagetable stuff */ |
1788 | * Set-up our pagetable stuff... unfortunately, this has become | ||
1789 | * messier than I'd like. Need to clean this up a bit. ;-) | ||
1790 | */ | ||
1791 | if (orb_direction == ORB_DIRECTION_NO_DATA_TRANSFER) { | 1872 | if (orb_direction == ORB_DIRECTION_NO_DATA_TRANSFER) { |
1792 | |||
1793 | SBP2_DEBUG("No data transfer"); | 1873 | SBP2_DEBUG("No data transfer"); |
1794 | |||
1795 | /* | ||
1796 | * Handle no data transfer | ||
1797 | */ | ||
1798 | command_orb->data_descriptor_hi = 0x0; | 1874 | command_orb->data_descriptor_hi = 0x0; |
1799 | command_orb->data_descriptor_lo = 0x0; | 1875 | command_orb->data_descriptor_lo = 0x0; |
1800 | command_orb->misc |= ORB_SET_DIRECTION(1); | 1876 | command_orb->misc |= ORB_SET_DIRECTION(1); |
1801 | |||
1802 | } else if (scsi_use_sg) { | 1877 | } else if (scsi_use_sg) { |
1803 | |||
1804 | SBP2_DEBUG("Use scatter/gather"); | 1878 | SBP2_DEBUG("Use scatter/gather"); |
1805 | 1879 | sbp2_prep_command_orb_sg(command_orb, hi, command, scsi_use_sg, | |
1806 | /* | 1880 | sgpnt, orb_direction, dma_dir); |
1807 | * Special case if only one element (and less than 64KB in size) | ||
1808 | */ | ||
1809 | if ((scsi_use_sg == 1) && (sgpnt[0].length <= SBP2_MAX_SG_ELEMENT_LENGTH)) { | ||
1810 | |||
1811 | SBP2_DEBUG("Only one s/g element"); | ||
1812 | command->dma_dir = dma_dir; | ||
1813 | command->dma_size = sgpnt[0].length; | ||
1814 | command->dma_type = CMD_DMA_PAGE; | ||
1815 | command->cmd_dma = pci_map_page(hi->host->pdev, | ||
1816 | sgpnt[0].page, | ||
1817 | sgpnt[0].offset, | ||
1818 | command->dma_size, | ||
1819 | command->dma_dir); | ||
1820 | SBP2_DMA_ALLOC("single page scatter element"); | ||
1821 | |||
1822 | command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); | ||
1823 | command_orb->data_descriptor_lo = command->cmd_dma; | ||
1824 | command_orb->misc |= ORB_SET_DATA_SIZE(command->dma_size); | ||
1825 | command_orb->misc |= ORB_SET_DIRECTION(orb_direction); | ||
1826 | |||
1827 | } else { | ||
1828 | int count = pci_map_sg(hi->host->pdev, sgpnt, scsi_use_sg, dma_dir); | ||
1829 | SBP2_DMA_ALLOC("scatter list"); | ||
1830 | |||
1831 | command->dma_size = scsi_use_sg; | ||
1832 | command->dma_dir = dma_dir; | ||
1833 | command->sge_buffer = sgpnt; | ||
1834 | |||
1835 | /* use page tables (s/g) */ | ||
1836 | command_orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); | ||
1837 | command_orb->misc |= ORB_SET_DIRECTION(orb_direction); | ||
1838 | command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); | ||
1839 | command_orb->data_descriptor_lo = command->sge_dma; | ||
1840 | |||
1841 | /* | ||
1842 | * Loop through and fill out our sbp-2 page tables | ||
1843 | * (and split up anything too large) | ||
1844 | */ | ||
1845 | for (i = 0, sg_count = 0 ; i < count; i++, sgpnt++) { | ||
1846 | sg_len = sg_dma_len(sgpnt); | ||
1847 | sg_addr = sg_dma_address(sgpnt); | ||
1848 | while (sg_len) { | ||
1849 | scatter_gather_element[sg_count].segment_base_lo = sg_addr; | ||
1850 | if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) { | ||
1851 | scatter_gather_element[sg_count].length_segment_base_hi = | ||
1852 | PAGE_TABLE_SET_SEGMENT_LENGTH(SBP2_MAX_SG_ELEMENT_LENGTH); | ||
1853 | sg_addr += SBP2_MAX_SG_ELEMENT_LENGTH; | ||
1854 | sg_len -= SBP2_MAX_SG_ELEMENT_LENGTH; | ||
1855 | } else { | ||
1856 | scatter_gather_element[sg_count].length_segment_base_hi = | ||
1857 | PAGE_TABLE_SET_SEGMENT_LENGTH(sg_len); | ||
1858 | sg_len = 0; | ||
1859 | } | ||
1860 | sg_count++; | ||
1861 | } | ||
1862 | } | ||
1863 | |||
1864 | /* Number of page table (s/g) elements */ | ||
1865 | command_orb->misc |= ORB_SET_DATA_SIZE(sg_count); | ||
1866 | |||
1867 | sbp2util_packet_dump(scatter_gather_element, | ||
1868 | (sizeof(struct sbp2_unrestricted_page_table)) * sg_count, | ||
1869 | "sbp2 s/g list", command->sge_dma); | ||
1870 | |||
1871 | /* | ||
1872 | * Byte swap page tables if necessary | ||
1873 | */ | ||
1874 | sbp2util_cpu_to_be32_buffer(scatter_gather_element, | ||
1875 | (sizeof(struct sbp2_unrestricted_page_table)) * | ||
1876 | sg_count); | ||
1877 | |||
1878 | } | ||
1879 | |||
1880 | } else { | 1881 | } else { |
1881 | |||
1882 | SBP2_DEBUG("No scatter/gather"); | 1882 | SBP2_DEBUG("No scatter/gather"); |
1883 | 1883 | sbp2_prep_command_orb_no_sg(command_orb, hi, command, sgpnt, | |
1884 | command->dma_dir = dma_dir; | 1884 | orb_direction, scsi_request_bufflen, |
1885 | command->dma_size = scsi_request_bufflen; | 1885 | scsi_request_buffer, dma_dir); |
1886 | command->dma_type = CMD_DMA_SINGLE; | ||
1887 | command->cmd_dma = pci_map_single (hi->host->pdev, scsi_request_buffer, | ||
1888 | command->dma_size, | ||
1889 | command->dma_dir); | ||
1890 | SBP2_DMA_ALLOC("single bulk"); | ||
1891 | |||
1892 | /* | ||
1893 | * Handle case where we get a command w/o s/g enabled (but | ||
1894 | * check for transfers larger than 64K) | ||
1895 | */ | ||
1896 | if (scsi_request_bufflen <= SBP2_MAX_SG_ELEMENT_LENGTH) { | ||
1897 | |||
1898 | command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); | ||
1899 | command_orb->data_descriptor_lo = command->cmd_dma; | ||
1900 | command_orb->misc |= ORB_SET_DATA_SIZE(scsi_request_bufflen); | ||
1901 | command_orb->misc |= ORB_SET_DIRECTION(orb_direction); | ||
1902 | |||
1903 | /* | ||
1904 | * Sanity, in case our direction table is not | ||
1905 | * up-to-date | ||
1906 | */ | ||
1907 | if (!scsi_request_bufflen) { | ||
1908 | command_orb->data_descriptor_hi = 0x0; | ||
1909 | command_orb->data_descriptor_lo = 0x0; | ||
1910 | command_orb->misc |= ORB_SET_DIRECTION(1); | ||
1911 | } | ||
1912 | |||
1913 | } else { | ||
1914 | /* | ||
1915 | * Need to turn this into page tables, since the | ||
1916 | * buffer is too large. | ||
1917 | */ | ||
1918 | command_orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); | ||
1919 | command_orb->data_descriptor_lo = command->sge_dma; | ||
1920 | |||
1921 | /* Use page tables (s/g) */ | ||
1922 | command_orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); | ||
1923 | command_orb->misc |= ORB_SET_DIRECTION(orb_direction); | ||
1924 | |||
1925 | /* | ||
1926 | * fill out our sbp-2 page tables (and split up | ||
1927 | * the large buffer) | ||
1928 | */ | ||
1929 | sg_count = 0; | ||
1930 | sg_len = scsi_request_bufflen; | ||
1931 | sg_addr = command->cmd_dma; | ||
1932 | while (sg_len) { | ||
1933 | scatter_gather_element[sg_count].segment_base_lo = sg_addr; | ||
1934 | if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) { | ||
1935 | scatter_gather_element[sg_count].length_segment_base_hi = | ||
1936 | PAGE_TABLE_SET_SEGMENT_LENGTH(SBP2_MAX_SG_ELEMENT_LENGTH); | ||
1937 | sg_addr += SBP2_MAX_SG_ELEMENT_LENGTH; | ||
1938 | sg_len -= SBP2_MAX_SG_ELEMENT_LENGTH; | ||
1939 | } else { | ||
1940 | scatter_gather_element[sg_count].length_segment_base_hi = | ||
1941 | PAGE_TABLE_SET_SEGMENT_LENGTH(sg_len); | ||
1942 | sg_len = 0; | ||
1943 | } | ||
1944 | sg_count++; | ||
1945 | } | ||
1946 | |||
1947 | /* Number of page table (s/g) elements */ | ||
1948 | command_orb->misc |= ORB_SET_DATA_SIZE(sg_count); | ||
1949 | |||
1950 | sbp2util_packet_dump(scatter_gather_element, | ||
1951 | (sizeof(struct sbp2_unrestricted_page_table)) * sg_count, | ||
1952 | "sbp2 s/g list", command->sge_dma); | ||
1953 | |||
1954 | /* | ||
1955 | * Byte swap page tables if necessary | ||
1956 | */ | ||
1957 | sbp2util_cpu_to_be32_buffer(scatter_gather_element, | ||
1958 | (sizeof(struct sbp2_unrestricted_page_table)) * | ||
1959 | sg_count); | ||
1960 | |||
1961 | } | ||
1962 | |||
1963 | } | 1886 | } |
1964 | 1887 | ||
1965 | /* | 1888 | /* Byte swap command ORB if necessary */ |
1966 | * Byte swap command ORB if necessary | ||
1967 | */ | ||
1968 | sbp2util_cpu_to_be32_buffer(command_orb, sizeof(struct sbp2_command_orb)); | 1889 | sbp2util_cpu_to_be32_buffer(command_orb, sizeof(struct sbp2_command_orb)); |
1969 | 1890 | ||
1970 | /* | 1891 | /* Put our scsi command in the command ORB */ |
1971 | * Put our scsi command in the command ORB | ||
1972 | */ | ||
1973 | memset(command_orb->cdb, 0, 12); | 1892 | memset(command_orb->cdb, 0, 12); |
1974 | memcpy(command_orb->cdb, scsi_cmd, COMMAND_SIZE(*scsi_cmd)); | 1893 | memcpy(command_orb->cdb, scsi_cmd, COMMAND_SIZE(*scsi_cmd)); |
1975 | |||
1976 | return(0); | ||
1977 | } | 1894 | } |
1978 | 1895 | ||
1979 | /* | 1896 | /* |
@@ -1989,7 +1906,7 @@ static int sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, | |||
1989 | 1906 | ||
1990 | outstanding_orb_incr; | 1907 | outstanding_orb_incr; |
1991 | SBP2_ORB_DEBUG("sending command orb %p, total orbs = %x", | 1908 | SBP2_ORB_DEBUG("sending command orb %p, total orbs = %x", |
1992 | command_orb, global_outstanding_command_orbs); | 1909 | command_orb, global_outstanding_command_orbs); |
1993 | 1910 | ||
1994 | pci_dma_sync_single_for_device(hi->host->pdev, command->command_orb_dma, | 1911 | pci_dma_sync_single_for_device(hi->host->pdev, command->command_orb_dma, |
1995 | sizeof(struct sbp2_command_orb), | 1912 | sizeof(struct sbp2_command_orb), |
@@ -2034,10 +1951,11 @@ static int sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, | |||
2034 | * both by the sbp2 device and us. | 1951 | * both by the sbp2 device and us. |
2035 | */ | 1952 | */ |
2036 | scsi_id->last_orb->next_ORB_lo = | 1953 | scsi_id->last_orb->next_ORB_lo = |
2037 | cpu_to_be32(command->command_orb_dma); | 1954 | cpu_to_be32(command->command_orb_dma); |
2038 | /* Tells hardware that this pointer is valid */ | 1955 | /* Tells hardware that this pointer is valid */ |
2039 | scsi_id->last_orb->next_ORB_hi = 0x0; | 1956 | scsi_id->last_orb->next_ORB_hi = 0x0; |
2040 | pci_dma_sync_single_for_device(hi->host->pdev, scsi_id->last_orb_dma, | 1957 | pci_dma_sync_single_for_device(hi->host->pdev, |
1958 | scsi_id->last_orb_dma, | ||
2041 | sizeof(struct sbp2_command_orb), | 1959 | sizeof(struct sbp2_command_orb), |
2042 | PCI_DMA_BIDIRECTIONAL); | 1960 | PCI_DMA_BIDIRECTIONAL); |
2043 | 1961 | ||
@@ -2051,14 +1969,14 @@ static int sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, | |||
2051 | 1969 | ||
2052 | if (sbp2util_node_write_no_wait(ne, addr, &data, 4) < 0) { | 1970 | if (sbp2util_node_write_no_wait(ne, addr, &data, 4) < 0) { |
2053 | SBP2_ERR("sbp2util_node_write_no_wait failed"); | 1971 | SBP2_ERR("sbp2util_node_write_no_wait failed"); |
2054 | return(-EIO); | 1972 | return -EIO; |
2055 | } | 1973 | } |
2056 | 1974 | ||
2057 | scsi_id->last_orb = command_orb; | 1975 | scsi_id->last_orb = command_orb; |
2058 | scsi_id->last_orb_dma = command->command_orb_dma; | 1976 | scsi_id->last_orb_dma = command->command_orb_dma; |
2059 | 1977 | ||
2060 | } | 1978 | } |
2061 | return(0); | 1979 | return 0; |
2062 | } | 1980 | } |
2063 | 1981 | ||
2064 | /* | 1982 | /* |
@@ -2085,7 +2003,7 @@ static int sbp2_send_command(struct scsi_id_instance_data *scsi_id, | |||
2085 | */ | 2003 | */ |
2086 | command = sbp2util_allocate_command_orb(scsi_id, SCpnt, done); | 2004 | command = sbp2util_allocate_command_orb(scsi_id, SCpnt, done); |
2087 | if (!command) { | 2005 | if (!command) { |
2088 | return(-EIO); | 2006 | return -EIO; |
2089 | } | 2007 | } |
2090 | 2008 | ||
2091 | /* | 2009 | /* |
@@ -2106,11 +2024,6 @@ static int sbp2_send_command(struct scsi_id_instance_data *scsi_id, | |||
2106 | sbp2_create_command_orb(scsi_id, command, cmd, SCpnt->use_sg, | 2024 | sbp2_create_command_orb(scsi_id, command, cmd, SCpnt->use_sg, |
2107 | request_bufflen, SCpnt->request_buffer, | 2025 | request_bufflen, SCpnt->request_buffer, |
2108 | SCpnt->sc_data_direction); | 2026 | SCpnt->sc_data_direction); |
2109 | /* | ||
2110 | * Update our cdb if necessary (to handle sbp2 RBC command set | ||
2111 | * differences). This is where the command set hacks go! =) | ||
2112 | */ | ||
2113 | sbp2_check_sbp2_command(scsi_id, command->command_orb.cdb); | ||
2114 | 2027 | ||
2115 | sbp2util_packet_dump(&command->command_orb, sizeof(struct sbp2_command_orb), | 2028 | sbp2util_packet_dump(&command->command_orb, sizeof(struct sbp2_command_orb), |
2116 | "sbp2 command orb", command->command_orb_dma); | 2029 | "sbp2 command orb", command->command_orb_dma); |
@@ -2125,112 +2038,7 @@ static int sbp2_send_command(struct scsi_id_instance_data *scsi_id, | |||
2125 | */ | 2038 | */ |
2126 | sbp2_link_orb_command(scsi_id, command); | 2039 | sbp2_link_orb_command(scsi_id, command); |
2127 | 2040 | ||
2128 | return(0); | 2041 | return 0; |
2129 | } | ||
2130 | |||
2131 | |||
2132 | /* | ||
2133 | * This function deals with command set differences between Linux scsi | ||
2134 | * command set and sbp2 RBC command set. | ||
2135 | */ | ||
2136 | static void sbp2_check_sbp2_command(struct scsi_id_instance_data *scsi_id, unchar *cmd) | ||
2137 | { | ||
2138 | unchar new_cmd[16]; | ||
2139 | u8 device_type = SBP2_DEVICE_TYPE (scsi_id->sbp2_device_type_and_lun); | ||
2140 | |||
2141 | SBP2_DEBUG("sbp2_check_sbp2_command"); | ||
2142 | |||
2143 | switch (*cmd) { | ||
2144 | |||
2145 | case READ_6: | ||
2146 | |||
2147 | if (sbp2_command_conversion_device_type(device_type)) { | ||
2148 | |||
2149 | SBP2_DEBUG("Convert READ_6 to READ_10"); | ||
2150 | |||
2151 | /* | ||
2152 | * Need to turn read_6 into read_10 | ||
2153 | */ | ||
2154 | new_cmd[0] = 0x28; | ||
2155 | new_cmd[1] = (cmd[1] & 0xe0); | ||
2156 | new_cmd[2] = 0x0; | ||
2157 | new_cmd[3] = (cmd[1] & 0x1f); | ||
2158 | new_cmd[4] = cmd[2]; | ||
2159 | new_cmd[5] = cmd[3]; | ||
2160 | new_cmd[6] = 0x0; | ||
2161 | new_cmd[7] = 0x0; | ||
2162 | new_cmd[8] = cmd[4]; | ||
2163 | new_cmd[9] = cmd[5]; | ||
2164 | |||
2165 | memcpy(cmd, new_cmd, 10); | ||
2166 | |||
2167 | } | ||
2168 | |||
2169 | break; | ||
2170 | |||
2171 | case WRITE_6: | ||
2172 | |||
2173 | if (sbp2_command_conversion_device_type(device_type)) { | ||
2174 | |||
2175 | SBP2_DEBUG("Convert WRITE_6 to WRITE_10"); | ||
2176 | |||
2177 | /* | ||
2178 | * Need to turn write_6 into write_10 | ||
2179 | */ | ||
2180 | new_cmd[0] = 0x2a; | ||
2181 | new_cmd[1] = (cmd[1] & 0xe0); | ||
2182 | new_cmd[2] = 0x0; | ||
2183 | new_cmd[3] = (cmd[1] & 0x1f); | ||
2184 | new_cmd[4] = cmd[2]; | ||
2185 | new_cmd[5] = cmd[3]; | ||
2186 | new_cmd[6] = 0x0; | ||
2187 | new_cmd[7] = 0x0; | ||
2188 | new_cmd[8] = cmd[4]; | ||
2189 | new_cmd[9] = cmd[5]; | ||
2190 | |||
2191 | memcpy(cmd, new_cmd, 10); | ||
2192 | |||
2193 | } | ||
2194 | |||
2195 | break; | ||
2196 | |||
2197 | case MODE_SENSE: | ||
2198 | |||
2199 | if (sbp2_command_conversion_device_type(device_type)) { | ||
2200 | |||
2201 | SBP2_DEBUG("Convert MODE_SENSE_6 to MODE_SENSE_10"); | ||
2202 | |||
2203 | /* | ||
2204 | * Need to turn mode_sense_6 into mode_sense_10 | ||
2205 | */ | ||
2206 | new_cmd[0] = 0x5a; | ||
2207 | new_cmd[1] = cmd[1]; | ||
2208 | new_cmd[2] = cmd[2]; | ||
2209 | new_cmd[3] = 0x0; | ||
2210 | new_cmd[4] = 0x0; | ||
2211 | new_cmd[5] = 0x0; | ||
2212 | new_cmd[6] = 0x0; | ||
2213 | new_cmd[7] = 0x0; | ||
2214 | new_cmd[8] = cmd[4]; | ||
2215 | new_cmd[9] = cmd[5]; | ||
2216 | |||
2217 | memcpy(cmd, new_cmd, 10); | ||
2218 | |||
2219 | } | ||
2220 | |||
2221 | break; | ||
2222 | |||
2223 | case MODE_SELECT: | ||
2224 | |||
2225 | /* | ||
2226 | * TODO. Probably need to change mode select to 10 byte version | ||
2227 | */ | ||
2228 | |||
2229 | default: | ||
2230 | break; | ||
2231 | } | ||
2232 | |||
2233 | return; | ||
2234 | } | 2042 | } |
2235 | 2043 | ||
2236 | /* | 2044 | /* |
@@ -2260,80 +2068,40 @@ static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense | |||
2260 | sense_data[14] = sbp2_status[20]; | 2068 | sense_data[14] = sbp2_status[20]; |
2261 | sense_data[15] = sbp2_status[21]; | 2069 | sense_data[15] = sbp2_status[21]; |
2262 | 2070 | ||
2263 | return(sbp2_status[8] & 0x3f); /* return scsi status */ | 2071 | return sbp2_status[8] & 0x3f; /* return scsi status */ |
2264 | } | 2072 | } |
2265 | 2073 | ||
2266 | /* | 2074 | /* |
2267 | * This function is called after a command is completed, in order to do any necessary SBP-2 | 2075 | * This function is called after a command is completed, in order to do any necessary SBP-2 |
2268 | * response data translations for the SCSI stack | 2076 | * response data translations for the SCSI stack |
2269 | */ | 2077 | */ |
2270 | static void sbp2_check_sbp2_response(struct scsi_id_instance_data *scsi_id, | 2078 | static void sbp2_check_sbp2_response(struct scsi_id_instance_data *scsi_id, |
2271 | struct scsi_cmnd *SCpnt) | 2079 | struct scsi_cmnd *SCpnt) |
2272 | { | 2080 | { |
2273 | u8 *scsi_buf = SCpnt->request_buffer; | 2081 | u8 *scsi_buf = SCpnt->request_buffer; |
2274 | u8 device_type = SBP2_DEVICE_TYPE (scsi_id->sbp2_device_type_and_lun); | ||
2275 | 2082 | ||
2276 | SBP2_DEBUG("sbp2_check_sbp2_response"); | 2083 | SBP2_DEBUG("sbp2_check_sbp2_response"); |
2277 | 2084 | ||
2278 | switch (SCpnt->cmnd[0]) { | 2085 | switch (SCpnt->cmnd[0]) { |
2279 | 2086 | ||
2280 | case INQUIRY: | 2087 | case INQUIRY: |
2281 | 2088 | /* | |
2282 | /* | 2089 | * Make sure data length is ok. Minimum length is 36 bytes |
2283 | * If scsi_id->sbp2_device_type_and_lun is uninitialized, then fill | 2090 | */ |
2284 | * this information in from the inquiry response data. Lun is set to zero. | 2091 | if (scsi_buf[4] == 0) { |
2285 | */ | 2092 | scsi_buf[4] = 36 - 5; |
2286 | if (scsi_id->sbp2_device_type_and_lun == SBP2_DEVICE_TYPE_LUN_UNINITIALIZED) { | 2093 | } |
2287 | SBP2_DEBUG("Creating sbp2_device_type_and_lun from scsi inquiry data"); | ||
2288 | scsi_id->sbp2_device_type_and_lun = (scsi_buf[0] & 0x1f) << 16; | ||
2289 | } | ||
2290 | |||
2291 | /* | ||
2292 | * Make sure data length is ok. Minimum length is 36 bytes | ||
2293 | */ | ||
2294 | if (scsi_buf[4] == 0) { | ||
2295 | scsi_buf[4] = 36 - 5; | ||
2296 | } | ||
2297 | |||
2298 | /* | ||
2299 | * Check for Simple Direct Access Device and change it to TYPE_DISK | ||
2300 | */ | ||
2301 | if ((scsi_buf[0] & 0x1f) == TYPE_RBC) { | ||
2302 | SBP2_DEBUG("Changing TYPE_RBC to TYPE_DISK"); | ||
2303 | scsi_buf[0] &= 0xe0; | ||
2304 | } | ||
2305 | |||
2306 | /* | ||
2307 | * Fix ansi revision and response data format | ||
2308 | */ | ||
2309 | scsi_buf[2] |= 2; | ||
2310 | scsi_buf[3] = (scsi_buf[3] & 0xf0) | 2; | ||
2311 | |||
2312 | break; | ||
2313 | |||
2314 | case MODE_SENSE: | ||
2315 | |||
2316 | if (sbp2_command_conversion_device_type(device_type)) { | ||
2317 | |||
2318 | SBP2_DEBUG("Modify mode sense response (10 byte version)"); | ||
2319 | |||
2320 | scsi_buf[0] = scsi_buf[1]; /* Mode data length */ | ||
2321 | scsi_buf[1] = scsi_buf[2]; /* Medium type */ | ||
2322 | scsi_buf[2] = scsi_buf[3]; /* Device specific parameter */ | ||
2323 | scsi_buf[3] = scsi_buf[7]; /* Block descriptor length */ | ||
2324 | memcpy(scsi_buf + 4, scsi_buf + 8, scsi_buf[0]); | ||
2325 | } | ||
2326 | |||
2327 | break; | ||
2328 | 2094 | ||
2329 | case MODE_SELECT: | 2095 | /* |
2096 | * Fix ansi revision and response data format | ||
2097 | */ | ||
2098 | scsi_buf[2] |= 2; | ||
2099 | scsi_buf[3] = (scsi_buf[3] & 0xf0) | 2; | ||
2330 | 2100 | ||
2331 | /* | 2101 | break; |
2332 | * TODO. Probably need to change mode select to 10 byte version | ||
2333 | */ | ||
2334 | 2102 | ||
2335 | default: | 2103 | default: |
2336 | break; | 2104 | break; |
2337 | } | 2105 | } |
2338 | return; | 2106 | return; |
2339 | } | 2107 | } |
@@ -2358,14 +2126,14 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int dest | |||
2358 | 2126 | ||
2359 | if (!host) { | 2127 | if (!host) { |
2360 | SBP2_ERR("host is NULL - this is bad!"); | 2128 | SBP2_ERR("host is NULL - this is bad!"); |
2361 | return(RCODE_ADDRESS_ERROR); | 2129 | return RCODE_ADDRESS_ERROR; |
2362 | } | 2130 | } |
2363 | 2131 | ||
2364 | hi = hpsb_get_hostinfo(&sbp2_highlevel, host); | 2132 | hi = hpsb_get_hostinfo(&sbp2_highlevel, host); |
2365 | 2133 | ||
2366 | if (!hi) { | 2134 | if (!hi) { |
2367 | SBP2_ERR("host info is NULL - this is bad!"); | 2135 | SBP2_ERR("host info is NULL - this is bad!"); |
2368 | return(RCODE_ADDRESS_ERROR); | 2136 | return RCODE_ADDRESS_ERROR; |
2369 | } | 2137 | } |
2370 | 2138 | ||
2371 | /* | 2139 | /* |
@@ -2382,7 +2150,7 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int dest | |||
2382 | 2150 | ||
2383 | if (!scsi_id) { | 2151 | if (!scsi_id) { |
2384 | SBP2_ERR("scsi_id is NULL - device is gone?"); | 2152 | SBP2_ERR("scsi_id is NULL - device is gone?"); |
2385 | return(RCODE_ADDRESS_ERROR); | 2153 | return RCODE_ADDRESS_ERROR; |
2386 | } | 2154 | } |
2387 | 2155 | ||
2388 | /* | 2156 | /* |
@@ -2480,10 +2248,9 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int dest | |||
2480 | SBP2_ORB_DEBUG("command orb completed"); | 2248 | SBP2_ORB_DEBUG("command orb completed"); |
2481 | } | 2249 | } |
2482 | 2250 | ||
2483 | return(RCODE_COMPLETE); | 2251 | return RCODE_COMPLETE; |
2484 | } | 2252 | } |
2485 | 2253 | ||
2486 | |||
2487 | /************************************** | 2254 | /************************************** |
2488 | * SCSI interface related section | 2255 | * SCSI interface related section |
2489 | **************************************/ | 2256 | **************************************/ |
@@ -2541,6 +2308,16 @@ static int sbp2scsi_queuecommand(struct scsi_cmnd *SCpnt, | |||
2541 | } | 2308 | } |
2542 | 2309 | ||
2543 | /* | 2310 | /* |
2311 | * Bidirectional commands are not yet implemented, | ||
2312 | * and unknown transfer direction not handled. | ||
2313 | */ | ||
2314 | if (SCpnt->sc_data_direction == DMA_BIDIRECTIONAL) { | ||
2315 | SBP2_ERR("Cannot handle DMA_BIDIRECTIONAL - rejecting command"); | ||
2316 | result = DID_ERROR << 16; | ||
2317 | goto done; | ||
2318 | } | ||
2319 | |||
2320 | /* | ||
2544 | * Try and send our SCSI command | 2321 | * Try and send our SCSI command |
2545 | */ | 2322 | */ |
2546 | if (sbp2_send_command(scsi_id, SCpnt, done)) { | 2323 | if (sbp2_send_command(scsi_id, SCpnt, done)) { |
@@ -2616,55 +2393,56 @@ static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id, | |||
2616 | * complete the command, just let it get retried at the end of the | 2393 | * complete the command, just let it get retried at the end of the |
2617 | * bus reset. | 2394 | * bus reset. |
2618 | */ | 2395 | */ |
2619 | if (!hpsb_node_entry_valid(scsi_id->ne) && (scsi_status != SBP2_SCSI_STATUS_GOOD)) { | 2396 | if (!hpsb_node_entry_valid(scsi_id->ne) |
2397 | && (scsi_status != SBP2_SCSI_STATUS_GOOD)) { | ||
2620 | SBP2_ERR("Bus reset in progress - retry command later"); | 2398 | SBP2_ERR("Bus reset in progress - retry command later"); |
2621 | return; | 2399 | return; |
2622 | } | 2400 | } |
2623 | 2401 | ||
2624 | /* | 2402 | /* |
2625 | * Switch on scsi status | 2403 | * Switch on scsi status |
2626 | */ | 2404 | */ |
2627 | switch (scsi_status) { | 2405 | switch (scsi_status) { |
2628 | case SBP2_SCSI_STATUS_GOOD: | 2406 | case SBP2_SCSI_STATUS_GOOD: |
2629 | SCpnt->result = DID_OK; | 2407 | SCpnt->result = DID_OK; |
2630 | break; | 2408 | break; |
2631 | 2409 | ||
2632 | case SBP2_SCSI_STATUS_BUSY: | 2410 | case SBP2_SCSI_STATUS_BUSY: |
2633 | SBP2_ERR("SBP2_SCSI_STATUS_BUSY"); | 2411 | SBP2_ERR("SBP2_SCSI_STATUS_BUSY"); |
2634 | SCpnt->result = DID_BUS_BUSY << 16; | 2412 | SCpnt->result = DID_BUS_BUSY << 16; |
2635 | break; | 2413 | break; |
2636 | 2414 | ||
2637 | case SBP2_SCSI_STATUS_CHECK_CONDITION: | 2415 | case SBP2_SCSI_STATUS_CHECK_CONDITION: |
2638 | SBP2_DEBUG("SBP2_SCSI_STATUS_CHECK_CONDITION"); | 2416 | SBP2_DEBUG("SBP2_SCSI_STATUS_CHECK_CONDITION"); |
2639 | SCpnt->result = CHECK_CONDITION << 1; | 2417 | SCpnt->result = CHECK_CONDITION << 1; |
2640 | 2418 | ||
2641 | /* | 2419 | /* |
2642 | * Debug stuff | 2420 | * Debug stuff |
2643 | */ | 2421 | */ |
2644 | #if CONFIG_IEEE1394_SBP2_DEBUG >= 1 | 2422 | #if CONFIG_IEEE1394_SBP2_DEBUG >= 1 |
2645 | scsi_print_command(SCpnt); | 2423 | scsi_print_command(SCpnt); |
2646 | scsi_print_sense("bh", SCpnt); | 2424 | scsi_print_sense("bh", SCpnt); |
2647 | #endif | 2425 | #endif |
2648 | 2426 | ||
2649 | break; | 2427 | break; |
2650 | 2428 | ||
2651 | case SBP2_SCSI_STATUS_SELECTION_TIMEOUT: | 2429 | case SBP2_SCSI_STATUS_SELECTION_TIMEOUT: |
2652 | SBP2_ERR("SBP2_SCSI_STATUS_SELECTION_TIMEOUT"); | 2430 | SBP2_ERR("SBP2_SCSI_STATUS_SELECTION_TIMEOUT"); |
2653 | SCpnt->result = DID_NO_CONNECT << 16; | 2431 | SCpnt->result = DID_NO_CONNECT << 16; |
2654 | scsi_print_command(SCpnt); | 2432 | scsi_print_command(SCpnt); |
2655 | break; | 2433 | break; |
2656 | 2434 | ||
2657 | case SBP2_SCSI_STATUS_CONDITION_MET: | 2435 | case SBP2_SCSI_STATUS_CONDITION_MET: |
2658 | case SBP2_SCSI_STATUS_RESERVATION_CONFLICT: | 2436 | case SBP2_SCSI_STATUS_RESERVATION_CONFLICT: |
2659 | case SBP2_SCSI_STATUS_COMMAND_TERMINATED: | 2437 | case SBP2_SCSI_STATUS_COMMAND_TERMINATED: |
2660 | SBP2_ERR("Bad SCSI status = %x", scsi_status); | 2438 | SBP2_ERR("Bad SCSI status = %x", scsi_status); |
2661 | SCpnt->result = DID_ERROR << 16; | 2439 | SCpnt->result = DID_ERROR << 16; |
2662 | scsi_print_command(SCpnt); | 2440 | scsi_print_command(SCpnt); |
2663 | break; | 2441 | break; |
2664 | 2442 | ||
2665 | default: | 2443 | default: |
2666 | SBP2_ERR("Unsupported SCSI status = %x", scsi_status); | 2444 | SBP2_ERR("Unsupported SCSI status = %x", scsi_status); |
2667 | SCpnt->result = DID_ERROR << 16; | 2445 | SCpnt->result = DID_ERROR << 16; |
2668 | } | 2446 | } |
2669 | 2447 | ||
2670 | /* | 2448 | /* |
@@ -2678,7 +2456,8 @@ static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id, | |||
2678 | * If a bus reset is in progress and there was an error, complete | 2456 | * If a bus reset is in progress and there was an error, complete |
2679 | * the command as busy so that it will get retried. | 2457 | * the command as busy so that it will get retried. |
2680 | */ | 2458 | */ |
2681 | if (!hpsb_node_entry_valid(scsi_id->ne) && (scsi_status != SBP2_SCSI_STATUS_GOOD)) { | 2459 | if (!hpsb_node_entry_valid(scsi_id->ne) |
2460 | && (scsi_status != SBP2_SCSI_STATUS_GOOD)) { | ||
2682 | SBP2_ERR("Completing command with busy (bus reset)"); | 2461 | SBP2_ERR("Completing command with busy (bus reset)"); |
2683 | SCpnt->result = DID_BUS_BUSY << 16; | 2462 | SCpnt->result = DID_BUS_BUSY << 16; |
2684 | } | 2463 | } |
@@ -2699,31 +2478,29 @@ static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id, | |||
2699 | /* | 2478 | /* |
2700 | * Tell scsi stack that we're done with this command | 2479 | * Tell scsi stack that we're done with this command |
2701 | */ | 2480 | */ |
2702 | done (SCpnt); | 2481 | done(SCpnt); |
2703 | } | 2482 | } |
2704 | 2483 | ||
2705 | |||
2706 | static int sbp2scsi_slave_alloc(struct scsi_device *sdev) | 2484 | static int sbp2scsi_slave_alloc(struct scsi_device *sdev) |
2707 | { | 2485 | { |
2708 | ((struct scsi_id_instance_data *)sdev->host->hostdata[0])->sdev = sdev; | 2486 | ((struct scsi_id_instance_data *)sdev->host->hostdata[0])->sdev = sdev; |
2709 | return 0; | 2487 | return 0; |
2710 | } | 2488 | } |
2711 | 2489 | ||
2712 | |||
2713 | static int sbp2scsi_slave_configure(struct scsi_device *sdev) | 2490 | static int sbp2scsi_slave_configure(struct scsi_device *sdev) |
2714 | { | 2491 | { |
2715 | blk_queue_dma_alignment(sdev->request_queue, (512 - 1)); | 2492 | blk_queue_dma_alignment(sdev->request_queue, (512 - 1)); |
2493 | sdev->use_10_for_rw = 1; | ||
2494 | sdev->use_10_for_ms = 1; | ||
2716 | return 0; | 2495 | return 0; |
2717 | } | 2496 | } |
2718 | 2497 | ||
2719 | |||
2720 | static void sbp2scsi_slave_destroy(struct scsi_device *sdev) | 2498 | static void sbp2scsi_slave_destroy(struct scsi_device *sdev) |
2721 | { | 2499 | { |
2722 | ((struct scsi_id_instance_data *)sdev->host->hostdata[0])->sdev = NULL; | 2500 | ((struct scsi_id_instance_data *)sdev->host->hostdata[0])->sdev = NULL; |
2723 | return; | 2501 | return; |
2724 | } | 2502 | } |
2725 | 2503 | ||
2726 | |||
2727 | /* | 2504 | /* |
2728 | * Called by scsi stack when something has really gone wrong. Usually | 2505 | * Called by scsi stack when something has really gone wrong. Usually |
2729 | * called when a command has timed-out for some reason. | 2506 | * called when a command has timed-out for some reason. |
@@ -2769,7 +2546,7 @@ static int sbp2scsi_abort(struct scsi_cmnd *SCpnt) | |||
2769 | sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY); | 2546 | sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY); |
2770 | } | 2547 | } |
2771 | 2548 | ||
2772 | return(SUCCESS); | 2549 | return SUCCESS; |
2773 | } | 2550 | } |
2774 | 2551 | ||
2775 | /* | 2552 | /* |
@@ -2779,28 +2556,20 @@ static int sbp2scsi_reset(struct scsi_cmnd *SCpnt) | |||
2779 | { | 2556 | { |
2780 | struct scsi_id_instance_data *scsi_id = | 2557 | struct scsi_id_instance_data *scsi_id = |
2781 | (struct scsi_id_instance_data *)SCpnt->device->host->hostdata[0]; | 2558 | (struct scsi_id_instance_data *)SCpnt->device->host->hostdata[0]; |
2782 | unsigned long flags; | ||
2783 | 2559 | ||
2784 | SBP2_ERR("reset requested"); | 2560 | SBP2_ERR("reset requested"); |
2785 | 2561 | ||
2786 | spin_lock_irqsave(SCpnt->device->host->host_lock, flags); | ||
2787 | |||
2788 | if (sbp2util_node_is_available(scsi_id)) { | 2562 | if (sbp2util_node_is_available(scsi_id)) { |
2789 | SBP2_ERR("Generating sbp2 fetch agent reset"); | 2563 | SBP2_ERR("Generating sbp2 fetch agent reset"); |
2790 | sbp2_agent_reset(scsi_id, 0); | 2564 | sbp2_agent_reset(scsi_id, 0); |
2791 | } | 2565 | } |
2792 | 2566 | ||
2793 | spin_unlock_irqrestore(SCpnt->device->host->host_lock, flags); | ||
2794 | |||
2795 | return SUCCESS; | 2567 | return SUCCESS; |
2796 | } | 2568 | } |
2797 | 2569 | ||
2798 | static const char *sbp2scsi_info (struct Scsi_Host *host) | 2570 | static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *dev, |
2799 | { | 2571 | struct device_attribute *attr, |
2800 | return "SCSI emulation for IEEE-1394 SBP-2 Devices"; | 2572 | char *buf) |
2801 | } | ||
2802 | |||
2803 | static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *dev, struct device_attribute *attr, char *buf) | ||
2804 | { | 2573 | { |
2805 | struct scsi_device *sdev; | 2574 | struct scsi_device *sdev; |
2806 | struct scsi_id_instance_data *scsi_id; | 2575 | struct scsi_id_instance_data *scsi_id; |
@@ -2812,10 +2581,7 @@ static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *dev, struct device_att | |||
2812 | if (!(scsi_id = (struct scsi_id_instance_data *)sdev->host->hostdata[0])) | 2581 | if (!(scsi_id = (struct scsi_id_instance_data *)sdev->host->hostdata[0])) |
2813 | return 0; | 2582 | return 0; |
2814 | 2583 | ||
2815 | if (scsi_id->sbp2_device_type_and_lun == SBP2_DEVICE_TYPE_LUN_UNINITIALIZED) | 2584 | lun = ORB_SET_LUN(scsi_id->sbp2_lun); |
2816 | lun = 0; | ||
2817 | else | ||
2818 | lun = ORB_SET_LUN(scsi_id->sbp2_device_type_and_lun); | ||
2819 | 2585 | ||
2820 | return sprintf(buf, "%016Lx:%d:%d\n", (unsigned long long)scsi_id->ne->guid, | 2586 | return sprintf(buf, "%016Lx:%d:%d\n", (unsigned long long)scsi_id->ne->guid, |
2821 | scsi_id->ud->id, lun); | 2587 | scsi_id->ud->id, lun); |
@@ -2837,12 +2603,9 @@ static struct scsi_host_template scsi_driver_template = { | |||
2837 | .module = THIS_MODULE, | 2603 | .module = THIS_MODULE, |
2838 | .name = "SBP-2 IEEE-1394", | 2604 | .name = "SBP-2 IEEE-1394", |
2839 | .proc_name = SBP2_DEVICE_NAME, | 2605 | .proc_name = SBP2_DEVICE_NAME, |
2840 | .info = sbp2scsi_info, | ||
2841 | .queuecommand = sbp2scsi_queuecommand, | 2606 | .queuecommand = sbp2scsi_queuecommand, |
2842 | .eh_abort_handler = sbp2scsi_abort, | 2607 | .eh_abort_handler = sbp2scsi_abort, |
2843 | .eh_device_reset_handler = sbp2scsi_reset, | 2608 | .eh_device_reset_handler = sbp2scsi_reset, |
2844 | .eh_bus_reset_handler = sbp2scsi_reset, | ||
2845 | .eh_host_reset_handler = sbp2scsi_reset, | ||
2846 | .slave_alloc = sbp2scsi_slave_alloc, | 2609 | .slave_alloc = sbp2scsi_slave_alloc, |
2847 | .slave_configure = sbp2scsi_slave_configure, | 2610 | .slave_configure = sbp2scsi_slave_configure, |
2848 | .slave_destroy = sbp2scsi_slave_destroy, | 2611 | .slave_destroy = sbp2scsi_slave_destroy, |
@@ -2861,8 +2624,6 @@ static int sbp2_module_init(void) | |||
2861 | 2624 | ||
2862 | SBP2_DEBUG("sbp2_module_init"); | 2625 | SBP2_DEBUG("sbp2_module_init"); |
2863 | 2626 | ||
2864 | printk(KERN_INFO "sbp2: %s\n", version); | ||
2865 | |||
2866 | /* Module load debug option to force one command at a time (serializing I/O) */ | 2627 | /* Module load debug option to force one command at a time (serializing I/O) */ |
2867 | if (serialize_io) { | 2628 | if (serialize_io) { |
2868 | SBP2_INFO("Driver forced to serialize I/O (serialize_io=1)"); | 2629 | SBP2_INFO("Driver forced to serialize I/O (serialize_io=1)"); |
@@ -2874,7 +2635,6 @@ static int sbp2_module_init(void) | |||
2874 | /* Set max sectors (module load option). Default is 255 sectors. */ | 2635 | /* Set max sectors (module load option). Default is 255 sectors. */ |
2875 | scsi_driver_template.max_sectors = max_sectors; | 2636 | scsi_driver_template.max_sectors = max_sectors; |
2876 | 2637 | ||
2877 | |||
2878 | /* Register our high level driver with 1394 stack */ | 2638 | /* Register our high level driver with 1394 stack */ |
2879 | hpsb_register_highlevel(&sbp2_highlevel); | 2639 | hpsb_register_highlevel(&sbp2_highlevel); |
2880 | 2640 | ||