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