^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* Driver for Microtek Scanmaker X6 USB scanner, and possibly others.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * (C) Copyright 2000 John Fremlin <vii@penguinpowered.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (C) Copyright 2000 Oliver Neukum <Oliver.Neukum@lrz.uni-muenchen.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Parts shamelessly stolen from usb-storage and copyright by their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * authors. Thanks to Matt Dharm for giving us permission!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This driver implements a SCSI host controller driver and a USB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * device driver. To avoid confusion, all the USB related stuff is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * prefixed by mts_usb_ and all the SCSI stuff by mts_scsi_.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Microtek (www.microtek.com) did not release the specifications for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * their USB protocol to us, so we had to reverse engineer them. We
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * don't know for which models they are valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * The X6 USB has three bulk endpoints, one output (0x1) down which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * commands and outgoing data are sent, and two input: 0x82 from which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * normal data is read from the scanner (in packets of maximum 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * bytes) and from which the status byte is read, and 0x83 from which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * the results of a scan (or preview) are read in up to 64 * 1024 byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * chunks by the Windows driver. We don't know how much it is possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * to read at a time from 0x83.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * It seems possible to read (with URB transfers) everything from 0x82
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * in one go, without bothering to read in 32 byte chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * There seems to be an optimisation of a further READ implicit if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * you simply read from 0x83.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * Guessed protocol:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Send raw SCSI command to EP 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * If there is data to receive:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * If the command was READ datatype=image:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * Read a lot of data from EP 0x83
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * Else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * Read data from EP 0x82
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * Else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * If there is data to transmit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * Write it to EP 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * Read status byte from EP 0x82
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * References:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * The SCSI command set for the scanner is available from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * ftp://ftp.microtek.com/microtek/devpack/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * Microtek NV sent us a more up to date version of the document. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * you want it, just send mail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * Status:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * Untested with multiple scanners.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * Untested on SMP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * Untested on a bigendian machine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * History:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * 20000417 starting history
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * 20000417 fixed load oops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * 20000417 fixed unload oops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * 20000419 fixed READ IMAGE detection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * 20000424 started conversion to use URBs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * 20000502 handled short transfers as errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * 20000513 rename and organisation of functions (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * 20000513 added IDs for all products supported by Windows driver (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * 20000514 Rewrote mts_scsi_queuecommand to use URBs (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * 20000514 Version 0.0.8j
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * 20000514 Fix reporting of non-existent devices to SCSI layer (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * 20000514 Added MTS_DEBUG_INT (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * 20000514 Changed "usb-microtek" to "microtek" for consistency (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * 20000514 Stupid bug fixes (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * 20000514 Version 0.0.9j
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * 20000515 Put transfer context and URB in mts_desc (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * 20000515 Added prelim turn off debugging support (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * 20000515 Version 0.0.10j
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * 20000515 Fixed up URB allocation (clear URB on alloc) (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * 20000515 Version 0.0.11j
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * 20000516 Removed unnecessary spinlock in mts_transfer_context (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * 20000516 Removed unnecessary up on instance lock in mts_remove_nolock (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * 20000516 Implemented (badly) scsi_abort (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * 20000516 Version 0.0.12j
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * 20000517 Hopefully removed mts_remove_nolock quasideadlock (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * 20000517 Added mts_debug_dump to print ll USB info (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * 20000518 Tweaks and documentation updates (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * 20000518 Version 0.0.13j
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * 20000518 Cleaned up abort handling (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * 20000523 Removed scsi_command and various scsi_..._resets (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * 20000523 Added unlink URB on scsi_abort, now OHCI supports it (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * 20000523 Fixed last tiresome compile warning (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * 20000523 Version 0.0.14j (though version 0.1 has come out?)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * 20000602 Added primitive reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * 20000602 Version 0.2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * 20000603 various cosmetic changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * 20000603 Version 0.2.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * 20000620 minor cosmetic changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * 20000620 Version 0.2.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * 20000822 Hopefully fixed deadlock in mts_remove_nolock()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * 20000822 Fixed minor race in mts_transfer_cleanup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * 20000822 Fixed deadlock on submission error in queuecommand
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * 20000822 Version 0.2.3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * 20000913 Reduced module size if debugging is off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * 20000913 Version 0.2.4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * 20010210 New abort logic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * 20010210 Version 0.3.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * 20010217 Merged scatter/gather
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * 20010218 Version 0.4.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * 20010218 Cosmetic fixes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * 20010218 Version 0.4.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * 20010306 Abort while using scatter/gather
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * 20010306 Version 0.4.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * 20010311 Remove all timeouts and tidy up generally (john)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * 20010320 check return value of scsi_register()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * 20010320 Version 0.4.3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * 20010408 Identify version on module load.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * 20011003 Fix multiple requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #include "../../scsi/scsi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #include "microtek.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #define DRIVER_AUTHOR "John Fremlin <vii@penguinpowered.com>, Oliver Neukum <Oliver.Neukum@lrz.uni-muenchen.de>"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define DRIVER_DESC "Microtek Scanmaker X6 USB scanner driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* Should we do debugging? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) //#define MTS_DO_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /* USB layer driver interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static int mts_usb_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) const struct usb_device_id *id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static void mts_usb_disconnect(struct usb_interface *intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static const struct usb_device_id mts_usb_ids[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static struct usb_driver mts_usb_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .name = "microtekX6",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) .probe = mts_usb_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) .disconnect = mts_usb_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) .id_table = mts_usb_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /* Internal driver stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #define MTS_VERSION "0.4.3"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #define MTS_NAME "microtek usb (rev " MTS_VERSION "): "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #define MTS_WARNING(x...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) printk( KERN_WARNING MTS_NAME x )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) #define MTS_ERROR(x...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) printk( KERN_ERR MTS_NAME x )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) #define MTS_INT_ERROR(x...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) MTS_ERROR(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) #define MTS_MESSAGE(x...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) printk( KERN_INFO MTS_NAME x )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #if defined MTS_DO_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #define MTS_DEBUG(x...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) printk( KERN_DEBUG MTS_NAME x )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #define MTS_DEBUG_GOT_HERE() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) MTS_DEBUG("got to %s:%d (%s)\n", __FILE__, (int)__LINE__, __func__ )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #define MTS_DEBUG_INT() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) do { MTS_DEBUG_GOT_HERE(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) MTS_DEBUG("transfer = 0x%x context = 0x%x\n",(int)transfer,(int)context ); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) MTS_DEBUG("status = 0x%x data-length = 0x%x sent = 0x%x\n",transfer->status,(int)context->data_length, (int)transfer->actual_length ); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) mts_debug_dump(context->instance);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) } while(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #define MTS_NUL_STATEMENT do { } while(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #define MTS_DEBUG(x...) MTS_NUL_STATEMENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #define MTS_DEBUG_GOT_HERE() MTS_NUL_STATEMENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #define MTS_DEBUG_INT() MTS_NUL_STATEMENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #define MTS_INT_INIT()\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct mts_transfer_context* context = (struct mts_transfer_context*)transfer->context; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) MTS_DEBUG_INT();\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #ifdef MTS_DO_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static inline void mts_debug_dump(struct mts_desc* desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) MTS_DEBUG("desc at 0x%x: toggle = %02x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) (int)desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) (int)desc->usb_dev->toggle[1],(int)desc->usb_dev->toggle[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) MTS_DEBUG("ep_out=%x ep_response=%x ep_image=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) usb_sndbulkpipe(desc->usb_dev,desc->ep_out),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) usb_rcvbulkpipe(desc->usb_dev,desc->ep_response),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) usb_rcvbulkpipe(desc->usb_dev,desc->ep_image)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static inline void mts_show_command(struct scsi_cmnd *srb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) char *what = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) switch (srb->cmnd[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) case TEST_UNIT_READY: what = "TEST_UNIT_READY"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) case REZERO_UNIT: what = "REZERO_UNIT"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) case REQUEST_SENSE: what = "REQUEST_SENSE"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) case FORMAT_UNIT: what = "FORMAT_UNIT"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) case READ_BLOCK_LIMITS: what = "READ_BLOCK_LIMITS"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) case REASSIGN_BLOCKS: what = "REASSIGN_BLOCKS"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) case READ_6: what = "READ_6"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) case WRITE_6: what = "WRITE_6"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) case SEEK_6: what = "SEEK_6"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) case READ_REVERSE: what = "READ_REVERSE"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) case WRITE_FILEMARKS: what = "WRITE_FILEMARKS"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) case SPACE: what = "SPACE"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) case INQUIRY: what = "INQUIRY"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) case RECOVER_BUFFERED_DATA: what = "RECOVER_BUFFERED_DATA"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) case MODE_SELECT: what = "MODE_SELECT"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) case RESERVE: what = "RESERVE"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) case RELEASE: what = "RELEASE"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) case COPY: what = "COPY"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) case ERASE: what = "ERASE"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) case MODE_SENSE: what = "MODE_SENSE"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) case START_STOP: what = "START_STOP"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) case RECEIVE_DIAGNOSTIC: what = "RECEIVE_DIAGNOSTIC"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) case SEND_DIAGNOSTIC: what = "SEND_DIAGNOSTIC"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) case ALLOW_MEDIUM_REMOVAL: what = "ALLOW_MEDIUM_REMOVAL"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) case SET_WINDOW: what = "SET_WINDOW"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) case READ_CAPACITY: what = "READ_CAPACITY"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) case READ_10: what = "READ_10"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) case WRITE_10: what = "WRITE_10"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) case SEEK_10: what = "SEEK_10"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) case WRITE_VERIFY: what = "WRITE_VERIFY"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) case VERIFY: what = "VERIFY"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) case SEARCH_HIGH: what = "SEARCH_HIGH"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) case SEARCH_EQUAL: what = "SEARCH_EQUAL"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) case SEARCH_LOW: what = "SEARCH_LOW"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) case SET_LIMITS: what = "SET_LIMITS"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) case READ_POSITION: what = "READ_POSITION"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) case SYNCHRONIZE_CACHE: what = "SYNCHRONIZE_CACHE"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) case LOCK_UNLOCK_CACHE: what = "LOCK_UNLOCK_CACHE"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) case READ_DEFECT_DATA: what = "READ_DEFECT_DATA"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) case MEDIUM_SCAN: what = "MEDIUM_SCAN"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) case COMPARE: what = "COMPARE"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) case COPY_VERIFY: what = "COPY_VERIFY"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) case WRITE_BUFFER: what = "WRITE_BUFFER"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) case READ_BUFFER: what = "READ_BUFFER"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) case UPDATE_BLOCK: what = "UPDATE_BLOCK"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) case READ_LONG: what = "READ_LONG"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) case WRITE_LONG: what = "WRITE_LONG"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) case CHANGE_DEFINITION: what = "CHANGE_DEFINITION"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) case WRITE_SAME: what = "WRITE_SAME"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) case READ_TOC: what = "READ_TOC"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) case LOG_SELECT: what = "LOG_SELECT"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) case LOG_SENSE: what = "LOG_SENSE"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) case MODE_SELECT_10: what = "MODE_SELECT_10"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) case MODE_SENSE_10: what = "MODE_SENSE_10"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) case MOVE_MEDIUM: what = "MOVE_MEDIUM"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) case READ_12: what = "READ_12"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) case WRITE_12: what = "WRITE_12"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) case WRITE_VERIFY_12: what = "WRITE_VERIFY_12"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) case SEARCH_HIGH_12: what = "SEARCH_HIGH_12"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) case SEARCH_EQUAL_12: what = "SEARCH_EQUAL_12"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) case SEARCH_LOW_12: what = "SEARCH_LOW_12"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) case READ_ELEMENT_STATUS: what = "READ_ELEMENT_STATUS"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) case SEND_VOLUME_TAG: what = "SEND_VOLUME_TAG"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) case WRITE_LONG_2: what = "WRITE_LONG_2"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) MTS_DEBUG("can't decode command\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) MTS_DEBUG( "Command %s (%d bytes)\n", what, srb->cmd_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) MTS_DEBUG( " %10ph\n", srb->cmnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static inline void mts_show_command(struct scsi_cmnd * dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static inline void mts_debug_dump(struct mts_desc* dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static inline void mts_urb_abort(struct mts_desc* desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) MTS_DEBUG_GOT_HERE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) mts_debug_dump(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) usb_kill_urb( desc->urb );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static int mts_slave_alloc (struct scsi_device *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) s->inquiry_len = 0x24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static int mts_slave_configure (struct scsi_device *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) blk_queue_dma_alignment(s->request_queue, (512 - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static int mts_scsi_abort(struct scsi_cmnd *srb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) MTS_DEBUG_GOT_HERE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) mts_urb_abort(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static int mts_scsi_host_reset(struct scsi_cmnd *srb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) MTS_DEBUG_GOT_HERE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) mts_debug_dump(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) result = usb_lock_device_for_reset(desc->usb_dev, desc->usb_intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (result == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) result = usb_reset_device(desc->usb_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) usb_unlock_device(desc->usb_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return result ? FAILED : SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) mts_scsi_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static void mts_transfer_cleanup( struct urb *transfer );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) static void mts_do_sg(struct urb * transfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) void mts_int_submit_urb (struct urb* transfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) int pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) void* data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) unsigned length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) usb_complete_t callback )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /* Interrupt context! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) /* Holding transfer->context->lock! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) MTS_INT_INIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) usb_fill_bulk_urb(transfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) context->instance->usb_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) res = usb_submit_urb( transfer, GFP_ATOMIC );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if ( unlikely(res) ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) MTS_INT_ERROR( "could not submit URB! Error was %d\n",(int)res );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) set_host_byte(context->srb, DID_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) mts_transfer_cleanup(transfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static void mts_transfer_cleanup( struct urb *transfer )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /* Interrupt context! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) MTS_INT_INIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if ( likely(context->final_callback != NULL) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) context->final_callback(context->srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static void mts_transfer_done( struct urb *transfer )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) MTS_INT_INIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) context->srb->result &= MTS_SCSI_ERR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) context->srb->result |= (unsigned)(*context->scsi_status)<<1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) mts_transfer_cleanup(transfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) static void mts_get_status( struct urb *transfer )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /* Interrupt context! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) MTS_INT_INIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) mts_int_submit_urb(transfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) usb_rcvbulkpipe(context->instance->usb_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) context->instance->ep_response),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) context->scsi_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) mts_transfer_done );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static void mts_data_done( struct urb* transfer )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /* Interrupt context! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) int status = transfer->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) MTS_INT_INIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if ( context->data_length != transfer->actual_length ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) scsi_set_resid(context->srb, context->data_length -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) transfer->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) } else if ( unlikely(status) ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) set_host_byte(context->srb, (status == -ENOENT ? DID_ABORT : DID_ERROR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) mts_get_status(transfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static void mts_command_done( struct urb *transfer )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) /* Interrupt context! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) int status = transfer->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) MTS_INT_INIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if ( unlikely(status) ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (status == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) /* We are being killed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) MTS_DEBUG_GOT_HERE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) set_host_byte(context->srb, DID_ABORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) /* A genuine error has occurred */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) MTS_DEBUG_GOT_HERE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) set_host_byte(context->srb, DID_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) mts_transfer_cleanup(transfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (context->srb->cmnd[0] == REQUEST_SENSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) mts_int_submit_urb(transfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) context->data_pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) context->srb->sense_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) context->data_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) mts_data_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) } else { if ( context->data ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) mts_int_submit_urb(transfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) context->data_pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) context->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) context->data_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) scsi_sg_count(context->srb) > 1 ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) mts_do_sg : mts_data_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) mts_get_status(transfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) static void mts_do_sg (struct urb* transfer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) int status = transfer->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) MTS_INT_INIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) MTS_DEBUG("Processing fragment %d of %d\n", context->fragment,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) scsi_sg_count(context->srb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (unlikely(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) set_host_byte(context->srb, (status == -ENOENT ? DID_ABORT : DID_ERROR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) mts_transfer_cleanup(transfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) context->curr_sg = sg_next(context->curr_sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) mts_int_submit_urb(transfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) context->data_pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) sg_virt(context->curr_sg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) context->curr_sg->length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) sg_is_last(context->curr_sg) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) mts_data_done : mts_do_sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) static const u8 mts_read_image_sig[] = { 0x28, 00, 00, 00 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) static const u8 mts_read_image_sig_len = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) static const unsigned char mts_direction[256/8] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 0x28, 0x81, 0x14, 0x14, 0x20, 0x01, 0x90, 0x77,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 0x0C, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) #define MTS_DIRECTION_IS_IN(x) ((mts_direction[x>>3] >> (x & 7)) & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) mts_build_transfer_context(struct scsi_cmnd *srb, struct mts_desc* desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) int pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) MTS_DEBUG_GOT_HERE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) desc->context.instance = desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) desc->context.srb = srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) if (!scsi_bufflen(srb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) desc->context.data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) desc->context.data_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) desc->context.curr_sg = scsi_sglist(srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) desc->context.data = sg_virt(desc->context.curr_sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) desc->context.data_length = desc->context.curr_sg->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) /* can't rely on srb->sc_data_direction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) /* Brutally ripped from usb-storage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) if ( !memcmp( srb->cmnd, mts_read_image_sig, mts_read_image_sig_len )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) ) { pipe = usb_rcvbulkpipe(desc->usb_dev,desc->ep_image);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) MTS_DEBUG( "transferring from desc->ep_image == %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) (int)desc->ep_image );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) } else if ( MTS_DIRECTION_IS_IN(srb->cmnd[0]) ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) pipe = usb_rcvbulkpipe(desc->usb_dev,desc->ep_response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) MTS_DEBUG( "transferring from desc->ep_response == %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) (int)desc->ep_response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) MTS_DEBUG("transferring to desc->ep_out == %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) (int)desc->ep_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) pipe = usb_sndbulkpipe(desc->usb_dev,desc->ep_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) desc->context.data_pipe = pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) mts_scsi_queuecommand_lck(struct scsi_cmnd *srb, mts_scsi_cmnd_callback callback)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) MTS_DEBUG_GOT_HERE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) mts_show_command(srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) mts_debug_dump(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if ( srb->device->lun || srb->device->id || srb->device->channel ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) MTS_DEBUG("Command to LUN=%d ID=%d CHANNEL=%d from SCSI layer\n",(int)srb->device->lun,(int)srb->device->id, (int)srb->device->channel );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) MTS_DEBUG("this device doesn't exist\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) set_host_byte(srb, DID_BAD_TARGET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) if(likely(callback != NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) callback(srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) usb_fill_bulk_urb(desc->urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) desc->usb_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) usb_sndbulkpipe(desc->usb_dev,desc->ep_out),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) srb->cmnd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) srb->cmd_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) mts_command_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) &desc->context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) mts_build_transfer_context( srb, desc );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) desc->context.final_callback = callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) /* here we need ATOMIC as we are called with the iolock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) res=usb_submit_urb(desc->urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) if(unlikely(res)){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) MTS_ERROR("error %d submitting URB\n",(int)res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) set_host_byte(srb, DID_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) if(likely(callback != NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) callback(srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) static DEF_SCSI_QCMD(mts_scsi_queuecommand)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) static struct scsi_host_template mts_scsi_host_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) .module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) .name = "microtekX6",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) .proc_name = "microtekX6",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) .queuecommand = mts_scsi_queuecommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) .eh_abort_handler = mts_scsi_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) .eh_host_reset_handler = mts_scsi_host_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) .sg_tablesize = SG_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) .can_queue = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) .this_id = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) .emulated = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) .slave_alloc = mts_slave_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) .slave_configure = mts_slave_configure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) .max_sectors= 256, /* 128 K */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) /* The entries of microtek_table must correspond, line-by-line to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) the entries of mts_supported_products[]. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) static const struct usb_device_id mts_usb_ids[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) { USB_DEVICE(0x4ce, 0x0300) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) { USB_DEVICE(0x5da, 0x0094) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) { USB_DEVICE(0x5da, 0x0099) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) { USB_DEVICE(0x5da, 0x009a) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) { USB_DEVICE(0x5da, 0x00a0) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) { USB_DEVICE(0x5da, 0x00a3) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) { USB_DEVICE(0x5da, 0x80a3) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) { USB_DEVICE(0x5da, 0x80ac) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) { USB_DEVICE(0x5da, 0x00b6) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) { } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) MODULE_DEVICE_TABLE (usb, mts_usb_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) static int mts_usb_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) int ep_out = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) int ep_in_set[3]; /* this will break if we have more than three endpoints
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) which is why we check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) int *ep_in_current = ep_in_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) int err_retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) struct mts_desc * new_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) struct usb_device *dev = interface_to_usbdev (intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) /* the current altsetting on the interface we're probing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) struct usb_host_interface *altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) MTS_DEBUG_GOT_HERE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) MTS_DEBUG( "usb-device descriptor at %x\n", (int)dev );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) MTS_DEBUG( "product id = 0x%x, vendor id = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) le16_to_cpu(dev->descriptor.idProduct),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) le16_to_cpu(dev->descriptor.idVendor) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) MTS_DEBUG_GOT_HERE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) /* the current altsetting on the interface we're probing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) altsetting = intf->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) /* Check if the config is sane */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) if ( altsetting->desc.bNumEndpoints != MTS_EP_TOTAL ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) MTS_WARNING( "expecting %d got %d endpoints! Bailing out.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) (int)MTS_EP_TOTAL, (int)altsetting->desc.bNumEndpoints );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) for( i = 0; i < altsetting->desc.bNumEndpoints; i++ ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) if ((altsetting->endpoint[i].desc.bmAttributes &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_BULK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) MTS_WARNING( "can only deal with bulk endpoints; endpoint %d is not bulk.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) (int)altsetting->endpoint[i].desc.bEndpointAddress );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) if (altsetting->endpoint[i].desc.bEndpointAddress &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) USB_DIR_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) *ep_in_current++
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) = altsetting->endpoint[i].desc.bEndpointAddress &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) USB_ENDPOINT_NUMBER_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) if ( ep_out != -1 ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) MTS_WARNING( "can only deal with one output endpoints. Bailing out." );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) ep_out = altsetting->endpoint[i].desc.bEndpointAddress &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) USB_ENDPOINT_NUMBER_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (ep_in_current != &ep_in_set[2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) MTS_WARNING("couldn't find two input bulk endpoints. Bailing out.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) if ( ep_out == -1 ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) MTS_WARNING( "couldn't find an output bulk endpoint. Bailing out.\n" );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) new_desc = kzalloc(sizeof(struct mts_desc), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) if (!new_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) new_desc->urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) if (!new_desc->urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) goto out_kfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) new_desc->context.scsi_status = kmalloc(1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) if (!new_desc->context.scsi_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) goto out_free_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) new_desc->usb_dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) new_desc->usb_intf = intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) /* endpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) new_desc->ep_out = ep_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) new_desc->ep_response = ep_in_set[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) new_desc->ep_image = ep_in_set[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) if ( new_desc->ep_out != MTS_EP_OUT )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) MTS_WARNING( "will this work? Command EP is not usually %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) (int)new_desc->ep_out );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) if ( new_desc->ep_response != MTS_EP_RESPONSE )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) MTS_WARNING( "will this work? Response EP is not usually %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) (int)new_desc->ep_response );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) if ( new_desc->ep_image != MTS_EP_IMAGE )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) MTS_WARNING( "will this work? Image data EP is not usually %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) (int)new_desc->ep_image );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) new_desc->host = scsi_host_alloc(&mts_scsi_host_template,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) sizeof(new_desc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) if (!new_desc->host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) goto out_kfree2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) new_desc->host->hostdata[0] = (unsigned long)new_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) if (scsi_add_host(new_desc->host, &dev->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) err_retval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) goto out_host_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) scsi_scan_host(new_desc->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) usb_set_intfdata(intf, new_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) out_host_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) scsi_host_put(new_desc->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) out_kfree2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) kfree(new_desc->context.scsi_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) out_free_urb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) usb_free_urb(new_desc->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) out_kfree:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) kfree(new_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) return err_retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) static void mts_usb_disconnect (struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) struct mts_desc *desc = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) usb_set_intfdata(intf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) usb_kill_urb(desc->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) scsi_remove_host(desc->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) scsi_host_put(desc->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) usb_free_urb(desc->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) kfree(desc->context.scsi_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) kfree(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) module_usb_driver(mts_usb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) MODULE_AUTHOR( DRIVER_AUTHOR );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) MODULE_DESCRIPTION( DRIVER_DESC );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) MODULE_LICENSE("GPL");