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