uas.c (05909cd9a0c8811731b38697af13075e8954314f) uas.c (93c747ed00c1c74316645f7761f0cdb3f3d3952d)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * USB Attached SCSI
4 * Note that this is not the same as the USB Mass Storage driver
5 *
6 * Copyright Hans de Goede <hdegoede@redhat.com> for Red Hat, Inc. 2013 - 2016
7 * Copyright Matthew Wilcox for Intel Corp, 2010
8 * Copyright Sarah Sharp for Intel Corp, 2010

--- 265 unchanged lines hidden (view full) ---

274}
275
276static bool uas_evaluate_response_iu(struct response_iu *riu, struct scsi_cmnd *cmnd)
277{
278 u8 response_code = riu->response_code;
279
280 switch (response_code) {
281 case RC_INCORRECT_LUN:
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * USB Attached SCSI
4 * Note that this is not the same as the USB Mass Storage driver
5 *
6 * Copyright Hans de Goede <hdegoede@redhat.com> for Red Hat, Inc. 2013 - 2016
7 * Copyright Matthew Wilcox for Intel Corp, 2010
8 * Copyright Sarah Sharp for Intel Corp, 2010

--- 265 unchanged lines hidden (view full) ---

274}
275
276static bool uas_evaluate_response_iu(struct response_iu *riu, struct scsi_cmnd *cmnd)
277{
278 u8 response_code = riu->response_code;
279
280 switch (response_code) {
281 case RC_INCORRECT_LUN:
282 cmnd->result = DID_BAD_TARGET << 16;
282 set_host_byte(cmnd, DID_BAD_TARGET);
283 break;
284 case RC_TMF_SUCCEEDED:
283 break;
284 case RC_TMF_SUCCEEDED:
285 cmnd->result = DID_OK << 16;
285 set_host_byte(cmnd, DID_OK);
286 break;
287 case RC_TMF_NOT_SUPPORTED:
286 break;
287 case RC_TMF_NOT_SUPPORTED:
288 cmnd->result = DID_TARGET_FAILURE << 16;
288 set_host_byte(cmnd, DID_TARGET_FAILURE);
289 break;
290 default:
291 uas_log_cmd_state(cmnd, "response iu", response_code);
289 break;
290 default:
291 uas_log_cmd_state(cmnd, "response iu", response_code);
292 cmnd->result = DID_ERROR << 16;
292 set_host_byte(cmnd, DID_ERROR);
293 break;
294 }
295
296 return response_code == RC_TMF_SUCCEEDED;
297}
298
299static void uas_stat_cmplt(struct urb *urb)
300{

--- 354 unchanged lines hidden (view full) ---

655 cmnd->result = SAM_STAT_CHECK_CONDITION;
656 cmnd->scsi_done(cmnd);
657 return 0;
658 }
659
660 spin_lock_irqsave(&devinfo->lock, flags);
661
662 if (devinfo->resetting) {
293 break;
294 }
295
296 return response_code == RC_TMF_SUCCEEDED;
297}
298
299static void uas_stat_cmplt(struct urb *urb)
300{

--- 354 unchanged lines hidden (view full) ---

655 cmnd->result = SAM_STAT_CHECK_CONDITION;
656 cmnd->scsi_done(cmnd);
657 return 0;
658 }
659
660 spin_lock_irqsave(&devinfo->lock, flags);
661
662 if (devinfo->resetting) {
663 cmnd->result = DID_ERROR << 16;
663 set_host_byte(cmnd, DID_ERROR);
664 cmnd->scsi_done(cmnd);
665 goto zombie;
666 }
667
668 /* Find a free uas-tag */
669 for (idx = 0; idx < devinfo->qdepth; idx++) {
670 if (!devinfo->cmnd[idx])
671 break;

--- 13 unchanged lines hidden (view full) ---

685 case DMA_FROM_DEVICE:
686 cmdinfo->state |= ALLOC_DATA_IN_URB | SUBMIT_DATA_IN_URB;
687 break;
688 case DMA_BIDIRECTIONAL:
689 cmdinfo->state |= ALLOC_DATA_IN_URB | SUBMIT_DATA_IN_URB;
690 fallthrough;
691 case DMA_TO_DEVICE:
692 cmdinfo->state |= ALLOC_DATA_OUT_URB | SUBMIT_DATA_OUT_URB;
664 cmnd->scsi_done(cmnd);
665 goto zombie;
666 }
667
668 /* Find a free uas-tag */
669 for (idx = 0; idx < devinfo->qdepth; idx++) {
670 if (!devinfo->cmnd[idx])
671 break;

--- 13 unchanged lines hidden (view full) ---

685 case DMA_FROM_DEVICE:
686 cmdinfo->state |= ALLOC_DATA_IN_URB | SUBMIT_DATA_IN_URB;
687 break;
688 case DMA_BIDIRECTIONAL:
689 cmdinfo->state |= ALLOC_DATA_IN_URB | SUBMIT_DATA_IN_URB;
690 fallthrough;
691 case DMA_TO_DEVICE:
692 cmdinfo->state |= ALLOC_DATA_OUT_URB | SUBMIT_DATA_OUT_URB;
693 break;
693 case DMA_NONE:
694 break;
695 }
696
697 if (!devinfo->use_streams)
698 cmdinfo->state &= ~(SUBMIT_DATA_IN_URB | SUBMIT_DATA_OUT_URB);
699
700 err = uas_submit_urbs(cmnd, devinfo);
701 /*
702 * in case of fatal errors the SCSI layer is peculiar
703 * a command that has finished is a success for the purpose
704 * of queueing, no matter how fatal the error
705 */
706 if (err == -ENODEV) {
694 case DMA_NONE:
695 break;
696 }
697
698 if (!devinfo->use_streams)
699 cmdinfo->state &= ~(SUBMIT_DATA_IN_URB | SUBMIT_DATA_OUT_URB);
700
701 err = uas_submit_urbs(cmnd, devinfo);
702 /*
703 * in case of fatal errors the SCSI layer is peculiar
704 * a command that has finished is a success for the purpose
705 * of queueing, no matter how fatal the error
706 */
707 if (err == -ENODEV) {
707 cmnd->result = DID_ERROR << 16;
708 set_host_byte(cmnd, DID_ERROR);
708 cmnd->scsi_done(cmnd);
709 goto zombie;
710 }
711 if (err) {
712 /* If we did nothing, give up now */
713 if (cmdinfo->state & SUBMIT_STATUS_URB) {
714 spin_unlock_irqrestore(&devinfo->lock, flags);
715 return SCSI_MLQUEUE_DEVICE_BUSY;

--- 116 unchanged lines hidden (view full) ---

832
833 /*
834 * The protocol has no requirements on alignment in the strict sense.
835 * Controllers may or may not have alignment restrictions.
836 * As this is not exported, we use an extremely conservative guess.
837 */
838 blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
839
709 cmnd->scsi_done(cmnd);
710 goto zombie;
711 }
712 if (err) {
713 /* If we did nothing, give up now */
714 if (cmdinfo->state & SUBMIT_STATUS_URB) {
715 spin_unlock_irqrestore(&devinfo->lock, flags);
716 return SCSI_MLQUEUE_DEVICE_BUSY;

--- 116 unchanged lines hidden (view full) ---

833
834 /*
835 * The protocol has no requirements on alignment in the strict sense.
836 * Controllers may or may not have alignment restrictions.
837 * As this is not exported, we use an extremely conservative guess.
838 */
839 blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
840
840 if (devinfo->flags & US_FL_MAX_SECTORS_64)
841 blk_queue_max_hw_sectors(sdev->request_queue, 64);
842 else if (devinfo->flags & US_FL_MAX_SECTORS_240)
843 blk_queue_max_hw_sectors(sdev->request_queue, 240);
844
845 return 0;
846}
847
848static int uas_slave_configure(struct scsi_device *sdev)
849{
850 struct uas_dev_info *devinfo = sdev->hostdata;
841 return 0;
842}
843
844static int uas_slave_configure(struct scsi_device *sdev)
845{
846 struct uas_dev_info *devinfo = sdev->hostdata;
847 struct device *dev = sdev->host->dma_dev;
851
848
849 if (devinfo->flags & US_FL_MAX_SECTORS_64)
850 blk_queue_max_hw_sectors(sdev->request_queue, 64);
851 else if (devinfo->flags & US_FL_MAX_SECTORS_240)
852 blk_queue_max_hw_sectors(sdev->request_queue, 240);
853 else if (devinfo->udev->speed >= USB_SPEED_SUPER)
854 blk_queue_max_hw_sectors(sdev->request_queue, 2048);
855
856 blk_queue_max_hw_sectors(sdev->request_queue,
857 min_t(size_t, queue_max_hw_sectors(sdev->request_queue),
858 dma_max_mapping_size(dev) >> SECTOR_SHIFT));
859
852 if (devinfo->flags & US_FL_NO_REPORT_OPCODES)
853 sdev->no_report_opcodes = 1;
854
855 /* A few buggy USB-ATA bridges don't understand FUA */
856 if (devinfo->flags & US_FL_BROKEN_FUA)
857 sdev->broken_fua = 1;
858
859 /* UAS also needs to support FL_ALWAYS_SYNC */

--- 168 unchanged lines hidden (view full) ---

1028
1029 /*
1030 * 1 tag is reserved for untagged commands +
1031 * 1 tag to avoid off by one errors in some bridge firmwares
1032 */
1033 shost->can_queue = devinfo->qdepth - 2;
1034
1035 usb_set_intfdata(intf, shost);
860 if (devinfo->flags & US_FL_NO_REPORT_OPCODES)
861 sdev->no_report_opcodes = 1;
862
863 /* A few buggy USB-ATA bridges don't understand FUA */
864 if (devinfo->flags & US_FL_BROKEN_FUA)
865 sdev->broken_fua = 1;
866
867 /* UAS also needs to support FL_ALWAYS_SYNC */

--- 168 unchanged lines hidden (view full) ---

1036
1037 /*
1038 * 1 tag is reserved for untagged commands +
1039 * 1 tag to avoid off by one errors in some bridge firmwares
1040 */
1041 shost->can_queue = devinfo->qdepth - 2;
1042
1043 usb_set_intfdata(intf, shost);
1036 result = scsi_add_host(shost, &intf->dev);
1044 result = scsi_add_host_with_dma(shost, &intf->dev, udev->bus->sysdev);
1037 if (result)
1038 goto free_streams;
1039
1040 /* Submit the delayed_work for SCSI-device scanning */
1041 schedule_work(&devinfo->scan_work);
1042
1043 return result;
1044

--- 240 unchanged lines hidden ---
1045 if (result)
1046 goto free_streams;
1047
1048 /* Submit the delayed_work for SCSI-device scanning */
1049 schedule_work(&devinfo->scan_work);
1050
1051 return result;
1052

--- 240 unchanged lines hidden ---