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)  *  speedtch.c  -  Alcatel SpeedTouch USB xDSL modem driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2001, Alcatel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 2003, Duncan Sands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Copyright (C) 2004, David Woodhouse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  Based on "modem_run.c", copyright (C) 2001, Benoit Papillault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/usb/ch9.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include "usbatm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define DRIVER_AUTHOR	"Johan Verrept, Duncan Sands <duncan.sands@free.fr>"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define DRIVER_DESC	"Alcatel SpeedTouch USB driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static const char speedtch_driver_name[] = "speedtch";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define CTRL_TIMEOUT 2000	/* milliseconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define DATA_TIMEOUT 2000	/* milliseconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define OFFSET_7	0		/* size 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define OFFSET_b	1		/* size 8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define OFFSET_d	9		/* size 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define OFFSET_e	13		/* size 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define OFFSET_f	14		/* size 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define SIZE_7		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define SIZE_b		8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define SIZE_d		4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define SIZE_e		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define SIZE_f		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define MIN_POLL_DELAY		5000	/* milliseconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define MAX_POLL_DELAY		60000	/* milliseconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define RESUBMIT_DELAY		1000	/* milliseconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define DEFAULT_BULK_ALTSETTING	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define DEFAULT_ISOC_ALTSETTING	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define DEFAULT_DL_512_FIRST	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define DEFAULT_ENABLE_ISOC	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define DEFAULT_SW_BUFFERING	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static unsigned int altsetting = 0; /* zero means: use the default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static bool dl_512_first = DEFAULT_DL_512_FIRST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static bool enable_isoc = DEFAULT_ENABLE_ISOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static bool sw_buffering = DEFAULT_SW_BUFFERING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define DEFAULT_B_MAX_DSL	8128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #define DEFAULT_MODEM_MODE	11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #define MODEM_OPTION_LENGTH	16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static const unsigned char DEFAULT_MODEM_OPTION[MODEM_OPTION_LENGTH] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static unsigned int BMaxDSL = DEFAULT_B_MAX_DSL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static unsigned char ModemMode = DEFAULT_MODEM_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static unsigned char ModemOption[MODEM_OPTION_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static unsigned int num_ModemOption;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) module_param(altsetting, uint, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) MODULE_PARM_DESC(altsetting,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		"Alternative setting for data interface (bulk_default: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		__MODULE_STRING(DEFAULT_BULK_ALTSETTING) "; isoc_default: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		__MODULE_STRING(DEFAULT_ISOC_ALTSETTING) ")");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) module_param(dl_512_first, bool, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) MODULE_PARM_DESC(dl_512_first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		 "Read 512 bytes before sending firmware (default: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		 __MODULE_STRING(DEFAULT_DL_512_FIRST) ")");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) module_param(enable_isoc, bool, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) MODULE_PARM_DESC(enable_isoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		"Use isochronous transfers if available (default: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		__MODULE_STRING(DEFAULT_ENABLE_ISOC) ")");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) module_param(sw_buffering, bool, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) MODULE_PARM_DESC(sw_buffering,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		 "Enable software buffering (default: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		 __MODULE_STRING(DEFAULT_SW_BUFFERING) ")");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) module_param(BMaxDSL, uint, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) MODULE_PARM_DESC(BMaxDSL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		"default: " __MODULE_STRING(DEFAULT_B_MAX_DSL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) module_param(ModemMode, byte, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) MODULE_PARM_DESC(ModemMode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		"default: " __MODULE_STRING(DEFAULT_MODEM_MODE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) module_param_array(ModemOption, byte, &num_ModemOption, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) MODULE_PARM_DESC(ModemOption, "default: 0x10,0x00,0x00,0x00,0x20");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define INTERFACE_DATA		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define ENDPOINT_INT		0x81
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define ENDPOINT_BULK_DATA	0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define ENDPOINT_ISOC_DATA	0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define ENDPOINT_FIRMWARE	0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct speedtch_params {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	unsigned int altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	unsigned int BMaxDSL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	unsigned char ModemMode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	unsigned char ModemOption[MODEM_OPTION_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct speedtch_instance_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct usbatm_data *usbatm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct speedtch_params params; /* set in probe, constant afterwards */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct timer_list status_check_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct work_struct status_check_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	unsigned char last_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	int poll_delay; /* milliseconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct timer_list resubmit_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct urb *int_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	unsigned char int_data[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	unsigned char scratch_buffer[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /***************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) **  firmware  **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) ***************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static void speedtch_set_swbuff(struct speedtch_instance_data *instance, int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct usbatm_data *usbatm = instance->usbatm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct usb_device *usb_dev = usbatm->usb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			      0x32, 0x40, state ? 0x01 : 0x00, 0x00, NULL, 0, CTRL_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		usb_warn(usbatm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			 "%sabling SW buffering: usb_control_msg returned %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			 state ? "En" : "Dis", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		usb_dbg(usbatm, "speedtch_set_swbuff: %sbled SW buffering\n", state ? "En" : "Dis");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static void speedtch_test_sequence(struct speedtch_instance_data *instance)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct usbatm_data *usbatm = instance->usbatm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct usb_device *usb_dev = usbatm->usb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	unsigned char *buf = instance->scratch_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	/* URB 147 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	buf[0] = 0x1c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	buf[1] = 0x50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			      0x01, 0x40, 0x0b, 0x00, buf, 2, CTRL_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		usb_warn(usbatm, "%s failed on URB147: %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	/* URB 148 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	buf[0] = 0x32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	buf[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			      0x01, 0x40, 0x02, 0x00, buf, 2, CTRL_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		usb_warn(usbatm, "%s failed on URB148: %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	/* URB 149 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	buf[0] = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	buf[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	buf[2] = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			      0x01, 0x40, 0x03, 0x00, buf, 3, CTRL_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		usb_warn(usbatm, "%s failed on URB149: %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	/* URB 150 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	buf[0] = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	buf[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	buf[2] = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			      0x01, 0x40, 0x04, 0x00, buf, 3, CTRL_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		usb_warn(usbatm, "%s failed on URB150: %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	/* Extra initialisation in recent drivers - gives higher speeds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	/* URBext1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	buf[0] = instance->params.ModemMode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			      0x01, 0x40, 0x11, 0x00, buf, 1, CTRL_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		usb_warn(usbatm, "%s failed on URBext1: %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	/* URBext2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	/* This seems to be the one which actually triggers the higher sync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	   rate -- it does require the new firmware too, although it works OK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	   with older firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			      0x01, 0x40, 0x14, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			      instance->params.ModemOption,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			      MODEM_OPTION_LENGTH, CTRL_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		usb_warn(usbatm, "%s failed on URBext2: %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	/* URBext3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	buf[0] = instance->params.BMaxDSL & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	buf[1] = instance->params.BMaxDSL >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			      0x01, 0x40, 0x12, 0x00, buf, 2, CTRL_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		usb_warn(usbatm, "%s failed on URBext3: %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static int speedtch_upload_firmware(struct speedtch_instance_data *instance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 				     const struct firmware *fw1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 				     const struct firmware *fw2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	unsigned char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct usbatm_data *usbatm = instance->usbatm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	struct usb_device *usb_dev = usbatm->usb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	int actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	usb_dbg(usbatm, "%s entered\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	buffer = (unsigned char *)__get_free_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	if (!buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		usb_dbg(usbatm, "%s: no memory for buffer!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	if (!usb_ifnum_to_if(usb_dev, 2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		usb_dbg(usbatm, "%s: interface not found!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	/* URB 7 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	if (dl_512_first) {	/* some modems need a read before writing the firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 				   buffer, 0x200, &actual_length, 2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		if (ret < 0 && ret != -ETIMEDOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			usb_warn(usbatm, "%s: read BLOCK0 from modem failed (%d)!\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			usb_dbg(usbatm, "%s: BLOCK0 downloaded (%d bytes)\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	/* URB 8 : both leds are static green */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	for (offset = 0; offset < fw1->size; offset += PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		int thislen = min_t(int, PAGE_SIZE, fw1->size - offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		memcpy(buffer, fw1->data + offset, thislen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 				   buffer, thislen, &actual_length, DATA_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			usb_err(usbatm, "%s: write BLOCK1 to modem failed (%d)!\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		usb_dbg(usbatm, "%s: BLOCK1 uploaded (%zu bytes)\n", __func__, fw1->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	/* USB led blinking green, ADSL led off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	/* URB 11 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			   buffer, 0x200, &actual_length, DATA_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		usb_err(usbatm, "%s: read BLOCK2 from modem failed (%d)!\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	usb_dbg(usbatm, "%s: BLOCK2 downloaded (%d bytes)\n", __func__, actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	/* URBs 12 to 139 - USB led blinking green, ADSL led off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	for (offset = 0; offset < fw2->size; offset += PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		int thislen = min_t(int, PAGE_SIZE, fw2->size - offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		memcpy(buffer, fw2->data + offset, thislen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 				   buffer, thislen, &actual_length, DATA_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			usb_err(usbatm, "%s: write BLOCK3 to modem failed (%d)!\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	usb_dbg(usbatm, "%s: BLOCK3 uploaded (%zu bytes)\n", __func__, fw2->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	/* USB led static green, ADSL led static red */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	/* URB 142 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			   buffer, 0x200, &actual_length, DATA_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		usb_err(usbatm, "%s: read BLOCK4 from modem failed (%d)!\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	/* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	usb_dbg(usbatm, "%s: BLOCK4 downloaded (%d bytes)\n", __func__, actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	/* Delay to allow firmware to start up. We can do this here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	   because we're in our own kernel thread anyway. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	msleep_interruptible(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, instance->params.altsetting)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		usb_err(usbatm, "%s: setting interface to %d failed (%d)!\n", __func__, instance->params.altsetting, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		goto out_free;
^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) 	/* Enable software buffering, if requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	if (sw_buffering)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		speedtch_set_swbuff(instance, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	/* Magic spell; don't ask us what this does */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	speedtch_test_sequence(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	free_page((unsigned long)buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static int speedtch_find_firmware(struct usbatm_data *usbatm, struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 				  int phase, const struct firmware **fw_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	struct device *dev = &intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	const u16 bcdDevice = le16_to_cpu(interface_to_usbdev(intf)->descriptor.bcdDevice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	const u8 major_revision = bcdDevice >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	const u8 minor_revision = bcdDevice & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	char buf[24];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	sprintf(buf, "speedtch-%d.bin.%x.%02x", phase, major_revision, minor_revision);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	if (request_firmware(fw_p, buf, dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		sprintf(buf, "speedtch-%d.bin.%x", phase, major_revision);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		if (request_firmware(fw_p, buf, dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			sprintf(buf, "speedtch-%d.bin", phase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			if (request_firmware(fw_p, buf, dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 				usb_err(usbatm, "%s: no stage %d firmware found!\n", __func__, phase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 				return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	usb_info(usbatm, "found stage %d firmware %s\n", phase, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static int speedtch_heavy_init(struct usbatm_data *usbatm, struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	const struct firmware *fw1, *fw2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	struct speedtch_instance_data *instance = usbatm->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	if ((ret = speedtch_find_firmware(usbatm, intf, 1, &fw1)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	if ((ret = speedtch_find_firmware(usbatm, intf, 2, &fw2)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		release_firmware(fw1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	if ((ret = speedtch_upload_firmware(instance, fw1, fw2)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		usb_err(usbatm, "%s: firmware upload failed (%d)!\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	release_firmware(fw2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	release_firmware(fw1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) /**********
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) **  ATM  **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) **********/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static int speedtch_read_status(struct speedtch_instance_data *instance)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	struct usbatm_data *usbatm = instance->usbatm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	struct usb_device *usb_dev = usbatm->usb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	unsigned char *buf = instance->scratch_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	memset(buf, 0, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			      0x12, 0xc0, 0x07, 0x00, buf + OFFSET_7, SIZE_7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 			      CTRL_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		atm_dbg(usbatm, "%s: MSG 7 failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			      0x12, 0xc0, 0x0b, 0x00, buf + OFFSET_b, SIZE_b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			      CTRL_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		atm_dbg(usbatm, "%s: MSG B failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 			      0x12, 0xc0, 0x0d, 0x00, buf + OFFSET_d, SIZE_d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			      CTRL_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		atm_dbg(usbatm, "%s: MSG D failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 			      0x01, 0xc0, 0x0e, 0x00, buf + OFFSET_e, SIZE_e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 			      CTRL_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		atm_dbg(usbatm, "%s: MSG E failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 			      0x01, 0xc0, 0x0f, 0x00, buf + OFFSET_f, SIZE_f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 			      CTRL_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		atm_dbg(usbatm, "%s: MSG F failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) static int speedtch_start_synchro(struct speedtch_instance_data *instance)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	struct usbatm_data *usbatm = instance->usbatm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	struct usb_device *usb_dev = usbatm->usb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	unsigned char *buf = instance->scratch_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	atm_dbg(usbatm, "%s entered\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	memset(buf, 0, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 			      0x12, 0xc0, 0x04, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 			      buf, 2, CTRL_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		atm_warn(usbatm, "failed to start ADSL synchronisation: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		atm_dbg(usbatm, "%s: modem prodded. %d bytes returned: %02x %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 			__func__, ret, buf[0], buf[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static void speedtch_check_status(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	struct speedtch_instance_data *instance =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		container_of(work, struct speedtch_instance_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 			     status_check_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	struct usbatm_data *usbatm = instance->usbatm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	struct atm_dev *atm_dev = usbatm->atm_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	unsigned char *buf = instance->scratch_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	int down_speed, up_speed, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	unsigned char status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) #ifdef VERBOSE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	atm_dbg(usbatm, "%s entered\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	ret = speedtch_read_status(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		atm_warn(usbatm, "error %d fetching device status\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		instance->poll_delay = min(2 * instance->poll_delay, MAX_POLL_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	instance->poll_delay = max(instance->poll_delay / 2, MIN_POLL_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	status = buf[OFFSET_7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	if ((status != instance->last_status) || !status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		atm_dbg(usbatm, "%s: line state 0x%02x\n", __func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 			atm_dev_signal_change(atm_dev, ATM_PHY_SIG_LOST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 			if (instance->last_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 				atm_info(usbatm, "ADSL line is down\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 			/* It may never resync again unless we ask it to... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 			ret = speedtch_start_synchro(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		case 0x08:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 			atm_dev_signal_change(atm_dev, ATM_PHY_SIG_UNKNOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 			atm_info(usbatm, "ADSL line is blocked?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		case 0x10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 			atm_dev_signal_change(atm_dev, ATM_PHY_SIG_LOST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 			atm_info(usbatm, "ADSL line is synchronising\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		case 0x20:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 			down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 				| (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 			up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 				| (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 			if (!(down_speed & 0x0000ffff) && !(up_speed & 0x0000ffff)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 				down_speed >>= 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 				up_speed >>= 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 			atm_dev->link_rate = down_speed * 1000 / 424;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 			atm_dev_signal_change(atm_dev, ATM_PHY_SIG_FOUND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 			atm_info(usbatm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 				 "ADSL line is up (%d kb/s down | %d kb/s up)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 				 down_speed, up_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 			atm_dev_signal_change(atm_dev, ATM_PHY_SIG_UNKNOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 			atm_info(usbatm, "unknown line state %02x\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 		instance->last_status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) static void speedtch_status_poll(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	struct speedtch_instance_data *instance = from_timer(instance, t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 						             status_check_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	schedule_work(&instance->status_check_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	/* The following check is racy, but the race is harmless */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	if (instance->poll_delay < MAX_POLL_DELAY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		mod_timer(&instance->status_check_timer, jiffies + msecs_to_jiffies(instance->poll_delay));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		atm_warn(instance->usbatm, "Too many failures - disabling line status polling\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) static void speedtch_resubmit_int(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	struct speedtch_instance_data *instance = from_timer(instance, t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 							     resubmit_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	struct urb *int_urb = instance->int_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	atm_dbg(instance->usbatm, "%s entered\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	if (int_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		ret = usb_submit_urb(int_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 			schedule_work(&instance->status_check_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 			atm_dbg(instance->usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 			mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) static void speedtch_handle_int(struct urb *int_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	struct speedtch_instance_data *instance = int_urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	struct usbatm_data *usbatm = instance->usbatm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	unsigned int count = int_urb->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	int status = int_urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	/* The magic interrupt for "up state" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	static const unsigned char up_int[6]   = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	/* The magic interrupt for "down state" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	static const unsigned char down_int[6] = { 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	atm_dbg(usbatm, "%s entered\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 		atm_dbg(usbatm, "%s: nonzero urb status %d!\n", __func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	if ((count == 6) && !memcmp(up_int, instance->int_data, 6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 		del_timer(&instance->status_check_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 		atm_info(usbatm, "DSL line goes up\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	} else if ((count == 6) && !memcmp(down_int, instance->int_data, 6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 		atm_info(usbatm, "DSL line goes down\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 		atm_dbg(usbatm, "%s: unknown interrupt packet of length %d:", __func__, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 		for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 			printk(" %02x", instance->int_data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 		printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	int_urb = instance->int_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	if (int_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		ret = usb_submit_urb(int_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		schedule_work(&instance->status_check_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 			atm_dbg(usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	int_urb = instance->int_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	if (int_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 		mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) static int speedtch_atm_start(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	struct usb_device *usb_dev = usbatm->usb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	struct speedtch_instance_data *instance = usbatm->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	unsigned char mac_str[13];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	atm_dbg(usbatm, "%s entered\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	/* Set MAC address, it is stored in the serial number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	memset(atm_dev->esi, 0, sizeof(atm_dev->esi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	if (usb_string(usb_dev, usb_dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 		for (i = 0; i < 6; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 			atm_dev->esi[i] = (hex_to_bin(mac_str[i * 2]) << 4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 				hex_to_bin(mac_str[i * 2 + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	/* Start modem synchronisation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	ret = speedtch_start_synchro(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	/* Set up interrupt endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	if (instance->int_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 		ret = usb_submit_urb(instance->int_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 			/* Doesn't matter; we'll poll anyway */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 			atm_dbg(usbatm, "%s: submission of interrupt URB failed (%d)!\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 			usb_free_urb(instance->int_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 			instance->int_urb = NULL;
^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) 	/* Start status polling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	mod_timer(&instance->status_check_timer, jiffies + msecs_to_jiffies(1000));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) static void speedtch_atm_stop(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	struct speedtch_instance_data *instance = usbatm->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	struct urb *int_urb = instance->int_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	atm_dbg(usbatm, "%s entered\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	del_timer_sync(&instance->status_check_timer);
^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) 	 * Since resubmit_timer and int_urb can schedule themselves and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	 * each other, shutting them down correctly takes some care
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	instance->int_urb = NULL; /* signal shutdown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	usb_kill_urb(int_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	del_timer_sync(&instance->resubmit_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	 * At this point, speedtch_handle_int and speedtch_resubmit_int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	 * can run or be running, but instance->int_urb == NULL means that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	 * they will not reschedule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	usb_kill_urb(int_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	del_timer_sync(&instance->resubmit_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	usb_free_urb(int_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	flush_work(&instance->status_check_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) static int speedtch_pre_reset(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) static int speedtch_post_reset(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) /**********
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) **  USB  **
^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 const struct usb_device_id speedtch_usb_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	{USB_DEVICE(0x06b9, 0x4061)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) MODULE_DEVICE_TABLE(usb, speedtch_usb_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) static int speedtch_usb_probe(struct usb_interface *, const struct usb_device_id *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) static struct usb_driver speedtch_usb_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	.name		= speedtch_driver_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	.probe		= speedtch_usb_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 	.disconnect	= usbatm_usb_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 	.pre_reset	= speedtch_pre_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	.post_reset	= speedtch_post_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	.id_table	= speedtch_usb_ids
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) static void speedtch_release_interfaces(struct usb_device *usb_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 					int num_interfaces)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	struct usb_interface *cur_intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	for (i = 0; i < num_interfaces; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 		cur_intf = usb_ifnum_to_if(usb_dev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 		if (cur_intf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 			usb_set_intfdata(cur_intf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 			usb_driver_release_interface(&speedtch_usb_driver, cur_intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) static int speedtch_bind(struct usbatm_data *usbatm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 			 struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 			 const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 	struct usb_device *usb_dev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 	struct usb_interface *cur_intf, *data_intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 	struct speedtch_instance_data *instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	int ifnum = intf->altsetting->desc.bInterfaceNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 	int num_interfaces = usb_dev->actconfig->desc.bNumInterfaces;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 	int use_isoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 	usb_dbg(usbatm, "%s entered\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	/* sanity checks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	if (usb_dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 		usb_err(usbatm, "%s: wrong device class %d\n", __func__, usb_dev->descriptor.bDeviceClass);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 	data_intf = usb_ifnum_to_if(usb_dev, INTERFACE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 	if (!data_intf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 		usb_err(usbatm, "%s: data interface not found!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 	/* claim all interfaces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	for (i = 0; i < num_interfaces; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 		cur_intf = usb_ifnum_to_if(usb_dev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 		if ((i != ifnum) && cur_intf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 			ret = usb_driver_claim_interface(&speedtch_usb_driver, cur_intf, usbatm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 			if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 				usb_err(usbatm, "%s: failed to claim interface %2d (%d)!\n", __func__, i, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 				speedtch_release_interfaces(usb_dev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 	instance = kzalloc(sizeof(*instance), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 	if (!instance) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 		goto fail_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 	instance->usbatm = usbatm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 	/* module parameters may change at any moment, so take a snapshot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 	instance->params.altsetting = altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 	instance->params.BMaxDSL = BMaxDSL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 	instance->params.ModemMode = ModemMode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	memcpy(instance->params.ModemOption, DEFAULT_MODEM_OPTION, MODEM_OPTION_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 	memcpy(instance->params.ModemOption, ModemOption, num_ModemOption);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 	use_isoc = enable_isoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 	if (instance->params.altsetting)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 		if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, instance->params.altsetting)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 			usb_err(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, instance->params.altsetting, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 			instance->params.altsetting = 0; /* fall back to default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 	if (!instance->params.altsetting && use_isoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 		if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, DEFAULT_ISOC_ALTSETTING)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 			usb_dbg(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, DEFAULT_ISOC_ALTSETTING, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 			use_isoc = 0; /* fall back to bulk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	if (use_isoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 		const struct usb_host_interface *desc = data_intf->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 		const __u8 target_address = USB_DIR_IN | usbatm->driver->isoc_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 		use_isoc = 0; /* fall back to bulk if endpoint not found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 		for (i = 0; i < desc->desc.bNumEndpoints; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 			const struct usb_endpoint_descriptor *endpoint_desc = &desc->endpoint[i].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 			if ((endpoint_desc->bEndpointAddress == target_address)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 				use_isoc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 					usb_endpoint_xfer_isoc(endpoint_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 		if (!use_isoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 			usb_info(usbatm, "isochronous transfer not supported - using bulk\n");
^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) 	if (!use_isoc && !instance->params.altsetting)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 		if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, DEFAULT_BULK_ALTSETTING)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 			usb_err(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, DEFAULT_BULK_ALTSETTING, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 			goto fail_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 	if (!instance->params.altsetting)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 		instance->params.altsetting = use_isoc ? DEFAULT_ISOC_ALTSETTING : DEFAULT_BULK_ALTSETTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 	usbatm->flags |= (use_isoc ? UDSL_USE_ISOC : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 	INIT_WORK(&instance->status_check_work, speedtch_check_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 	timer_setup(&instance->status_check_timer, speedtch_status_poll, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 	instance->last_status = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 	instance->poll_delay = MIN_POLL_DELAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 	timer_setup(&instance->resubmit_timer, speedtch_resubmit_int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 	instance->int_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 	if (instance->int_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 		usb_fill_int_urb(instance->int_urb, usb_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) 				 usb_rcvintpipe(usb_dev, ENDPOINT_INT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) 				 instance->int_data, sizeof(instance->int_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 				 speedtch_handle_int, instance, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 		usb_dbg(usbatm, "%s: no memory for interrupt urb!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 	/* check whether the modem already seems to be alive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 	ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 			      0x12, 0xc0, 0x07, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 			      instance->scratch_buffer + OFFSET_7, SIZE_7, 500);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 	usbatm->flags |= (ret == SIZE_7 ? UDSL_SKIP_HEAVY_INIT : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 	usb_dbg(usbatm, "%s: firmware %s loaded\n", __func__, usbatm->flags & UDSL_SKIP_HEAVY_INIT ? "already" : "not");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) 	if (!(usbatm->flags & UDSL_SKIP_HEAVY_INIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 		if ((ret = usb_reset_device(usb_dev)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 			usb_err(usbatm, "%s: device reset failed (%d)!\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) 			goto fail_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)         usbatm->driver_data = instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) fail_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) 	usb_free_urb(instance->int_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) 	kfree(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) fail_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) 	speedtch_release_interfaces(usb_dev, num_interfaces);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) static void speedtch_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) 	struct usb_device *usb_dev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) 	struct speedtch_instance_data *instance = usbatm->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) 	usb_dbg(usbatm, "%s entered\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) 	speedtch_release_interfaces(usb_dev, usb_dev->actconfig->desc.bNumInterfaces);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) 	usb_free_urb(instance->int_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) 	kfree(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) /***********
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) **  init  **
^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 struct usbatm_driver speedtch_usbatm_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) 	.driver_name	= speedtch_driver_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) 	.bind		= speedtch_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) 	.heavy_init	= speedtch_heavy_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) 	.unbind		= speedtch_unbind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) 	.atm_start	= speedtch_atm_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) 	.atm_stop	= speedtch_atm_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) 	.bulk_in	= ENDPOINT_BULK_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) 	.bulk_out	= ENDPOINT_BULK_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) 	.isoc_in	= ENDPOINT_ISOC_DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) static int speedtch_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) 	return usbatm_usb_probe(intf, id, &speedtch_usbatm_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) module_usb_driver(speedtch_usb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) MODULE_AUTHOR(DRIVER_AUTHOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) MODULE_LICENSE("GPL");