^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Driver for Freecom USB/IDE adaptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Freecom v0.1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * First release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Current development and maintenance by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * (C) 2000 David Brown <usb-storage@davidb.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * This driver was developed with information provided in FREECOM's USB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Programmers Reference Guide. For further information contact Freecom
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * (https://www.freecom.de/)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "usb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "transport.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "protocol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "scsiglue.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define DRV_NAME "ums-freecom"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) MODULE_DESCRIPTION("Driver for Freecom USB/IDE adaptor");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) MODULE_AUTHOR("David Brown <usb-storage@davidb.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) MODULE_IMPORT_NS(USB_STORAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #ifdef CONFIG_USB_STORAGE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static void pdump(struct us_data *us, void *ibuffer, int length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* Bits of HD_STATUS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define ERR_STAT 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define DRQ_STAT 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* All of the outgoing packets are 64 bytes long. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct freecom_cb_wrap {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) u8 Type; /* Command type. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) u8 Timeout; /* Timeout in seconds. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u8 Atapi[12]; /* An ATAPI packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u8 Filler[50]; /* Padding Data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct freecom_xfer_wrap {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) u8 Type; /* Command type. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u8 Timeout; /* Timeout in seconds. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) __le32 Count; /* Number of bytes to transfer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u8 Pad[58];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) } __attribute__ ((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct freecom_ide_out {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) u8 Type; /* Type + IDE register. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) u8 Pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) __le16 Value; /* Value to write. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) u8 Pad2[60];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct freecom_ide_in {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u8 Type; /* Type | IDE register. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) u8 Pad[63];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct freecom_status {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) u8 Status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) u8 Reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) __le16 Count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) u8 Pad[60];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * Freecom stuffs the interrupt status in the INDEX_STAT bit of the ide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define FCM_INT_STATUS 0x02 /* INDEX_STAT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define FCM_STATUS_BUSY 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * These are the packet types. The low bit indicates that this command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * should wait for an interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define FCM_PACKET_ATAPI 0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define FCM_PACKET_STATUS 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * Receive data from the IDE interface. The ATAPI packet has already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * waited, so the data should be immediately available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define FCM_PACKET_INPUT 0x81
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* Send data to the IDE interface. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define FCM_PACKET_OUTPUT 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * Write a value to an ide register. Or the ide register to write after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * munging the address a bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define FCM_PACKET_IDE_WRITE 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define FCM_PACKET_IDE_READ 0xC0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* All packets (except for status) are 64 bytes long. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define FCM_PACKET_LENGTH 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define FCM_STATUS_PACKET_LENGTH 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static int init_freecom(struct us_data *us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * The table of devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) vendorName, productName, useProtocol, useTransport, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) initFunction, flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .driver_info = (flags) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static struct usb_device_id freecom_usb_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) # include "unusual_freecom.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) { } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) MODULE_DEVICE_TABLE(usb, freecom_usb_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #undef UNUSUAL_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * The flags table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) vendor_name, product_name, use_protocol, use_transport, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) init_function, Flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .vendorName = vendor_name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .productName = product_name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .useProtocol = use_protocol, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .useTransport = use_transport, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .initFunction = init_function, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static struct us_unusual_dev freecom_unusual_dev_list[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) # include "unusual_freecom.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) { } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #undef UNUSUAL_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) freecom_readdata (struct scsi_cmnd *srb, struct us_data *us,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) unsigned int ipipe, unsigned int opipe, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct freecom_xfer_wrap *fxfr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) (struct freecom_xfer_wrap *) us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) fxfr->Type = FCM_PACKET_INPUT | 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) fxfr->Timeout = 0; /* Short timeout for debugging. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) fxfr->Count = cpu_to_le32 (count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) memset (fxfr->Pad, 0, sizeof (fxfr->Pad));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) usb_stor_dbg(us, "Read data Freecom! (c=%d)\n", count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* Issue the transfer command. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) result = usb_stor_bulk_transfer_buf (us, opipe, fxfr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) FCM_PACKET_LENGTH, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (result != USB_STOR_XFER_GOOD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) usb_stor_dbg(us, "Freecom readdata transport error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return USB_STOR_TRANSPORT_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* Now transfer all of our blocks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) usb_stor_dbg(us, "Start of read\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) result = usb_stor_bulk_srb(us, ipipe, srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) usb_stor_dbg(us, "freecom_readdata done!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (result > USB_STOR_XFER_SHORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return USB_STOR_TRANSPORT_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return USB_STOR_TRANSPORT_GOOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) freecom_writedata (struct scsi_cmnd *srb, struct us_data *us,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) int unsigned ipipe, unsigned int opipe, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct freecom_xfer_wrap *fxfr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) (struct freecom_xfer_wrap *) us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) fxfr->Type = FCM_PACKET_OUTPUT | 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) fxfr->Timeout = 0; /* Short timeout for debugging. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) fxfr->Count = cpu_to_le32 (count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) memset (fxfr->Pad, 0, sizeof (fxfr->Pad));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) usb_stor_dbg(us, "Write data Freecom! (c=%d)\n", count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* Issue the transfer command. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) result = usb_stor_bulk_transfer_buf (us, opipe, fxfr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) FCM_PACKET_LENGTH, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (result != USB_STOR_XFER_GOOD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) usb_stor_dbg(us, "Freecom writedata transport error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return USB_STOR_TRANSPORT_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /* Now transfer all of our blocks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) usb_stor_dbg(us, "Start of write\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) result = usb_stor_bulk_srb(us, opipe, srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) usb_stor_dbg(us, "freecom_writedata done!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (result > USB_STOR_XFER_SHORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return USB_STOR_TRANSPORT_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return USB_STOR_TRANSPORT_GOOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * Transport for the Freecom USB/IDE adaptor.
^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) static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct freecom_cb_wrap *fcb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct freecom_status *fst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) unsigned int ipipe, opipe; /* We need both pipes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) unsigned int partial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) fcb = (struct freecom_cb_wrap *) us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) fst = (struct freecom_status *) us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) usb_stor_dbg(us, "Freecom TRANSPORT STARTED\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /* Get handles for both transports. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) opipe = us->send_bulk_pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) ipipe = us->recv_bulk_pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /* The ATAPI Command always goes out first. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) fcb->Type = FCM_PACKET_ATAPI | 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) fcb->Timeout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) memcpy (fcb->Atapi, srb->cmnd, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) memset (fcb->Filler, 0, sizeof (fcb->Filler));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) US_DEBUG(pdump(us, srb->cmnd, 12));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /* Send it out. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) result = usb_stor_bulk_transfer_buf (us, opipe, fcb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) FCM_PACKET_LENGTH, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * The Freecom device will only fail if there is something wrong in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * USB land. It returns the status in its own registers, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * come back in the bulk pipe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (result != USB_STOR_XFER_GOOD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) usb_stor_dbg(us, "freecom transport error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return USB_STOR_TRANSPORT_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * There are times we can optimize out this status read, but it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * doesn't hurt us to always do it now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) result = usb_stor_bulk_transfer_buf (us, ipipe, fst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) FCM_STATUS_PACKET_LENGTH, &partial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) usb_stor_dbg(us, "foo Status result %d %u\n", result, partial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (result != USB_STOR_XFER_GOOD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return USB_STOR_TRANSPORT_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) US_DEBUG(pdump(us, (void *)fst, partial));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * The firmware will time-out commands after 20 seconds. Some commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * can legitimately take longer than this, so we use a different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * command that only waits for the interrupt and then sends status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * without having to send a new ATAPI command to the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * NOTE: There is some indication that a data transfer after a timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * may not work, but that is a condition that should never happen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) while (fst->Status & FCM_STATUS_BUSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) usb_stor_dbg(us, "20 second USB/ATAPI bridge TIMEOUT occurred!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) usb_stor_dbg(us, "fst->Status is %x\n", fst->Status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /* Get the status again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) fcb->Type = FCM_PACKET_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) fcb->Timeout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) memset (fcb->Atapi, 0, sizeof(fcb->Atapi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) memset (fcb->Filler, 0, sizeof (fcb->Filler));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /* Send it out. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) result = usb_stor_bulk_transfer_buf (us, opipe, fcb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) FCM_PACKET_LENGTH, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * The Freecom device will only fail if there is something
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * wrong in USB land. It returns the status in its own
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * registers, which come back in the bulk pipe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (result != USB_STOR_XFER_GOOD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) usb_stor_dbg(us, "freecom transport error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return USB_STOR_TRANSPORT_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) /* get the data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) result = usb_stor_bulk_transfer_buf (us, ipipe, fst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) FCM_STATUS_PACKET_LENGTH, &partial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) usb_stor_dbg(us, "bar Status result %d %u\n", result, partial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (result != USB_STOR_XFER_GOOD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return USB_STOR_TRANSPORT_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) US_DEBUG(pdump(us, (void *)fst, partial));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (partial != 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) return USB_STOR_TRANSPORT_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if ((fst->Status & 1) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) usb_stor_dbg(us, "operation failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) return USB_STOR_TRANSPORT_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * The device might not have as much data available as we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * requested. If you ask for more than the device has, this reads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * and such will hang.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) usb_stor_dbg(us, "Device indicates that it has %d bytes available\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) le16_to_cpu(fst->Count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) usb_stor_dbg(us, "SCSI requested %d\n", scsi_bufflen(srb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /* Find the length we desire to read. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) switch (srb->cmnd[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) case INQUIRY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) case REQUEST_SENSE: /* 16 or 18 bytes? spec says 18, lots of devices only have 16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) case MODE_SENSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) case MODE_SENSE_10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) length = le16_to_cpu(fst->Count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) length = scsi_bufflen(srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) /* verify that this amount is legal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (length > scsi_bufflen(srb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) length = scsi_bufflen(srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) usb_stor_dbg(us, "Truncating request to match buffer length: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) * What we do now depends on what direction the data is supposed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * move in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) switch (us->srb->sc_data_direction) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) case DMA_FROM_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) /* catch bogus "read 0 length" case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (!length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * Make sure that the status indicates that the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * wants data as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if ((fst->Status & DRQ_STAT) == 0 || (fst->Reason & 3) != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) usb_stor_dbg(us, "SCSI wants data, drive doesn't have any\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) return USB_STOR_TRANSPORT_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) result = freecom_readdata (srb, us, ipipe, opipe, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (result != USB_STOR_TRANSPORT_GOOD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) usb_stor_dbg(us, "Waiting for status\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) result = usb_stor_bulk_transfer_buf (us, ipipe, fst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) FCM_PACKET_LENGTH, &partial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) US_DEBUG(pdump(us, (void *)fst, partial));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (partial != 4 || result > USB_STOR_XFER_SHORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return USB_STOR_TRANSPORT_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if ((fst->Status & ERR_STAT) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) usb_stor_dbg(us, "operation failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return USB_STOR_TRANSPORT_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if ((fst->Reason & 3) != 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) usb_stor_dbg(us, "Drive seems still hungry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return USB_STOR_TRANSPORT_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) usb_stor_dbg(us, "Transfer happy\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) case DMA_TO_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) /* catch bogus "write 0 length" case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (!length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * Make sure the status indicates that the device wants to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * send us data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) /* !!IMPLEMENT!! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) result = freecom_writedata (srb, us, ipipe, opipe, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (result != USB_STOR_TRANSPORT_GOOD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) usb_stor_dbg(us, "Waiting for status\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) result = usb_stor_bulk_transfer_buf (us, ipipe, fst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) FCM_PACKET_LENGTH, &partial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (partial != 4 || result > USB_STOR_XFER_SHORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) return USB_STOR_TRANSPORT_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if ((fst->Status & ERR_STAT) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) usb_stor_dbg(us, "operation failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) return USB_STOR_TRANSPORT_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if ((fst->Reason & 3) != 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) usb_stor_dbg(us, "Drive seems still hungry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return USB_STOR_TRANSPORT_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) usb_stor_dbg(us, "Transfer happy\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) case DMA_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) /* Easy, do nothing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) /* should never hit here -- filtered in usb.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) usb_stor_dbg(us, "freecom unimplemented direction: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) us->srb->sc_data_direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /* Return fail, SCSI seems to handle this better. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) return USB_STOR_TRANSPORT_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) return USB_STOR_TRANSPORT_GOOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) static int init_freecom(struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) char *buffer = us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * The DMA-mapped I/O buffer is 64 bytes long, just right for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) * all our packets. No need to allocate any extra buffer space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) result = usb_stor_control_msg(us, us->recv_ctrl_pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 0x4c, 0xc0, 0x4346, 0x0, buffer, 0x20, 3*HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) buffer[32] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) usb_stor_dbg(us, "String returned from FC init is: %s\n", buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * Special thanks to the people at Freecom for providing me with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * this "magic sequence", which they use in their Windows and MacOS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * drivers to make sure that all the attached perhiperals are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * properly reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) /* send reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) result = usb_stor_control_msg(us, us->send_ctrl_pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 0x4d, 0x40, 0x24d8, 0x0, NULL, 0x0, 3*HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) usb_stor_dbg(us, "result from activate reset is %d\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) /* wait 250ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) msleep(250);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) /* clear reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) result = usb_stor_control_msg(us, us->send_ctrl_pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 0x4d, 0x40, 0x24f8, 0x0, NULL, 0x0, 3*HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) usb_stor_dbg(us, "result from clear reset is %d\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) /* wait 3 seconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) msleep(3 * 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return USB_STOR_TRANSPORT_GOOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static int usb_stor_freecom_reset(struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) printk (KERN_CRIT "freecom reset called\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) /* We don't really have this feature. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return FAILED;
^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) #ifdef CONFIG_USB_STORAGE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static void pdump(struct us_data *us, void *ibuffer, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) static char line[80];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) int offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) unsigned char *buffer = (unsigned char *) ibuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) int from, base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) for (i = 0; i < length; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if ((i & 15) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (i > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) offset += sprintf (line+offset, " - ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) for (j = i - 16; j < i; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (buffer[j] >= 32 && buffer[j] <= 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) line[offset++] = buffer[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) line[offset++] = '.';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) line[offset] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) usb_stor_dbg(us, "%s\n", line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) offset += sprintf (line+offset, "%08x:", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) } else if ((i & 7) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) offset += sprintf (line+offset, " -");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) offset += sprintf (line+offset, " %02x", buffer[i] & 0xff);
^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) /* Add the last "chunk" of data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) from = (length - 1) % 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) base = ((length - 1) / 16) * 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) for (i = from + 1; i < 16; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) offset += sprintf (line+offset, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) if (from < 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) offset += sprintf (line+offset, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) offset += sprintf (line+offset, " - ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) for (i = 0; i <= from; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (buffer[base+i] >= 32 && buffer[base+i] <= 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) line[offset++] = buffer[base+i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) line[offset++] = '.';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) line[offset] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) usb_stor_dbg(us, "%s\n", line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) static struct scsi_host_template freecom_host_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) static int freecom_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) struct us_data *us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) result = usb_stor_probe1(&us, intf, id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) (id - freecom_usb_ids) + freecom_unusual_dev_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) &freecom_host_template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) us->transport_name = "Freecom";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) us->transport = freecom_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) us->transport_reset = usb_stor_freecom_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) us->max_lun = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) result = usb_stor_probe2(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) return result;
^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 struct usb_driver freecom_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) .name = DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) .probe = freecom_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) .disconnect = usb_stor_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) .suspend = usb_stor_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) .resume = usb_stor_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) .reset_resume = usb_stor_reset_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) .pre_reset = usb_stor_pre_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) .post_reset = usb_stor_post_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) .id_table = freecom_usb_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) .soft_unbind = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) .no_dynamic_id = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) module_usb_stor_driver(freecom_driver, freecom_host_template, DRV_NAME);