GNU Linux-libre 4.9.337-gnu1
[releases.git] / drivers / usb / storage / alauda.c
1 /*
2  * Driver for Alauda-based card readers
3  *
4  * Current development and maintenance by:
5  *   (c) 2005 Daniel Drake <dsd@gentoo.org>
6  *
7  * The 'Alauda' is a chip manufacturered by RATOC for OEM use.
8  *
9  * Alauda implements a vendor-specific command set to access two media reader
10  * ports (XD, SmartMedia). This driver converts SCSI commands to the commands
11  * which are accepted by these devices.
12  *
13  * The driver was developed through reverse-engineering, with the help of the
14  * sddr09 driver which has many similarities, and with some help from the
15  * (very old) vendor-supplied GPL sma03 driver.
16  *
17  * For protocol info, see http://alauda.sourceforge.net
18  *
19  * This program is free software; you can redistribute it and/or modify it
20  * under the terms of the GNU General Public License as published by the
21  * Free Software Foundation; either version 2, or (at your option) any
22  * later version.
23  *
24  * This program is distributed in the hope that it will be useful, but
25  * WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27  * General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License along
30  * with this program; if not, write to the Free Software Foundation, Inc.,
31  * 675 Mass Ave, Cambridge, MA 02139, USA.
32  */
33
34 #include <linux/module.h>
35 #include <linux/slab.h>
36
37 #include <scsi/scsi.h>
38 #include <scsi/scsi_cmnd.h>
39 #include <scsi/scsi_device.h>
40
41 #include "usb.h"
42 #include "transport.h"
43 #include "protocol.h"
44 #include "debug.h"
45 #include "scsiglue.h"
46
47 #define DRV_NAME "ums-alauda"
48
49 MODULE_DESCRIPTION("Driver for Alauda-based card readers");
50 MODULE_AUTHOR("Daniel Drake <dsd@gentoo.org>");
51 MODULE_LICENSE("GPL");
52
53 /*
54  * Status bytes
55  */
56 #define ALAUDA_STATUS_ERROR             0x01
57 #define ALAUDA_STATUS_READY             0x40
58
59 /*
60  * Control opcodes (for request field)
61  */
62 #define ALAUDA_GET_XD_MEDIA_STATUS      0x08
63 #define ALAUDA_GET_SM_MEDIA_STATUS      0x98
64 #define ALAUDA_ACK_XD_MEDIA_CHANGE      0x0a
65 #define ALAUDA_ACK_SM_MEDIA_CHANGE      0x9a
66 #define ALAUDA_GET_XD_MEDIA_SIG         0x86
67 #define ALAUDA_GET_SM_MEDIA_SIG         0x96
68
69 /*
70  * Bulk command identity (byte 0)
71  */
72 #define ALAUDA_BULK_CMD                 0x40
73
74 /*
75  * Bulk opcodes (byte 1)
76  */
77 #define ALAUDA_BULK_GET_REDU_DATA       0x85
78 #define ALAUDA_BULK_READ_BLOCK          0x94
79 #define ALAUDA_BULK_ERASE_BLOCK         0xa3
80 #define ALAUDA_BULK_WRITE_BLOCK         0xb4
81 #define ALAUDA_BULK_GET_STATUS2         0xb7
82 #define ALAUDA_BULK_RESET_MEDIA         0xe0
83
84 /*
85  * Port to operate on (byte 8)
86  */
87 #define ALAUDA_PORT_XD                  0x00
88 #define ALAUDA_PORT_SM                  0x01
89
90 /*
91  * LBA and PBA are unsigned ints. Special values.
92  */
93 #define UNDEF    0xffff
94 #define SPARE    0xfffe
95 #define UNUSABLE 0xfffd
96
97 struct alauda_media_info {
98         unsigned long capacity;         /* total media size in bytes */
99         unsigned int pagesize;          /* page size in bytes */
100         unsigned int blocksize;         /* number of pages per block */
101         unsigned int uzonesize;         /* number of usable blocks per zone */
102         unsigned int zonesize;          /* number of blocks per zone */
103         unsigned int blockmask;         /* mask to get page from address */
104
105         unsigned char pageshift;
106         unsigned char blockshift;
107         unsigned char zoneshift;
108
109         u16 **lba_to_pba;               /* logical to physical block map */
110         u16 **pba_to_lba;               /* physical to logical block map */
111 };
112
113 struct alauda_info {
114         struct alauda_media_info port[2];
115         int wr_ep;                      /* endpoint to write data out of */
116
117         unsigned char sense_key;
118         unsigned long sense_asc;        /* additional sense code */
119         unsigned long sense_ascq;       /* additional sense code qualifier */
120 };
121
122 #define short_pack(lsb,msb) ( ((u16)(lsb)) | ( ((u16)(msb))<<8 ) )
123 #define LSB_of(s) ((s)&0xFF)
124 #define MSB_of(s) ((s)>>8)
125
126 #define MEDIA_PORT(us) us->srb->device->lun
127 #define MEDIA_INFO(us) ((struct alauda_info *)us->extra)->port[MEDIA_PORT(us)]
128
129 #define PBA_LO(pba) ((pba & 0xF) << 5)
130 #define PBA_HI(pba) (pba >> 3)
131 #define PBA_ZONE(pba) (pba >> 11)
132
133 static int init_alauda(struct us_data *us);
134
135
136 /*
137  * The table of devices
138  */
139 #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
140                     vendorName, productName, useProtocol, useTransport, \
141                     initFunction, flags) \
142 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
143   .driver_info = (flags) }
144
145 static struct usb_device_id alauda_usb_ids[] = {
146 #       include "unusual_alauda.h"
147         { }             /* Terminating entry */
148 };
149 MODULE_DEVICE_TABLE(usb, alauda_usb_ids);
150
151 #undef UNUSUAL_DEV
152
153 /*
154  * The flags table
155  */
156 #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
157                     vendor_name, product_name, use_protocol, use_transport, \
158                     init_function, Flags) \
159 { \
160         .vendorName = vendor_name,      \
161         .productName = product_name,    \
162         .useProtocol = use_protocol,    \
163         .useTransport = use_transport,  \
164         .initFunction = init_function,  \
165 }
166
167 static struct us_unusual_dev alauda_unusual_dev_list[] = {
168 #       include "unusual_alauda.h"
169         { }             /* Terminating entry */
170 };
171
172 #undef UNUSUAL_DEV
173
174
175 /*
176  * Media handling
177  */
178
179 struct alauda_card_info {
180         unsigned char id;               /* id byte */
181         unsigned char chipshift;        /* 1<<cs bytes total capacity */
182         unsigned char pageshift;        /* 1<<ps bytes in a page */
183         unsigned char blockshift;       /* 1<<bs pages per block */
184         unsigned char zoneshift;        /* 1<<zs blocks per zone */
185 };
186
187 static struct alauda_card_info alauda_card_ids[] = {
188         /* NAND flash */
189         { 0x6e, 20, 8, 4, 8},   /* 1 MB */
190         { 0xe8, 20, 8, 4, 8},   /* 1 MB */
191         { 0xec, 20, 8, 4, 8},   /* 1 MB */
192         { 0x64, 21, 8, 4, 9},   /* 2 MB */
193         { 0xea, 21, 8, 4, 9},   /* 2 MB */
194         { 0x6b, 22, 9, 4, 9},   /* 4 MB */
195         { 0xe3, 22, 9, 4, 9},   /* 4 MB */
196         { 0xe5, 22, 9, 4, 9},   /* 4 MB */
197         { 0xe6, 23, 9, 4, 10},  /* 8 MB */
198         { 0x73, 24, 9, 5, 10},  /* 16 MB */
199         { 0x75, 25, 9, 5, 10},  /* 32 MB */
200         { 0x76, 26, 9, 5, 10},  /* 64 MB */
201         { 0x79, 27, 9, 5, 10},  /* 128 MB */
202         { 0x71, 28, 9, 5, 10},  /* 256 MB */
203
204         /* MASK ROM */
205         { 0x5d, 21, 9, 4, 8},   /* 2 MB */
206         { 0xd5, 22, 9, 4, 9},   /* 4 MB */
207         { 0xd6, 23, 9, 4, 10},  /* 8 MB */
208         { 0x57, 24, 9, 4, 11},  /* 16 MB */
209         { 0x58, 25, 9, 4, 12},  /* 32 MB */
210         { 0,}
211 };
212
213 static struct alauda_card_info *alauda_card_find_id(unsigned char id)
214 {
215         int i;
216
217         for (i = 0; alauda_card_ids[i].id != 0; i++)
218                 if (alauda_card_ids[i].id == id)
219                         return &(alauda_card_ids[i]);
220         return NULL;
221 }
222
223 /*
224  * ECC computation.
225  */
226
227 static unsigned char parity[256];
228 static unsigned char ecc2[256];
229
230 static void nand_init_ecc(void)
231 {
232         int i, j, a;
233
234         parity[0] = 0;
235         for (i = 1; i < 256; i++)
236                 parity[i] = (parity[i&(i-1)] ^ 1);
237
238         for (i = 0; i < 256; i++) {
239                 a = 0;
240                 for (j = 0; j < 8; j++) {
241                         if (i & (1<<j)) {
242                                 if ((j & 1) == 0)
243                                         a ^= 0x04;
244                                 if ((j & 2) == 0)
245                                         a ^= 0x10;
246                                 if ((j & 4) == 0)
247                                         a ^= 0x40;
248                         }
249                 }
250                 ecc2[i] = ~(a ^ (a<<1) ^ (parity[i] ? 0xa8 : 0));
251         }
252 }
253
254 /* compute 3-byte ecc on 256 bytes */
255 static void nand_compute_ecc(unsigned char *data, unsigned char *ecc)
256 {
257         int i, j, a;
258         unsigned char par = 0, bit, bits[8] = {0};
259
260         /* collect 16 checksum bits */
261         for (i = 0; i < 256; i++) {
262                 par ^= data[i];
263                 bit = parity[data[i]];
264                 for (j = 0; j < 8; j++)
265                         if ((i & (1<<j)) == 0)
266                                 bits[j] ^= bit;
267         }
268
269         /* put 4+4+4 = 12 bits in the ecc */
270         a = (bits[3] << 6) + (bits[2] << 4) + (bits[1] << 2) + bits[0];
271         ecc[0] = ~(a ^ (a<<1) ^ (parity[par] ? 0xaa : 0));
272
273         a = (bits[7] << 6) + (bits[6] << 4) + (bits[5] << 2) + bits[4];
274         ecc[1] = ~(a ^ (a<<1) ^ (parity[par] ? 0xaa : 0));
275
276         ecc[2] = ecc2[par];
277 }
278
279 static int nand_compare_ecc(unsigned char *data, unsigned char *ecc)
280 {
281         return (data[0] == ecc[0] && data[1] == ecc[1] && data[2] == ecc[2]);
282 }
283
284 static void nand_store_ecc(unsigned char *data, unsigned char *ecc)
285 {
286         memcpy(data, ecc, 3);
287 }
288
289 /*
290  * Alauda driver
291  */
292
293 /*
294  * Forget our PBA <---> LBA mappings for a particular port
295  */
296 static void alauda_free_maps (struct alauda_media_info *media_info)
297 {
298         unsigned int shift = media_info->zoneshift
299                 + media_info->blockshift + media_info->pageshift;
300         unsigned int num_zones = media_info->capacity >> shift;
301         unsigned int i;
302
303         if (media_info->lba_to_pba != NULL)
304                 for (i = 0; i < num_zones; i++) {
305                         kfree(media_info->lba_to_pba[i]);
306                         media_info->lba_to_pba[i] = NULL;
307                 }
308
309         if (media_info->pba_to_lba != NULL)
310                 for (i = 0; i < num_zones; i++) {
311                         kfree(media_info->pba_to_lba[i]);
312                         media_info->pba_to_lba[i] = NULL;
313                 }
314 }
315
316 /*
317  * Returns 2 bytes of status data
318  * The first byte describes media status, and second byte describes door status
319  */
320 static int alauda_get_media_status(struct us_data *us, unsigned char *data)
321 {
322         int rc;
323         unsigned char command;
324
325         if (MEDIA_PORT(us) == ALAUDA_PORT_XD)
326                 command = ALAUDA_GET_XD_MEDIA_STATUS;
327         else
328                 command = ALAUDA_GET_SM_MEDIA_STATUS;
329
330         rc = usb_stor_ctrl_transfer(us, us->recv_ctrl_pipe,
331                 command, 0xc0, 0, 1, data, 2);
332
333         usb_stor_dbg(us, "Media status %02X %02X\n", data[0], data[1]);
334
335         return rc;
336 }
337
338 /*
339  * Clears the "media was changed" bit so that we know when it changes again
340  * in the future.
341  */
342 static int alauda_ack_media(struct us_data *us)
343 {
344         unsigned char command;
345
346         if (MEDIA_PORT(us) == ALAUDA_PORT_XD)
347                 command = ALAUDA_ACK_XD_MEDIA_CHANGE;
348         else
349                 command = ALAUDA_ACK_SM_MEDIA_CHANGE;
350
351         return usb_stor_ctrl_transfer(us, us->send_ctrl_pipe,
352                 command, 0x40, 0, 1, NULL, 0);
353 }
354
355 /*
356  * Retrieves a 4-byte media signature, which indicates manufacturer, capacity,
357  * and some other details.
358  */
359 static int alauda_get_media_signature(struct us_data *us, unsigned char *data)
360 {
361         unsigned char command;
362
363         if (MEDIA_PORT(us) == ALAUDA_PORT_XD)
364                 command = ALAUDA_GET_XD_MEDIA_SIG;
365         else
366                 command = ALAUDA_GET_SM_MEDIA_SIG;
367
368         return usb_stor_ctrl_transfer(us, us->recv_ctrl_pipe,
369                 command, 0xc0, 0, 0, data, 4);
370 }
371
372 /*
373  * Resets the media status (but not the whole device?)
374  */
375 static int alauda_reset_media(struct us_data *us)
376 {
377         unsigned char *command = us->iobuf;
378
379         memset(command, 0, 9);
380         command[0] = ALAUDA_BULK_CMD;
381         command[1] = ALAUDA_BULK_RESET_MEDIA;
382         command[8] = MEDIA_PORT(us);
383
384         return usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
385                 command, 9, NULL);
386 }
387
388 /*
389  * Examines the media and deduces capacity, etc.
390  */
391 static int alauda_init_media(struct us_data *us)
392 {
393         unsigned char *data = us->iobuf;
394         int ready = 0;
395         struct alauda_card_info *media_info;
396         unsigned int num_zones;
397
398         while (ready == 0) {
399                 msleep(20);
400
401                 if (alauda_get_media_status(us, data) != USB_STOR_XFER_GOOD)
402                         return USB_STOR_TRANSPORT_ERROR;
403
404                 if (data[0] & 0x10)
405                         ready = 1;
406         }
407
408         usb_stor_dbg(us, "We are ready for action!\n");
409
410         if (alauda_ack_media(us) != USB_STOR_XFER_GOOD)
411                 return USB_STOR_TRANSPORT_ERROR;
412
413         msleep(10);
414
415         if (alauda_get_media_status(us, data) != USB_STOR_XFER_GOOD)
416                 return USB_STOR_TRANSPORT_ERROR;
417
418         if (data[0] != 0x14) {
419                 usb_stor_dbg(us, "Media not ready after ack\n");
420                 return USB_STOR_TRANSPORT_ERROR;
421         }
422
423         if (alauda_get_media_signature(us, data) != USB_STOR_XFER_GOOD)
424                 return USB_STOR_TRANSPORT_ERROR;
425
426         usb_stor_dbg(us, "Media signature: %4ph\n", data);
427         media_info = alauda_card_find_id(data[1]);
428         if (media_info == NULL) {
429                 pr_warn("alauda_init_media: Unrecognised media signature: %4ph\n",
430                         data);
431                 return USB_STOR_TRANSPORT_ERROR;
432         }
433
434         MEDIA_INFO(us).capacity = 1 << media_info->chipshift;
435         usb_stor_dbg(us, "Found media with capacity: %ldMB\n",
436                      MEDIA_INFO(us).capacity >> 20);
437
438         MEDIA_INFO(us).pageshift = media_info->pageshift;
439         MEDIA_INFO(us).blockshift = media_info->blockshift;
440         MEDIA_INFO(us).zoneshift = media_info->zoneshift;
441
442         MEDIA_INFO(us).pagesize = 1 << media_info->pageshift;
443         MEDIA_INFO(us).blocksize = 1 << media_info->blockshift;
444         MEDIA_INFO(us).zonesize = 1 << media_info->zoneshift;
445
446         MEDIA_INFO(us).uzonesize = ((1 << media_info->zoneshift) / 128) * 125;
447         MEDIA_INFO(us).blockmask = MEDIA_INFO(us).blocksize - 1;
448
449         num_zones = MEDIA_INFO(us).capacity >> (MEDIA_INFO(us).zoneshift
450                 + MEDIA_INFO(us).blockshift + MEDIA_INFO(us).pageshift);
451         MEDIA_INFO(us).pba_to_lba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO);
452         MEDIA_INFO(us).lba_to_pba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO);
453         if (MEDIA_INFO(us).pba_to_lba == NULL || MEDIA_INFO(us).lba_to_pba == NULL)
454                 return USB_STOR_TRANSPORT_ERROR;
455
456         if (alauda_reset_media(us) != USB_STOR_XFER_GOOD)
457                 return USB_STOR_TRANSPORT_ERROR;
458
459         return USB_STOR_TRANSPORT_GOOD;
460 }
461
462 /*
463  * Examines the media status and does the right thing when the media has gone,
464  * appeared, or changed.
465  */
466 static int alauda_check_media(struct us_data *us)
467 {
468         struct alauda_info *info = (struct alauda_info *) us->extra;
469         unsigned char status[2];
470         int rc;
471
472         rc = alauda_get_media_status(us, status);
473
474         /* Check for no media or door open */
475         if ((status[0] & 0x80) || ((status[0] & 0x1F) == 0x10)
476                 || ((status[1] & 0x01) == 0)) {
477                 usb_stor_dbg(us, "No media, or door open\n");
478                 alauda_free_maps(&MEDIA_INFO(us));
479                 info->sense_key = 0x02;
480                 info->sense_asc = 0x3A;
481                 info->sense_ascq = 0x00;
482                 return USB_STOR_TRANSPORT_FAILED;
483         }
484
485         /* Check for media change */
486         if (status[0] & 0x08) {
487                 usb_stor_dbg(us, "Media change detected\n");
488                 alauda_free_maps(&MEDIA_INFO(us));
489                 alauda_init_media(us);
490
491                 info->sense_key = UNIT_ATTENTION;
492                 info->sense_asc = 0x28;
493                 info->sense_ascq = 0x00;
494                 return USB_STOR_TRANSPORT_FAILED;
495         }
496
497         return USB_STOR_TRANSPORT_GOOD;
498 }
499
500 /*
501  * Checks the status from the 2nd status register
502  * Returns 3 bytes of status data, only the first is known
503  */
504 static int alauda_check_status2(struct us_data *us)
505 {
506         int rc;
507         unsigned char command[] = {
508                 ALAUDA_BULK_CMD, ALAUDA_BULK_GET_STATUS2,
509                 0, 0, 0, 0, 3, 0, MEDIA_PORT(us)
510         };
511         unsigned char data[3];
512
513         rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
514                 command, 9, NULL);
515         if (rc != USB_STOR_XFER_GOOD)
516                 return rc;
517
518         rc = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
519                 data, 3, NULL);
520         if (rc != USB_STOR_XFER_GOOD)
521                 return rc;
522
523         usb_stor_dbg(us, "%3ph\n", data);
524         if (data[0] & ALAUDA_STATUS_ERROR)
525                 return USB_STOR_XFER_ERROR;
526
527         return USB_STOR_XFER_GOOD;
528 }
529
530 /*
531  * Gets the redundancy data for the first page of a PBA
532  * Returns 16 bytes.
533  */
534 static int alauda_get_redu_data(struct us_data *us, u16 pba, unsigned char *data)
535 {
536         int rc;
537         unsigned char command[] = {
538                 ALAUDA_BULK_CMD, ALAUDA_BULK_GET_REDU_DATA,
539                 PBA_HI(pba), PBA_ZONE(pba), 0, PBA_LO(pba), 0, 0, MEDIA_PORT(us)
540         };
541
542         rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
543                 command, 9, NULL);
544         if (rc != USB_STOR_XFER_GOOD)
545                 return rc;
546
547         return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
548                 data, 16, NULL);
549 }
550
551 /*
552  * Finds the first unused PBA in a zone
553  * Returns the absolute PBA of an unused PBA, or 0 if none found.
554  */
555 static u16 alauda_find_unused_pba(struct alauda_media_info *info,
556         unsigned int zone)
557 {
558         u16 *pba_to_lba = info->pba_to_lba[zone];
559         unsigned int i;
560
561         for (i = 0; i < info->zonesize; i++)
562                 if (pba_to_lba[i] == UNDEF)
563                         return (zone << info->zoneshift) + i;
564
565         return 0;
566 }
567
568 /*
569  * Reads the redundancy data for all PBA's in a zone
570  * Produces lba <--> pba mappings
571  */
572 static int alauda_read_map(struct us_data *us, unsigned int zone)
573 {
574         unsigned char *data = us->iobuf;
575         int result;
576         int i, j;
577         unsigned int zonesize = MEDIA_INFO(us).zonesize;
578         unsigned int uzonesize = MEDIA_INFO(us).uzonesize;
579         unsigned int lba_offset, lba_real, blocknum;
580         unsigned int zone_base_lba = zone * uzonesize;
581         unsigned int zone_base_pba = zone * zonesize;
582         u16 *lba_to_pba = kcalloc(zonesize, sizeof(u16), GFP_NOIO);
583         u16 *pba_to_lba = kcalloc(zonesize, sizeof(u16), GFP_NOIO);
584         if (lba_to_pba == NULL || pba_to_lba == NULL) {
585                 result = USB_STOR_TRANSPORT_ERROR;
586                 goto error;
587         }
588
589         usb_stor_dbg(us, "Mapping blocks for zone %d\n", zone);
590
591         /* 1024 PBA's per zone */
592         for (i = 0; i < zonesize; i++)
593                 lba_to_pba[i] = pba_to_lba[i] = UNDEF;
594
595         for (i = 0; i < zonesize; i++) {
596                 blocknum = zone_base_pba + i;
597
598                 result = alauda_get_redu_data(us, blocknum, data);
599                 if (result != USB_STOR_XFER_GOOD) {
600                         result = USB_STOR_TRANSPORT_ERROR;
601                         goto error;
602                 }
603
604                 /* special PBAs have control field 0^16 */
605                 for (j = 0; j < 16; j++)
606                         if (data[j] != 0)
607                                 goto nonz;
608                 pba_to_lba[i] = UNUSABLE;
609                 usb_stor_dbg(us, "PBA %d has no logical mapping\n", blocknum);
610                 continue;
611
612         nonz:
613                 /* unwritten PBAs have control field FF^16 */
614                 for (j = 0; j < 16; j++)
615                         if (data[j] != 0xff)
616                                 goto nonff;
617                 continue;
618
619         nonff:
620                 /* normal PBAs start with six FFs */
621                 if (j < 6) {
622                         usb_stor_dbg(us, "PBA %d has no logical mapping: reserved area = %02X%02X%02X%02X data status %02X block status %02X\n",
623                                      blocknum,
624                                      data[0], data[1], data[2], data[3],
625                                      data[4], data[5]);
626                         pba_to_lba[i] = UNUSABLE;
627                         continue;
628                 }
629
630                 if ((data[6] >> 4) != 0x01) {
631                         usb_stor_dbg(us, "PBA %d has invalid address field %02X%02X/%02X%02X\n",
632                                      blocknum, data[6], data[7],
633                                      data[11], data[12]);
634                         pba_to_lba[i] = UNUSABLE;
635                         continue;
636                 }
637
638                 /* check even parity */
639                 if (parity[data[6] ^ data[7]]) {
640                         printk(KERN_WARNING
641                                "alauda_read_map: Bad parity in LBA for block %d"
642                                " (%02X %02X)\n", i, data[6], data[7]);
643                         pba_to_lba[i] = UNUSABLE;
644                         continue;
645                 }
646
647                 lba_offset = short_pack(data[7], data[6]);
648                 lba_offset = (lba_offset & 0x07FF) >> 1;
649                 lba_real = lba_offset + zone_base_lba;
650
651                 /*
652                  * Every 1024 physical blocks ("zone"), the LBA numbers
653                  * go back to zero, but are within a higher block of LBA's.
654                  * Also, there is a maximum of 1000 LBA's per zone.
655                  * In other words, in PBA 1024-2047 you will find LBA 0-999
656                  * which are really LBA 1000-1999. This allows for 24 bad
657                  * or special physical blocks per zone.
658                  */
659
660                 if (lba_offset >= uzonesize) {
661                         printk(KERN_WARNING
662                                "alauda_read_map: Bad low LBA %d for block %d\n",
663                                lba_real, blocknum);
664                         continue;
665                 }
666
667                 if (lba_to_pba[lba_offset] != UNDEF) {
668                         printk(KERN_WARNING
669                                "alauda_read_map: "
670                                "LBA %d seen for PBA %d and %d\n",
671                                lba_real, lba_to_pba[lba_offset], blocknum);
672                         continue;
673                 }
674
675                 pba_to_lba[i] = lba_real;
676                 lba_to_pba[lba_offset] = blocknum;
677                 continue;
678         }
679
680         MEDIA_INFO(us).lba_to_pba[zone] = lba_to_pba;
681         MEDIA_INFO(us).pba_to_lba[zone] = pba_to_lba;
682         result = 0;
683         goto out;
684
685 error:
686         kfree(lba_to_pba);
687         kfree(pba_to_lba);
688 out:
689         return result;
690 }
691
692 /*
693  * Checks to see whether we have already mapped a certain zone
694  * If we haven't, the map is generated
695  */
696 static void alauda_ensure_map_for_zone(struct us_data *us, unsigned int zone)
697 {
698         if (MEDIA_INFO(us).lba_to_pba[zone] == NULL
699                 || MEDIA_INFO(us).pba_to_lba[zone] == NULL)
700                 alauda_read_map(us, zone);
701 }
702
703 /*
704  * Erases an entire block
705  */
706 static int alauda_erase_block(struct us_data *us, u16 pba)
707 {
708         int rc;
709         unsigned char command[] = {
710                 ALAUDA_BULK_CMD, ALAUDA_BULK_ERASE_BLOCK, PBA_HI(pba),
711                 PBA_ZONE(pba), 0, PBA_LO(pba), 0x02, 0, MEDIA_PORT(us)
712         };
713         unsigned char buf[2];
714
715         usb_stor_dbg(us, "Erasing PBA %d\n", pba);
716
717         rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
718                 command, 9, NULL);
719         if (rc != USB_STOR_XFER_GOOD)
720                 return rc;
721
722         rc = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
723                 buf, 2, NULL);
724         if (rc != USB_STOR_XFER_GOOD)
725                 return rc;
726
727         usb_stor_dbg(us, "Erase result: %02X %02X\n", buf[0], buf[1]);
728         return rc;
729 }
730
731 /*
732  * Reads data from a certain offset page inside a PBA, including interleaved
733  * redundancy data. Returns (pagesize+64)*pages bytes in data.
734  */
735 static int alauda_read_block_raw(struct us_data *us, u16 pba,
736                 unsigned int page, unsigned int pages, unsigned char *data)
737 {
738         int rc;
739         unsigned char command[] = {
740                 ALAUDA_BULK_CMD, ALAUDA_BULK_READ_BLOCK, PBA_HI(pba),
741                 PBA_ZONE(pba), 0, PBA_LO(pba) + page, pages, 0, MEDIA_PORT(us)
742         };
743
744         usb_stor_dbg(us, "pba %d page %d count %d\n", pba, page, pages);
745
746         rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
747                 command, 9, NULL);
748         if (rc != USB_STOR_XFER_GOOD)
749                 return rc;
750
751         return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
752                 data, (MEDIA_INFO(us).pagesize + 64) * pages, NULL);
753 }
754
755 /*
756  * Reads data from a certain offset page inside a PBA, excluding redundancy
757  * data. Returns pagesize*pages bytes in data. Note that data must be big enough
758  * to hold (pagesize+64)*pages bytes of data, but you can ignore those 'extra'
759  * trailing bytes outside this function.
760  */
761 static int alauda_read_block(struct us_data *us, u16 pba,
762                 unsigned int page, unsigned int pages, unsigned char *data)
763 {
764         int i, rc;
765         unsigned int pagesize = MEDIA_INFO(us).pagesize;
766
767         rc = alauda_read_block_raw(us, pba, page, pages, data);
768         if (rc != USB_STOR_XFER_GOOD)
769                 return rc;
770
771         /* Cut out the redundancy data */
772         for (i = 0; i < pages; i++) {
773                 int dest_offset = i * pagesize;
774                 int src_offset = i * (pagesize + 64);
775                 memmove(data + dest_offset, data + src_offset, pagesize);
776         }
777
778         return rc;
779 }
780
781 /*
782  * Writes an entire block of data and checks status after write.
783  * Redundancy data must be already included in data. Data should be
784  * (pagesize+64)*blocksize bytes in length.
785  */
786 static int alauda_write_block(struct us_data *us, u16 pba, unsigned char *data)
787 {
788         int rc;
789         struct alauda_info *info = (struct alauda_info *) us->extra;
790         unsigned char command[] = {
791                 ALAUDA_BULK_CMD, ALAUDA_BULK_WRITE_BLOCK, PBA_HI(pba),
792                 PBA_ZONE(pba), 0, PBA_LO(pba), 32, 0, MEDIA_PORT(us)
793         };
794
795         usb_stor_dbg(us, "pba %d\n", pba);
796
797         rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
798                 command, 9, NULL);
799         if (rc != USB_STOR_XFER_GOOD)
800                 return rc;
801
802         rc = usb_stor_bulk_transfer_buf(us, info->wr_ep, data,
803                 (MEDIA_INFO(us).pagesize + 64) * MEDIA_INFO(us).blocksize,
804                 NULL);
805         if (rc != USB_STOR_XFER_GOOD)
806                 return rc;
807
808         return alauda_check_status2(us);
809 }
810
811 /*
812  * Write some data to a specific LBA.
813  */
814 static int alauda_write_lba(struct us_data *us, u16 lba,
815                  unsigned int page, unsigned int pages,
816                  unsigned char *ptr, unsigned char *blockbuffer)
817 {
818         u16 pba, lbap, new_pba;
819         unsigned char *bptr, *cptr, *xptr;
820         unsigned char ecc[3];
821         int i, result;
822         unsigned int uzonesize = MEDIA_INFO(us).uzonesize;
823         unsigned int zonesize = MEDIA_INFO(us).zonesize;
824         unsigned int pagesize = MEDIA_INFO(us).pagesize;
825         unsigned int blocksize = MEDIA_INFO(us).blocksize;
826         unsigned int lba_offset = lba % uzonesize;
827         unsigned int new_pba_offset;
828         unsigned int zone = lba / uzonesize;
829
830         alauda_ensure_map_for_zone(us, zone);
831
832         pba = MEDIA_INFO(us).lba_to_pba[zone][lba_offset];
833         if (pba == 1) {
834                 /*
835                  * Maybe it is impossible to write to PBA 1.
836                  * Fake success, but don't do anything.
837                  */
838                 printk(KERN_WARNING
839                        "alauda_write_lba: avoid writing to pba 1\n");
840                 return USB_STOR_TRANSPORT_GOOD;
841         }
842
843         new_pba = alauda_find_unused_pba(&MEDIA_INFO(us), zone);
844         if (!new_pba) {
845                 printk(KERN_WARNING
846                        "alauda_write_lba: Out of unused blocks\n");
847                 return USB_STOR_TRANSPORT_ERROR;
848         }
849
850         /* read old contents */
851         if (pba != UNDEF) {
852                 result = alauda_read_block_raw(us, pba, 0,
853                         blocksize, blockbuffer);
854                 if (result != USB_STOR_XFER_GOOD)
855                         return result;
856         } else {
857                 memset(blockbuffer, 0, blocksize * (pagesize + 64));
858         }
859
860         lbap = (lba_offset << 1) | 0x1000;
861         if (parity[MSB_of(lbap) ^ LSB_of(lbap)])
862                 lbap ^= 1;
863
864         /* check old contents and fill lba */
865         for (i = 0; i < blocksize; i++) {
866                 bptr = blockbuffer + (i * (pagesize + 64));
867                 cptr = bptr + pagesize;
868                 nand_compute_ecc(bptr, ecc);
869                 if (!nand_compare_ecc(cptr+13, ecc)) {
870                         usb_stor_dbg(us, "Warning: bad ecc in page %d- of pba %d\n",
871                                      i, pba);
872                         nand_store_ecc(cptr+13, ecc);
873                 }
874                 nand_compute_ecc(bptr + (pagesize / 2), ecc);
875                 if (!nand_compare_ecc(cptr+8, ecc)) {
876                         usb_stor_dbg(us, "Warning: bad ecc in page %d+ of pba %d\n",
877                                      i, pba);
878                         nand_store_ecc(cptr+8, ecc);
879                 }
880                 cptr[6] = cptr[11] = MSB_of(lbap);
881                 cptr[7] = cptr[12] = LSB_of(lbap);
882         }
883
884         /* copy in new stuff and compute ECC */
885         xptr = ptr;
886         for (i = page; i < page+pages; i++) {
887                 bptr = blockbuffer + (i * (pagesize + 64));
888                 cptr = bptr + pagesize;
889                 memcpy(bptr, xptr, pagesize);
890                 xptr += pagesize;
891                 nand_compute_ecc(bptr, ecc);
892                 nand_store_ecc(cptr+13, ecc);
893                 nand_compute_ecc(bptr + (pagesize / 2), ecc);
894                 nand_store_ecc(cptr+8, ecc);
895         }
896
897         result = alauda_write_block(us, new_pba, blockbuffer);
898         if (result != USB_STOR_XFER_GOOD)
899                 return result;
900
901         new_pba_offset = new_pba - (zone * zonesize);
902         MEDIA_INFO(us).pba_to_lba[zone][new_pba_offset] = lba;
903         MEDIA_INFO(us).lba_to_pba[zone][lba_offset] = new_pba;
904         usb_stor_dbg(us, "Remapped LBA %d to PBA %d\n", lba, new_pba);
905
906         if (pba != UNDEF) {
907                 unsigned int pba_offset = pba - (zone * zonesize);
908                 result = alauda_erase_block(us, pba);
909                 if (result != USB_STOR_XFER_GOOD)
910                         return result;
911                 MEDIA_INFO(us).pba_to_lba[zone][pba_offset] = UNDEF;
912         }
913
914         return USB_STOR_TRANSPORT_GOOD;
915 }
916
917 /*
918  * Read data from a specific sector address
919  */
920 static int alauda_read_data(struct us_data *us, unsigned long address,
921                 unsigned int sectors)
922 {
923         unsigned char *buffer;
924         u16 lba, max_lba;
925         unsigned int page, len, offset;
926         unsigned int blockshift = MEDIA_INFO(us).blockshift;
927         unsigned int pageshift = MEDIA_INFO(us).pageshift;
928         unsigned int blocksize = MEDIA_INFO(us).blocksize;
929         unsigned int pagesize = MEDIA_INFO(us).pagesize;
930         unsigned int uzonesize = MEDIA_INFO(us).uzonesize;
931         struct scatterlist *sg;
932         int result;
933
934         /*
935          * Since we only read in one block at a time, we have to create
936          * a bounce buffer and move the data a piece at a time between the
937          * bounce buffer and the actual transfer buffer.
938          * We make this buffer big enough to hold temporary redundancy data,
939          * which we use when reading the data blocks.
940          */
941
942         len = min(sectors, blocksize) * (pagesize + 64);
943         buffer = kmalloc(len, GFP_NOIO);
944         if (!buffer)
945                 return USB_STOR_TRANSPORT_ERROR;
946
947         /* Figure out the initial LBA and page */
948         lba = address >> blockshift;
949         page = (address & MEDIA_INFO(us).blockmask);
950         max_lba = MEDIA_INFO(us).capacity >> (blockshift + pageshift);
951
952         result = USB_STOR_TRANSPORT_GOOD;
953         offset = 0;
954         sg = NULL;
955
956         while (sectors > 0) {
957                 unsigned int zone = lba / uzonesize; /* integer division */
958                 unsigned int lba_offset = lba - (zone * uzonesize);
959                 unsigned int pages;
960                 u16 pba;
961                 alauda_ensure_map_for_zone(us, zone);
962
963                 /* Not overflowing capacity? */
964                 if (lba >= max_lba) {
965                         usb_stor_dbg(us, "Error: Requested lba %u exceeds maximum %u\n",
966                                      lba, max_lba);
967                         result = USB_STOR_TRANSPORT_ERROR;
968                         break;
969                 }
970
971                 /* Find number of pages we can read in this block */
972                 pages = min(sectors, blocksize - page);
973                 len = pages << pageshift;
974
975                 /* Find where this lba lives on disk */
976                 pba = MEDIA_INFO(us).lba_to_pba[zone][lba_offset];
977
978                 if (pba == UNDEF) {     /* this lba was never written */
979                         usb_stor_dbg(us, "Read %d zero pages (LBA %d) page %d\n",
980                                      pages, lba, page);
981
982                         /*
983                          * This is not really an error. It just means
984                          * that the block has never been written.
985                          * Instead of returning USB_STOR_TRANSPORT_ERROR
986                          * it is better to return all zero data.
987                          */
988
989                         memset(buffer, 0, len);
990                 } else {
991                         usb_stor_dbg(us, "Read %d pages, from PBA %d (LBA %d) page %d\n",
992                                      pages, pba, lba, page);
993
994                         result = alauda_read_block(us, pba, page, pages, buffer);
995                         if (result != USB_STOR_TRANSPORT_GOOD)
996                                 break;
997                 }
998
999                 /* Store the data in the transfer buffer */
1000                 usb_stor_access_xfer_buf(buffer, len, us->srb,
1001                                 &sg, &offset, TO_XFER_BUF);
1002
1003                 page = 0;
1004                 lba++;
1005                 sectors -= pages;
1006         }
1007
1008         kfree(buffer);
1009         return result;
1010 }
1011
1012 /*
1013  * Write data to a specific sector address
1014  */
1015 static int alauda_write_data(struct us_data *us, unsigned long address,
1016                 unsigned int sectors)
1017 {
1018         unsigned char *buffer, *blockbuffer;
1019         unsigned int page, len, offset;
1020         unsigned int blockshift = MEDIA_INFO(us).blockshift;
1021         unsigned int pageshift = MEDIA_INFO(us).pageshift;
1022         unsigned int blocksize = MEDIA_INFO(us).blocksize;
1023         unsigned int pagesize = MEDIA_INFO(us).pagesize;
1024         struct scatterlist *sg;
1025         u16 lba, max_lba;
1026         int result;
1027
1028         /*
1029          * Since we don't write the user data directly to the device,
1030          * we have to create a bounce buffer and move the data a piece
1031          * at a time between the bounce buffer and the actual transfer buffer.
1032          */
1033
1034         len = min(sectors, blocksize) * pagesize;
1035         buffer = kmalloc(len, GFP_NOIO);
1036         if (!buffer)
1037                 return USB_STOR_TRANSPORT_ERROR;
1038
1039         /*
1040          * We also need a temporary block buffer, where we read in the old data,
1041          * overwrite parts with the new data, and manipulate the redundancy data
1042          */
1043         blockbuffer = kmalloc((pagesize + 64) * blocksize, GFP_NOIO);
1044         if (!blockbuffer) {
1045                 kfree(buffer);
1046                 return USB_STOR_TRANSPORT_ERROR;
1047         }
1048
1049         /* Figure out the initial LBA and page */
1050         lba = address >> blockshift;
1051         page = (address & MEDIA_INFO(us).blockmask);
1052         max_lba = MEDIA_INFO(us).capacity >> (pageshift + blockshift);
1053
1054         result = USB_STOR_TRANSPORT_GOOD;
1055         offset = 0;
1056         sg = NULL;
1057
1058         while (sectors > 0) {
1059                 /* Write as many sectors as possible in this block */
1060                 unsigned int pages = min(sectors, blocksize - page);
1061                 len = pages << pageshift;
1062
1063                 /* Not overflowing capacity? */
1064                 if (lba >= max_lba) {
1065                         usb_stor_dbg(us, "Requested lba %u exceeds maximum %u\n",
1066                                      lba, max_lba);
1067                         result = USB_STOR_TRANSPORT_ERROR;
1068                         break;
1069                 }
1070
1071                 /* Get the data from the transfer buffer */
1072                 usb_stor_access_xfer_buf(buffer, len, us->srb,
1073                                 &sg, &offset, FROM_XFER_BUF);
1074
1075                 result = alauda_write_lba(us, lba, page, pages, buffer,
1076                         blockbuffer);
1077                 if (result != USB_STOR_TRANSPORT_GOOD)
1078                         break;
1079
1080                 page = 0;
1081                 lba++;
1082                 sectors -= pages;
1083         }
1084
1085         kfree(buffer);
1086         kfree(blockbuffer);
1087         return result;
1088 }
1089
1090 /*
1091  * Our interface with the rest of the world
1092  */
1093
1094 static void alauda_info_destructor(void *extra)
1095 {
1096         struct alauda_info *info = (struct alauda_info *) extra;
1097         int port;
1098
1099         if (!info)
1100                 return;
1101
1102         for (port = 0; port < 2; port++) {
1103                 struct alauda_media_info *media_info = &info->port[port];
1104
1105                 alauda_free_maps(media_info);
1106                 kfree(media_info->lba_to_pba);
1107                 kfree(media_info->pba_to_lba);
1108         }
1109 }
1110
1111 /*
1112  * Initialize alauda_info struct and find the data-write endpoint
1113  */
1114 static int init_alauda(struct us_data *us)
1115 {
1116         struct alauda_info *info;
1117         struct usb_host_interface *altsetting = us->pusb_intf->cur_altsetting;
1118         nand_init_ecc();
1119
1120         us->extra = kzalloc(sizeof(struct alauda_info), GFP_NOIO);
1121         if (!us->extra)
1122                 return USB_STOR_TRANSPORT_ERROR;
1123
1124         info = (struct alauda_info *) us->extra;
1125         us->extra_destructor = alauda_info_destructor;
1126
1127         info->wr_ep = usb_sndbulkpipe(us->pusb_dev,
1128                 altsetting->endpoint[0].desc.bEndpointAddress
1129                 & USB_ENDPOINT_NUMBER_MASK);
1130
1131         return USB_STOR_TRANSPORT_GOOD;
1132 }
1133
1134 static int alauda_transport(struct scsi_cmnd *srb, struct us_data *us)
1135 {
1136         int rc;
1137         struct alauda_info *info = (struct alauda_info *) us->extra;
1138         unsigned char *ptr = us->iobuf;
1139         static unsigned char inquiry_response[36] = {
1140                 0x00, 0x80, 0x00, 0x01, 0x1F, 0x00, 0x00, 0x00
1141         };
1142
1143         if (srb->cmnd[0] == INQUIRY) {
1144                 usb_stor_dbg(us, "INQUIRY - Returning bogus response\n");
1145                 memcpy(ptr, inquiry_response, sizeof(inquiry_response));
1146                 fill_inquiry_response(us, ptr, 36);
1147                 return USB_STOR_TRANSPORT_GOOD;
1148         }
1149
1150         if (srb->cmnd[0] == TEST_UNIT_READY) {
1151                 usb_stor_dbg(us, "TEST_UNIT_READY\n");
1152                 return alauda_check_media(us);
1153         }
1154
1155         if (srb->cmnd[0] == READ_CAPACITY) {
1156                 unsigned int num_zones;
1157                 unsigned long capacity;
1158
1159                 rc = alauda_check_media(us);
1160                 if (rc != USB_STOR_TRANSPORT_GOOD)
1161                         return rc;
1162
1163                 num_zones = MEDIA_INFO(us).capacity >> (MEDIA_INFO(us).zoneshift
1164                         + MEDIA_INFO(us).blockshift + MEDIA_INFO(us).pageshift);
1165
1166                 capacity = num_zones * MEDIA_INFO(us).uzonesize
1167                         * MEDIA_INFO(us).blocksize;
1168
1169                 /* Report capacity and page size */
1170                 ((__be32 *) ptr)[0] = cpu_to_be32(capacity - 1);
1171                 ((__be32 *) ptr)[1] = cpu_to_be32(512);
1172
1173                 usb_stor_set_xfer_buf(ptr, 8, srb);
1174                 return USB_STOR_TRANSPORT_GOOD;
1175         }
1176
1177         if (srb->cmnd[0] == READ_10) {
1178                 unsigned int page, pages;
1179
1180                 rc = alauda_check_media(us);
1181                 if (rc != USB_STOR_TRANSPORT_GOOD)
1182                         return rc;
1183
1184                 page = short_pack(srb->cmnd[3], srb->cmnd[2]);
1185                 page <<= 16;
1186                 page |= short_pack(srb->cmnd[5], srb->cmnd[4]);
1187                 pages = short_pack(srb->cmnd[8], srb->cmnd[7]);
1188
1189                 usb_stor_dbg(us, "READ_10: page %d pagect %d\n", page, pages);
1190
1191                 return alauda_read_data(us, page, pages);
1192         }
1193
1194         if (srb->cmnd[0] == WRITE_10) {
1195                 unsigned int page, pages;
1196
1197                 rc = alauda_check_media(us);
1198                 if (rc != USB_STOR_TRANSPORT_GOOD)
1199                         return rc;
1200
1201                 page = short_pack(srb->cmnd[3], srb->cmnd[2]);
1202                 page <<= 16;
1203                 page |= short_pack(srb->cmnd[5], srb->cmnd[4]);
1204                 pages = short_pack(srb->cmnd[8], srb->cmnd[7]);
1205
1206                 usb_stor_dbg(us, "WRITE_10: page %d pagect %d\n", page, pages);
1207
1208                 return alauda_write_data(us, page, pages);
1209         }
1210
1211         if (srb->cmnd[0] == REQUEST_SENSE) {
1212                 usb_stor_dbg(us, "REQUEST_SENSE\n");
1213
1214                 memset(ptr, 0, 18);
1215                 ptr[0] = 0xF0;
1216                 ptr[2] = info->sense_key;
1217                 ptr[7] = 11;
1218                 ptr[12] = info->sense_asc;
1219                 ptr[13] = info->sense_ascq;
1220                 usb_stor_set_xfer_buf(ptr, 18, srb);
1221
1222                 return USB_STOR_TRANSPORT_GOOD;
1223         }
1224
1225         if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
1226                 /*
1227                  * sure.  whatever.  not like we can stop the user from popping
1228                  * the media out of the device (no locking doors, etc)
1229                  */
1230                 return USB_STOR_TRANSPORT_GOOD;
1231         }
1232
1233         usb_stor_dbg(us, "Gah! Unknown command: %d (0x%x)\n",
1234                      srb->cmnd[0], srb->cmnd[0]);
1235         info->sense_key = 0x05;
1236         info->sense_asc = 0x20;
1237         info->sense_ascq = 0x00;
1238         return USB_STOR_TRANSPORT_FAILED;
1239 }
1240
1241 static struct scsi_host_template alauda_host_template;
1242
1243 static int alauda_probe(struct usb_interface *intf,
1244                          const struct usb_device_id *id)
1245 {
1246         struct us_data *us;
1247         int result;
1248
1249         result = usb_stor_probe1(&us, intf, id,
1250                         (id - alauda_usb_ids) + alauda_unusual_dev_list,
1251                         &alauda_host_template);
1252         if (result)
1253                 return result;
1254
1255         us->transport_name  = "Alauda Control/Bulk";
1256         us->transport = alauda_transport;
1257         us->transport_reset = usb_stor_Bulk_reset;
1258         us->max_lun = 1;
1259
1260         result = usb_stor_probe2(us);
1261         return result;
1262 }
1263
1264 static struct usb_driver alauda_driver = {
1265         .name =         DRV_NAME,
1266         .probe =        alauda_probe,
1267         .disconnect =   usb_stor_disconnect,
1268         .suspend =      usb_stor_suspend,
1269         .resume =       usb_stor_resume,
1270         .reset_resume = usb_stor_reset_resume,
1271         .pre_reset =    usb_stor_pre_reset,
1272         .post_reset =   usb_stor_post_reset,
1273         .id_table =     alauda_usb_ids,
1274         .soft_unbind =  1,
1275         .no_dynamic_id = 1,
1276 };
1277
1278 module_usb_stor_driver(alauda_driver, alauda_host_template, DRV_NAME);