wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1 | /* |
Wolfgang Denk | 460c322 | 2005-08-04 01:14:12 +0200 | [diff] [blame] | 2 | * Most of this source has been derived from the Linux USB |
| 3 | * project: |
| 4 | * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net) |
| 5 | * (c) 2000 David L. Brown, Jr. (usb-storage@davidb.org) |
| 6 | * (c) 1999 Michael Gee (michael@linuxspecific.com) |
| 7 | * (c) 2000 Yggdrasil Computing, Inc. |
| 8 | * |
| 9 | * |
| 10 | * Adapted for U-Boot: |
| 11 | * (C) Copyright 2001 Denis Peter, MPL AG Switzerland |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 12 | * |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 13 | * For BBB support (C) Copyright 2003 |
Detlev Zundel | 792a09e | 2009-05-13 10:54:10 +0200 | [diff] [blame] | 14 | * Gary Jennejohn, DENX Software Engineering <garyj@denx.de> |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 15 | * |
Wolfgang Denk | 460c322 | 2005-08-04 01:14:12 +0200 | [diff] [blame] | 16 | * BBB support based on /sys/dev/usb/umass.c from |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 17 | * FreeBSD. |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 18 | * |
| 19 | * See file CREDITS for list of people who contributed to this |
| 20 | * project. |
| 21 | * |
| 22 | * This program is free software; you can redistribute it and/or |
| 23 | * modify it under the terms of the GNU General Public License as |
| 24 | * published by the Free Software Foundation; either version 2 of |
| 25 | * the License, or (at your option) any later version. |
| 26 | * |
| 27 | * This program is distributed in the hope that it will be useful, |
| 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 30 | * GNU General Public License for more details. |
| 31 | * |
| 32 | * You should have received a copy of the GNU General Public License |
| 33 | * along with this program; if not, write to the Free Software |
| 34 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 35 | * MA 02111-1307 USA |
| 36 | * |
| 37 | */ |
| 38 | |
| 39 | /* Note: |
| 40 | * Currently only the CBI transport protocoll has been implemented, and it |
| 41 | * is only tested with a TEAC USB Floppy. Other Massstorages with CBI or CB |
| 42 | * transport protocoll may work as well. |
| 43 | */ |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 44 | /* |
| 45 | * New Note: |
| 46 | * Support for USB Mass Storage Devices (BBB) has been added. It has |
| 47 | * only been tested with USB memory sticks. |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 48 | */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 49 | |
| 50 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 51 | #include <common.h> |
| 52 | #include <command.h> |
Christian Eggers | c918261 | 2008-05-21 22:12:00 +0200 | [diff] [blame] | 53 | #include <asm/byteorder.h> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 54 | #include <asm/processor.h> |
| 55 | |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 56 | #include <part.h> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 57 | #include <usb.h> |
| 58 | |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 59 | #undef BBB_COMDAT_TRACE |
| 60 | #undef BBB_XPORT_TRACE |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 61 | |
| 62 | #ifdef USB_STOR_DEBUG |
Marek Vasut | 86bd3ff | 2011-10-25 11:39:16 +0200 | [diff] [blame] | 63 | #define USB_BLK_DEBUG 1 |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 64 | #else |
Marek Vasut | 86bd3ff | 2011-10-25 11:39:16 +0200 | [diff] [blame] | 65 | #define USB_BLK_DEBUG 0 |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 66 | #endif |
| 67 | |
Marek Vasut | 86bd3ff | 2011-10-25 11:39:16 +0200 | [diff] [blame] | 68 | #define USB_STOR_PRINTF(fmt, args...) debug_cond(USB_BLK_DEBUG, fmt, ##args) |
| 69 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 70 | #include <scsi.h> |
| 71 | /* direction table -- this indicates the direction of the data |
| 72 | * transfer for each command code -- a 1 indicates input |
| 73 | */ |
Mike Frysinger | 2ff12285 | 2010-10-20 07:16:04 -0400 | [diff] [blame] | 74 | static const unsigned char us_direction[256/8] = { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 75 | 0x28, 0x81, 0x14, 0x14, 0x20, 0x01, 0x90, 0x77, |
| 76 | 0x0C, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, |
| 77 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, |
| 78 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 79 | }; |
| 80 | #define US_DIRECTION(x) ((us_direction[x>>3] >> (x & 7)) & 1) |
| 81 | |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 82 | static ccb usb_ccb __attribute__((aligned(ARCH_DMA_MINALIGN))); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 83 | |
| 84 | /* |
| 85 | * CBI style |
| 86 | */ |
| 87 | |
| 88 | #define US_CBI_ADSC 0 |
| 89 | |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 90 | /* |
| 91 | * BULK only |
| 92 | */ |
| 93 | #define US_BBB_RESET 0xff |
| 94 | #define US_BBB_GET_MAX_LUN 0xfe |
| 95 | |
| 96 | /* Command Block Wrapper */ |
| 97 | typedef struct { |
| 98 | __u32 dCBWSignature; |
| 99 | # define CBWSIGNATURE 0x43425355 |
| 100 | __u32 dCBWTag; |
| 101 | __u32 dCBWDataTransferLength; |
| 102 | __u8 bCBWFlags; |
| 103 | # define CBWFLAGS_OUT 0x00 |
| 104 | # define CBWFLAGS_IN 0x80 |
| 105 | __u8 bCBWLUN; |
| 106 | __u8 bCDBLength; |
| 107 | # define CBWCDBLENGTH 16 |
| 108 | __u8 CBWCDB[CBWCDBLENGTH]; |
| 109 | } umass_bbb_cbw_t; |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 110 | #define UMASS_BBB_CBW_SIZE 31 |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 111 | static __u32 CBWTag; |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 112 | |
| 113 | /* Command Status Wrapper */ |
| 114 | typedef struct { |
| 115 | __u32 dCSWSignature; |
| 116 | # define CSWSIGNATURE 0x53425355 |
| 117 | __u32 dCSWTag; |
| 118 | __u32 dCSWDataResidue; |
| 119 | __u8 bCSWStatus; |
| 120 | # define CSWSTATUS_GOOD 0x0 |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 121 | # define CSWSTATUS_FAILED 0x1 |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 122 | # define CSWSTATUS_PHASE 0x2 |
| 123 | } umass_bbb_csw_t; |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 124 | #define UMASS_BBB_CSW_SIZE 13 |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 125 | |
| 126 | #define USB_MAX_STOR_DEV 5 |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 127 | static int usb_max_devs; /* number of highest available usb device */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 128 | |
| 129 | static block_dev_desc_t usb_dev_desc[USB_MAX_STOR_DEV]; |
| 130 | |
| 131 | struct us_data; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 132 | typedef int (*trans_cmnd)(ccb *cb, struct us_data *data); |
| 133 | typedef int (*trans_reset)(struct us_data *data); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 134 | |
| 135 | struct us_data { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 136 | struct usb_device *pusb_dev; /* this usb_device */ |
| 137 | |
| 138 | unsigned int flags; /* from filter initially */ |
| 139 | unsigned char ifnum; /* interface number */ |
| 140 | unsigned char ep_in; /* in endpoint */ |
| 141 | unsigned char ep_out; /* out ....... */ |
| 142 | unsigned char ep_int; /* interrupt . */ |
| 143 | unsigned char subclass; /* as in overview */ |
| 144 | unsigned char protocol; /* .............. */ |
| 145 | unsigned char attention_done; /* force attn on first cmd */ |
| 146 | unsigned short ip_data; /* interrupt data */ |
| 147 | int action; /* what to do */ |
| 148 | int ip_wanted; /* needed */ |
| 149 | int *irq_handle; /* for USB int requests */ |
| 150 | unsigned int irqpipe; /* pipe for release_irq */ |
| 151 | unsigned char irqmaxp; /* max packed for irq Pipe */ |
| 152 | unsigned char irqinterval; /* Intervall for IRQ Pipe */ |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 153 | unsigned long max_xfer_blk; /* Max blocks per xfer */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 154 | ccb *srb; /* current srb */ |
| 155 | trans_reset transport_reset; /* reset routine */ |
| 156 | trans_cmnd transport; /* transport routine */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | static struct us_data usb_stor[USB_MAX_STOR_DEV]; |
| 160 | |
| 161 | |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 162 | #define USB_STOR_TRANSPORT_GOOD 0 |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 163 | #define USB_STOR_TRANSPORT_FAILED -1 |
| 164 | #define USB_STOR_TRANSPORT_ERROR -2 |
| 165 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 166 | int usb_stor_get_info(struct usb_device *dev, struct us_data *us, |
| 167 | block_dev_desc_t *dev_desc); |
| 168 | int usb_storage_probe(struct usb_device *dev, unsigned int ifnum, |
| 169 | struct us_data *ss); |
| 170 | unsigned long usb_stor_read(int device, unsigned long blknr, |
| 171 | unsigned long blkcnt, void *buffer); |
Mahavir Jain | 127e108 | 2009-11-03 12:22:10 +0530 | [diff] [blame] | 172 | unsigned long usb_stor_write(int device, unsigned long blknr, |
| 173 | unsigned long blkcnt, const void *buffer); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 174 | struct usb_device * usb_get_dev_index(int index); |
| 175 | void uhci_show_temp_int_td(void); |
| 176 | |
Matthew McClintock | df3fc52 | 2011-05-24 05:31:19 +0000 | [diff] [blame] | 177 | #ifdef CONFIG_PARTITIONS |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 178 | block_dev_desc_t *usb_stor_get_dev(int index) |
| 179 | { |
Kim B. Heino | aaad108 | 2010-03-12 15:46:56 +0200 | [diff] [blame] | 180 | return (index < usb_max_devs) ? &usb_dev_desc[index] : NULL; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 181 | } |
Matthew McClintock | df3fc52 | 2011-05-24 05:31:19 +0000 | [diff] [blame] | 182 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 183 | |
| 184 | void usb_show_progress(void) |
| 185 | { |
Wolfgang Denk | 226fa9b | 2010-07-19 11:36:59 +0200 | [diff] [blame] | 186 | debug("."); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 189 | /******************************************************************************* |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 190 | * show info on storage devices; 'usb start/init' must be invoked earlier |
| 191 | * as we only retrieve structures populated during devices initialization |
| 192 | */ |
Aras Vaichas | f6b44e0 | 2008-03-25 12:09:07 +1100 | [diff] [blame] | 193 | int usb_stor_info(void) |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 194 | { |
| 195 | int i; |
| 196 | |
Aras Vaichas | f6b44e0 | 2008-03-25 12:09:07 +1100 | [diff] [blame] | 197 | if (usb_max_devs > 0) { |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 198 | for (i = 0; i < usb_max_devs; i++) { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 199 | printf(" Device %d: ", i); |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 200 | dev_print(&usb_dev_desc[i]); |
| 201 | } |
Markus Klotzbuecher | b9e749e | 2008-03-26 18:26:43 +0100 | [diff] [blame] | 202 | return 0; |
Aras Vaichas | f6b44e0 | 2008-03-25 12:09:07 +1100 | [diff] [blame] | 203 | } |
Wolfgang Denk | 1aeed8d | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 204 | |
Markus Klotzbuecher | b9e749e | 2008-03-26 18:26:43 +0100 | [diff] [blame] | 205 | printf("No storage devices, perhaps not 'usb start'ed..?\n"); |
| 206 | return 1; |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 207 | } |
| 208 | |
Ludovic Courtès | 99e9ed1 | 2010-10-05 22:04:26 +0200 | [diff] [blame] | 209 | static unsigned int usb_get_max_lun(struct us_data *us) |
| 210 | { |
| 211 | int len; |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 212 | ALLOC_CACHE_ALIGN_BUFFER(unsigned char, result, 1); |
Ludovic Courtès | 99e9ed1 | 2010-10-05 22:04:26 +0200 | [diff] [blame] | 213 | len = usb_control_msg(us->pusb_dev, |
| 214 | usb_rcvctrlpipe(us->pusb_dev, 0), |
| 215 | US_BBB_GET_MAX_LUN, |
| 216 | USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, |
| 217 | 0, us->ifnum, |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 218 | result, sizeof(char), |
Ludovic Courtès | 99e9ed1 | 2010-10-05 22:04:26 +0200 | [diff] [blame] | 219 | USB_CNTL_TIMEOUT * 5); |
| 220 | USB_STOR_PRINTF("Get Max LUN -> len = %i, result = %i\n", |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 221 | len, (int) *result); |
| 222 | return (len > 0) ? *result : 0; |
Ludovic Courtès | 99e9ed1 | 2010-10-05 22:04:26 +0200 | [diff] [blame] | 223 | } |
| 224 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 225 | /******************************************************************************* |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 226 | * scan the usb and reports device info |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 227 | * to the user if mode = 1 |
| 228 | * returns current device or -1 if no |
| 229 | */ |
| 230 | int usb_stor_scan(int mode) |
| 231 | { |
| 232 | unsigned char i; |
| 233 | struct usb_device *dev; |
| 234 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 235 | if (mode == 1) |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 236 | printf(" scanning bus for storage devices... "); |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 237 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 238 | usb_disable_asynch(1); /* asynch transfer not allowed */ |
| 239 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 240 | for (i = 0; i < USB_MAX_STOR_DEV; i++) { |
| 241 | memset(&usb_dev_desc[i], 0, sizeof(block_dev_desc_t)); |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 242 | usb_dev_desc[i].if_type = IF_TYPE_USB; |
| 243 | usb_dev_desc[i].dev = i; |
| 244 | usb_dev_desc[i].part_type = PART_TYPE_UNKNOWN; |
Wolfgang Denk | a17c548 | 2010-07-19 11:36:56 +0200 | [diff] [blame] | 245 | usb_dev_desc[i].target = 0xff; |
| 246 | usb_dev_desc[i].type = DEV_TYPE_UNKNOWN; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 247 | usb_dev_desc[i].block_read = usb_stor_read; |
Mahavir Jain | 127e108 | 2009-11-03 12:22:10 +0530 | [diff] [blame] | 248 | usb_dev_desc[i].block_write = usb_stor_write; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 249 | } |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 250 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 251 | usb_max_devs = 0; |
| 252 | for (i = 0; i < USB_MAX_DEVICE; i++) { |
| 253 | dev = usb_get_dev_index(i); /* get device */ |
| 254 | USB_STOR_PRINTF("i=%d\n", i); |
| 255 | if (dev == NULL) |
Loïc Minier | 6052cba | 2011-02-03 22:04:26 +0100 | [diff] [blame] | 256 | break; /* no more devices available */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 257 | |
| 258 | if (usb_storage_probe(dev, 0, &usb_stor[usb_max_devs])) { |
Ludovic Courtès | 99e9ed1 | 2010-10-05 22:04:26 +0200 | [diff] [blame] | 259 | /* OK, it's a storage device. Iterate over its LUNs |
| 260 | * and populate `usb_dev_desc'. |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 261 | */ |
Ludovic Courtès | 99e9ed1 | 2010-10-05 22:04:26 +0200 | [diff] [blame] | 262 | int lun, max_lun, start = usb_max_devs; |
| 263 | |
| 264 | max_lun = usb_get_max_lun(&usb_stor[usb_max_devs]); |
| 265 | for (lun = 0; |
| 266 | lun <= max_lun && usb_max_devs < USB_MAX_STOR_DEV; |
| 267 | lun++) { |
| 268 | usb_dev_desc[usb_max_devs].lun = lun; |
| 269 | if (usb_stor_get_info(dev, &usb_stor[start], |
| 270 | &usb_dev_desc[usb_max_devs]) == 1) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 271 | usb_max_devs++; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 272 | } |
Ludovic Courtès | 99e9ed1 | 2010-10-05 22:04:26 +0200 | [diff] [blame] | 273 | } |
| 274 | } |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 275 | /* if storage device */ |
| 276 | if (usb_max_devs == USB_MAX_STOR_DEV) { |
| 277 | printf("max USB Storage Device reached: %d stopping\n", |
| 278 | usb_max_devs); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 279 | break; |
| 280 | } |
| 281 | } /* for */ |
Wolfgang Denk | 095b8a3 | 2005-08-02 17:06:17 +0200 | [diff] [blame] | 282 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 283 | usb_disable_asynch(0); /* asynch transfer allowed */ |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 284 | printf("%d Storage Device(s) found\n", usb_max_devs); |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 285 | if (usb_max_devs > 0) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 286 | return 0; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 287 | return -1; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | static int usb_stor_irq(struct usb_device *dev) |
| 291 | { |
| 292 | struct us_data *us; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 293 | us = (struct us_data *)dev->privptr; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 294 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 295 | if (us->ip_wanted) |
| 296 | us->ip_wanted = 0; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | |
| 301 | #ifdef USB_STOR_DEBUG |
| 302 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 303 | static void usb_show_srb(ccb *pccb) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 304 | { |
| 305 | int i; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 306 | printf("SRB: len %d datalen 0x%lX\n ", pccb->cmdlen, pccb->datalen); |
| 307 | for (i = 0; i < 12; i++) |
| 308 | printf("%02X ", pccb->cmd[i]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 309 | printf("\n"); |
| 310 | } |
| 311 | |
| 312 | static void display_int_status(unsigned long tmp) |
| 313 | { |
| 314 | printf("Status: %s %s %s %s %s %s %s\n", |
| 315 | (tmp & USB_ST_ACTIVE) ? "Active" : "", |
| 316 | (tmp & USB_ST_STALLED) ? "Stalled" : "", |
| 317 | (tmp & USB_ST_BUF_ERR) ? "Buffer Error" : "", |
| 318 | (tmp & USB_ST_BABBLE_DET) ? "Babble Det" : "", |
| 319 | (tmp & USB_ST_NAK_REC) ? "NAKed" : "", |
| 320 | (tmp & USB_ST_CRC_ERR) ? "CRC Error" : "", |
| 321 | (tmp & USB_ST_BIT_ERR) ? "Bitstuff Error" : ""); |
| 322 | } |
| 323 | #endif |
| 324 | /*********************************************************************** |
| 325 | * Data transfer routines |
| 326 | ***********************************************************************/ |
| 327 | |
| 328 | static int us_one_transfer(struct us_data *us, int pipe, char *buf, int length) |
| 329 | { |
| 330 | int max_size; |
| 331 | int this_xfer; |
| 332 | int result; |
| 333 | int partial; |
| 334 | int maxtry; |
| 335 | int stat; |
| 336 | |
| 337 | /* determine the maximum packet size for these transfers */ |
| 338 | max_size = usb_maxpacket(us->pusb_dev, pipe) * 16; |
| 339 | |
| 340 | /* while we have data left to transfer */ |
| 341 | while (length) { |
| 342 | |
| 343 | /* calculate how long this will be -- maximum or a remainder */ |
| 344 | this_xfer = length > max_size ? max_size : length; |
| 345 | length -= this_xfer; |
| 346 | |
| 347 | /* setup the retry counter */ |
| 348 | maxtry = 10; |
| 349 | |
| 350 | /* set up the transfer loop */ |
| 351 | do { |
| 352 | /* transfer the data */ |
| 353 | USB_STOR_PRINTF("Bulk xfer 0x%x(%d) try #%d\n", |
| 354 | (unsigned int)buf, this_xfer, 11 - maxtry); |
| 355 | result = usb_bulk_msg(us->pusb_dev, pipe, buf, |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 356 | this_xfer, &partial, |
| 357 | USB_CNTL_TIMEOUT * 5); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 358 | USB_STOR_PRINTF("bulk_msg returned %d xferred %d/%d\n", |
| 359 | result, partial, this_xfer); |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 360 | if (us->pusb_dev->status != 0) { |
| 361 | /* if we stall, we need to clear it before |
| 362 | * we go on |
| 363 | */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 364 | #ifdef USB_STOR_DEBUG |
| 365 | display_int_status(us->pusb_dev->status); |
| 366 | #endif |
| 367 | if (us->pusb_dev->status & USB_ST_STALLED) { |
| 368 | USB_STOR_PRINTF("stalled ->clearing endpoint halt for pipe 0x%x\n", pipe); |
| 369 | stat = us->pusb_dev->status; |
| 370 | usb_clear_halt(us->pusb_dev, pipe); |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 371 | us->pusb_dev->status = stat; |
| 372 | if (this_xfer == partial) { |
Marek Vasut | 4b210e8 | 2011-10-25 11:39:17 +0200 | [diff] [blame] | 373 | USB_STOR_PRINTF("bulk transferred with error %lX, but data ok\n", us->pusb_dev->status); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 374 | return 0; |
| 375 | } |
| 376 | else |
| 377 | return result; |
| 378 | } |
| 379 | if (us->pusb_dev->status & USB_ST_NAK_REC) { |
| 380 | USB_STOR_PRINTF("Device NAKed bulk_msg\n"); |
| 381 | return result; |
| 382 | } |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 383 | USB_STOR_PRINTF("bulk transferred with error"); |
| 384 | if (this_xfer == partial) { |
Marek Vasut | 4b210e8 | 2011-10-25 11:39:17 +0200 | [diff] [blame] | 385 | USB_STOR_PRINTF(" %ld, but data ok\n", |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 386 | us->pusb_dev->status); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 387 | return 0; |
| 388 | } |
| 389 | /* if our try counter reaches 0, bail out */ |
Marek Vasut | 4b210e8 | 2011-10-25 11:39:17 +0200 | [diff] [blame] | 390 | USB_STOR_PRINTF(" %ld, data %d\n", |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 391 | us->pusb_dev->status, partial); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 392 | if (!maxtry--) |
| 393 | return result; |
| 394 | } |
| 395 | /* update to show what data was transferred */ |
| 396 | this_xfer -= partial; |
| 397 | buf += partial; |
| 398 | /* continue until this transfer is done */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 399 | } while (this_xfer); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /* if we get here, we're done and successful */ |
| 403 | return 0; |
| 404 | } |
| 405 | |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 406 | static int usb_stor_BBB_reset(struct us_data *us) |
| 407 | { |
| 408 | int result; |
| 409 | unsigned int pipe; |
| 410 | |
| 411 | /* |
| 412 | * Reset recovery (5.3.4 in Universal Serial Bus Mass Storage Class) |
| 413 | * |
| 414 | * For Reset Recovery the host shall issue in the following order: |
| 415 | * a) a Bulk-Only Mass Storage Reset |
| 416 | * b) a Clear Feature HALT to the Bulk-In endpoint |
| 417 | * c) a Clear Feature HALT to the Bulk-Out endpoint |
| 418 | * |
| 419 | * This is done in 3 steps. |
| 420 | * |
| 421 | * If the reset doesn't succeed, the device should be port reset. |
| 422 | * |
| 423 | * This comment stolen from FreeBSD's /sys/dev/usb/umass.c. |
| 424 | */ |
| 425 | USB_STOR_PRINTF("BBB_reset\n"); |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 426 | result = usb_control_msg(us->pusb_dev, usb_sndctrlpipe(us->pusb_dev, 0), |
| 427 | US_BBB_RESET, |
| 428 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 429 | 0, us->ifnum, 0, 0, USB_CNTL_TIMEOUT * 5); |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 430 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 431 | if ((result < 0) && (us->pusb_dev->status & USB_ST_STALLED)) { |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 432 | USB_STOR_PRINTF("RESET:stall\n"); |
| 433 | return -1; |
| 434 | } |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 435 | |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 436 | /* long wait for reset */ |
Mike Frysinger | 5b84dd6 | 2012-03-05 13:47:00 +0000 | [diff] [blame] | 437 | mdelay(150); |
Marek Vasut | 4b210e8 | 2011-10-25 11:39:17 +0200 | [diff] [blame] | 438 | USB_STOR_PRINTF("BBB_reset result %d: status %lX reset\n", result, |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 439 | us->pusb_dev->status); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 440 | pipe = usb_rcvbulkpipe(us->pusb_dev, us->ep_in); |
| 441 | result = usb_clear_halt(us->pusb_dev, pipe); |
| 442 | /* long wait for reset */ |
Mike Frysinger | 5b84dd6 | 2012-03-05 13:47:00 +0000 | [diff] [blame] | 443 | mdelay(150); |
Marek Vasut | 4b210e8 | 2011-10-25 11:39:17 +0200 | [diff] [blame] | 444 | USB_STOR_PRINTF("BBB_reset result %d: status %lX clearing IN endpoint\n", |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 445 | result, us->pusb_dev->status); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 446 | /* long wait for reset */ |
| 447 | pipe = usb_sndbulkpipe(us->pusb_dev, us->ep_out); |
| 448 | result = usb_clear_halt(us->pusb_dev, pipe); |
Mike Frysinger | 5b84dd6 | 2012-03-05 13:47:00 +0000 | [diff] [blame] | 449 | mdelay(150); |
Marek Vasut | 4b210e8 | 2011-10-25 11:39:17 +0200 | [diff] [blame] | 450 | USB_STOR_PRINTF("BBB_reset result %d: status %lX" |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 451 | " clearing OUT endpoint\n", result, |
| 452 | us->pusb_dev->status); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 453 | USB_STOR_PRINTF("BBB_reset done\n"); |
| 454 | return 0; |
| 455 | } |
| 456 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 457 | /* FIXME: this reset function doesn't really reset the port, and it |
| 458 | * should. Actually it should probably do what it's doing here, and |
| 459 | * reset the port physically |
| 460 | */ |
| 461 | static int usb_stor_CB_reset(struct us_data *us) |
| 462 | { |
| 463 | unsigned char cmd[12]; |
| 464 | int result; |
| 465 | |
| 466 | USB_STOR_PRINTF("CB_reset\n"); |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 467 | memset(cmd, 0xff, sizeof(cmd)); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 468 | cmd[0] = SCSI_SEND_DIAG; |
| 469 | cmd[1] = 4; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 470 | result = usb_control_msg(us->pusb_dev, usb_sndctrlpipe(us->pusb_dev, 0), |
| 471 | US_CBI_ADSC, |
| 472 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 473 | 0, us->ifnum, cmd, sizeof(cmd), |
| 474 | USB_CNTL_TIMEOUT * 5); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 475 | |
| 476 | /* long wait for reset */ |
Mike Frysinger | 5b84dd6 | 2012-03-05 13:47:00 +0000 | [diff] [blame] | 477 | mdelay(1500); |
Marek Vasut | 4b210e8 | 2011-10-25 11:39:17 +0200 | [diff] [blame] | 478 | USB_STOR_PRINTF("CB_reset result %d: status %lX" |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 479 | " clearing endpoint halt\n", result, |
| 480 | us->pusb_dev->status); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 481 | usb_clear_halt(us->pusb_dev, usb_rcvbulkpipe(us->pusb_dev, us->ep_in)); |
| 482 | usb_clear_halt(us->pusb_dev, usb_rcvbulkpipe(us->pusb_dev, us->ep_out)); |
| 483 | |
| 484 | USB_STOR_PRINTF("CB_reset done\n"); |
| 485 | return 0; |
| 486 | } |
| 487 | |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 488 | /* |
| 489 | * Set up the command for a BBB device. Note that the actual SCSI |
| 490 | * command is copied into cbw.CBWCDB. |
| 491 | */ |
| 492 | int usb_stor_BBB_comdat(ccb *srb, struct us_data *us) |
| 493 | { |
| 494 | int result; |
| 495 | int actlen; |
| 496 | int dir_in; |
| 497 | unsigned int pipe; |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 498 | ALLOC_CACHE_ALIGN_BUFFER(umass_bbb_cbw_t, cbw, 1); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 499 | |
| 500 | dir_in = US_DIRECTION(srb->cmd[0]); |
| 501 | |
| 502 | #ifdef BBB_COMDAT_TRACE |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 503 | printf("dir %d lun %d cmdlen %d cmd %p datalen %d pdata %p\n", |
| 504 | dir_in, srb->lun, srb->cmdlen, srb->cmd, srb->datalen, |
| 505 | srb->pdata); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 506 | if (srb->cmdlen) { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 507 | for (result = 0; result < srb->cmdlen; result++) |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 508 | printf("cmd[%d] %#x ", result, srb->cmd[result]); |
| 509 | printf("\n"); |
| 510 | } |
| 511 | #endif |
| 512 | /* sanity checks */ |
| 513 | if (!(srb->cmdlen <= CBWCDBLENGTH)) { |
| 514 | USB_STOR_PRINTF("usb_stor_BBB_comdat:cmdlen too large\n"); |
| 515 | return -1; |
| 516 | } |
| 517 | |
| 518 | /* always OUT to the ep */ |
| 519 | pipe = usb_sndbulkpipe(us->pusb_dev, us->ep_out); |
| 520 | |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 521 | cbw->dCBWSignature = cpu_to_le32(CBWSIGNATURE); |
| 522 | cbw->dCBWTag = cpu_to_le32(CBWTag++); |
| 523 | cbw->dCBWDataTransferLength = cpu_to_le32(srb->datalen); |
| 524 | cbw->bCBWFlags = (dir_in ? CBWFLAGS_IN : CBWFLAGS_OUT); |
| 525 | cbw->bCBWLUN = srb->lun; |
| 526 | cbw->bCDBLength = srb->cmdlen; |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 527 | /* copy the command data into the CBW command data buffer */ |
| 528 | /* DST SRC LEN!!! */ |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 529 | memcpy(cbw->CBWCDB, srb->cmd, srb->cmdlen); |
| 530 | result = usb_bulk_msg(us->pusb_dev, pipe, cbw, UMASS_BBB_CBW_SIZE, |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 531 | &actlen, USB_CNTL_TIMEOUT * 5); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 532 | if (result < 0) |
| 533 | USB_STOR_PRINTF("usb_stor_BBB_comdat:usb_bulk_msg error\n"); |
| 534 | return result; |
| 535 | } |
| 536 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 537 | /* FIXME: we also need a CBI_command which sets up the completion |
| 538 | * interrupt, and waits for it |
| 539 | */ |
| 540 | int usb_stor_CB_comdat(ccb *srb, struct us_data *us) |
| 541 | { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 542 | int result = 0; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 543 | int dir_in, retry; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 544 | unsigned int pipe; |
| 545 | unsigned long status; |
| 546 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 547 | retry = 5; |
| 548 | dir_in = US_DIRECTION(srb->cmd[0]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 549 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 550 | if (dir_in) |
| 551 | pipe = usb_rcvbulkpipe(us->pusb_dev, us->ep_in); |
| 552 | else |
| 553 | pipe = usb_sndbulkpipe(us->pusb_dev, us->ep_out); |
| 554 | |
| 555 | while (retry--) { |
| 556 | USB_STOR_PRINTF("CBI gets a command: Try %d\n", 5 - retry); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 557 | #ifdef USB_STOR_DEBUG |
| 558 | usb_show_srb(srb); |
| 559 | #endif |
| 560 | /* let's send the command via the control pipe */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 561 | result = usb_control_msg(us->pusb_dev, |
| 562 | usb_sndctrlpipe(us->pusb_dev , 0), |
| 563 | US_CBI_ADSC, |
| 564 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 565 | 0, us->ifnum, |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 566 | srb->cmd, srb->cmdlen, |
| 567 | USB_CNTL_TIMEOUT * 5); |
| 568 | USB_STOR_PRINTF("CB_transport: control msg returned %d," |
Marek Vasut | 4b210e8 | 2011-10-25 11:39:17 +0200 | [diff] [blame] | 569 | " status %lX\n", result, us->pusb_dev->status); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 570 | /* check the return code for the command */ |
| 571 | if (result < 0) { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 572 | if (us->pusb_dev->status & USB_ST_STALLED) { |
| 573 | status = us->pusb_dev->status; |
| 574 | USB_STOR_PRINTF(" stall during command found," |
| 575 | " clear pipe\n"); |
| 576 | usb_clear_halt(us->pusb_dev, |
| 577 | usb_sndctrlpipe(us->pusb_dev, 0)); |
| 578 | us->pusb_dev->status = status; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 579 | } |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 580 | USB_STOR_PRINTF(" error during command %02X" |
Marek Vasut | 4b210e8 | 2011-10-25 11:39:17 +0200 | [diff] [blame] | 581 | " Stat = %lX\n", srb->cmd[0], |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 582 | us->pusb_dev->status); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 583 | return result; |
| 584 | } |
| 585 | /* transfer the data payload for this command, if one exists*/ |
| 586 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 587 | USB_STOR_PRINTF("CB_transport: control msg returned %d," |
| 588 | " direction is %s to go 0x%lx\n", result, |
| 589 | dir_in ? "IN" : "OUT", srb->datalen); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 590 | if (srb->datalen) { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 591 | result = us_one_transfer(us, pipe, (char *)srb->pdata, |
| 592 | srb->datalen); |
| 593 | USB_STOR_PRINTF("CBI attempted to transfer data," |
| 594 | " result is %d status %lX, len %d\n", |
| 595 | result, us->pusb_dev->status, |
| 596 | us->pusb_dev->act_len); |
| 597 | if (!(us->pusb_dev->status & USB_ST_NAK_REC)) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 598 | break; |
| 599 | } /* if (srb->datalen) */ |
| 600 | else |
| 601 | break; |
| 602 | } |
| 603 | /* return result */ |
| 604 | |
| 605 | return result; |
| 606 | } |
| 607 | |
| 608 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 609 | int usb_stor_CBI_get_status(ccb *srb, struct us_data *us) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 610 | { |
| 611 | int timeout; |
| 612 | |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 613 | us->ip_wanted = 1; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 614 | submit_int_msg(us->pusb_dev, us->irqpipe, |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 615 | (void *) &us->ip_data, us->irqmaxp, us->irqinterval); |
| 616 | timeout = 1000; |
| 617 | while (timeout--) { |
| 618 | if ((volatile int *) us->ip_wanted == 0) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 619 | break; |
Mike Frysinger | 5b84dd6 | 2012-03-05 13:47:00 +0000 | [diff] [blame] | 620 | mdelay(10); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 621 | } |
| 622 | if (us->ip_wanted) { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 623 | printf(" Did not get interrupt on CBI\n"); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 624 | us->ip_wanted = 0; |
| 625 | return USB_STOR_TRANSPORT_ERROR; |
| 626 | } |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 627 | USB_STOR_PRINTF |
| 628 | ("Got interrupt data 0x%x, transfered %d status 0x%lX\n", |
| 629 | us->ip_data, us->pusb_dev->irq_act_len, |
| 630 | us->pusb_dev->irq_status); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 631 | /* UFI gives us ASC and ASCQ, like a request sense */ |
| 632 | if (us->subclass == US_SC_UFI) { |
| 633 | if (srb->cmd[0] == SCSI_REQ_SENSE || |
| 634 | srb->cmd[0] == SCSI_INQUIRY) |
| 635 | return USB_STOR_TRANSPORT_GOOD; /* Good */ |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 636 | else if (us->ip_data) |
| 637 | return USB_STOR_TRANSPORT_FAILED; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 638 | else |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 639 | return USB_STOR_TRANSPORT_GOOD; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 640 | } |
| 641 | /* otherwise, we interpret the data normally */ |
| 642 | switch (us->ip_data) { |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 643 | case 0x0001: |
| 644 | return USB_STOR_TRANSPORT_GOOD; |
| 645 | case 0x0002: |
| 646 | return USB_STOR_TRANSPORT_FAILED; |
| 647 | default: |
| 648 | return USB_STOR_TRANSPORT_ERROR; |
| 649 | } /* switch */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 650 | return USB_STOR_TRANSPORT_ERROR; |
| 651 | } |
| 652 | |
| 653 | #define USB_TRANSPORT_UNKNOWN_RETRY 5 |
| 654 | #define USB_TRANSPORT_NOT_READY_RETRY 10 |
| 655 | |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 656 | /* clear a stall on an endpoint - special for BBB devices */ |
| 657 | int usb_stor_BBB_clear_endpt_stall(struct us_data *us, __u8 endpt) |
| 658 | { |
| 659 | int result; |
| 660 | |
| 661 | /* ENDPOINT_HALT = 0, so set value to 0 */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 662 | result = usb_control_msg(us->pusb_dev, usb_sndctrlpipe(us->pusb_dev, 0), |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 663 | USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT, |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 664 | 0, endpt, 0, 0, USB_CNTL_TIMEOUT * 5); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 665 | return result; |
| 666 | } |
| 667 | |
| 668 | int usb_stor_BBB_transport(ccb *srb, struct us_data *us) |
| 669 | { |
| 670 | int result, retry; |
| 671 | int dir_in; |
| 672 | int actlen, data_actlen; |
| 673 | unsigned int pipe, pipein, pipeout; |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 674 | ALLOC_CACHE_ALIGN_BUFFER(umass_bbb_csw_t, csw, 1); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 675 | #ifdef BBB_XPORT_TRACE |
| 676 | unsigned char *ptr; |
| 677 | int index; |
| 678 | #endif |
| 679 | |
| 680 | dir_in = US_DIRECTION(srb->cmd[0]); |
| 681 | |
| 682 | /* COMMAND phase */ |
| 683 | USB_STOR_PRINTF("COMMAND phase\n"); |
| 684 | result = usb_stor_BBB_comdat(srb, us); |
| 685 | if (result < 0) { |
| 686 | USB_STOR_PRINTF("failed to send CBW status %ld\n", |
| 687 | us->pusb_dev->status); |
| 688 | usb_stor_BBB_reset(us); |
| 689 | return USB_STOR_TRANSPORT_FAILED; |
| 690 | } |
Mike Frysinger | 5b84dd6 | 2012-03-05 13:47:00 +0000 | [diff] [blame] | 691 | mdelay(5); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 692 | pipein = usb_rcvbulkpipe(us->pusb_dev, us->ep_in); |
| 693 | pipeout = usb_sndbulkpipe(us->pusb_dev, us->ep_out); |
| 694 | /* DATA phase + error handling */ |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 695 | data_actlen = 0; |
| 696 | /* no data, go immediately to the STATUS phase */ |
| 697 | if (srb->datalen == 0) |
| 698 | goto st; |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 699 | USB_STOR_PRINTF("DATA phase\n"); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 700 | if (dir_in) |
| 701 | pipe = pipein; |
| 702 | else |
| 703 | pipe = pipeout; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 704 | result = usb_bulk_msg(us->pusb_dev, pipe, srb->pdata, srb->datalen, |
| 705 | &data_actlen, USB_CNTL_TIMEOUT * 5); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 706 | /* special handling of STALL in DATA phase */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 707 | if ((result < 0) && (us->pusb_dev->status & USB_ST_STALLED)) { |
wdenk | a43278a | 2003-09-11 19:48:06 +0000 | [diff] [blame] | 708 | USB_STOR_PRINTF("DATA:stall\n"); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 709 | /* clear the STALL on the endpoint */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 710 | result = usb_stor_BBB_clear_endpt_stall(us, |
| 711 | dir_in ? us->ep_in : us->ep_out); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 712 | if (result >= 0) |
| 713 | /* continue on to STATUS phase */ |
| 714 | goto st; |
| 715 | } |
| 716 | if (result < 0) { |
| 717 | USB_STOR_PRINTF("usb_bulk_msg error status %ld\n", |
| 718 | us->pusb_dev->status); |
| 719 | usb_stor_BBB_reset(us); |
| 720 | return USB_STOR_TRANSPORT_FAILED; |
| 721 | } |
| 722 | #ifdef BBB_XPORT_TRACE |
| 723 | for (index = 0; index < data_actlen; index++) |
| 724 | printf("pdata[%d] %#x ", index, srb->pdata[index]); |
| 725 | printf("\n"); |
| 726 | #endif |
| 727 | /* STATUS phase + error handling */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 728 | st: |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 729 | retry = 0; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 730 | again: |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 731 | USB_STOR_PRINTF("STATUS phase\n"); |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 732 | result = usb_bulk_msg(us->pusb_dev, pipein, csw, UMASS_BBB_CSW_SIZE, |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 733 | &actlen, USB_CNTL_TIMEOUT*5); |
| 734 | |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 735 | /* special handling of STALL in STATUS phase */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 736 | if ((result < 0) && (retry < 1) && |
| 737 | (us->pusb_dev->status & USB_ST_STALLED)) { |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 738 | USB_STOR_PRINTF("STATUS:stall\n"); |
| 739 | /* clear the STALL on the endpoint */ |
| 740 | result = usb_stor_BBB_clear_endpt_stall(us, us->ep_in); |
| 741 | if (result >= 0 && (retry++ < 1)) |
| 742 | /* do a retry */ |
| 743 | goto again; |
| 744 | } |
| 745 | if (result < 0) { |
| 746 | USB_STOR_PRINTF("usb_bulk_msg error status %ld\n", |
| 747 | us->pusb_dev->status); |
| 748 | usb_stor_BBB_reset(us); |
| 749 | return USB_STOR_TRANSPORT_FAILED; |
| 750 | } |
| 751 | #ifdef BBB_XPORT_TRACE |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 752 | ptr = (unsigned char *)csw; |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 753 | for (index = 0; index < UMASS_BBB_CSW_SIZE; index++) |
| 754 | printf("ptr[%d] %#x ", index, ptr[index]); |
| 755 | printf("\n"); |
| 756 | #endif |
| 757 | /* misuse pipe to get the residue */ |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 758 | pipe = le32_to_cpu(csw->dCSWDataResidue); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 759 | if (pipe == 0 && srb->datalen != 0 && srb->datalen - data_actlen != 0) |
| 760 | pipe = srb->datalen - data_actlen; |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 761 | if (CSWSIGNATURE != le32_to_cpu(csw->dCSWSignature)) { |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 762 | USB_STOR_PRINTF("!CSWSIGNATURE\n"); |
| 763 | usb_stor_BBB_reset(us); |
| 764 | return USB_STOR_TRANSPORT_FAILED; |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 765 | } else if ((CBWTag - 1) != le32_to_cpu(csw->dCSWTag)) { |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 766 | USB_STOR_PRINTF("!Tag\n"); |
| 767 | usb_stor_BBB_reset(us); |
| 768 | return USB_STOR_TRANSPORT_FAILED; |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 769 | } else if (csw->bCSWStatus > CSWSTATUS_PHASE) { |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 770 | USB_STOR_PRINTF(">PHASE\n"); |
| 771 | usb_stor_BBB_reset(us); |
| 772 | return USB_STOR_TRANSPORT_FAILED; |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 773 | } else if (csw->bCSWStatus == CSWSTATUS_PHASE) { |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 774 | USB_STOR_PRINTF("=PHASE\n"); |
| 775 | usb_stor_BBB_reset(us); |
| 776 | return USB_STOR_TRANSPORT_FAILED; |
| 777 | } else if (data_actlen > srb->datalen) { |
Marek Vasut | 4b210e8 | 2011-10-25 11:39:17 +0200 | [diff] [blame] | 778 | USB_STOR_PRINTF("transferred %dB instead of %ldB\n", |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 779 | data_actlen, srb->datalen); |
| 780 | return USB_STOR_TRANSPORT_FAILED; |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 781 | } else if (csw->bCSWStatus == CSWSTATUS_FAILED) { |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 782 | USB_STOR_PRINTF("FAILED\n"); |
| 783 | return USB_STOR_TRANSPORT_FAILED; |
| 784 | } |
| 785 | |
| 786 | return result; |
| 787 | } |
| 788 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 789 | int usb_stor_CB_transport(ccb *srb, struct us_data *us) |
| 790 | { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 791 | int result, status; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 792 | ccb *psrb; |
| 793 | ccb reqsrb; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 794 | int retry, notready; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 795 | |
Wolfgang Denk | d0ff51b | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 796 | psrb = &reqsrb; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 797 | status = USB_STOR_TRANSPORT_GOOD; |
| 798 | retry = 0; |
| 799 | notready = 0; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 800 | /* issue the command */ |
| 801 | do_retry: |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 802 | result = usb_stor_CB_comdat(srb, us); |
Marek Vasut | 4b210e8 | 2011-10-25 11:39:17 +0200 | [diff] [blame] | 803 | USB_STOR_PRINTF("command / Data returned %d, status %lX\n", |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 804 | result, us->pusb_dev->status); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 805 | /* if this is an CBI Protocol, get IRQ */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 806 | if (us->protocol == US_PR_CBI) { |
| 807 | status = usb_stor_CBI_get_status(srb, us); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 808 | /* if the status is error, report it */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 809 | if (status == USB_STOR_TRANSPORT_ERROR) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 810 | USB_STOR_PRINTF(" USB CBI Command Error\n"); |
| 811 | return status; |
| 812 | } |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 813 | srb->sense_buf[12] = (unsigned char)(us->ip_data >> 8); |
| 814 | srb->sense_buf[13] = (unsigned char)(us->ip_data & 0xff); |
| 815 | if (!us->ip_data) { |
| 816 | /* if the status is good, report it */ |
| 817 | if (status == USB_STOR_TRANSPORT_GOOD) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 818 | USB_STOR_PRINTF(" USB CBI Command Good\n"); |
| 819 | return status; |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | /* do we have to issue an auto request? */ |
| 824 | /* HERE we have to check the result */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 825 | if ((result < 0) && !(us->pusb_dev->status & USB_ST_STALLED)) { |
Marek Vasut | 4b210e8 | 2011-10-25 11:39:17 +0200 | [diff] [blame] | 826 | USB_STOR_PRINTF("ERROR %lX\n", us->pusb_dev->status); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 827 | us->transport_reset(us); |
| 828 | return USB_STOR_TRANSPORT_ERROR; |
| 829 | } |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 830 | if ((us->protocol == US_PR_CBI) && |
| 831 | ((srb->cmd[0] == SCSI_REQ_SENSE) || |
| 832 | (srb->cmd[0] == SCSI_INQUIRY))) { |
| 833 | /* do not issue an autorequest after request sense */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 834 | USB_STOR_PRINTF("No auto request and good\n"); |
| 835 | return USB_STOR_TRANSPORT_GOOD; |
| 836 | } |
| 837 | /* issue an request_sense */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 838 | memset(&psrb->cmd[0], 0, 12); |
| 839 | psrb->cmd[0] = SCSI_REQ_SENSE; |
| 840 | psrb->cmd[1] = srb->lun << 5; |
| 841 | psrb->cmd[4] = 18; |
| 842 | psrb->datalen = 18; |
Wolfgang Denk | d0ff51b | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 843 | psrb->pdata = &srb->sense_buf[0]; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 844 | psrb->cmdlen = 12; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 845 | /* issue the command */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 846 | result = usb_stor_CB_comdat(psrb, us); |
| 847 | USB_STOR_PRINTF("auto request returned %d\n", result); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 848 | /* if this is an CBI Protocol, get IRQ */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 849 | if (us->protocol == US_PR_CBI) |
| 850 | status = usb_stor_CBI_get_status(psrb, us); |
| 851 | |
| 852 | if ((result < 0) && !(us->pusb_dev->status & USB_ST_STALLED)) { |
Marek Vasut | 4b210e8 | 2011-10-25 11:39:17 +0200 | [diff] [blame] | 853 | USB_STOR_PRINTF(" AUTO REQUEST ERROR %ld\n", |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 854 | us->pusb_dev->status); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 855 | return USB_STOR_TRANSPORT_ERROR; |
| 856 | } |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 857 | USB_STOR_PRINTF("autorequest returned 0x%02X 0x%02X 0x%02X 0x%02X\n", |
| 858 | srb->sense_buf[0], srb->sense_buf[2], |
| 859 | srb->sense_buf[12], srb->sense_buf[13]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 860 | /* Check the auto request result */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 861 | if ((srb->sense_buf[2] == 0) && |
| 862 | (srb->sense_buf[12] == 0) && |
| 863 | (srb->sense_buf[13] == 0)) { |
| 864 | /* ok, no sense */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 865 | return USB_STOR_TRANSPORT_GOOD; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 866 | } |
| 867 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 868 | /* Check the auto request result */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 869 | switch (srb->sense_buf[2]) { |
| 870 | case 0x01: |
| 871 | /* Recovered Error */ |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 872 | return USB_STOR_TRANSPORT_GOOD; |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 873 | break; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 874 | case 0x02: |
| 875 | /* Not Ready */ |
| 876 | if (notready++ > USB_TRANSPORT_NOT_READY_RETRY) { |
| 877 | printf("cmd 0x%02X returned 0x%02X 0x%02X 0x%02X" |
| 878 | " 0x%02X (NOT READY)\n", srb->cmd[0], |
| 879 | srb->sense_buf[0], srb->sense_buf[2], |
| 880 | srb->sense_buf[12], srb->sense_buf[13]); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 881 | return USB_STOR_TRANSPORT_FAILED; |
| 882 | } else { |
Mike Frysinger | 5b84dd6 | 2012-03-05 13:47:00 +0000 | [diff] [blame] | 883 | mdelay(100); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 884 | goto do_retry; |
| 885 | } |
| 886 | break; |
| 887 | default: |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 888 | if (retry++ > USB_TRANSPORT_UNKNOWN_RETRY) { |
| 889 | printf("cmd 0x%02X returned 0x%02X 0x%02X 0x%02X" |
| 890 | " 0x%02X\n", srb->cmd[0], srb->sense_buf[0], |
| 891 | srb->sense_buf[2], srb->sense_buf[12], |
| 892 | srb->sense_buf[13]); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 893 | return USB_STOR_TRANSPORT_FAILED; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 894 | } else |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 895 | goto do_retry; |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 896 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 897 | } |
| 898 | return USB_STOR_TRANSPORT_FAILED; |
| 899 | } |
| 900 | |
| 901 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 902 | static int usb_inquiry(ccb *srb, struct us_data *ss) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 903 | { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 904 | int retry, i; |
| 905 | retry = 5; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 906 | do { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 907 | memset(&srb->cmd[0], 0, 12); |
| 908 | srb->cmd[0] = SCSI_INQUIRY; |
Ludovic Courtès | 99e9ed1 | 2010-10-05 22:04:26 +0200 | [diff] [blame] | 909 | srb->cmd[1] = srb->lun << 5; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 910 | srb->cmd[4] = 36; |
| 911 | srb->datalen = 36; |
| 912 | srb->cmdlen = 12; |
| 913 | i = ss->transport(srb, ss); |
| 914 | USB_STOR_PRINTF("inquiry returns %d\n", i); |
| 915 | if (i == 0) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 916 | break; |
Kim B. Heino | fac71cc | 2010-03-12 10:07:00 +0200 | [diff] [blame] | 917 | } while (--retry); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 918 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 919 | if (!retry) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 920 | printf("error in inquiry\n"); |
| 921 | return -1; |
| 922 | } |
| 923 | return 0; |
| 924 | } |
| 925 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 926 | static int usb_request_sense(ccb *srb, struct us_data *ss) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 927 | { |
| 928 | char *ptr; |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 929 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 930 | ptr = (char *)srb->pdata; |
| 931 | memset(&srb->cmd[0], 0, 12); |
| 932 | srb->cmd[0] = SCSI_REQ_SENSE; |
Ludovic Courtès | 99e9ed1 | 2010-10-05 22:04:26 +0200 | [diff] [blame] | 933 | srb->cmd[1] = srb->lun << 5; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 934 | srb->cmd[4] = 18; |
| 935 | srb->datalen = 18; |
Wolfgang Denk | d0ff51b | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 936 | srb->pdata = &srb->sense_buf[0]; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 937 | srb->cmdlen = 12; |
| 938 | ss->transport(srb, ss); |
| 939 | USB_STOR_PRINTF("Request Sense returned %02X %02X %02X\n", |
| 940 | srb->sense_buf[2], srb->sense_buf[12], |
| 941 | srb->sense_buf[13]); |
| 942 | srb->pdata = (uchar *)ptr; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 943 | return 0; |
| 944 | } |
| 945 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 946 | static int usb_test_unit_ready(ccb *srb, struct us_data *ss) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 947 | { |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 948 | int retries = 10; |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 949 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 950 | do { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 951 | memset(&srb->cmd[0], 0, 12); |
| 952 | srb->cmd[0] = SCSI_TST_U_RDY; |
Ludovic Courtès | 99e9ed1 | 2010-10-05 22:04:26 +0200 | [diff] [blame] | 953 | srb->cmd[1] = srb->lun << 5; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 954 | srb->datalen = 0; |
| 955 | srb->cmdlen = 12; |
| 956 | if (ss->transport(srb, ss) == USB_STOR_TRANSPORT_GOOD) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 957 | return 0; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 958 | usb_request_sense(srb, ss); |
Mike Frysinger | 5b84dd6 | 2012-03-05 13:47:00 +0000 | [diff] [blame] | 959 | mdelay(100); |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 960 | } while (retries--); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 961 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 962 | return -1; |
| 963 | } |
| 964 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 965 | static int usb_read_capacity(ccb *srb, struct us_data *ss) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 966 | { |
| 967 | int retry; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 968 | /* XXX retries */ |
| 969 | retry = 3; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 970 | do { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 971 | memset(&srb->cmd[0], 0, 12); |
| 972 | srb->cmd[0] = SCSI_RD_CAPAC; |
Ludovic Courtès | 99e9ed1 | 2010-10-05 22:04:26 +0200 | [diff] [blame] | 973 | srb->cmd[1] = srb->lun << 5; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 974 | srb->datalen = 8; |
| 975 | srb->cmdlen = 12; |
| 976 | if (ss->transport(srb, ss) == USB_STOR_TRANSPORT_GOOD) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 977 | return 0; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 978 | } while (retry--); |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 979 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 980 | return -1; |
| 981 | } |
| 982 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 983 | static int usb_read_10(ccb *srb, struct us_data *ss, unsigned long start, |
| 984 | unsigned short blocks) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 985 | { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 986 | memset(&srb->cmd[0], 0, 12); |
| 987 | srb->cmd[0] = SCSI_READ10; |
Ludovic Courtès | 99e9ed1 | 2010-10-05 22:04:26 +0200 | [diff] [blame] | 988 | srb->cmd[1] = srb->lun << 5; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 989 | srb->cmd[2] = ((unsigned char) (start >> 24)) & 0xff; |
| 990 | srb->cmd[3] = ((unsigned char) (start >> 16)) & 0xff; |
| 991 | srb->cmd[4] = ((unsigned char) (start >> 8)) & 0xff; |
| 992 | srb->cmd[5] = ((unsigned char) (start)) & 0xff; |
| 993 | srb->cmd[7] = ((unsigned char) (blocks >> 8)) & 0xff; |
| 994 | srb->cmd[8] = (unsigned char) blocks & 0xff; |
| 995 | srb->cmdlen = 12; |
| 996 | USB_STOR_PRINTF("read10: start %lx blocks %x\n", start, blocks); |
| 997 | return ss->transport(srb, ss); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 998 | } |
| 999 | |
Mahavir Jain | 127e108 | 2009-11-03 12:22:10 +0530 | [diff] [blame] | 1000 | static int usb_write_10(ccb *srb, struct us_data *ss, unsigned long start, |
| 1001 | unsigned short blocks) |
| 1002 | { |
| 1003 | memset(&srb->cmd[0], 0, 12); |
| 1004 | srb->cmd[0] = SCSI_WRITE10; |
Ludovic Courtès | 99e9ed1 | 2010-10-05 22:04:26 +0200 | [diff] [blame] | 1005 | srb->cmd[1] = srb->lun << 5; |
Mahavir Jain | 127e108 | 2009-11-03 12:22:10 +0530 | [diff] [blame] | 1006 | srb->cmd[2] = ((unsigned char) (start >> 24)) & 0xff; |
| 1007 | srb->cmd[3] = ((unsigned char) (start >> 16)) & 0xff; |
| 1008 | srb->cmd[4] = ((unsigned char) (start >> 8)) & 0xff; |
| 1009 | srb->cmd[5] = ((unsigned char) (start)) & 0xff; |
| 1010 | srb->cmd[7] = ((unsigned char) (blocks >> 8)) & 0xff; |
| 1011 | srb->cmd[8] = (unsigned char) blocks & 0xff; |
| 1012 | srb->cmdlen = 12; |
| 1013 | USB_STOR_PRINTF("write10: start %lx blocks %x\n", start, blocks); |
| 1014 | return ss->transport(srb, ss); |
| 1015 | } |
| 1016 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1017 | |
Bartlomiej Sieka | ddde6b7 | 2006-08-22 10:38:18 +0200 | [diff] [blame] | 1018 | #ifdef CONFIG_USB_BIN_FIXUP |
| 1019 | /* |
| 1020 | * Some USB storage devices queried for SCSI identification data respond with |
| 1021 | * binary strings, which if output to the console freeze the terminal. The |
| 1022 | * workaround is to modify the vendor and product strings read from such |
| 1023 | * device with proper values (as reported by 'usb info'). |
| 1024 | * |
| 1025 | * Vendor and product length limits are taken from the definition of |
| 1026 | * block_dev_desc_t in include/part.h. |
| 1027 | */ |
| 1028 | static void usb_bin_fixup(struct usb_device_descriptor descriptor, |
| 1029 | unsigned char vendor[], |
| 1030 | unsigned char product[]) { |
| 1031 | const unsigned char max_vendor_len = 40; |
| 1032 | const unsigned char max_product_len = 20; |
| 1033 | if (descriptor.idVendor == 0x0424 && descriptor.idProduct == 0x223a) { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1034 | strncpy((char *)vendor, "SMSC", max_vendor_len); |
| 1035 | strncpy((char *)product, "Flash Media Cntrller", |
| 1036 | max_product_len); |
Bartlomiej Sieka | ddde6b7 | 2006-08-22 10:38:18 +0200 | [diff] [blame] | 1037 | } |
| 1038 | } |
| 1039 | #endif /* CONFIG_USB_BIN_FIXUP */ |
| 1040 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1041 | unsigned long usb_stor_read(int device, unsigned long blknr, |
| 1042 | unsigned long blkcnt, void *buffer) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1043 | { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1044 | unsigned long start, blks, buf_addr; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1045 | unsigned short smallblks; |
| 1046 | struct usb_device *dev; |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1047 | struct us_data *ss; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1048 | int retry, i; |
wdenk | f8d813e | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 1049 | ccb *srb = &usb_ccb; |
| 1050 | |
| 1051 | if (blkcnt == 0) |
| 1052 | return 0; |
| 1053 | |
| 1054 | device &= 0xff; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1055 | /* Setup device */ |
| 1056 | USB_STOR_PRINTF("\nusb_read: dev %d \n", device); |
| 1057 | dev = NULL; |
| 1058 | for (i = 0; i < USB_MAX_DEVICE; i++) { |
| 1059 | dev = usb_get_dev_index(i); |
| 1060 | if (dev == NULL) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1061 | return 0; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1062 | if (dev->devnum == usb_dev_desc[device].target) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1063 | break; |
| 1064 | } |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1065 | ss = (struct us_data *)dev->privptr; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1066 | |
| 1067 | usb_disable_asynch(1); /* asynch transfer not allowed */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1068 | srb->lun = usb_dev_desc[device].lun; |
| 1069 | buf_addr = (unsigned long)buffer; |
| 1070 | start = blknr; |
| 1071 | blks = blkcnt; |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1072 | if (usb_test_unit_ready(srb, ss)) { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1073 | printf("Device NOT ready\n Request Sense returned %02X %02X" |
| 1074 | " %02X\n", srb->sense_buf[2], srb->sense_buf[12], |
| 1075 | srb->sense_buf[13]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1076 | return 0; |
| 1077 | } |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1078 | |
| 1079 | USB_STOR_PRINTF("\nusb_read: dev %d startblk %lx, blccnt %lx" |
| 1080 | " buffer %lx\n", device, start, blks, buf_addr); |
| 1081 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1082 | do { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1083 | /* XXX need some comment here */ |
| 1084 | retry = 2; |
| 1085 | srb->pdata = (unsigned char *)buf_addr; |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1086 | if (blks > ss->max_xfer_blk) |
| 1087 | smallblks = ss->max_xfer_blk; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1088 | else |
| 1089 | smallblks = (unsigned short) blks; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1090 | retry_it: |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1091 | if (smallblks == ss->max_xfer_blk) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1092 | usb_show_progress(); |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1093 | srb->datalen = usb_dev_desc[device].blksz * smallblks; |
| 1094 | srb->pdata = (unsigned char *)buf_addr; |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1095 | if (usb_read_10(srb, ss, start, smallblks)) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1096 | USB_STOR_PRINTF("Read ERROR\n"); |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1097 | usb_request_sense(srb, ss); |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1098 | if (retry--) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1099 | goto retry_it; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1100 | blkcnt -= blks; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1101 | break; |
| 1102 | } |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1103 | start += smallblks; |
| 1104 | blks -= smallblks; |
| 1105 | buf_addr += srb->datalen; |
| 1106 | } while (blks != 0); |
| 1107 | |
| 1108 | USB_STOR_PRINTF("usb_read: end startblk %lx, blccnt %x buffer %lx\n", |
| 1109 | start, smallblks, buf_addr); |
| 1110 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1111 | usb_disable_asynch(0); /* asynch transfer allowed */ |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1112 | if (blkcnt >= ss->max_xfer_blk) |
Wolfgang Denk | 226fa9b | 2010-07-19 11:36:59 +0200 | [diff] [blame] | 1113 | debug("\n"); |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1114 | return blkcnt; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
Mahavir Jain | 127e108 | 2009-11-03 12:22:10 +0530 | [diff] [blame] | 1117 | unsigned long usb_stor_write(int device, unsigned long blknr, |
| 1118 | unsigned long blkcnt, const void *buffer) |
| 1119 | { |
| 1120 | unsigned long start, blks, buf_addr; |
| 1121 | unsigned short smallblks; |
| 1122 | struct usb_device *dev; |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1123 | struct us_data *ss; |
Mahavir Jain | 127e108 | 2009-11-03 12:22:10 +0530 | [diff] [blame] | 1124 | int retry, i; |
| 1125 | ccb *srb = &usb_ccb; |
| 1126 | |
| 1127 | if (blkcnt == 0) |
| 1128 | return 0; |
| 1129 | |
| 1130 | device &= 0xff; |
| 1131 | /* Setup device */ |
| 1132 | USB_STOR_PRINTF("\nusb_write: dev %d \n", device); |
| 1133 | dev = NULL; |
| 1134 | for (i = 0; i < USB_MAX_DEVICE; i++) { |
| 1135 | dev = usb_get_dev_index(i); |
| 1136 | if (dev == NULL) |
| 1137 | return 0; |
| 1138 | if (dev->devnum == usb_dev_desc[device].target) |
| 1139 | break; |
| 1140 | } |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1141 | ss = (struct us_data *)dev->privptr; |
Mahavir Jain | 127e108 | 2009-11-03 12:22:10 +0530 | [diff] [blame] | 1142 | |
| 1143 | usb_disable_asynch(1); /* asynch transfer not allowed */ |
| 1144 | |
| 1145 | srb->lun = usb_dev_desc[device].lun; |
| 1146 | buf_addr = (unsigned long)buffer; |
| 1147 | start = blknr; |
| 1148 | blks = blkcnt; |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1149 | if (usb_test_unit_ready(srb, ss)) { |
Mahavir Jain | 127e108 | 2009-11-03 12:22:10 +0530 | [diff] [blame] | 1150 | printf("Device NOT ready\n Request Sense returned %02X %02X" |
| 1151 | " %02X\n", srb->sense_buf[2], srb->sense_buf[12], |
| 1152 | srb->sense_buf[13]); |
| 1153 | return 0; |
| 1154 | } |
| 1155 | |
| 1156 | USB_STOR_PRINTF("\nusb_write: dev %d startblk %lx, blccnt %lx" |
| 1157 | " buffer %lx\n", device, start, blks, buf_addr); |
| 1158 | |
| 1159 | do { |
| 1160 | /* If write fails retry for max retry count else |
| 1161 | * return with number of blocks written successfully. |
| 1162 | */ |
| 1163 | retry = 2; |
| 1164 | srb->pdata = (unsigned char *)buf_addr; |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1165 | if (blks > ss->max_xfer_blk) |
| 1166 | smallblks = ss->max_xfer_blk; |
Mahavir Jain | 127e108 | 2009-11-03 12:22:10 +0530 | [diff] [blame] | 1167 | else |
| 1168 | smallblks = (unsigned short) blks; |
| 1169 | retry_it: |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1170 | if (smallblks == ss->max_xfer_blk) |
Mahavir Jain | 127e108 | 2009-11-03 12:22:10 +0530 | [diff] [blame] | 1171 | usb_show_progress(); |
| 1172 | srb->datalen = usb_dev_desc[device].blksz * smallblks; |
| 1173 | srb->pdata = (unsigned char *)buf_addr; |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1174 | if (usb_write_10(srb, ss, start, smallblks)) { |
Mahavir Jain | 127e108 | 2009-11-03 12:22:10 +0530 | [diff] [blame] | 1175 | USB_STOR_PRINTF("Write ERROR\n"); |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1176 | usb_request_sense(srb, ss); |
Mahavir Jain | 127e108 | 2009-11-03 12:22:10 +0530 | [diff] [blame] | 1177 | if (retry--) |
| 1178 | goto retry_it; |
| 1179 | blkcnt -= blks; |
| 1180 | break; |
| 1181 | } |
| 1182 | start += smallblks; |
| 1183 | blks -= smallblks; |
| 1184 | buf_addr += srb->datalen; |
| 1185 | } while (blks != 0); |
| 1186 | |
| 1187 | USB_STOR_PRINTF("usb_write: end startblk %lx, blccnt %x buffer %lx\n", |
| 1188 | start, smallblks, buf_addr); |
| 1189 | |
| 1190 | usb_disable_asynch(0); /* asynch transfer allowed */ |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1191 | if (blkcnt >= ss->max_xfer_blk) |
Wolfgang Denk | 226fa9b | 2010-07-19 11:36:59 +0200 | [diff] [blame] | 1192 | debug("\n"); |
Mahavir Jain | 127e108 | 2009-11-03 12:22:10 +0530 | [diff] [blame] | 1193 | return blkcnt; |
| 1194 | |
| 1195 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1196 | |
| 1197 | /* Probe to see if a new device is actually a Storage device */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1198 | int usb_storage_probe(struct usb_device *dev, unsigned int ifnum, |
| 1199 | struct us_data *ss) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1200 | { |
Tom Rix | 8f8bd56 | 2009-10-31 12:37:38 -0500 | [diff] [blame] | 1201 | struct usb_interface *iface; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1202 | int i; |
| 1203 | unsigned int flags = 0; |
| 1204 | |
| 1205 | int protocol = 0; |
| 1206 | int subclass = 0; |
| 1207 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1208 | /* let's examine the device now */ |
| 1209 | iface = &dev->config.if_desc[ifnum]; |
| 1210 | |
| 1211 | #if 0 |
| 1212 | /* this is the place to patch some storage devices */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1213 | USB_STOR_PRINTF("iVendor %X iProduct %X\n", dev->descriptor.idVendor, |
| 1214 | dev->descriptor.idProduct); |
| 1215 | |
| 1216 | if ((dev->descriptor.idVendor) == 0x066b && |
| 1217 | (dev->descriptor.idProduct) == 0x0103) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1218 | USB_STOR_PRINTF("patched for E-USB\n"); |
| 1219 | protocol = US_PR_CB; |
| 1220 | subclass = US_SC_UFI; /* an assumption */ |
| 1221 | } |
| 1222 | #endif |
| 1223 | |
| 1224 | if (dev->descriptor.bDeviceClass != 0 || |
Tom Rix | 8f8bd56 | 2009-10-31 12:37:38 -0500 | [diff] [blame] | 1225 | iface->desc.bInterfaceClass != USB_CLASS_MASS_STORAGE || |
| 1226 | iface->desc.bInterfaceSubClass < US_SC_MIN || |
| 1227 | iface->desc.bInterfaceSubClass > US_SC_MAX) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1228 | /* if it's not a mass storage, we go no further */ |
| 1229 | return 0; |
| 1230 | } |
| 1231 | |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 1232 | memset(ss, 0, sizeof(struct us_data)); |
| 1233 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1234 | /* At this point, we know we've got a live one */ |
| 1235 | USB_STOR_PRINTF("\n\nUSB Mass Storage device detected\n"); |
| 1236 | |
| 1237 | /* Initialize the us_data structure with some useful info */ |
| 1238 | ss->flags = flags; |
| 1239 | ss->ifnum = ifnum; |
| 1240 | ss->pusb_dev = dev; |
| 1241 | ss->attention_done = 0; |
| 1242 | |
| 1243 | /* If the device has subclass and protocol, then use that. Otherwise, |
| 1244 | * take data from the specific interface. |
| 1245 | */ |
| 1246 | if (subclass) { |
| 1247 | ss->subclass = subclass; |
| 1248 | ss->protocol = protocol; |
| 1249 | } else { |
Tom Rix | 8f8bd56 | 2009-10-31 12:37:38 -0500 | [diff] [blame] | 1250 | ss->subclass = iface->desc.bInterfaceSubClass; |
| 1251 | ss->protocol = iface->desc.bInterfaceProtocol; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | /* set the handler pointers based on the protocol */ |
| 1255 | USB_STOR_PRINTF("Transport: "); |
| 1256 | switch (ss->protocol) { |
| 1257 | case US_PR_CB: |
| 1258 | USB_STOR_PRINTF("Control/Bulk\n"); |
| 1259 | ss->transport = usb_stor_CB_transport; |
| 1260 | ss->transport_reset = usb_stor_CB_reset; |
| 1261 | break; |
| 1262 | |
| 1263 | case US_PR_CBI: |
| 1264 | USB_STOR_PRINTF("Control/Bulk/Interrupt\n"); |
| 1265 | ss->transport = usb_stor_CB_transport; |
| 1266 | ss->transport_reset = usb_stor_CB_reset; |
| 1267 | break; |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 1268 | case US_PR_BULK: |
| 1269 | USB_STOR_PRINTF("Bulk/Bulk/Bulk\n"); |
| 1270 | ss->transport = usb_stor_BBB_transport; |
| 1271 | ss->transport_reset = usb_stor_BBB_reset; |
| 1272 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1273 | default: |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 1274 | printf("USB Storage Transport unknown / not yet implemented\n"); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1275 | return 0; |
| 1276 | break; |
| 1277 | } |
| 1278 | |
| 1279 | /* |
| 1280 | * We are expecting a minimum of 2 endpoints - in and out (bulk). |
| 1281 | * An optional interrupt is OK (necessary for CBI protocol). |
| 1282 | * We will ignore any others. |
| 1283 | */ |
Tom Rix | 8f8bd56 | 2009-10-31 12:37:38 -0500 | [diff] [blame] | 1284 | for (i = 0; i < iface->desc.bNumEndpoints; i++) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1285 | /* is it an BULK endpoint? */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1286 | if ((iface->ep_desc[i].bmAttributes & |
| 1287 | USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1288 | if (iface->ep_desc[i].bEndpointAddress & USB_DIR_IN) |
| 1289 | ss->ep_in = iface->ep_desc[i].bEndpointAddress & |
| 1290 | USB_ENDPOINT_NUMBER_MASK; |
| 1291 | else |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1292 | ss->ep_out = |
| 1293 | iface->ep_desc[i].bEndpointAddress & |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1294 | USB_ENDPOINT_NUMBER_MASK; |
| 1295 | } |
| 1296 | |
| 1297 | /* is it an interrupt endpoint? */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1298 | if ((iface->ep_desc[i].bmAttributes & |
| 1299 | USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1300 | ss->ep_int = iface->ep_desc[i].bEndpointAddress & |
| 1301 | USB_ENDPOINT_NUMBER_MASK; |
| 1302 | ss->irqinterval = iface->ep_desc[i].bInterval; |
| 1303 | } |
| 1304 | } |
| 1305 | USB_STOR_PRINTF("Endpoints In %d Out %d Int %d\n", |
| 1306 | ss->ep_in, ss->ep_out, ss->ep_int); |
| 1307 | |
| 1308 | /* Do some basic sanity checks, and bail if we find a problem */ |
Tom Rix | 8f8bd56 | 2009-10-31 12:37:38 -0500 | [diff] [blame] | 1309 | if (usb_set_interface(dev, iface->desc.bInterfaceNumber, 0) || |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1310 | !ss->ep_in || !ss->ep_out || |
| 1311 | (ss->protocol == US_PR_CBI && ss->ep_int == 0)) { |
| 1312 | USB_STOR_PRINTF("Problems with device\n"); |
| 1313 | return 0; |
| 1314 | } |
| 1315 | /* set class specific stuff */ |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 1316 | /* We only handle certain protocols. Currently, these are |
| 1317 | * the only ones. |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 1318 | * The SFF8070 accepts the requests used in u-boot |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1319 | */ |
wdenk | 80885a9 | 2004-02-26 23:46:20 +0000 | [diff] [blame] | 1320 | if (ss->subclass != US_SC_UFI && ss->subclass != US_SC_SCSI && |
| 1321 | ss->subclass != US_SC_8070) { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1322 | printf("Sorry, protocol %d not yet supported.\n", ss->subclass); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1323 | return 0; |
| 1324 | } |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1325 | if (ss->ep_int) { |
| 1326 | /* we had found an interrupt endpoint, prepare irq pipe |
| 1327 | * set up the IRQ pipe and handler |
| 1328 | */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1329 | ss->irqinterval = (ss->irqinterval > 0) ? ss->irqinterval : 255; |
| 1330 | ss->irqpipe = usb_rcvintpipe(ss->pusb_dev, ss->ep_int); |
| 1331 | ss->irqmaxp = usb_maxpacket(dev, ss->irqpipe); |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1332 | dev->irq_handle = usb_stor_irq; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1333 | } |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1334 | dev->privptr = (void *)ss; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1335 | return 1; |
| 1336 | } |
| 1337 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1338 | int usb_stor_get_info(struct usb_device *dev, struct us_data *ss, |
| 1339 | block_dev_desc_t *dev_desc) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1340 | { |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1341 | unsigned char perq, modi; |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 1342 | ALLOC_CACHE_ALIGN_BUFFER(unsigned long, cap, 2); |
| 1343 | ALLOC_CACHE_ALIGN_BUFFER(unsigned char, usb_stor_buf, 36); |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1344 | unsigned long *capacity, *blksz; |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 1345 | ccb *pccb = &usb_ccb; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1346 | |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 1347 | pccb->pdata = usb_stor_buf; |
| 1348 | |
| 1349 | dev_desc->target = dev->devnum; |
| 1350 | pccb->lun = dev_desc->lun; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1351 | USB_STOR_PRINTF(" address %d\n", dev_desc->target); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1352 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1353 | if (usb_inquiry(pccb, ss)) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1354 | return -1; |
Wolfgang Denk | 095b8a3 | 2005-08-02 17:06:17 +0200 | [diff] [blame] | 1355 | |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 1356 | perq = usb_stor_buf[0]; |
| 1357 | modi = usb_stor_buf[1]; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1358 | |
| 1359 | if ((perq & 0x1f) == 0x1f) { |
| 1360 | /* skip unknown devices */ |
| 1361 | return 0; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1362 | } |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1363 | if ((modi&0x80) == 0x80) { |
| 1364 | /* drive is removable */ |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 1365 | dev_desc->removable = 1; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1366 | } |
Puneet Saxena | f576613 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 1367 | memcpy(&dev_desc->vendor[0], (const void *) &usb_stor_buf[8], 8); |
| 1368 | memcpy(&dev_desc->product[0], (const void *) &usb_stor_buf[16], 16); |
| 1369 | memcpy(&dev_desc->revision[0], (const void *) &usb_stor_buf[32], 4); |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 1370 | dev_desc->vendor[8] = 0; |
| 1371 | dev_desc->product[16] = 0; |
| 1372 | dev_desc->revision[4] = 0; |
Bartlomiej Sieka | ddde6b7 | 2006-08-22 10:38:18 +0200 | [diff] [blame] | 1373 | #ifdef CONFIG_USB_BIN_FIXUP |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1374 | usb_bin_fixup(dev->descriptor, (uchar *)dev_desc->vendor, |
| 1375 | (uchar *)dev_desc->product); |
Bartlomiej Sieka | ddde6b7 | 2006-08-22 10:38:18 +0200 | [diff] [blame] | 1376 | #endif /* CONFIG_USB_BIN_FIXUP */ |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1377 | USB_STOR_PRINTF("ISO Vers %X, Response Data %X\n", usb_stor_buf[2], |
| 1378 | usb_stor_buf[3]); |
| 1379 | if (usb_test_unit_ready(pccb, ss)) { |
| 1380 | printf("Device NOT ready\n" |
| 1381 | " Request Sense returned %02X %02X %02X\n", |
| 1382 | pccb->sense_buf[2], pccb->sense_buf[12], |
| 1383 | pccb->sense_buf[13]); |
| 1384 | if (dev_desc->removable == 1) { |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 1385 | dev_desc->type = perq; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1386 | return 1; |
| 1387 | } |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1388 | return 0; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1389 | } |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 1390 | pccb->pdata = (unsigned char *)&cap[0]; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1391 | memset(pccb->pdata, 0, 8); |
| 1392 | if (usb_read_capacity(pccb, ss) != 0) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1393 | printf("READ_CAP ERROR\n"); |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 1394 | cap[0] = 2880; |
| 1395 | cap[1] = 0x200; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1396 | } |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1397 | USB_STOR_PRINTF("Read Capacity returns: 0x%lx, 0x%lx\n", cap[0], |
| 1398 | cap[1]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1399 | #if 0 |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1400 | if (cap[0] > (0x200000 * 10)) /* greater than 10 GByte */ |
| 1401 | cap[0] >>= 16; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1402 | #endif |
Christian Eggers | c918261 | 2008-05-21 22:12:00 +0200 | [diff] [blame] | 1403 | cap[0] = cpu_to_be32(cap[0]); |
| 1404 | cap[1] = cpu_to_be32(cap[1]); |
| 1405 | |
wdenk | 149dded | 2003-09-10 18:20:28 +0000 | [diff] [blame] | 1406 | /* this assumes bigendian! */ |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 1407 | cap[0] += 1; |
| 1408 | capacity = &cap[0]; |
| 1409 | blksz = &cap[1]; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1410 | USB_STOR_PRINTF("Capacity = 0x%lx, blocksz = 0x%lx\n", |
| 1411 | *capacity, *blksz); |
Wolfgang Denk | 9c998aa | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 1412 | dev_desc->lba = *capacity; |
| 1413 | dev_desc->blksz = *blksz; |
| 1414 | dev_desc->type = perq; |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1415 | USB_STOR_PRINTF(" address %d\n", dev_desc->target); |
| 1416 | USB_STOR_PRINTF("partype: %d\n", dev_desc->part_type); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1417 | |
Kyle Moffett | 5dd95cf | 2011-12-21 07:08:12 +0000 | [diff] [blame] | 1418 | /* |
| 1419 | * The U-Boot EHCI driver cannot handle more than 4096 * 5 bytes in a |
| 1420 | * transfer without running itself out of qt_buffers. |
| 1421 | */ |
| 1422 | ss->max_xfer_blk = (4096 * 5) / dev_desc->blksz; |
| 1423 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1424 | init_part(dev_desc); |
| 1425 | |
Michael Trimarchi | a0cb3fc | 2008-12-10 15:52:06 +0100 | [diff] [blame] | 1426 | USB_STOR_PRINTF("partype: %d\n", dev_desc->part_type); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1427 | return 1; |
| 1428 | } |