Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[SCSI] usb: transport - convert to accessors and !use_sg code path removal

- This patch depends on:
usb: transport.c use scsi_eh API in REQUEST_SENSE execution

- Use scsi data accessors and remove of !use_sg code path.
- New usb_stor_bulk_srb() for use by drivers

[jejb: updated with corrective fix.

had a bug in residual handling in the new usb_stor_bulk_srb()
function. Found by Gabriel C. in -mm tree.

Tested-by: Gabriel C <nix.or.die@googlemail.com>
]

Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
Acked-by: Matthew Dharm <mdharm-scsi@one-eyed-alien.net>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>

authored by

Boaz Harrosh and committed by
James Bottomley
6d416e61 4776e99e

+30 -17
+28 -17
drivers/usb/storage/transport.c
··· 459 459 } 460 460 461 461 /* 462 + * Common used function. Transfer a complete command 463 + * via usb_stor_bulk_transfer_sglist() above. Set cmnd resid 464 + */ 465 + int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe, 466 + struct scsi_cmnd* srb) 467 + { 468 + unsigned int partial; 469 + int result = usb_stor_bulk_transfer_sglist(us, pipe, scsi_sglist(srb), 470 + scsi_sg_count(srb), scsi_bufflen(srb), 471 + &partial); 472 + 473 + scsi_set_resid(srb, scsi_bufflen(srb) - partial); 474 + return result; 475 + } 476 + 477 + /* 462 478 * Transfer an entire SCSI command's worth of data payload over the bulk 463 479 * pipe. 464 480 * ··· 524 508 int result; 525 509 526 510 /* send the command to the transport layer */ 527 - srb->resid = 0; 511 + scsi_set_resid(srb, 0); 528 512 result = us->transport(srb, us); 529 513 530 514 /* if the command gets aborted by the higher layers, we need to ··· 584 568 * A short transfer on a command where we don't expect it 585 569 * is unusual, but it doesn't mean we need to auto-sense. 586 570 */ 587 - if ((srb->resid > 0) && 571 + if ((scsi_get_resid(srb) > 0) && 588 572 !((srb->cmnd[0] == REQUEST_SENSE) || 589 573 (srb->cmnd[0] == INQUIRY) || 590 574 (srb->cmnd[0] == MODE_SENSE) || ··· 609 593 srb->cmd_len = 12; 610 594 611 595 /* issue the auto-sense command */ 612 - srb->resid = 0; 596 + scsi_set_resid(srb, 0); 613 597 temp_result = us->transport(us->srb, us); 614 598 615 599 /* let's clean up right away */ ··· 665 649 666 650 /* Did we transfer less than the minimum amount required? */ 667 651 if (srb->result == SAM_STAT_GOOD && 668 - srb->request_bufflen - srb->resid < srb->underflow) 652 + scsi_bufflen(srb) - scsi_get_resid(srb) < srb->underflow) 669 653 srb->result = (DID_ERROR << 16) | (SUGGEST_RETRY << 24); 670 654 671 655 return; ··· 724 708 725 709 int usb_stor_CBI_transport(struct scsi_cmnd *srb, struct us_data *us) 726 710 { 727 - unsigned int transfer_length = srb->request_bufflen; 711 + unsigned int transfer_length = scsi_bufflen(srb); 728 712 unsigned int pipe = 0; 729 713 int result; 730 714 ··· 753 737 if (transfer_length) { 754 738 pipe = srb->sc_data_direction == DMA_FROM_DEVICE ? 755 739 us->recv_bulk_pipe : us->send_bulk_pipe; 756 - result = usb_stor_bulk_transfer_sg(us, pipe, 757 - srb->request_buffer, transfer_length, 758 - srb->use_sg, &srb->resid); 740 + result = usb_stor_bulk_srb(us, pipe, srb); 759 741 US_DEBUGP("CBI data stage result is 0x%x\n", result); 760 742 761 743 /* if we stalled the data transfer it means command failed */ ··· 822 808 */ 823 809 int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us) 824 810 { 825 - unsigned int transfer_length = srb->request_bufflen; 811 + unsigned int transfer_length = scsi_bufflen(srb); 826 812 int result; 827 813 828 814 /* COMMAND STAGE */ ··· 850 836 if (transfer_length) { 851 837 unsigned int pipe = srb->sc_data_direction == DMA_FROM_DEVICE ? 852 838 us->recv_bulk_pipe : us->send_bulk_pipe; 853 - result = usb_stor_bulk_transfer_sg(us, pipe, 854 - srb->request_buffer, transfer_length, 855 - srb->use_sg, &srb->resid); 839 + result = usb_stor_bulk_srb(us, pipe, srb); 856 840 US_DEBUGP("CB data stage result is 0x%x\n", result); 857 841 858 842 /* if we stalled the data transfer it means command failed */ ··· 916 904 { 917 905 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 918 906 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf; 919 - unsigned int transfer_length = srb->request_bufflen; 907 + unsigned int transfer_length = scsi_bufflen(srb); 920 908 unsigned int residue; 921 909 int result; 922 910 int fake_sense = 0; ··· 967 955 if (transfer_length) { 968 956 unsigned int pipe = srb->sc_data_direction == DMA_FROM_DEVICE ? 969 957 us->recv_bulk_pipe : us->send_bulk_pipe; 970 - result = usb_stor_bulk_transfer_sg(us, pipe, 971 - srb->request_buffer, transfer_length, 972 - srb->use_sg, &srb->resid); 958 + result = usb_stor_bulk_srb(us, pipe, srb); 973 959 US_DEBUGP("Bulk data transfer result 0x%x\n", result); 974 960 if (result == USB_STOR_XFER_ERROR) 975 961 return USB_STOR_TRANSPORT_ERROR; ··· 1046 1036 if (residue) { 1047 1037 if (!(us->flags & US_FL_IGNORE_RESIDUE)) { 1048 1038 residue = min(residue, transfer_length); 1049 - srb->resid = max(srb->resid, (int) residue); 1039 + scsi_set_resid(srb, max(scsi_get_resid(srb), 1040 + (int) residue)); 1050 1041 } 1051 1042 } 1052 1043
+2
drivers/usb/storage/transport.h
··· 139 139 void *buf, unsigned int length, unsigned int *act_len); 140 140 extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe, 141 141 void *buf, unsigned int length, int use_sg, int *residual); 142 + extern int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe, 143 + struct scsi_cmnd* srb); 142 144 143 145 extern int usb_stor_port_reset(struct us_data *us); 144 146 #endif