Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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 USB Mass Storage compliant devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Current development and maintenance by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *   (c) 1999-2003 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Developed with the assistance of:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *   (c) 2000 David L. Brown, Jr. (usb-storage@davidb.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *   (c) 2003-2009 Alan Stern (stern@rowland.harvard.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  * Initial work by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *   (c) 1999 Michael Gee (michael@linuxspecific.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  * usb_device_id support by Adam J. Richter (adam@yggdrasil.com):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *   (c) 2000 Yggdrasil Computing, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  * This driver is based on the 'USB Mass Storage Class' document. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  * describes in detail the protocol used to communicate with such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  * devices.  Clearly, the designers had SCSI and ATAPI commands in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  * mind when they created this document.  The commands are all very
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  * similar to commands in the SCSI-II and ATAPI specifications.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  * It is important to note that in a number of cases this class
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  * exhibits class-specific exemptions from the USB specification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  * Notably the usage of NAK, STALL and ACK differs from the norm, in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  * that they are used to communicate wait, failed and OK on commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  * Also, for certain devices, the interrupt endpoint is used to convey
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  * status of a command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #ifdef CONFIG_USB_STORAGE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #define DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <linux/utsname.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include "usb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include "scsiglue.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include "transport.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include "protocol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include "initializers.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include "sierra_ms.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #include "option_ms.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #if IS_ENABLED(CONFIG_USB_UAS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #include "uas-detect.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #define DRV_NAME "usb-storage"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) /* Some informational data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) MODULE_AUTHOR("Matthew Dharm <mdharm-usb@one-eyed-alien.net>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) MODULE_DESCRIPTION("USB Mass Storage driver for Linux");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) static unsigned int delay_use = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) module_param(delay_use, uint, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) MODULE_PARM_DESC(delay_use, "seconds to delay before using a new device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) static char quirks[128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) module_param_string(quirks, quirks, sizeof(quirks), S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) MODULE_PARM_DESC(quirks, "supplemental list of device IDs and their quirks");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80)  * The entries in this table correspond, line for line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81)  * with the entries in usb_storage_usb_ids[], defined in usual-tables.c.
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85)  *The vendor name should be kept at eight characters or less, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86)  * the product name should be kept at 16 characters or less. If a device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87)  * has the US_FL_FIX_INQUIRY flag, then the vendor and product names
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88)  * normally generated by a device through the INQUIRY response will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89)  * taken from this list, and this is the reason for the above size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90)  * restriction. However, if the flag is not present, then you
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  * are free to use as many characters as you like.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 		    vendor_name, product_name, use_protocol, use_transport, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 		    init_function, Flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	.vendorName = vendor_name,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	.productName = product_name,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	.useProtocol = use_protocol,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	.useTransport = use_transport,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	.initFunction = init_function,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) #define COMPLIANT_DEV	UNUSUAL_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) #define USUAL_DEV(use_protocol, use_transport) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	.useProtocol = use_protocol,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	.useTransport = use_transport,	\
^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) #define UNUSUAL_VENDOR_INTF(idVendor, cl, sc, pr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 		vendor_name, product_name, use_protocol, use_transport, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 		init_function, Flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	.vendorName = vendor_name,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	.productName = product_name,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	.useProtocol = use_protocol,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	.useTransport = use_transport,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	.initFunction = init_function,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) static const struct us_unusual_dev us_unusual_dev_list[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) #	include "unusual_devs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	{ }		/* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) static const struct us_unusual_dev for_dynamic_ids =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 		USUAL_DEV(USB_SC_SCSI, USB_PR_BULK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) #undef UNUSUAL_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) #undef COMPLIANT_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) #undef USUAL_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) #undef UNUSUAL_VENDOR_INTF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) #ifdef CONFIG_LOCKDEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) static struct lock_class_key us_interface_key[USB_MAXINTERFACES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) static void us_set_lock_class(struct mutex *mutex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 		struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	struct usb_device *udev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	struct usb_host_config *config = udev->actconfig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	for (i = 0; i < config->desc.bNumInterfaces; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		if (config->interface[i] == intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	BUG_ON(i == config->desc.bNumInterfaces);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	lockdep_set_class(mutex, &us_interface_key[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) static void us_set_lock_class(struct mutex *mutex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 		struct usb_interface *intf)
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) #ifdef CONFIG_PM	/* Minimal support for suspend and resume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) int usb_stor_suspend(struct usb_interface *iface, pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	struct us_data *us = usb_get_intfdata(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	/* Wait until no command is running */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	mutex_lock(&us->dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	if (us->suspend_resume_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		(us->suspend_resume_hook)(us, US_SUSPEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	 * When runtime PM is working, we'll set a flag to indicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	 * whether we should autoresume when a SCSI request arrives.
^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) 	mutex_unlock(&us->dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) EXPORT_SYMBOL_GPL(usb_stor_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) int usb_stor_resume(struct usb_interface *iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	struct us_data *us = usb_get_intfdata(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	mutex_lock(&us->dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	if (us->suspend_resume_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 		(us->suspend_resume_hook)(us, US_RESUME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	mutex_unlock(&us->dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) EXPORT_SYMBOL_GPL(usb_stor_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) int usb_stor_reset_resume(struct usb_interface *iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	struct us_data *us = usb_get_intfdata(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	/* Report the reset to the SCSI core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	usb_stor_report_bus_reset(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	 * If any of the subdrivers implemented a reinitialization scheme,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	 * this is where the callback would be invoked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) EXPORT_SYMBOL_GPL(usb_stor_reset_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) #endif /* CONFIG_PM */
^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)  * The next two routines get called just before and just after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222)  * a USB port reset, whether from this driver or a different one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) int usb_stor_pre_reset(struct usb_interface *iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	struct us_data *us = usb_get_intfdata(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	/* Make sure no command runs during the reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	mutex_lock(&us->dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) EXPORT_SYMBOL_GPL(usb_stor_pre_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) int usb_stor_post_reset(struct usb_interface *iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	struct us_data *us = usb_get_intfdata(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	/* Report the reset to the SCSI core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	usb_stor_report_bus_reset(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	 * If any of the subdrivers implemented a reinitialization scheme,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	 * this is where the callback would be invoked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	mutex_unlock(&us->dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) EXPORT_SYMBOL_GPL(usb_stor_post_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253)  * fill_inquiry_response takes an unsigned char array (which must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254)  * be at least 36 characters) and populates the vendor name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255)  * product name, and revision fields. Then the array is copied
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256)  * into the SCSI command's response buffer (oddly enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257)  * called request_buffer). data_len contains the length of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258)  * data array, which again must be at least 36.
^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) void fill_inquiry_response(struct us_data *us, unsigned char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 		unsigned int data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	if (data_len < 36) /* You lose. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	memset(data+8, ' ', 28);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	if (data[0]&0x20) { /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 			     * USB device currently not connected. Return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 			     * peripheral qualifier 001b ("...however, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 			     * physical device is not currently connected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 			     * to this logical unit") and leave vendor and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 			     * product identification empty. ("If the target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 			     * does store some of the INQUIRY data on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 			     * device, it may return zeros or ASCII spaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 			     * (20h) in those fields until the data is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 			     * available from the device.").
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 			     */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 		u16 bcdDevice = le16_to_cpu(us->pusb_dev->descriptor.bcdDevice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 		int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		n = strlen(us->unusual_dev->vendorName);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 		memcpy(data+8, us->unusual_dev->vendorName, min(8, n));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		n = strlen(us->unusual_dev->productName);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		memcpy(data+16, us->unusual_dev->productName, min(16, n));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 		data[32] = 0x30 + ((bcdDevice>>12) & 0x0F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 		data[33] = 0x30 + ((bcdDevice>>8) & 0x0F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 		data[34] = 0x30 + ((bcdDevice>>4) & 0x0F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		data[35] = 0x30 + ((bcdDevice) & 0x0F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	usb_stor_set_xfer_buf(data, data_len, us->srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) EXPORT_SYMBOL_GPL(fill_inquiry_response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) static int usb_stor_control_thread(void * __us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	struct us_data *us = (struct us_data *)__us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	struct Scsi_Host *host = us_to_host(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	struct scsi_cmnd *srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		usb_stor_dbg(us, "*** thread sleeping\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		if (wait_for_completion_interruptible(&us->cmnd_ready))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		usb_stor_dbg(us, "*** thread awakened\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		/* lock the device pointers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		mutex_lock(&(us->dev_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		/* lock access to the state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		scsi_lock(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		/* When we are called with no command pending, we're done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		srb = us->srb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		if (srb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 			scsi_unlock(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 			mutex_unlock(&us->dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 			usb_stor_dbg(us, "-- exiting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		/* has the command timed out *already* ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 			srb->result = DID_ABORT << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 			goto SkipForAbort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		scsi_unlock(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		 * reject the command if the direction indicator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		 * is UNKNOWN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 		if (srb->sc_data_direction == DMA_BIDIRECTIONAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 			usb_stor_dbg(us, "UNKNOWN data direction\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 			srb->result = DID_ERROR << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		}
^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) 		 * reject if target != 0 or if LUN is higher than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		 * the maximum known LUN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		else if (srb->device->id &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 				!(us->fflags & US_FL_SCM_MULT_TARG)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 			usb_stor_dbg(us, "Bad target number (%d:%llu)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 				     srb->device->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 				     srb->device->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 			srb->result = DID_BAD_TARGET << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 		else if (srb->device->lun > us->max_lun) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 			usb_stor_dbg(us, "Bad LUN (%d:%llu)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 				     srb->device->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 				     srb->device->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 			srb->result = DID_BAD_TARGET << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		 * Handle those devices which need us to fake
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 		 * their inquiry data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		else if ((srb->cmnd[0] == INQUIRY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 			    (us->fflags & US_FL_FIX_INQUIRY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 			unsigned char data_ptr[36] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			    0x00, 0x80, 0x02, 0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 			    0x1F, 0x00, 0x00, 0x00};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 			usb_stor_dbg(us, "Faking INQUIRY command\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 			fill_inquiry_response(us, data_ptr, 36);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 			srb->result = SAM_STAT_GOOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 		/* we've got a command, let's do it! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 			US_DEBUG(usb_stor_show_command(us, srb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 			us->proto_handler(srb, us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 			usb_mark_last_busy(us->pusb_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		/* lock access to the state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		scsi_lock(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		/* was the command aborted? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		if (srb->result == DID_ABORT << 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) SkipForAbort:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 			usb_stor_dbg(us, "scsi command aborted\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 			srb = NULL;	/* Don't call srb->scsi_done() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		 * If an abort request was received we need to signal that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 		 * the abort has finished.  The proper test for this is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 		 * the TIMED_OUT flag, not srb->result == DID_ABORT, because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		 * the timeout might have occurred after the command had
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		 * already completed with a different result code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 			complete(&(us->notify));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 			/* Allow USB transfers to resume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 			clear_bit(US_FLIDX_ABORTING, &us->dflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 			clear_bit(US_FLIDX_TIMED_OUT, &us->dflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 		/* finished working on this command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		us->srb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		scsi_unlock(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		/* unlock the device pointers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		mutex_unlock(&us->dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		/* now that the locks are released, notify the SCSI core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		if (srb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 			usb_stor_dbg(us, "scsi cmd done, result=0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 					srb->result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 			srb->scsi_done(srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	} /* for (;;) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	/* Wait until we are told to stop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		if (kthread_should_stop())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	__set_current_state(TASK_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) /***********************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436)  * Device probing and disconnecting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437)  ***********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) /* Associate our private data with the USB device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) static int associate_dev(struct us_data *us, struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	/* Fill in the device-related fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	us->pusb_dev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	us->pusb_intf = intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	us->ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	usb_stor_dbg(us, "Vendor: 0x%04x, Product: 0x%04x, Revision: 0x%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		     le16_to_cpu(us->pusb_dev->descriptor.idVendor),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		     le16_to_cpu(us->pusb_dev->descriptor.idProduct),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		     le16_to_cpu(us->pusb_dev->descriptor.bcdDevice));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	usb_stor_dbg(us, "Interface Subclass: 0x%02x, Protocol: 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		     intf->cur_altsetting->desc.bInterfaceSubClass,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		     intf->cur_altsetting->desc.bInterfaceProtocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	/* Store our private data in the interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	usb_set_intfdata(intf, us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	/* Allocate the control/setup and DMA-mapped buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	us->cr = kmalloc(sizeof(*us->cr), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	if (!us->cr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	us->iobuf = usb_alloc_coherent(us->pusb_dev, US_IOBUF_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 			GFP_KERNEL, &us->iobuf_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	if (!us->iobuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 		usb_stor_dbg(us, "I/O buffer allocation failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) /* Works only for digits and letters, but small and fast */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) #define TOLOWER(x) ((x) | 0x20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) /* Adjust device flags based on the "quirks=" module parameter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) void usb_stor_adjust_quirks(struct usb_device *udev, unsigned long *fflags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	u16 vid = le16_to_cpu(udev->descriptor.idVendor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	u16 pid = le16_to_cpu(udev->descriptor.idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	unsigned f = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	unsigned int mask = (US_FL_SANE_SENSE | US_FL_BAD_SENSE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 			US_FL_FIX_CAPACITY | US_FL_IGNORE_UAS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 			US_FL_CAPACITY_HEURISTICS | US_FL_IGNORE_DEVICE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 			US_FL_NOT_LOCKABLE | US_FL_MAX_SECTORS_64 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 			US_FL_CAPACITY_OK | US_FL_IGNORE_RESIDUE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 			US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 			US_FL_NO_READ_DISC_INFO | US_FL_NO_READ_CAPACITY_16 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 			US_FL_INITIAL_READ10 | US_FL_WRITE_CACHE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 			US_FL_NO_ATA_1X | US_FL_NO_REPORT_OPCODES |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 			US_FL_MAX_SECTORS_240 | US_FL_NO_REPORT_LUNS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 			US_FL_ALWAYS_SYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	p = quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	while (*p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		/* Each entry consists of VID:PID:flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		if (vid == simple_strtoul(p, &p, 16) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 				*p == ':' &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 				pid == simple_strtoul(p+1, &p, 16) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 				*p == ':')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		/* Move forward to the next entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		while (*p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 			if (*p++ == ',')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	if (!*p)	/* No match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	/* Collect the flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	while (*++p && *p != ',') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		switch (TOLOWER(*p)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 		case 'a':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 			f |= US_FL_SANE_SENSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 		case 'b':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 			f |= US_FL_BAD_SENSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		case 'c':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 			f |= US_FL_FIX_CAPACITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		case 'd':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 			f |= US_FL_NO_READ_DISC_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 		case 'e':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 			f |= US_FL_NO_READ_CAPACITY_16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		case 'f':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 			f |= US_FL_NO_REPORT_OPCODES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		case 'g':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 			f |= US_FL_MAX_SECTORS_240;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		case 'h':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 			f |= US_FL_CAPACITY_HEURISTICS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		case 'i':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 			f |= US_FL_IGNORE_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		case 'j':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 			f |= US_FL_NO_REPORT_LUNS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		case 'k':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 			f |= US_FL_NO_SAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 		case 'l':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 			f |= US_FL_NOT_LOCKABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		case 'm':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 			f |= US_FL_MAX_SECTORS_64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 		case 'n':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 			f |= US_FL_INITIAL_READ10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		case 'o':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 			f |= US_FL_CAPACITY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		case 'p':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 			f |= US_FL_WRITE_CACHE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 		case 'r':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 			f |= US_FL_IGNORE_RESIDUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 		case 's':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 			f |= US_FL_SINGLE_LUN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		case 't':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 			f |= US_FL_NO_ATA_1X;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		case 'u':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 			f |= US_FL_IGNORE_UAS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		case 'w':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 			f |= US_FL_NO_WP_DETECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 		case 'y':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 			f |= US_FL_ALWAYS_SYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		/* Ignore unrecognized flag characters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	*fflags = (*fflags & ~mask) | f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) EXPORT_SYMBOL_GPL(usb_stor_adjust_quirks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) /* Get the unusual_devs entries and the string descriptors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) static int get_device_info(struct us_data *us, const struct usb_device_id *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		const struct us_unusual_dev *unusual_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	struct usb_device *dev = us->pusb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	struct usb_interface_descriptor *idesc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		&us->pusb_intf->cur_altsetting->desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	struct device *pdev = &us->pusb_intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	/* Store the entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	us->unusual_dev = unusual_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	us->subclass = (unusual_dev->useProtocol == USB_SC_DEVICE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 			idesc->bInterfaceSubClass :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 			unusual_dev->useProtocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	us->protocol = (unusual_dev->useTransport == USB_PR_DEVICE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 			idesc->bInterfaceProtocol :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 			unusual_dev->useTransport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	us->fflags = id->driver_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	usb_stor_adjust_quirks(us->pusb_dev, &us->fflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	if (us->fflags & US_FL_IGNORE_DEVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		dev_info(pdev, "device ignored\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	 * This flag is only needed when we're in high-speed, so let's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	 * disable it if we're in full-speed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	if (dev->speed != USB_SPEED_HIGH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 		us->fflags &= ~US_FL_GO_SLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	if (us->fflags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		dev_info(pdev, "Quirks match for vid %04x pid %04x: %lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 				le16_to_cpu(dev->descriptor.idVendor),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 				le16_to_cpu(dev->descriptor.idProduct),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 				us->fflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	 * Log a message if a non-generic unusual_dev entry contains an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	 * unnecessary subclass or protocol override.  This may stimulate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	 * reports from users that will help us remove unneeded entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	 * from the unusual_devs.h table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	if (id->idVendor || id->idProduct) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		static const char *msgs[3] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 			"an unneeded SubClass entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 			"an unneeded Protocol entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 			"unneeded SubClass and Protocol entries"};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		struct usb_device_descriptor *ddesc = &dev->descriptor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 		int msg = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		if (unusual_dev->useProtocol != USB_SC_DEVICE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 			us->subclass == idesc->bInterfaceSubClass)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 			msg += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		if (unusual_dev->useTransport != USB_PR_DEVICE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 			us->protocol == idesc->bInterfaceProtocol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 			msg += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		if (msg >= 0 && !(us->fflags & US_FL_NEED_OVERRIDE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 			dev_notice(pdev, "This device "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 					"(%04x,%04x,%04x S %02x P %02x)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 					" has %s in unusual_devs.h (kernel"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 					" %s)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 					"   Please send a copy of this message to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 					"<linux-usb@vger.kernel.org> and "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 					"<usb-storage@lists.one-eyed-alien.net>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 					le16_to_cpu(ddesc->idVendor),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 					le16_to_cpu(ddesc->idProduct),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 					le16_to_cpu(ddesc->bcdDevice),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 					idesc->bInterfaceSubClass,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 					idesc->bInterfaceProtocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 					msgs[msg],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 					utsname()->release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) /* Get the transport settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) static void get_transport(struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	switch (us->protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	case USB_PR_CB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		us->transport_name = "Control/Bulk";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		us->transport = usb_stor_CB_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		us->transport_reset = usb_stor_CB_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		us->max_lun = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	case USB_PR_CBI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		us->transport_name = "Control/Bulk/Interrupt";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		us->transport = usb_stor_CB_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		us->transport_reset = usb_stor_CB_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		us->max_lun = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	case USB_PR_BULK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		us->transport_name = "Bulk";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		us->transport = usb_stor_Bulk_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		us->transport_reset = usb_stor_Bulk_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) /* Get the protocol settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) static void get_protocol(struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	switch (us->subclass) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	case USB_SC_RBC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		us->protocol_name = "Reduced Block Commands (RBC)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		us->proto_handler = usb_stor_transparent_scsi_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	case USB_SC_8020:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 		us->protocol_name = "8020i";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		us->proto_handler = usb_stor_pad12_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		us->max_lun = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	case USB_SC_QIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 		us->protocol_name = "QIC-157";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 		us->proto_handler = usb_stor_pad12_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		us->max_lun = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	case USB_SC_8070:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		us->protocol_name = "8070i";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		us->proto_handler = usb_stor_pad12_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 		us->max_lun = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	case USB_SC_SCSI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		us->protocol_name = "Transparent SCSI";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		us->proto_handler = usb_stor_transparent_scsi_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	case USB_SC_UFI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		us->protocol_name = "Uniform Floppy Interface (UFI)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		us->proto_handler = usb_stor_ufi_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		break;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) /* Get the pipe settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) static int get_pipes(struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	struct usb_host_interface *alt = us->pusb_intf->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	struct usb_endpoint_descriptor *ep_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	struct usb_endpoint_descriptor *ep_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	struct usb_endpoint_descriptor *ep_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	 * Find the first endpoint of each type we need.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	 * We are expecting a minimum of 2 endpoints - in and out (bulk).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	 * An optional interrupt-in is OK (necessary for CBI protocol).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	 * We will ignore any others.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	res = usb_find_common_endpoints(alt, &ep_in, &ep_out, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		usb_stor_dbg(us, "bulk endpoints not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	res = usb_find_int_in_endpoint(alt, &ep_int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	if (res && us->protocol == USB_PR_CBI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		usb_stor_dbg(us, "interrupt endpoint not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	/* Calculate and store the pipe values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	us->send_ctrl_pipe = usb_sndctrlpipe(us->pusb_dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	us->recv_ctrl_pipe = usb_rcvctrlpipe(us->pusb_dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	us->send_bulk_pipe = usb_sndbulkpipe(us->pusb_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		usb_endpoint_num(ep_out));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	us->recv_bulk_pipe = usb_rcvbulkpipe(us->pusb_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		usb_endpoint_num(ep_in));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	if (ep_int) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		us->recv_intr_pipe = usb_rcvintpipe(us->pusb_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 			usb_endpoint_num(ep_int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		us->ep_bInterval = ep_int->bInterval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) /* Initialize all the dynamic resources we need */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) static int usb_stor_acquire_resources(struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	int p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	struct task_struct *th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	us->current_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	if (!us->current_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	 * Just before we start our control thread, initialize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	 * the device if it needs initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	if (us->unusual_dev->initFunction) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		p = us->unusual_dev->initFunction(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		if (p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 			return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	/* Start up our control thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	th = kthread_run(usb_stor_control_thread, us, "usb-storage");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	if (IS_ERR(th)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		dev_warn(&us->pusb_intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 				"Unable to start control thread\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		return PTR_ERR(th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	us->ctl_thread = th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) /* Release all our dynamic resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) static void usb_stor_release_resources(struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	 * Tell the control thread to exit.  The SCSI host must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	 * already have been removed and the DISCONNECTING flag set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	 * so that we won't accept any more commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	usb_stor_dbg(us, "-- sending exit command to thread\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	complete(&us->cmnd_ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	if (us->ctl_thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		kthread_stop(us->ctl_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	/* Call the destructor routine, if it exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	if (us->extra_destructor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		usb_stor_dbg(us, "-- calling extra_destructor()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		us->extra_destructor(us->extra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	/* Free the extra data and the URB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	kfree(us->extra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	usb_free_urb(us->current_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) /* Dissociate from the USB device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) static void dissociate_dev(struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	/* Free the buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	kfree(us->cr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	usb_free_coherent(us->pusb_dev, US_IOBUF_SIZE, us->iobuf, us->iobuf_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	/* Remove our private data from the interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	usb_set_intfdata(us->pusb_intf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840)  * First stage of disconnect processing: stop SCSI scanning,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841)  * remove the host, and stop accepting new commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) static void quiesce_and_remove_host(struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	struct Scsi_Host *host = us_to_host(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	/* If the device is really gone, cut short reset delays */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	if (us->pusb_dev->state == USB_STATE_NOTATTACHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		set_bit(US_FLIDX_DISCONNECTING, &us->dflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		wake_up(&us->delay_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	 * Prevent SCSI scanning (if it hasn't started yet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	 * or wait for the SCSI-scanning routine to stop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	cancel_delayed_work_sync(&us->scan_dwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	/* Balance autopm calls if scanning was cancelled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	if (test_bit(US_FLIDX_SCAN_PENDING, &us->dflags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 		usb_autopm_put_interface_no_suspend(us->pusb_intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	 * Removing the host will perform an orderly shutdown: caches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	 * synchronized, disks spun down, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	scsi_remove_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	 * Prevent any new commands from being accepted and cut short
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	 * reset delays.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	scsi_lock(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	set_bit(US_FLIDX_DISCONNECTING, &us->dflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	scsi_unlock(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	wake_up(&us->delay_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) /* Second stage of disconnect processing: deallocate all resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) static void release_everything(struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	usb_stor_release_resources(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	dissociate_dev(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	 * Drop our reference to the host; the SCSI core will free it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	 * (and "us" along with it) when the refcount becomes 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	scsi_host_put(us_to_host(us));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) /* Delayed-work routine to carry out SCSI-device scanning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) static void usb_stor_scan_dwork(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	struct us_data *us = container_of(work, struct us_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 			scan_dwork.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	struct device *dev = &us->pusb_intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	dev_dbg(dev, "starting scan\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	/* For bulk-only devices, determine the max LUN value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	if (us->protocol == USB_PR_BULK &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	    !(us->fflags & US_FL_SINGLE_LUN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	    !(us->fflags & US_FL_SCM_MULT_TARG)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		mutex_lock(&us->dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		us->max_lun = usb_stor_Bulk_max_lun(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 		 * Allow proper scanning of devices that present more than 8 LUNs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		 * While not affecting other devices that may need the previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		 * behavior
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		if (us->max_lun >= 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 			us_to_host(us)->max_lun = us->max_lun+1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		mutex_unlock(&us->dev_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	scsi_scan_host(us_to_host(us));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	dev_dbg(dev, "scan complete\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	/* Should we unbind if no devices were detected? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	usb_autopm_put_interface(us->pusb_intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	clear_bit(US_FLIDX_SCAN_PENDING, &us->dflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) static unsigned int usb_stor_sg_tablesize(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	struct usb_device *usb_dev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	if (usb_dev->bus->sg_tablesize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		return usb_dev->bus->sg_tablesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	return SG_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) /* First part of general USB mass-storage probing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) int usb_stor_probe1(struct us_data **pus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		const struct usb_device_id *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		const struct us_unusual_dev *unusual_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		struct scsi_host_template *sht)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	struct Scsi_Host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	struct us_data *us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	dev_info(&intf->dev, "USB Mass Storage device detected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	 * Ask the SCSI layer to allocate a host structure, with extra
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	 * space at the end for our private us_data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	host = scsi_host_alloc(sht, sizeof(*us));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	if (!host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		dev_warn(&intf->dev, "Unable to allocate the scsi host\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	 * Allow 16-byte CDBs and thus > 2TB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	host->max_cmd_len = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	host->sg_tablesize = usb_stor_sg_tablesize(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	*pus = us = host_to_us(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	mutex_init(&(us->dev_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	us_set_lock_class(&us->dev_mutex, intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	init_completion(&us->cmnd_ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	init_completion(&(us->notify));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	init_waitqueue_head(&us->delay_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	INIT_DELAYED_WORK(&us->scan_dwork, usb_stor_scan_dwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	/* Associate the us_data structure with the USB device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	result = associate_dev(us, intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 		goto BadDevice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	/* Get the unusual_devs entries and the descriptors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	result = get_device_info(us, id, unusual_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		goto BadDevice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	/* Get standard transport and protocol settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	get_transport(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	get_protocol(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	 * Give the caller a chance to fill in specialized transport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	 * or protocol settings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) BadDevice:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	usb_stor_dbg(us, "storage_probe() failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	release_everything(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) EXPORT_SYMBOL_GPL(usb_stor_probe1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) /* Second part of general USB mass-storage probing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) int usb_stor_probe2(struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	struct device *dev = &us->pusb_intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	/* Make sure the transport and protocol have both been set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	if (!us->transport || !us->proto_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 		result = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 		goto BadDevice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	usb_stor_dbg(us, "Transport: %s\n", us->transport_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	usb_stor_dbg(us, "Protocol: %s\n", us->protocol_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	if (us->fflags & US_FL_SCM_MULT_TARG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		 * SCM eUSCSI bridge devices can have different numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		 * of LUNs on different targets; allow all to be probed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 		us->max_lun = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		/* The eUSCSI itself has ID 7, so avoid scanning that */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		us_to_host(us)->this_id = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		/* max_id is 8 initially, so no need to set it here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 		/* In the normal case there is only a single target */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		us_to_host(us)->max_id = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		 * Like Windows, we won't store the LUN bits in CDB[1] for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 		 * SCSI-2 devices using the Bulk-Only transport (even though
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 		 * this violates the SCSI spec).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		if (us->transport == usb_stor_Bulk_transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 			us_to_host(us)->no_scsi2_lun_in_cdb = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	/* fix for single-lun devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	if (us->fflags & US_FL_SINGLE_LUN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		us->max_lun = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	/* Find the endpoints and calculate pipe values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	result = get_pipes(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		goto BadDevice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	 * If the device returns invalid data for the first READ(10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	 * command, indicate the command should be retried.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	if (us->fflags & US_FL_INITIAL_READ10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		set_bit(US_FLIDX_REDO_READ10, &us->dflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	/* Acquire all the other resources and add the host */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	result = usb_stor_acquire_resources(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 		goto BadDevice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	usb_autopm_get_interface_no_resume(us->pusb_intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	snprintf(us->scsi_name, sizeof(us->scsi_name), "usb-storage %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 					dev_name(&us->pusb_intf->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	result = scsi_add_host(us_to_host(us), dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		dev_warn(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 				"Unable to add the scsi host\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		goto HostAddErr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	/* Submit the delayed_work for SCSI-device scanning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	set_bit(US_FLIDX_SCAN_PENDING, &us->dflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	if (delay_use > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		dev_dbg(dev, "waiting for device to settle before scanning\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	queue_delayed_work(system_freezable_wq, &us->scan_dwork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 			delay_use * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	/* We come here if there are any problems */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) HostAddErr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	usb_autopm_put_interface_no_suspend(us->pusb_intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) BadDevice:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	usb_stor_dbg(us, "storage_probe() failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	release_everything(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) EXPORT_SYMBOL_GPL(usb_stor_probe2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) /* Handle a USB mass-storage disconnect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) void usb_stor_disconnect(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	struct us_data *us = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	quiesce_and_remove_host(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	release_everything(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) EXPORT_SYMBOL_GPL(usb_stor_disconnect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) static struct scsi_host_template usb_stor_host_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) /* The main probe routine for standard devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) static int storage_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 			 const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	const struct us_unusual_dev *unusual_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	struct us_data *us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	/* If uas is enabled and this device can do uas then ignore it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) #if IS_ENABLED(CONFIG_USB_UAS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	if (uas_use_uas_driver(intf, id, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	 * If the device isn't standard (is handled by a subdriver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	 * module) then don't accept it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	if (usb_usual_ignore_device(intf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	 * Call the general probe procedures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	 * The unusual_dev_list array is parallel to the usb_storage_usb_ids
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	 * table, so we use the index of the id entry to find the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	 * corresponding unusual_devs entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	size = ARRAY_SIZE(us_unusual_dev_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	if (id >= usb_storage_usb_ids && id < usb_storage_usb_ids + size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 		unusual_dev = (id - usb_storage_usb_ids) + us_unusual_dev_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		unusual_dev = &for_dynamic_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 		dev_dbg(&intf->dev, "Use Bulk-Only transport with the Transparent SCSI protocol for dynamic id: 0x%04x 0x%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 			id->idVendor, id->idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	result = usb_stor_probe1(&us, intf, id, unusual_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 				 &usb_stor_host_template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	/* No special transport or protocol settings in the main module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	result = usb_stor_probe2(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) static struct usb_driver usb_storage_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	.name =		DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	.probe =	storage_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	.disconnect =	usb_stor_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	.suspend =	usb_stor_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	.resume =	usb_stor_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	.reset_resume =	usb_stor_reset_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	.pre_reset =	usb_stor_pre_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	.post_reset =	usb_stor_post_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	.id_table =	usb_storage_usb_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	.supports_autosuspend = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	.soft_unbind =	1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) module_usb_stor_driver(usb_storage_driver, usb_stor_host_template, DRV_NAME);