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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Intel Wireless WiMAX Connection 2400m
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Linux driver model glue for USB device, reset & fw upload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2007-2008 Intel Corporation <linux-wimax@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Yanir Lubetkin <yanirx.lubetkin@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * See i2400m-usb.h for a general description of this driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * This file implements driver model glue, and hook ups for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * generic driver to implement the bus-specific functions (device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * communication setup/tear down, firmware upload and resetting).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * ROADMAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * i2400mu_probe()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *   alloc_netdev()...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *     i2400mu_netdev_setup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *       i2400mu_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *       i2400m_netdev_setup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *   i2400m_setup()...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * i2400mu_disconnect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *   i2400m_release()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *   free_netdev()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * i2400mu_suspend()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *   i2400m_cmd_enter_powersave()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *   i2400mu_notification_release()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * i2400mu_resume()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *   i2400mu_notification_setup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * i2400mu_bus_dev_start()        Called by i2400m_dev_start() [who is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *   i2400mu_tx_setup()           called by i2400m_setup()]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  *   i2400mu_rx_setup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *   i2400mu_notification_setup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * i2400mu_bus_dev_stop()         Called by i2400m_dev_stop() [who is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *   i2400mu_notification_release()  called by i2400m_release()]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  *   i2400mu_rx_release()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  *   i2400mu_tx_release()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * i2400mu_bus_reset()            Called by i2400m_reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  *   __i2400mu_reset()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  *     __i2400mu_send_barker()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  *   usb_reset_device()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #include "i2400m-usb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #include <linux/wimax/i2400m.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define D_SUBMODULE usb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #include "usb-debug-levels.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static char i2400mu_debug_params[128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) module_param_string(debug, i2400mu_debug_params, sizeof(i2400mu_debug_params),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		    0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) MODULE_PARM_DESC(debug,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		 "String of space-separated NAME:VALUE pairs, where NAMEs "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		 "are the different debug submodules and VALUE are the "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		 "initial debug value to set.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) /* Our firmware file name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static const char *i2400mu_bus_fw_names_5x50[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #define I2400MU_FW_FILE_NAME_v1_5 "i2400m-fw-usb-1.5.sbcf"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	I2400MU_FW_FILE_NAME_v1_5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #define I2400MU_FW_FILE_NAME_v1_4 "i2400m-fw-usb-1.4.sbcf"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	I2400MU_FW_FILE_NAME_v1_4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) };
^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) static const char *i2400mu_bus_fw_names_6050[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #define I6050U_FW_FILE_NAME_v1_5 "i6050-fw-usb-1.5.sbcf"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	I6050U_FW_FILE_NAME_v1_5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	NULL,
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) int i2400mu_bus_dev_start(struct i2400m *i2400m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct device *dev = &i2400mu->usb_iface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	result = i2400mu_tx_setup(i2400mu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		goto error_usb_tx_setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	result = i2400mu_rx_setup(i2400mu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		goto error_usb_rx_setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	result = i2400mu_notification_setup(i2400mu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		goto error_notif_setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) error_notif_setup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	i2400mu_rx_release(i2400mu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) error_usb_rx_setup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	i2400mu_tx_release(i2400mu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) error_usb_tx_setup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) void i2400mu_bus_dev_stop(struct i2400m *i2400m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	struct device *dev = &i2400mu->usb_iface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	i2400mu_notification_release(i2400mu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	i2400mu_rx_release(i2400mu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	i2400mu_tx_release(i2400mu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  * Sends a barker buffer to the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  * This helper will allocate a kmalloced buffer and use it to transmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * (then free it). Reason for this is that other arches cannot use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * stack/vmalloc/text areas for DMA transfers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  * Error recovery here is simpler: anything is considered a hard error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * and will move the reset code to use a last-resort bus-based reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int __i2400mu_send_barker(struct i2400mu *i2400mu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			  const __le32 *barker,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			  size_t barker_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			  unsigned endpoint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct usb_endpoint_descriptor *epd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	int pipe, actual_len, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct device *dev = &i2400mu->usb_iface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	void *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	int do_autopm = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	ret = usb_autopm_get_interface(i2400mu->usb_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		dev_err(dev, "RESET: can't get autopm: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		do_autopm = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	buffer = kmalloc(barker_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (buffer == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		goto error_kzalloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	epd = usb_get_epd(i2400mu->usb_iface, endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	pipe = usb_sndbulkpipe(i2400mu->usb_dev, epd->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	memcpy(buffer, barker, barker_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	ret = usb_bulk_msg(i2400mu->usb_dev, pipe, buffer, barker_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			   &actual_len, 200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	switch (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		if (actual_len != barker_size) {	/* Too short? drop it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			dev_err(dev, "E: %s: short write (%d B vs %zu "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 				"expected)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				__func__, actual_len, barker_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	case -EPIPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		 * Stall -- maybe the device is choking with our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		 * requests. Clear it and give it some time. If they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		 * happen to often, it might be another symptom, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		 * reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		 * No error handling for usb_clear_halt(0; if it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		 * works, the retry works; if it fails, this switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		 * does the error handling for us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		if (edc_inc(&i2400mu->urb_edc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			    10 * EDC_MAX_ERRORS, EDC_ERROR_TIMEFRAME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			dev_err(dev, "E: %s: too many stalls in "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 				"URB; resetting device\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			usb_queue_reset_device(i2400mu->usb_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			/* fallthrough */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			usb_clear_halt(i2400mu->usb_dev, pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			msleep(10);	/* give the device some time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	case -EINVAL:			/* while removing driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	case -ENODEV:			/* dev disconnect ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	case -ENOENT:			/* just ignore it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	case -ESHUTDOWN:		/* and exit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		ret = -ESHUTDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	default:			/* Some error? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		if (edc_inc(&i2400mu->urb_edc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			    EDC_MAX_ERRORS, EDC_ERROR_TIMEFRAME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			dev_err(dev, "E: %s: maximum errors in URB "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 				"exceeded; resetting device\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 				__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			usb_queue_reset_device(i2400mu->usb_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			dev_warn(dev, "W: %s: cannot send URB: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 				 __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) error_kzalloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (do_autopm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		usb_autopm_put_interface(i2400mu->usb_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  * Reset a device at different levels (warm, cold or bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  * @i2400m: device descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  * @reset_type: soft, warm or bus reset (I2400M_RT_WARM/SOFT/BUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * Warm and cold resets get a USB reset if they fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * Warm reset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  * The device will be fully reset internally, but won't be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * disconnected from the USB bus (so no reenumeration will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  * happen). Firmware upload will be necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  * The device will send a reboot barker in the notification endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  * that will trigger the driver to reinitialize the state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  * automatically from notif.c:i2400m_notification_grok() into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  * i2400m_dev_bootstrap_delayed().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  * Cold and bus (USB) reset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * The device will be fully reset internally, disconnected from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  * USB bus an a reenumeration will happen. Firmware upload will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  * necessary. Thus, we don't do any locking or struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  * reinitialization, as we are going to be fully disconnected and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  * reenumerated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  * Note we need to return -ENODEV if a warm reset was requested and we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  * had to resort to a bus reset. See i2400m_op_reset(), wimax_reset()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  * and wimax_dev->op_reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)  * WARNING: no driver state saved/fixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) int i2400mu_bus_reset(struct i2400m *i2400m, enum i2400m_reset_type rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	struct i2400mu *i2400mu =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		container_of(i2400m, struct i2400mu, i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	struct device *dev = i2400m_dev(i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	static const __le32 i2400m_WARM_BOOT_BARKER[4] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		cpu_to_le32(I2400M_WARM_RESET_BARKER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		cpu_to_le32(I2400M_WARM_RESET_BARKER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		cpu_to_le32(I2400M_WARM_RESET_BARKER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		cpu_to_le32(I2400M_WARM_RESET_BARKER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	static const __le32 i2400m_COLD_BOOT_BARKER[4] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		cpu_to_le32(I2400M_COLD_RESET_BARKER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		cpu_to_le32(I2400M_COLD_RESET_BARKER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		cpu_to_le32(I2400M_COLD_RESET_BARKER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		cpu_to_le32(I2400M_COLD_RESET_BARKER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	d_fnstart(3, dev, "(i2400m %p rt %u)\n", i2400m, rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (rt == I2400M_RT_WARM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		result = __i2400mu_send_barker(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			i2400mu, i2400m_WARM_BOOT_BARKER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			sizeof(i2400m_WARM_BOOT_BARKER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			i2400mu->endpoint_cfg.bulk_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	else if (rt == I2400M_RT_COLD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		result = __i2400mu_send_barker(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			i2400mu, i2400m_COLD_BOOT_BARKER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			sizeof(i2400m_COLD_BOOT_BARKER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			i2400mu->endpoint_cfg.reset_cold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	else if (rt == I2400M_RT_BUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		result = usb_reset_device(i2400mu->usb_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		switch (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		case -EINVAL:	/* device is gone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		case -ENODEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			break;	/* We assume the device is disconnected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			dev_err(dev, "USB reset failed (%d), giving up!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 				result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		result = -EINVAL;	/* shut gcc up in certain arches */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	if (result < 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	    && result != -EINVAL	/* device is gone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	    && rt != I2400M_RT_BUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		 * Things failed -- resort to lower level reset, that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		 * we queue in another context; the reason for this is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		 * that the pre and post reset functionality requires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		 * the i2400m->init_mutex; RT_WARM and RT_COLD can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		 * come from areas where i2400m->init_mutex is taken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		dev_err(dev, "%s reset failed (%d); trying USB reset\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			rt == I2400M_RT_WARM ? "warm" : "cold", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		usb_queue_reset_device(i2400mu->usb_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		result = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	d_fnend(3, dev, "(i2400m %p rt %u) = %d\n", i2400m, rt, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static void i2400mu_get_drvinfo(struct net_device *net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)                                 struct ethtool_drvinfo *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	struct usb_device *udev = i2400mu->usb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	strlcpy(info->fw_version, i2400m->fw_name ? : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		sizeof(info->fw_version));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	usb_make_path(udev, info->bus_info, sizeof(info->bus_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static const struct ethtool_ops i2400mu_ethtool_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	.get_drvinfo = i2400mu_get_drvinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	.get_link = ethtool_op_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) void i2400mu_netdev_setup(struct net_device *net_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	i2400mu_init(i2400mu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	i2400m_netdev_setup(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	net_dev->ethtool_ops = &i2400mu_ethtool_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)  * Debug levels control; see debug.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) struct d_level D_LEVEL[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	D_SUBMODULE_DEFINE(usb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	D_SUBMODULE_DEFINE(fw),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	D_SUBMODULE_DEFINE(notif),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	D_SUBMODULE_DEFINE(rx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	D_SUBMODULE_DEFINE(tx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) void i2400mu_debugfs_add(struct i2400mu *i2400mu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	struct dentry *dentry = i2400mu->i2400m.wimax_dev.debugfs_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	dentry = debugfs_create_dir("i2400m-usb", dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	i2400mu->debugfs_dentry = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	d_level_register_debugfs("dl_", usb, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	d_level_register_debugfs("dl_", fw, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	d_level_register_debugfs("dl_", notif, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	d_level_register_debugfs("dl_", rx, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	d_level_register_debugfs("dl_", tx, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	/* Don't touch these if you don't know what you are doing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	debugfs_create_u8("rx_size_auto_shrink", 0600, dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 			  &i2400mu->rx_size_auto_shrink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	debugfs_create_size_t("rx_size", 0600, dentry, &i2400mu->rx_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static struct device_type i2400mu_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	.name	= "wimax",
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)  * Probe a i2400m interface and register it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)  * @iface:   USB interface to link to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)  * @id:      USB class/subclass/protocol id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)  * @returns: 0 if ok, < 0 errno code on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  * Alloc a net device, initialize the bus-specific details and then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  * calls the bus-generic initialization routine. That will register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)  * the wimax and netdev devices, upload the firmware [using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  * _bus_bm_*()], call _bus_dev_start() to finalize the setup of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)  * communication with the device and then will start to talk to it to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)  * finnish setting it up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) int i2400mu_probe(struct usb_interface *iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		  const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	struct net_device *net_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	struct device *dev = &iface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	struct i2400m *i2400m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	struct i2400mu *i2400mu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	struct usb_device *usb_dev = interface_to_usbdev(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	if (iface->cur_altsetting->desc.bNumEndpoints < 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	if (usb_dev->speed != USB_SPEED_HIGH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		dev_err(dev, "device not connected as high speed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	/* Allocate instance [calls i2400m_netdev_setup() on it]. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	result = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	net_dev = alloc_netdev(sizeof(*i2400mu), "wmx%d", NET_NAME_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			       i2400mu_netdev_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	if (net_dev == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		dev_err(dev, "no memory for network device instance\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		goto error_alloc_netdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	SET_NETDEV_DEV(net_dev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	SET_NETDEV_DEVTYPE(net_dev, &i2400mu_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	i2400m = net_dev_to_i2400m(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	i2400mu = container_of(i2400m, struct i2400mu, i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	i2400m->wimax_dev.net_dev = net_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	i2400mu->usb_dev = usb_get_dev(usb_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	i2400mu->usb_iface = iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	usb_set_intfdata(iface, i2400mu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	i2400m->bus_tx_block_size = I2400MU_BLK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	 * Room required in the Tx queue for USB message to accommodate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	 * a smallest payload while allocating header space is 16 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	 * Adding this room  for the new tx message increases the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	 * possibilities of including any payload with size <= 16 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	i2400m->bus_tx_room_min = I2400MU_BLK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	i2400m->bus_pl_size_max = I2400MU_PL_SIZE_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	i2400m->bus_setup = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	i2400m->bus_dev_start = i2400mu_bus_dev_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	i2400m->bus_dev_stop = i2400mu_bus_dev_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	i2400m->bus_release = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	i2400m->bus_tx_kick = i2400mu_bus_tx_kick;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	i2400m->bus_reset = i2400mu_bus_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	i2400m->bus_bm_retries = I2400M_USB_BOOT_RETRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	i2400m->bus_bm_cmd_send = i2400mu_bus_bm_cmd_send;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	i2400m->bus_bm_wait_for_ack = i2400mu_bus_bm_wait_for_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	i2400m->bus_bm_mac_addr_impaired = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	switch (id->idProduct) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	case USB_DEVICE_ID_I6050:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	case USB_DEVICE_ID_I6050_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	case USB_DEVICE_ID_I6150:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	case USB_DEVICE_ID_I6150_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	case USB_DEVICE_ID_I6150_3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	case USB_DEVICE_ID_I6250:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		i2400mu->i6050 = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	if (i2400mu->i6050) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		i2400m->bus_fw_names = i2400mu_bus_fw_names_6050;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		i2400mu->endpoint_cfg.bulk_out = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		i2400mu->endpoint_cfg.notification = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		i2400mu->endpoint_cfg.reset_cold = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		i2400mu->endpoint_cfg.bulk_in = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		i2400m->bus_fw_names = i2400mu_bus_fw_names_5x50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		i2400mu->endpoint_cfg.bulk_out = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		i2400mu->endpoint_cfg.notification = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		i2400mu->endpoint_cfg.reset_cold = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		i2400mu->endpoint_cfg.bulk_in = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	iface->needs_remote_wakeup = 1;		/* autosuspend (15s delay) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	device_init_wakeup(dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	pm_runtime_set_autosuspend_delay(&usb_dev->dev, 15000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	usb_enable_autosuspend(usb_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	result = i2400m_setup(i2400m, I2400M_BRI_MAC_REINIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	if (result < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		dev_err(dev, "cannot setup device: %d\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		goto error_setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	i2400mu_debugfs_add(i2400mu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) error_setup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	usb_set_intfdata(iface, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	usb_put_dev(i2400mu->usb_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	free_netdev(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) error_alloc_netdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)  * Disconnect a i2400m from the system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)  * i2400m_stop() has been called before, so al the rx and tx contexts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)  * have been taken down already. Make sure the queue is stopped,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)  * unregister netdev and i2400m, free and kill.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) void i2400mu_disconnect(struct usb_interface *iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	struct i2400mu *i2400mu = usb_get_intfdata(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	struct i2400m *i2400m = &i2400mu->i2400m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	struct net_device *net_dev = i2400m->wimax_dev.net_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	struct device *dev = &iface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	d_fnstart(3, dev, "(iface %p i2400m %p)\n", iface, i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	debugfs_remove_recursive(i2400mu->debugfs_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	i2400m_release(i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	usb_set_intfdata(iface, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	usb_put_dev(i2400mu->usb_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	free_netdev(net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	d_fnend(3, dev, "(iface %p i2400m %p) = void\n", iface, i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)  * Get the device ready for USB port or system standby and hibernation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)  * USB port and system standby are handled the same.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)  * When the system hibernates, the USB device is powered down and then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)  * up, so we don't really have to do much here, as it will be seen as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)  * a reconnect. Still for simplicity we consider this case the same as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)  * suspend, so that the device has a chance to do notify the base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)  * station (if connected).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)  * So at the end, the three cases require common handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)  * If at the time of this call the device's firmware is not loaded,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)  * nothing has to be done. Note we can be "loose" about not reading
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)  * i2400m->updown under i2400m->init_mutex. If it happens to change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)  * inmediately, other parts of the call flow will fail and effectively
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)  * catch it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)  * If the firmware is loaded, we need to:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)  *  - tell the device to go into host interface power save mode, wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)  *    for it to ack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)  *    This is quite more interesting than it is; we need to execute a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)  *    command, but this time, we don't want the code in usb-{tx,rx}.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)  *    to call the usb_autopm_get/put_interface() barriers as it'd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)  *    deadlock, so we need to decrement i2400mu->do_autopm, that acts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)  *    as a poor man's semaphore. Ugly, but it works.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)  *    As well, the device might refuse going to sleep for whichever
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)  *    reason. In this case we just fail. For system suspend/hibernate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)  *    we *can't* fail. We check PMSG_IS_AUTO to see if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)  *    suspend call comes from the USB stack or from the system and act
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)  *    in consequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)  *  - stop the notification endpoint polling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) int i2400mu_suspend(struct usb_interface *iface, pm_message_t pm_msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	struct device *dev = &iface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	struct i2400mu *i2400mu = usb_get_intfdata(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	unsigned is_autosuspend = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	struct i2400m *i2400m = &i2400mu->i2400m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	if (PMSG_IS_AUTO(pm_msg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 		is_autosuspend = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	d_fnstart(3, dev, "(iface %p pm_msg %u)\n", iface, pm_msg.event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	rmb();		/* see i2400m->updown's documentation  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	if (i2400m->updown == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 		goto no_firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	if (i2400m->state == I2400M_SS_DATA_PATH_CONNECTED && is_autosuspend) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 		/* ugh -- the device is connected and this suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 		 * request is an autosuspend one (not a system standby
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 		 * / hibernate).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 		 * The only way the device can go to standby is if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 		 * link with the base station is in IDLE mode; that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		 * were the case, we'd be in status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 		 * I2400M_SS_CONNECTED_IDLE. But we are not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 		 * If we *tell* him to go power save now, it'll reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 		 * as a precautionary measure, so if this is an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 		 * autosuspend thing, say no and it'll come back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 		 * later, when the link is IDLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 		result = -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 		d_printf(1, dev, "fw up, link up, not-idle, autosuspend: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 			 "not entering powersave\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		goto error_not_now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	d_printf(1, dev, "fw up: entering powersave\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	atomic_dec(&i2400mu->do_autopm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	result = i2400m_cmd_enter_powersave(i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	atomic_inc(&i2400mu->do_autopm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	if (result < 0 && !is_autosuspend) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 		/* System suspend, can't fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 		dev_err(dev, "failed to suspend, will reset on resume\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 		result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 		goto error_enter_powersave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	i2400mu_notification_release(i2400mu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	d_printf(1, dev, "powersave requested\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) error_enter_powersave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) error_not_now:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) no_firmware:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	d_fnend(3, dev, "(iface %p pm_msg %u) = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		iface, pm_msg.event, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) int i2400mu_resume(struct usb_interface *iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	struct device *dev = &iface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	struct i2400mu *i2400mu = usb_get_intfdata(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	struct i2400m *i2400m = &i2400mu->i2400m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	d_fnstart(3, dev, "(iface %p)\n", iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	rmb();		/* see i2400m->updown's documentation  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	if (i2400m->updown == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 		d_printf(1, dev, "fw was down, no resume needed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	d_printf(1, dev, "fw was up, resuming\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	i2400mu_notification_setup(i2400mu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	/* USB has flow control, so we don't need to give it time to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	 * come back; otherwise, we'd use something like a get-state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	 * command... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	d_fnend(3, dev, "(iface %p) = %d\n", iface, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^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) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) int i2400mu_reset_resume(struct usb_interface *iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	struct device *dev = &iface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	struct i2400mu *i2400mu = usb_get_intfdata(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	struct i2400m *i2400m = &i2400mu->i2400m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	d_fnstart(3, dev, "(iface %p)\n", iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	result = i2400m_dev_reset_handle(i2400m, "device reset on resume");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	d_fnend(3, dev, "(iface %p) = %d\n", iface, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	return result < 0 ? result : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)  * Another driver or user space is triggering a reset on the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)  * which contains the interface passed as an argument. Cease IO and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)  * save any device state you need to restore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)  * If you need to allocate memory here, use GFP_NOIO or GFP_ATOMIC, if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)  * you are in atomic context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) int i2400mu_pre_reset(struct usb_interface *iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	struct i2400mu *i2400mu = usb_get_intfdata(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	return i2400m_pre_reset(&i2400mu->i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)  * The reset has completed.  Restore any saved device state and begin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)  * using the device again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)  * If you need to allocate memory here, use GFP_NOIO or GFP_ATOMIC, if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)  * you are in atomic context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) int i2400mu_post_reset(struct usb_interface *iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	struct i2400mu *i2400mu = usb_get_intfdata(iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	return i2400m_post_reset(&i2400mu->i2400m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) struct usb_device_id i2400mu_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	{ USB_DEVICE(0x8086, USB_DEVICE_ID_I6050) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	{ USB_DEVICE(0x8086, USB_DEVICE_ID_I6050_2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	{ USB_DEVICE(0x8087, USB_DEVICE_ID_I6150) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	{ USB_DEVICE(0x8087, USB_DEVICE_ID_I6150_2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	{ USB_DEVICE(0x8087, USB_DEVICE_ID_I6150_3) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	{ USB_DEVICE(0x8086, USB_DEVICE_ID_I6250) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 	{ USB_DEVICE(0x8086, 0x0181) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	{ USB_DEVICE(0x8086, 0x1403) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	{ USB_DEVICE(0x8086, 0x1405) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	{ USB_DEVICE(0x8086, 0x0180) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	{ USB_DEVICE(0x8086, 0x0182) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	{ USB_DEVICE(0x8086, 0x1406) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	{ USB_DEVICE(0x8086, 0x1403) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) MODULE_DEVICE_TABLE(usb, i2400mu_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) struct usb_driver i2400mu_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	.name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	.suspend = i2400mu_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	.resume = i2400mu_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	.reset_resume = i2400mu_reset_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 	.probe = i2400mu_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	.disconnect = i2400mu_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 	.pre_reset = i2400mu_pre_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	.post_reset = i2400mu_post_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	.id_table = i2400mu_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	.supports_autosuspend = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) int __init i2400mu_driver_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400mu_debug_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 		       "i2400m_usb.debug");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	return usb_register(&i2400mu_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) module_init(i2400mu_driver_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) void __exit i2400mu_driver_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	usb_deregister(&i2400mu_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) module_exit(i2400mu_driver_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) MODULE_DESCRIPTION("Driver for USB based Intel Wireless WiMAX Connection 2400M "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 		   "(5x50 & 6050)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) MODULE_FIRMWARE(I2400MU_FW_FILE_NAME_v1_5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) MODULE_FIRMWARE(I6050U_FW_FILE_NAME_v1_5);