Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * USB Attached SCSI |
| 3 | * Note that this is not the same as the USB Mass Storage driver |
| 4 | * |
| 5 | * Copyright Matthew Wilcox for Intel Corp, 2010 |
| 6 | * Copyright Sarah Sharp for Intel Corp, 2010 |
| 7 | * |
| 8 | * Distributed under the terms of the GNU GPL, version two. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/blkdev.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/types.h> |
Paul Gortmaker | 6eb0de8 | 2011-07-03 16:09:31 -0400 | [diff] [blame] | 14 | #include <linux/module.h> |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 15 | #include <linux/usb.h> |
Sebastian Andrzej Siewior | c898add | 2012-01-11 12:42:32 +0100 | [diff] [blame] | 16 | #include <linux/usb/hcd.h> |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 17 | #include <linux/usb/storage.h> |
Sebastian Andrzej Siewior | 348748b | 2012-01-11 12:45:56 +0100 | [diff] [blame] | 18 | #include <linux/usb/uas.h> |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 19 | |
| 20 | #include <scsi/scsi.h> |
| 21 | #include <scsi/scsi_dbg.h> |
| 22 | #include <scsi/scsi_cmnd.h> |
| 23 | #include <scsi/scsi_device.h> |
| 24 | #include <scsi/scsi_host.h> |
| 25 | #include <scsi/scsi_tcq.h> |
| 26 | |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 27 | /* |
| 28 | * The r00-r01c specs define this version of the SENSE IU data structure. |
| 29 | * It's still in use by several different firmware releases. |
| 30 | */ |
| 31 | struct sense_iu_old { |
| 32 | __u8 iu_id; |
| 33 | __u8 rsvd1; |
| 34 | __be16 tag; |
| 35 | __be16 len; |
| 36 | __u8 status; |
| 37 | __u8 service_response; |
| 38 | __u8 sense[SCSI_SENSE_BUFFERSIZE]; |
| 39 | }; |
| 40 | |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 41 | struct uas_dev_info { |
| 42 | struct usb_interface *intf; |
| 43 | struct usb_device *udev; |
Gerd Hoffmann | a0e39e3 | 2012-09-25 10:47:04 +0200 | [diff] [blame] | 44 | struct usb_anchor cmd_urbs; |
Gerd Hoffmann | bdd000f | 2012-06-19 09:54:53 +0200 | [diff] [blame] | 45 | struct usb_anchor sense_urbs; |
| 46 | struct usb_anchor data_urbs; |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 47 | int qdepth, resetting; |
| 48 | struct response_ui response; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 49 | unsigned cmd_pipe, status_pipe, data_in_pipe, data_out_pipe; |
| 50 | unsigned use_streams:1; |
| 51 | unsigned uas_sense_old:1; |
Sebastian Andrzej Siewior | 22188f4 | 2011-12-19 20:22:39 +0100 | [diff] [blame] | 52 | struct scsi_cmnd *cmnd; |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 53 | spinlock_t lock; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | enum { |
Matthew Wilcox | 92a3f76 | 2010-12-15 15:44:04 -0500 | [diff] [blame] | 57 | SUBMIT_STATUS_URB = (1 << 1), |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 58 | ALLOC_DATA_IN_URB = (1 << 2), |
| 59 | SUBMIT_DATA_IN_URB = (1 << 3), |
| 60 | ALLOC_DATA_OUT_URB = (1 << 4), |
| 61 | SUBMIT_DATA_OUT_URB = (1 << 5), |
| 62 | ALLOC_CMD_URB = (1 << 6), |
| 63 | SUBMIT_CMD_URB = (1 << 7), |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 64 | COMMAND_INFLIGHT = (1 << 8), |
| 65 | DATA_IN_URB_INFLIGHT = (1 << 9), |
| 66 | DATA_OUT_URB_INFLIGHT = (1 << 10), |
| 67 | COMMAND_COMPLETED = (1 << 11), |
Gerd Hoffmann | ef018cc9 | 2012-09-25 10:47:06 +0200 | [diff] [blame] | 68 | COMMAND_ABORTED = (1 << 12), |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | /* Overrides scsi_pointer */ |
| 72 | struct uas_cmd_info { |
| 73 | unsigned int state; |
| 74 | unsigned int stream; |
| 75 | struct urb *cmd_urb; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 76 | struct urb *data_in_urb; |
| 77 | struct urb *data_out_urb; |
| 78 | struct list_head list; |
| 79 | }; |
| 80 | |
| 81 | /* I hate forward declarations, but I actually have a loop */ |
| 82 | static int uas_submit_urbs(struct scsi_cmnd *cmnd, |
| 83 | struct uas_dev_info *devinfo, gfp_t gfp); |
Sarah Sharp | ea9da1c | 2011-12-02 11:55:44 -0800 | [diff] [blame] | 84 | static void uas_do_work(struct work_struct *work); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 85 | |
Sarah Sharp | ea9da1c | 2011-12-02 11:55:44 -0800 | [diff] [blame] | 86 | static DECLARE_WORK(uas_work, uas_do_work); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 87 | static DEFINE_SPINLOCK(uas_work_lock); |
| 88 | static LIST_HEAD(uas_work_list); |
| 89 | |
| 90 | static void uas_do_work(struct work_struct *work) |
| 91 | { |
| 92 | struct uas_cmd_info *cmdinfo; |
Sarah Sharp | ea9da1c | 2011-12-02 11:55:44 -0800 | [diff] [blame] | 93 | struct uas_cmd_info *temp; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 94 | struct list_head list; |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 95 | unsigned long flags; |
Sarah Sharp | ea9da1c | 2011-12-02 11:55:44 -0800 | [diff] [blame] | 96 | int err; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 97 | |
| 98 | spin_lock_irq(&uas_work_lock); |
| 99 | list_replace_init(&uas_work_list, &list); |
| 100 | spin_unlock_irq(&uas_work_lock); |
| 101 | |
Sarah Sharp | ea9da1c | 2011-12-02 11:55:44 -0800 | [diff] [blame] | 102 | list_for_each_entry_safe(cmdinfo, temp, &list, list) { |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 103 | struct scsi_pointer *scp = (void *)cmdinfo; |
| 104 | struct scsi_cmnd *cmnd = container_of(scp, |
| 105 | struct scsi_cmnd, SCp); |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 106 | struct uas_dev_info *devinfo = (void *)cmnd->device->hostdata; |
| 107 | spin_lock_irqsave(&devinfo->lock, flags); |
| 108 | err = uas_submit_urbs(cmnd, cmnd->device->hostdata, GFP_ATOMIC); |
| 109 | spin_unlock_irqrestore(&devinfo->lock, flags); |
Sarah Sharp | ea9da1c | 2011-12-02 11:55:44 -0800 | [diff] [blame] | 110 | if (err) { |
| 111 | list_del(&cmdinfo->list); |
| 112 | spin_lock_irq(&uas_work_lock); |
| 113 | list_add_tail(&cmdinfo->list, &uas_work_list); |
| 114 | spin_unlock_irq(&uas_work_lock); |
| 115 | schedule_work(&uas_work); |
| 116 | } |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 120 | static void uas_sense(struct urb *urb, struct scsi_cmnd *cmnd) |
| 121 | { |
| 122 | struct sense_iu *sense_iu = urb->transfer_buffer; |
| 123 | struct scsi_device *sdev = cmnd->device; |
| 124 | |
| 125 | if (urb->actual_length > 16) { |
| 126 | unsigned len = be16_to_cpup(&sense_iu->len); |
| 127 | if (len + 16 != urb->actual_length) { |
| 128 | int newlen = min(len + 16, urb->actual_length) - 16; |
| 129 | if (newlen < 0) |
| 130 | newlen = 0; |
| 131 | sdev_printk(KERN_INFO, sdev, "%s: urb length %d " |
| 132 | "disagrees with IU sense data length %d, " |
| 133 | "using %d bytes of sense data\n", __func__, |
| 134 | urb->actual_length, len, newlen); |
| 135 | len = newlen; |
| 136 | } |
| 137 | memcpy(cmnd->sense_buffer, sense_iu->sense, len); |
| 138 | } |
| 139 | |
| 140 | cmnd->result = sense_iu->status; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | static void uas_sense_old(struct urb *urb, struct scsi_cmnd *cmnd) |
| 144 | { |
| 145 | struct sense_iu_old *sense_iu = urb->transfer_buffer; |
| 146 | struct scsi_device *sdev = cmnd->device; |
| 147 | |
| 148 | if (urb->actual_length > 8) { |
| 149 | unsigned len = be16_to_cpup(&sense_iu->len) - 2; |
| 150 | if (len + 8 != urb->actual_length) { |
| 151 | int newlen = min(len + 8, urb->actual_length) - 8; |
| 152 | if (newlen < 0) |
| 153 | newlen = 0; |
| 154 | sdev_printk(KERN_INFO, sdev, "%s: urb length %d " |
| 155 | "disagrees with IU sense data length %d, " |
| 156 | "using %d bytes of sense data\n", __func__, |
| 157 | urb->actual_length, len, newlen); |
| 158 | len = newlen; |
| 159 | } |
| 160 | memcpy(cmnd->sense_buffer, sense_iu->sense, len); |
| 161 | } |
| 162 | |
| 163 | cmnd->result = sense_iu->status; |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | static void uas_log_cmd_state(struct scsi_cmnd *cmnd, const char *caller) |
| 167 | { |
| 168 | struct uas_cmd_info *ci = (void *)&cmnd->SCp; |
| 169 | |
| 170 | scmd_printk(KERN_INFO, cmnd, "%s %p tag %d, inflight:" |
Gerd Hoffmann | ef018cc9 | 2012-09-25 10:47:06 +0200 | [diff] [blame] | 171 | "%s%s%s%s%s%s%s%s%s%s%s%s\n", |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 172 | caller, cmnd, cmnd->request->tag, |
| 173 | (ci->state & SUBMIT_STATUS_URB) ? " s-st" : "", |
| 174 | (ci->state & ALLOC_DATA_IN_URB) ? " a-in" : "", |
| 175 | (ci->state & SUBMIT_DATA_IN_URB) ? " s-in" : "", |
| 176 | (ci->state & ALLOC_DATA_OUT_URB) ? " a-out" : "", |
| 177 | (ci->state & SUBMIT_DATA_OUT_URB) ? " s-out" : "", |
| 178 | (ci->state & ALLOC_CMD_URB) ? " a-cmd" : "", |
| 179 | (ci->state & SUBMIT_CMD_URB) ? " s-cmd" : "", |
| 180 | (ci->state & COMMAND_INFLIGHT) ? " CMD" : "", |
| 181 | (ci->state & DATA_IN_URB_INFLIGHT) ? " IN" : "", |
| 182 | (ci->state & DATA_OUT_URB_INFLIGHT) ? " OUT" : "", |
Gerd Hoffmann | ef018cc9 | 2012-09-25 10:47:06 +0200 | [diff] [blame] | 183 | (ci->state & COMMAND_COMPLETED) ? " done" : "", |
| 184 | (ci->state & COMMAND_ABORTED) ? " abort" : ""); |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | static int uas_try_complete(struct scsi_cmnd *cmnd, const char *caller) |
| 188 | { |
| 189 | struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 190 | struct uas_dev_info *devinfo = (void *)cmnd->device->hostdata; |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 191 | |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 192 | WARN_ON(!spin_is_locked(&devinfo->lock)); |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 193 | if (cmdinfo->state & (COMMAND_INFLIGHT | |
| 194 | DATA_IN_URB_INFLIGHT | |
| 195 | DATA_OUT_URB_INFLIGHT)) |
| 196 | return -EBUSY; |
| 197 | BUG_ON(cmdinfo->state & COMMAND_COMPLETED); |
| 198 | cmdinfo->state |= COMMAND_COMPLETED; |
| 199 | usb_free_urb(cmdinfo->data_in_urb); |
| 200 | usb_free_urb(cmdinfo->data_out_urb); |
Gerd Hoffmann | 0871d7d | 2012-09-25 10:47:07 +0200 | [diff] [blame] | 201 | if (cmdinfo->state & COMMAND_ABORTED) { |
| 202 | scmd_printk(KERN_INFO, cmnd, "abort completed\n"); |
| 203 | cmnd->result = DID_ABORT << 16; |
| 204 | } |
Gerd Hoffmann | c621a81 | 2012-06-19 09:54:48 +0200 | [diff] [blame] | 205 | cmnd->scsi_done(cmnd); |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 206 | return 0; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | static void uas_xfer_data(struct urb *urb, struct scsi_cmnd *cmnd, |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 210 | unsigned direction) |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 211 | { |
| 212 | struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; |
| 213 | int err; |
| 214 | |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 215 | cmdinfo->state |= direction | SUBMIT_STATUS_URB; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 216 | err = uas_submit_urbs(cmnd, cmnd->device->hostdata, GFP_ATOMIC); |
| 217 | if (err) { |
| 218 | spin_lock(&uas_work_lock); |
| 219 | list_add_tail(&cmdinfo->list, &uas_work_list); |
| 220 | spin_unlock(&uas_work_lock); |
| 221 | schedule_work(&uas_work); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | static void uas_stat_cmplt(struct urb *urb) |
| 226 | { |
| 227 | struct iu *iu = urb->transfer_buffer; |
Sebastian Andrzej Siewior | 22188f4 | 2011-12-19 20:22:39 +0100 | [diff] [blame] | 228 | struct Scsi_Host *shost = urb->context; |
| 229 | struct uas_dev_info *devinfo = (void *)shost->hostdata[0]; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 230 | struct scsi_cmnd *cmnd; |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 231 | struct uas_cmd_info *cmdinfo; |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 232 | unsigned long flags; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 233 | u16 tag; |
| 234 | |
| 235 | if (urb->status) { |
| 236 | dev_err(&urb->dev->dev, "URB BAD STATUS %d\n", urb->status); |
Gerd Hoffmann | db32de1 | 2012-06-19 09:54:49 +0200 | [diff] [blame] | 237 | usb_free_urb(urb); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 238 | return; |
| 239 | } |
| 240 | |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 241 | if (devinfo->resetting) { |
| 242 | usb_free_urb(urb); |
| 243 | return; |
| 244 | } |
| 245 | |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 246 | spin_lock_irqsave(&devinfo->lock, flags); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 247 | tag = be16_to_cpup(&iu->tag) - 1; |
Sebastian Andrzej Siewior | 22188f4 | 2011-12-19 20:22:39 +0100 | [diff] [blame] | 248 | if (tag == 0) |
| 249 | cmnd = devinfo->cmnd; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 250 | else |
Sebastian Andrzej Siewior | 22188f4 | 2011-12-19 20:22:39 +0100 | [diff] [blame] | 251 | cmnd = scsi_host_find_tag(shost, tag - 1); |
Sarah Sharp | 96c1eb9 | 2011-12-02 11:55:48 -0800 | [diff] [blame] | 252 | if (!cmnd) { |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 253 | if (iu->iu_id != IU_ID_RESPONSE) { |
| 254 | usb_free_urb(urb); |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 255 | spin_unlock_irqrestore(&devinfo->lock, flags); |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 256 | return; |
| 257 | } |
| 258 | } else { |
| 259 | cmdinfo = (void *)&cmnd->SCp; |
Sarah Sharp | 96c1eb9 | 2011-12-02 11:55:48 -0800 | [diff] [blame] | 260 | } |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 261 | |
| 262 | switch (iu->iu_id) { |
| 263 | case IU_ID_STATUS: |
Sebastian Andrzej Siewior | 22188f4 | 2011-12-19 20:22:39 +0100 | [diff] [blame] | 264 | if (devinfo->cmnd == cmnd) |
| 265 | devinfo->cmnd = NULL; |
| 266 | |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 267 | if (urb->actual_length < 16) |
| 268 | devinfo->uas_sense_old = 1; |
| 269 | if (devinfo->uas_sense_old) |
| 270 | uas_sense_old(urb, cmnd); |
| 271 | else |
| 272 | uas_sense(urb, cmnd); |
Gerd Hoffmann | 8aac863 | 2012-06-19 09:54:52 +0200 | [diff] [blame] | 273 | if (cmnd->result != 0) { |
| 274 | /* cancel data transfers on error */ |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 275 | if (cmdinfo->state & DATA_IN_URB_INFLIGHT) { |
| 276 | spin_unlock_irqrestore(&devinfo->lock, flags); |
Gerd Hoffmann | 8aac863 | 2012-06-19 09:54:52 +0200 | [diff] [blame] | 277 | usb_unlink_urb(cmdinfo->data_in_urb); |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 278 | spin_lock_irqsave(&devinfo->lock, flags); |
| 279 | } |
| 280 | if (cmdinfo->state & DATA_OUT_URB_INFLIGHT) { |
| 281 | spin_unlock_irqrestore(&devinfo->lock, flags); |
Gerd Hoffmann | 8aac863 | 2012-06-19 09:54:52 +0200 | [diff] [blame] | 282 | usb_unlink_urb(cmdinfo->data_out_urb); |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 283 | spin_lock_irqsave(&devinfo->lock, flags); |
| 284 | } |
Gerd Hoffmann | 8aac863 | 2012-06-19 09:54:52 +0200 | [diff] [blame] | 285 | } |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 286 | cmdinfo->state &= ~COMMAND_INFLIGHT; |
| 287 | uas_try_complete(cmnd, __func__); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 288 | break; |
| 289 | case IU_ID_READ_READY: |
| 290 | uas_xfer_data(urb, cmnd, SUBMIT_DATA_IN_URB); |
| 291 | break; |
| 292 | case IU_ID_WRITE_READY: |
| 293 | uas_xfer_data(urb, cmnd, SUBMIT_DATA_OUT_URB); |
| 294 | break; |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 295 | case IU_ID_RESPONSE: |
| 296 | /* store results for uas_eh_task_mgmt() */ |
| 297 | memcpy(&devinfo->response, iu, sizeof(devinfo->response)); |
| 298 | break; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 299 | default: |
| 300 | scmd_printk(KERN_ERR, cmnd, |
| 301 | "Bogus IU (%d) received on status pipe\n", iu->iu_id); |
| 302 | } |
Gerd Hoffmann | e9bd7e1 | 2012-06-19 09:54:50 +0200 | [diff] [blame] | 303 | usb_free_urb(urb); |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 304 | spin_unlock_irqrestore(&devinfo->lock, flags); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 305 | } |
| 306 | |
Gerd Hoffmann | c621a81 | 2012-06-19 09:54:48 +0200 | [diff] [blame] | 307 | static void uas_data_cmplt(struct urb *urb) |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 308 | { |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 309 | struct scsi_cmnd *cmnd = urb->context; |
| 310 | struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 311 | struct uas_dev_info *devinfo = (void *)cmnd->device->hostdata; |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 312 | struct scsi_data_buffer *sdb = NULL; |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 313 | unsigned long flags; |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 314 | |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 315 | spin_lock_irqsave(&devinfo->lock, flags); |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 316 | if (cmdinfo->data_in_urb == urb) { |
| 317 | sdb = scsi_in(cmnd); |
| 318 | cmdinfo->state &= ~DATA_IN_URB_INFLIGHT; |
| 319 | } else if (cmdinfo->data_out_urb == urb) { |
| 320 | sdb = scsi_out(cmnd); |
| 321 | cmdinfo->state &= ~DATA_OUT_URB_INFLIGHT; |
| 322 | } |
| 323 | BUG_ON(sdb == NULL); |
Gerd Hoffmann | 8aac863 | 2012-06-19 09:54:52 +0200 | [diff] [blame] | 324 | if (urb->status) { |
| 325 | /* error: no data transfered */ |
| 326 | sdb->resid = sdb->length; |
| 327 | } else { |
| 328 | sdb->resid = sdb->length - urb->actual_length; |
| 329 | } |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 330 | uas_try_complete(cmnd, __func__); |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 331 | spin_unlock_irqrestore(&devinfo->lock, flags); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | static struct urb *uas_alloc_data_urb(struct uas_dev_info *devinfo, gfp_t gfp, |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 335 | unsigned int pipe, u16 stream_id, |
| 336 | struct scsi_cmnd *cmnd, |
| 337 | enum dma_data_direction dir) |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 338 | { |
| 339 | struct usb_device *udev = devinfo->udev; |
| 340 | struct urb *urb = usb_alloc_urb(0, gfp); |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 341 | struct scsi_data_buffer *sdb = (dir == DMA_FROM_DEVICE) |
| 342 | ? scsi_in(cmnd) : scsi_out(cmnd); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 343 | |
| 344 | if (!urb) |
| 345 | goto out; |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 346 | usb_fill_bulk_urb(urb, udev, pipe, NULL, sdb->length, |
| 347 | uas_data_cmplt, cmnd); |
Gerd Hoffmann | c621a81 | 2012-06-19 09:54:48 +0200 | [diff] [blame] | 348 | if (devinfo->use_streams) |
| 349 | urb->stream_id = stream_id; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 350 | urb->num_sgs = udev->bus->sg_tablesize ? sdb->table.nents : 0; |
| 351 | urb->sg = sdb->table.sgl; |
| 352 | out: |
| 353 | return urb; |
| 354 | } |
| 355 | |
| 356 | static struct urb *uas_alloc_sense_urb(struct uas_dev_info *devinfo, gfp_t gfp, |
Gerd Hoffmann | e9bd7e1 | 2012-06-19 09:54:50 +0200 | [diff] [blame] | 357 | struct Scsi_Host *shost, u16 stream_id) |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 358 | { |
| 359 | struct usb_device *udev = devinfo->udev; |
| 360 | struct urb *urb = usb_alloc_urb(0, gfp); |
| 361 | struct sense_iu *iu; |
| 362 | |
| 363 | if (!urb) |
| 364 | goto out; |
| 365 | |
Matthew Wilcox | ac563cf | 2010-12-15 15:44:03 -0500 | [diff] [blame] | 366 | iu = kzalloc(sizeof(*iu), gfp); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 367 | if (!iu) |
| 368 | goto free; |
| 369 | |
| 370 | usb_fill_bulk_urb(urb, udev, devinfo->status_pipe, iu, sizeof(*iu), |
Gerd Hoffmann | e9bd7e1 | 2012-06-19 09:54:50 +0200 | [diff] [blame] | 371 | uas_stat_cmplt, shost); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 372 | urb->stream_id = stream_id; |
| 373 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 374 | out: |
| 375 | return urb; |
| 376 | free: |
| 377 | usb_free_urb(urb); |
| 378 | return NULL; |
| 379 | } |
| 380 | |
| 381 | static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp, |
| 382 | struct scsi_cmnd *cmnd, u16 stream_id) |
| 383 | { |
| 384 | struct usb_device *udev = devinfo->udev; |
| 385 | struct scsi_device *sdev = cmnd->device; |
| 386 | struct urb *urb = usb_alloc_urb(0, gfp); |
| 387 | struct command_iu *iu; |
| 388 | int len; |
| 389 | |
| 390 | if (!urb) |
| 391 | goto out; |
| 392 | |
| 393 | len = cmnd->cmd_len - 16; |
| 394 | if (len < 0) |
| 395 | len = 0; |
| 396 | len = ALIGN(len, 4); |
Matthew Wilcox | ac563cf | 2010-12-15 15:44:03 -0500 | [diff] [blame] | 397 | iu = kzalloc(sizeof(*iu) + len, gfp); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 398 | if (!iu) |
| 399 | goto free; |
| 400 | |
| 401 | iu->iu_id = IU_ID_COMMAND; |
Sarah Sharp | 9eb4454 | 2011-12-02 11:55:46 -0800 | [diff] [blame] | 402 | if (blk_rq_tagged(cmnd->request)) |
Sebastian Andrzej Siewior | 22188f4 | 2011-12-19 20:22:39 +0100 | [diff] [blame] | 403 | iu->tag = cpu_to_be16(cmnd->request->tag + 2); |
Sarah Sharp | 9eb4454 | 2011-12-02 11:55:46 -0800 | [diff] [blame] | 404 | else |
| 405 | iu->tag = cpu_to_be16(1); |
Christoph Hellwig | 02e031c | 2010-11-10 14:54:09 +0100 | [diff] [blame] | 406 | iu->prio_attr = UAS_SIMPLE_TAG; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 407 | iu->len = len; |
| 408 | int_to_scsilun(sdev->lun, &iu->lun); |
| 409 | memcpy(iu->cdb, cmnd->cmnd, cmnd->cmd_len); |
| 410 | |
| 411 | usb_fill_bulk_urb(urb, udev, devinfo->cmd_pipe, iu, sizeof(*iu) + len, |
| 412 | usb_free_urb, NULL); |
| 413 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 414 | out: |
| 415 | return urb; |
| 416 | free: |
| 417 | usb_free_urb(urb); |
| 418 | return NULL; |
| 419 | } |
| 420 | |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 421 | static int uas_submit_task_urb(struct scsi_cmnd *cmnd, gfp_t gfp, |
| 422 | u8 function, u16 stream_id) |
| 423 | { |
| 424 | struct uas_dev_info *devinfo = (void *)cmnd->device->hostdata; |
| 425 | struct usb_device *udev = devinfo->udev; |
| 426 | struct urb *urb = usb_alloc_urb(0, gfp); |
| 427 | struct task_mgmt_iu *iu; |
| 428 | int err = -ENOMEM; |
| 429 | |
| 430 | if (!urb) |
| 431 | goto err; |
| 432 | |
| 433 | iu = kzalloc(sizeof(*iu), gfp); |
| 434 | if (!iu) |
| 435 | goto err; |
| 436 | |
| 437 | iu->iu_id = IU_ID_TASK_MGMT; |
| 438 | iu->tag = cpu_to_be16(stream_id); |
| 439 | int_to_scsilun(cmnd->device->lun, &iu->lun); |
| 440 | |
| 441 | iu->function = function; |
| 442 | switch (function) { |
| 443 | case TMF_ABORT_TASK: |
| 444 | if (blk_rq_tagged(cmnd->request)) |
| 445 | iu->task_tag = cpu_to_be16(cmnd->request->tag + 2); |
| 446 | else |
| 447 | iu->task_tag = cpu_to_be16(1); |
| 448 | break; |
| 449 | } |
| 450 | |
| 451 | usb_fill_bulk_urb(urb, udev, devinfo->cmd_pipe, iu, sizeof(*iu), |
| 452 | usb_free_urb, NULL); |
| 453 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 454 | |
| 455 | err = usb_submit_urb(urb, gfp); |
| 456 | if (err) |
| 457 | goto err; |
Gerd Hoffmann | a0e39e3 | 2012-09-25 10:47:04 +0200 | [diff] [blame] | 458 | usb_anchor_urb(urb, &devinfo->cmd_urbs); |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 459 | |
| 460 | return 0; |
| 461 | |
| 462 | err: |
| 463 | usb_free_urb(urb); |
| 464 | return err; |
| 465 | } |
| 466 | |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 467 | /* |
| 468 | * Why should I request the Status IU before sending the Command IU? Spec |
| 469 | * says to, but also says the device may receive them in any order. Seems |
| 470 | * daft to me. |
| 471 | */ |
| 472 | |
Gerd Hoffmann | e9bd7e1 | 2012-06-19 09:54:50 +0200 | [diff] [blame] | 473 | static int uas_submit_sense_urb(struct Scsi_Host *shost, |
| 474 | gfp_t gfp, unsigned int stream) |
| 475 | { |
| 476 | struct uas_dev_info *devinfo = (void *)shost->hostdata[0]; |
| 477 | struct urb *urb; |
| 478 | |
| 479 | urb = uas_alloc_sense_urb(devinfo, gfp, shost, stream); |
| 480 | if (!urb) |
| 481 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 482 | if (usb_submit_urb(urb, gfp)) { |
| 483 | shost_printk(KERN_INFO, shost, |
| 484 | "sense urb submission failure\n"); |
| 485 | usb_free_urb(urb); |
| 486 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 487 | } |
Gerd Hoffmann | bdd000f | 2012-06-19 09:54:53 +0200 | [diff] [blame] | 488 | usb_anchor_urb(urb, &devinfo->sense_urbs); |
Gerd Hoffmann | e9bd7e1 | 2012-06-19 09:54:50 +0200 | [diff] [blame] | 489 | return 0; |
| 490 | } |
| 491 | |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 492 | static int uas_submit_urbs(struct scsi_cmnd *cmnd, |
Gerd Hoffmann | e9bd7e1 | 2012-06-19 09:54:50 +0200 | [diff] [blame] | 493 | struct uas_dev_info *devinfo, gfp_t gfp) |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 494 | { |
| 495 | struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; |
Gerd Hoffmann | e9bd7e1 | 2012-06-19 09:54:50 +0200 | [diff] [blame] | 496 | int err; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 497 | |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 498 | WARN_ON(!spin_is_locked(&devinfo->lock)); |
Matthew Wilcox | 92a3f76 | 2010-12-15 15:44:04 -0500 | [diff] [blame] | 499 | if (cmdinfo->state & SUBMIT_STATUS_URB) { |
Gerd Hoffmann | e9bd7e1 | 2012-06-19 09:54:50 +0200 | [diff] [blame] | 500 | err = uas_submit_sense_urb(cmnd->device->host, gfp, |
| 501 | cmdinfo->stream); |
| 502 | if (err) { |
| 503 | return err; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 504 | } |
Matthew Wilcox | 92a3f76 | 2010-12-15 15:44:04 -0500 | [diff] [blame] | 505 | cmdinfo->state &= ~SUBMIT_STATUS_URB; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | if (cmdinfo->state & ALLOC_DATA_IN_URB) { |
| 509 | cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, gfp, |
Gerd Hoffmann | c621a81 | 2012-06-19 09:54:48 +0200 | [diff] [blame] | 510 | devinfo->data_in_pipe, cmdinfo->stream, |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 511 | cmnd, DMA_FROM_DEVICE); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 512 | if (!cmdinfo->data_in_urb) |
| 513 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 514 | cmdinfo->state &= ~ALLOC_DATA_IN_URB; |
| 515 | } |
| 516 | |
| 517 | if (cmdinfo->state & SUBMIT_DATA_IN_URB) { |
| 518 | if (usb_submit_urb(cmdinfo->data_in_urb, gfp)) { |
| 519 | scmd_printk(KERN_INFO, cmnd, |
| 520 | "data in urb submission failure\n"); |
| 521 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 522 | } |
| 523 | cmdinfo->state &= ~SUBMIT_DATA_IN_URB; |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 524 | cmdinfo->state |= DATA_IN_URB_INFLIGHT; |
Gerd Hoffmann | bdd000f | 2012-06-19 09:54:53 +0200 | [diff] [blame] | 525 | usb_anchor_urb(cmdinfo->data_in_urb, &devinfo->data_urbs); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | if (cmdinfo->state & ALLOC_DATA_OUT_URB) { |
| 529 | cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, gfp, |
Gerd Hoffmann | c621a81 | 2012-06-19 09:54:48 +0200 | [diff] [blame] | 530 | devinfo->data_out_pipe, cmdinfo->stream, |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 531 | cmnd, DMA_TO_DEVICE); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 532 | if (!cmdinfo->data_out_urb) |
| 533 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 534 | cmdinfo->state &= ~ALLOC_DATA_OUT_URB; |
| 535 | } |
| 536 | |
| 537 | if (cmdinfo->state & SUBMIT_DATA_OUT_URB) { |
| 538 | if (usb_submit_urb(cmdinfo->data_out_urb, gfp)) { |
| 539 | scmd_printk(KERN_INFO, cmnd, |
| 540 | "data out urb submission failure\n"); |
| 541 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 542 | } |
| 543 | cmdinfo->state &= ~SUBMIT_DATA_OUT_URB; |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 544 | cmdinfo->state |= DATA_OUT_URB_INFLIGHT; |
Gerd Hoffmann | bdd000f | 2012-06-19 09:54:53 +0200 | [diff] [blame] | 545 | usb_anchor_urb(cmdinfo->data_out_urb, &devinfo->data_urbs); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | if (cmdinfo->state & ALLOC_CMD_URB) { |
| 549 | cmdinfo->cmd_urb = uas_alloc_cmd_urb(devinfo, gfp, cmnd, |
Gerd Hoffmann | a0e39e3 | 2012-09-25 10:47:04 +0200 | [diff] [blame] | 550 | cmdinfo->stream); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 551 | if (!cmdinfo->cmd_urb) |
| 552 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 553 | cmdinfo->state &= ~ALLOC_CMD_URB; |
| 554 | } |
| 555 | |
| 556 | if (cmdinfo->state & SUBMIT_CMD_URB) { |
Gerd Hoffmann | a0e39e3 | 2012-09-25 10:47:04 +0200 | [diff] [blame] | 557 | usb_get_urb(cmdinfo->cmd_urb); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 558 | if (usb_submit_urb(cmdinfo->cmd_urb, gfp)) { |
| 559 | scmd_printk(KERN_INFO, cmnd, |
| 560 | "cmd urb submission failure\n"); |
| 561 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 562 | } |
Gerd Hoffmann | a0e39e3 | 2012-09-25 10:47:04 +0200 | [diff] [blame] | 563 | usb_anchor_urb(cmdinfo->cmd_urb, &devinfo->cmd_urbs); |
| 564 | usb_put_urb(cmdinfo->cmd_urb); |
| 565 | cmdinfo->cmd_urb = NULL; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 566 | cmdinfo->state &= ~SUBMIT_CMD_URB; |
Gerd Hoffmann | b1d6769 | 2012-06-19 09:54:51 +0200 | [diff] [blame] | 567 | cmdinfo->state |= COMMAND_INFLIGHT; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 573 | static int uas_queuecommand_lck(struct scsi_cmnd *cmnd, |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 574 | void (*done)(struct scsi_cmnd *)) |
| 575 | { |
| 576 | struct scsi_device *sdev = cmnd->device; |
| 577 | struct uas_dev_info *devinfo = sdev->hostdata; |
| 578 | struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 579 | unsigned long flags; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 580 | int err; |
| 581 | |
| 582 | BUILD_BUG_ON(sizeof(struct uas_cmd_info) > sizeof(struct scsi_pointer)); |
| 583 | |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 584 | spin_lock_irqsave(&devinfo->lock, flags); |
| 585 | if (devinfo->cmnd) { |
| 586 | spin_unlock_irqrestore(&devinfo->lock, flags); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 587 | return SCSI_MLQUEUE_DEVICE_BUSY; |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 588 | } |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 589 | |
| 590 | if (blk_rq_tagged(cmnd->request)) { |
Sebastian Andrzej Siewior | 22188f4 | 2011-12-19 20:22:39 +0100 | [diff] [blame] | 591 | cmdinfo->stream = cmnd->request->tag + 2; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 592 | } else { |
Sebastian Andrzej Siewior | 22188f4 | 2011-12-19 20:22:39 +0100 | [diff] [blame] | 593 | devinfo->cmnd = cmnd; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 594 | cmdinfo->stream = 1; |
| 595 | } |
| 596 | |
| 597 | cmnd->scsi_done = done; |
| 598 | |
Gerd Hoffmann | e9bd7e1 | 2012-06-19 09:54:50 +0200 | [diff] [blame] | 599 | cmdinfo->state = SUBMIT_STATUS_URB | |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 600 | ALLOC_CMD_URB | SUBMIT_CMD_URB; |
| 601 | |
| 602 | switch (cmnd->sc_data_direction) { |
| 603 | case DMA_FROM_DEVICE: |
| 604 | cmdinfo->state |= ALLOC_DATA_IN_URB | SUBMIT_DATA_IN_URB; |
| 605 | break; |
| 606 | case DMA_BIDIRECTIONAL: |
| 607 | cmdinfo->state |= ALLOC_DATA_IN_URB | SUBMIT_DATA_IN_URB; |
| 608 | case DMA_TO_DEVICE: |
| 609 | cmdinfo->state |= ALLOC_DATA_OUT_URB | SUBMIT_DATA_OUT_URB; |
| 610 | case DMA_NONE: |
| 611 | break; |
| 612 | } |
| 613 | |
| 614 | if (!devinfo->use_streams) { |
Gerd Hoffmann | db32de1 | 2012-06-19 09:54:49 +0200 | [diff] [blame] | 615 | cmdinfo->state &= ~(SUBMIT_DATA_IN_URB | SUBMIT_DATA_OUT_URB); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 616 | cmdinfo->stream = 0; |
| 617 | } |
| 618 | |
| 619 | err = uas_submit_urbs(cmnd, devinfo, GFP_ATOMIC); |
| 620 | if (err) { |
| 621 | /* If we did nothing, give up now */ |
Matthew Wilcox | 92a3f76 | 2010-12-15 15:44:04 -0500 | [diff] [blame] | 622 | if (cmdinfo->state & SUBMIT_STATUS_URB) { |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 623 | spin_unlock_irqrestore(&devinfo->lock, flags); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 624 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 625 | } |
| 626 | spin_lock(&uas_work_lock); |
| 627 | list_add_tail(&cmdinfo->list, &uas_work_list); |
| 628 | spin_unlock(&uas_work_lock); |
| 629 | schedule_work(&uas_work); |
| 630 | } |
| 631 | |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 632 | spin_unlock_irqrestore(&devinfo->lock, flags); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 633 | return 0; |
| 634 | } |
| 635 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 636 | static DEF_SCSI_QCMD(uas_queuecommand) |
| 637 | |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 638 | static int uas_eh_task_mgmt(struct scsi_cmnd *cmnd, |
| 639 | const char *fname, u8 function) |
| 640 | { |
| 641 | struct Scsi_Host *shost = cmnd->device->host; |
| 642 | struct uas_dev_info *devinfo = (void *)shost->hostdata[0]; |
Gerd Hoffmann | 0393986 | 2012-09-25 10:47:05 +0200 | [diff] [blame] | 643 | u16 tag = devinfo->qdepth - 1; |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 644 | unsigned long flags; |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 645 | |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 646 | spin_lock_irqsave(&devinfo->lock, flags); |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 647 | memset(&devinfo->response, 0, sizeof(devinfo->response)); |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 648 | if (uas_submit_sense_urb(shost, GFP_ATOMIC, tag)) { |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 649 | shost_printk(KERN_INFO, shost, |
| 650 | "%s: %s: submit sense urb failed\n", |
| 651 | __func__, fname); |
| 652 | return FAILED; |
| 653 | } |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 654 | if (uas_submit_task_urb(cmnd, GFP_ATOMIC, function, tag)) { |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 655 | shost_printk(KERN_INFO, shost, |
| 656 | "%s: %s: submit task mgmt urb failed\n", |
| 657 | __func__, fname); |
| 658 | return FAILED; |
| 659 | } |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 660 | spin_unlock_irqrestore(&devinfo->lock, flags); |
| 661 | |
| 662 | if (usb_wait_anchor_empty_timeout(&devinfo->sense_urbs, 3000) == 0) { |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 663 | shost_printk(KERN_INFO, shost, |
| 664 | "%s: %s timed out\n", __func__, fname); |
| 665 | return FAILED; |
| 666 | } |
| 667 | if (be16_to_cpu(devinfo->response.tag) != tag) { |
| 668 | shost_printk(KERN_INFO, shost, |
| 669 | "%s: %s failed (wrong tag %d/%d)\n", __func__, |
| 670 | fname, be16_to_cpu(devinfo->response.tag), tag); |
| 671 | return FAILED; |
| 672 | } |
| 673 | if (devinfo->response.response_code != RC_TMF_COMPLETE) { |
| 674 | shost_printk(KERN_INFO, shost, |
| 675 | "%s: %s failed (rc 0x%x)\n", __func__, |
| 676 | fname, devinfo->response.response_code); |
| 677 | return FAILED; |
| 678 | } |
| 679 | return SUCCESS; |
| 680 | } |
| 681 | |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 682 | static int uas_eh_abort_handler(struct scsi_cmnd *cmnd) |
| 683 | { |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 684 | struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 685 | struct uas_dev_info *devinfo = (void *)cmnd->device->hostdata; |
| 686 | unsigned long flags; |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 687 | int ret; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 688 | |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 689 | uas_log_cmd_state(cmnd, __func__); |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 690 | spin_lock_irqsave(&devinfo->lock, flags); |
Gerd Hoffmann | ef018cc9 | 2012-09-25 10:47:06 +0200 | [diff] [blame] | 691 | cmdinfo->state |= COMMAND_ABORTED; |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 692 | spin_unlock_irqrestore(&devinfo->lock, flags); |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 693 | ret = uas_eh_task_mgmt(cmnd, "ABORT TASK", TMF_ABORT_TASK); |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 694 | return ret; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | static int uas_eh_device_reset_handler(struct scsi_cmnd *cmnd) |
| 698 | { |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 699 | sdev_printk(KERN_INFO, cmnd->device, "%s\n", __func__); |
| 700 | return uas_eh_task_mgmt(cmnd, "LOGICAL UNIT RESET", |
| 701 | TMF_LOGICAL_UNIT_RESET); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | static int uas_eh_bus_reset_handler(struct scsi_cmnd *cmnd) |
| 705 | { |
| 706 | struct scsi_device *sdev = cmnd->device; |
| 707 | struct uas_dev_info *devinfo = sdev->hostdata; |
| 708 | struct usb_device *udev = devinfo->udev; |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 709 | int err; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 710 | |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 711 | devinfo->resetting = 1; |
Gerd Hoffmann | a0e39e3 | 2012-09-25 10:47:04 +0200 | [diff] [blame] | 712 | usb_kill_anchored_urbs(&devinfo->cmd_urbs); |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 713 | usb_kill_anchored_urbs(&devinfo->sense_urbs); |
| 714 | usb_kill_anchored_urbs(&devinfo->data_urbs); |
| 715 | err = usb_reset_device(udev); |
| 716 | devinfo->resetting = 0; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 717 | |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 718 | if (err) { |
| 719 | shost_printk(KERN_INFO, sdev->host, "%s FAILED\n", __func__); |
| 720 | return FAILED; |
| 721 | } |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 722 | |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 723 | shost_printk(KERN_INFO, sdev->host, "%s success\n", __func__); |
| 724 | return SUCCESS; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | static int uas_slave_alloc(struct scsi_device *sdev) |
| 728 | { |
| 729 | sdev->hostdata = (void *)sdev->host->hostdata[0]; |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | static int uas_slave_configure(struct scsi_device *sdev) |
| 734 | { |
| 735 | struct uas_dev_info *devinfo = sdev->hostdata; |
| 736 | scsi_set_tag_type(sdev, MSG_ORDERED_TAG); |
Gerd Hoffmann | 0393986 | 2012-09-25 10:47:05 +0200 | [diff] [blame] | 737 | scsi_activate_tcq(sdev, devinfo->qdepth - 3); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | static struct scsi_host_template uas_host_template = { |
| 742 | .module = THIS_MODULE, |
| 743 | .name = "uas", |
| 744 | .queuecommand = uas_queuecommand, |
| 745 | .slave_alloc = uas_slave_alloc, |
| 746 | .slave_configure = uas_slave_configure, |
| 747 | .eh_abort_handler = uas_eh_abort_handler, |
| 748 | .eh_device_reset_handler = uas_eh_device_reset_handler, |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 749 | .eh_bus_reset_handler = uas_eh_bus_reset_handler, |
| 750 | .can_queue = 65536, /* Is there a limit on the _host_ ? */ |
| 751 | .this_id = -1, |
| 752 | .sg_tablesize = SG_NONE, |
| 753 | .cmd_per_lun = 1, /* until we override it */ |
| 754 | .skip_settle_delay = 1, |
| 755 | .ordered_tag = 1, |
| 756 | }; |
| 757 | |
| 758 | static struct usb_device_id uas_usb_ids[] = { |
| 759 | { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, USB_SC_SCSI, USB_PR_BULK) }, |
| 760 | { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, USB_SC_SCSI, USB_PR_UAS) }, |
| 761 | /* 0xaa is a prototype device I happen to have access to */ |
| 762 | { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, USB_SC_SCSI, 0xaa) }, |
| 763 | { } |
| 764 | }; |
| 765 | MODULE_DEVICE_TABLE(usb, uas_usb_ids); |
| 766 | |
Matthew Wilcox | 89dc290 | 2010-12-15 15:44:05 -0500 | [diff] [blame] | 767 | static int uas_is_interface(struct usb_host_interface *intf) |
| 768 | { |
| 769 | return (intf->desc.bInterfaceClass == USB_CLASS_MASS_STORAGE && |
| 770 | intf->desc.bInterfaceSubClass == USB_SC_SCSI && |
| 771 | intf->desc.bInterfaceProtocol == USB_PR_UAS); |
| 772 | } |
| 773 | |
Sebastian Andrzej Siewior | c898add | 2012-01-11 12:42:32 +0100 | [diff] [blame] | 774 | static int uas_isnt_supported(struct usb_device *udev) |
| 775 | { |
| 776 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); |
| 777 | |
| 778 | dev_warn(&udev->dev, "The driver for the USB controller %s does not " |
| 779 | "support scatter-gather which is\n", |
| 780 | hcd->driver->description); |
| 781 | dev_warn(&udev->dev, "required by the UAS driver. Please try an" |
| 782 | "alternative USB controller if you wish to use UAS.\n"); |
| 783 | return -ENODEV; |
| 784 | } |
| 785 | |
Matthew Wilcox | 89dc290 | 2010-12-15 15:44:05 -0500 | [diff] [blame] | 786 | static int uas_switch_interface(struct usb_device *udev, |
| 787 | struct usb_interface *intf) |
| 788 | { |
| 789 | int i; |
Sebastian Andrzej Siewior | c898add | 2012-01-11 12:42:32 +0100 | [diff] [blame] | 790 | int sg_supported = udev->bus->sg_tablesize != 0; |
Matthew Wilcox | 89dc290 | 2010-12-15 15:44:05 -0500 | [diff] [blame] | 791 | |
| 792 | for (i = 0; i < intf->num_altsetting; i++) { |
| 793 | struct usb_host_interface *alt = &intf->altsetting[i]; |
Sebastian Andrzej Siewior | c898add | 2012-01-11 12:42:32 +0100 | [diff] [blame] | 794 | |
| 795 | if (uas_is_interface(alt)) { |
| 796 | if (!sg_supported) |
| 797 | return uas_isnt_supported(udev); |
Matthew Wilcox | 89dc290 | 2010-12-15 15:44:05 -0500 | [diff] [blame] | 798 | return usb_set_interface(udev, |
| 799 | alt->desc.bInterfaceNumber, |
| 800 | alt->desc.bAlternateSetting); |
Sebastian Andrzej Siewior | c898add | 2012-01-11 12:42:32 +0100 | [diff] [blame] | 801 | } |
Matthew Wilcox | 89dc290 | 2010-12-15 15:44:05 -0500 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | return -ENODEV; |
| 805 | } |
| 806 | |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 807 | static void uas_configure_endpoints(struct uas_dev_info *devinfo) |
| 808 | { |
| 809 | struct usb_host_endpoint *eps[4] = { }; |
| 810 | struct usb_interface *intf = devinfo->intf; |
| 811 | struct usb_device *udev = devinfo->udev; |
| 812 | struct usb_host_endpoint *endpoint = intf->cur_altsetting->endpoint; |
| 813 | unsigned i, n_endpoints = intf->cur_altsetting->desc.bNumEndpoints; |
| 814 | |
| 815 | devinfo->uas_sense_old = 0; |
Sebastian Andrzej Siewior | 22188f4 | 2011-12-19 20:22:39 +0100 | [diff] [blame] | 816 | devinfo->cmnd = NULL; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 817 | |
| 818 | for (i = 0; i < n_endpoints; i++) { |
| 819 | unsigned char *extra = endpoint[i].extra; |
| 820 | int len = endpoint[i].extralen; |
| 821 | while (len > 1) { |
| 822 | if (extra[1] == USB_DT_PIPE_USAGE) { |
| 823 | unsigned pipe_id = extra[2]; |
| 824 | if (pipe_id > 0 && pipe_id < 5) |
| 825 | eps[pipe_id - 1] = &endpoint[i]; |
| 826 | break; |
| 827 | } |
| 828 | len -= extra[0]; |
| 829 | extra += extra[0]; |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | /* |
| 834 | * Assume that if we didn't find a control pipe descriptor, we're |
| 835 | * using a device with old firmware that happens to be set up like |
| 836 | * this. |
| 837 | */ |
| 838 | if (!eps[0]) { |
| 839 | devinfo->cmd_pipe = usb_sndbulkpipe(udev, 1); |
| 840 | devinfo->status_pipe = usb_rcvbulkpipe(udev, 1); |
| 841 | devinfo->data_in_pipe = usb_rcvbulkpipe(udev, 2); |
| 842 | devinfo->data_out_pipe = usb_sndbulkpipe(udev, 2); |
| 843 | |
| 844 | eps[1] = usb_pipe_endpoint(udev, devinfo->status_pipe); |
| 845 | eps[2] = usb_pipe_endpoint(udev, devinfo->data_in_pipe); |
| 846 | eps[3] = usb_pipe_endpoint(udev, devinfo->data_out_pipe); |
| 847 | } else { |
| 848 | devinfo->cmd_pipe = usb_sndbulkpipe(udev, |
| 849 | eps[0]->desc.bEndpointAddress); |
| 850 | devinfo->status_pipe = usb_rcvbulkpipe(udev, |
| 851 | eps[1]->desc.bEndpointAddress); |
| 852 | devinfo->data_in_pipe = usb_rcvbulkpipe(udev, |
| 853 | eps[2]->desc.bEndpointAddress); |
| 854 | devinfo->data_out_pipe = usb_sndbulkpipe(udev, |
| 855 | eps[3]->desc.bEndpointAddress); |
| 856 | } |
| 857 | |
| 858 | devinfo->qdepth = usb_alloc_streams(devinfo->intf, eps + 1, 3, 256, |
| 859 | GFP_KERNEL); |
| 860 | if (devinfo->qdepth < 0) { |
| 861 | devinfo->qdepth = 256; |
| 862 | devinfo->use_streams = 0; |
| 863 | } else { |
| 864 | devinfo->use_streams = 1; |
| 865 | } |
| 866 | } |
| 867 | |
Sebastian Andrzej Siewior | dae5154 | 2011-12-19 17:06:08 +0100 | [diff] [blame] | 868 | static void uas_free_streams(struct uas_dev_info *devinfo) |
| 869 | { |
| 870 | struct usb_device *udev = devinfo->udev; |
| 871 | struct usb_host_endpoint *eps[3]; |
| 872 | |
| 873 | eps[0] = usb_pipe_endpoint(udev, devinfo->status_pipe); |
| 874 | eps[1] = usb_pipe_endpoint(udev, devinfo->data_in_pipe); |
| 875 | eps[2] = usb_pipe_endpoint(udev, devinfo->data_out_pipe); |
| 876 | usb_free_streams(devinfo->intf, eps, 3, GFP_KERNEL); |
| 877 | } |
| 878 | |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 879 | /* |
| 880 | * XXX: What I'd like to do here is register a SCSI host for each USB host in |
| 881 | * the system. Follow usb-storage's design of registering a SCSI host for |
| 882 | * each USB device for the moment. Can implement this by walking up the |
| 883 | * USB hierarchy until we find a USB host. |
| 884 | */ |
| 885 | static int uas_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 886 | { |
| 887 | int result; |
| 888 | struct Scsi_Host *shost; |
| 889 | struct uas_dev_info *devinfo; |
| 890 | struct usb_device *udev = interface_to_usbdev(intf); |
| 891 | |
Matthew Wilcox | 89dc290 | 2010-12-15 15:44:05 -0500 | [diff] [blame] | 892 | if (uas_switch_interface(udev, intf)) |
| 893 | return -ENODEV; |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 894 | |
| 895 | devinfo = kmalloc(sizeof(struct uas_dev_info), GFP_KERNEL); |
| 896 | if (!devinfo) |
| 897 | return -ENOMEM; |
| 898 | |
| 899 | result = -ENOMEM; |
| 900 | shost = scsi_host_alloc(&uas_host_template, sizeof(void *)); |
| 901 | if (!shost) |
| 902 | goto free; |
| 903 | |
| 904 | shost->max_cmd_len = 16 + 252; |
| 905 | shost->max_id = 1; |
| 906 | shost->sg_tablesize = udev->bus->sg_tablesize; |
| 907 | |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 908 | devinfo->intf = intf; |
| 909 | devinfo->udev = udev; |
Gerd Hoffmann | 023b515 | 2012-06-19 09:54:54 +0200 | [diff] [blame] | 910 | devinfo->resetting = 0; |
Gerd Hoffmann | a0e39e3 | 2012-09-25 10:47:04 +0200 | [diff] [blame] | 911 | init_usb_anchor(&devinfo->cmd_urbs); |
Gerd Hoffmann | bdd000f | 2012-06-19 09:54:53 +0200 | [diff] [blame] | 912 | init_usb_anchor(&devinfo->sense_urbs); |
| 913 | init_usb_anchor(&devinfo->data_urbs); |
Gerd Hoffmann | e064852 | 2012-09-25 10:47:08 +0200 | [diff] [blame^] | 914 | spin_lock_init(&devinfo->lock); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 915 | uas_configure_endpoints(devinfo); |
| 916 | |
Gerd Hoffmann | 0393986 | 2012-09-25 10:47:05 +0200 | [diff] [blame] | 917 | result = scsi_init_shared_tag_map(shost, devinfo->qdepth - 3); |
Sebastian Andrzej Siewior | dae5154 | 2011-12-19 17:06:08 +0100 | [diff] [blame] | 918 | if (result) |
| 919 | goto free; |
| 920 | |
| 921 | result = scsi_add_host(shost, &intf->dev); |
| 922 | if (result) |
| 923 | goto deconfig_eps; |
| 924 | |
| 925 | shost->hostdata[0] = (unsigned long)devinfo; |
| 926 | |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 927 | scsi_scan_host(shost); |
| 928 | usb_set_intfdata(intf, shost); |
| 929 | return result; |
Sebastian Andrzej Siewior | dae5154 | 2011-12-19 17:06:08 +0100 | [diff] [blame] | 930 | |
| 931 | deconfig_eps: |
| 932 | uas_free_streams(devinfo); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 933 | free: |
| 934 | kfree(devinfo); |
| 935 | if (shost) |
| 936 | scsi_host_put(shost); |
| 937 | return result; |
| 938 | } |
| 939 | |
| 940 | static int uas_pre_reset(struct usb_interface *intf) |
| 941 | { |
| 942 | /* XXX: Need to return 1 if it's not our device in error handling */ |
| 943 | return 0; |
| 944 | } |
| 945 | |
| 946 | static int uas_post_reset(struct usb_interface *intf) |
| 947 | { |
| 948 | /* XXX: Need to return 1 if it's not our device in error handling */ |
| 949 | return 0; |
| 950 | } |
| 951 | |
| 952 | static void uas_disconnect(struct usb_interface *intf) |
| 953 | { |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 954 | struct Scsi_Host *shost = usb_get_intfdata(intf); |
| 955 | struct uas_dev_info *devinfo = (void *)shost->hostdata[0]; |
| 956 | |
| 957 | scsi_remove_host(shost); |
Gerd Hoffmann | a0e39e3 | 2012-09-25 10:47:04 +0200 | [diff] [blame] | 958 | usb_kill_anchored_urbs(&devinfo->cmd_urbs); |
Gerd Hoffmann | bdd000f | 2012-06-19 09:54:53 +0200 | [diff] [blame] | 959 | usb_kill_anchored_urbs(&devinfo->sense_urbs); |
| 960 | usb_kill_anchored_urbs(&devinfo->data_urbs); |
Sebastian Andrzej Siewior | dae5154 | 2011-12-19 17:06:08 +0100 | [diff] [blame] | 961 | uas_free_streams(devinfo); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 962 | kfree(devinfo); |
| 963 | } |
| 964 | |
| 965 | /* |
| 966 | * XXX: Should this plug into libusual so we can auto-upgrade devices from |
| 967 | * Bulk-Only to UAS? |
| 968 | */ |
| 969 | static struct usb_driver uas_driver = { |
| 970 | .name = "uas", |
| 971 | .probe = uas_probe, |
| 972 | .disconnect = uas_disconnect, |
| 973 | .pre_reset = uas_pre_reset, |
| 974 | .post_reset = uas_post_reset, |
| 975 | .id_table = uas_usb_ids, |
| 976 | }; |
| 977 | |
Greg Kroah-Hartman | 65db430 | 2011-11-18 09:34:02 -0800 | [diff] [blame] | 978 | module_usb_driver(uas_driver); |
Matthew Wilcox | 115bb1f | 2010-10-07 13:05:23 +0200 | [diff] [blame] | 979 | |
| 980 | MODULE_LICENSE("GPL"); |
| 981 | MODULE_AUTHOR("Matthew Wilcox and Sarah Sharp"); |