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)  *  cxacru.c  -  driver for USB ADSL modems based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *               Conexant AccessRunner chipset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *  Copyright (C) 2004 David Woodhouse, Duncan Sands, Roman Kagan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *  Copyright (C) 2005 Duncan Sands, Roman Kagan (rkagan % mail ! ru)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *  Copyright (C) 2007 Simon Arlott
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *  Copyright (C) 2009 Simon Arlott
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *  Credit is due for Josep Comas, who created the original patch to speedtch.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *  to support the different padding used by the AccessRunner (now generalized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *  into usbatm), and the userspace firmware loading utility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/kernel.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/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include "usbatm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #define DRIVER_AUTHOR	"Roman Kagan, David Woodhouse, Duncan Sands, Simon Arlott"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #define DRIVER_DESC	"Conexant AccessRunner ADSL USB modem driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) static const char cxacru_driver_name[] = "cxacru";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #define CXACRU_EP_CMD		0x01	/* Bulk/interrupt in/out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #define CXACRU_EP_DATA		0x02	/* Bulk in/out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #define CMD_PACKET_SIZE		64	/* Should be maxpacket(ep)? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #define CMD_MAX_CONFIG		((CMD_PACKET_SIZE / 4 - 1) / 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) /* Addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #define PLLFCLK_ADDR	0x00350068
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #define PLLBCLK_ADDR	0x0035006c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #define SDRAMEN_ADDR	0x00350010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #define FW_ADDR		0x00801000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #define BR_ADDR		0x00180600
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #define SIG_ADDR	0x00180500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #define BR_STACK_ADDR	0x00187f10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) /* Values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #define SDRAM_ENA	0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #define CMD_TIMEOUT	2000	/* msecs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #define POLL_INTERVAL	1	/* secs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) /* commands for interaction with the modem through the control channel before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58)  * firmware is loaded  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) enum cxacru_fw_request {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	FW_CMD_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	FW_GET_VER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	FW_READ_MEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	FW_WRITE_MEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	FW_RMW_MEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 	FW_CHECKSUM_MEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	FW_GOTO_MEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) /* commands for interaction with the modem through the control channel once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70)  * firmware is loaded  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) enum cxacru_cm_request {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	CM_REQUEST_UNDEFINED = 0x80,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	CM_REQUEST_TEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	CM_REQUEST_CHIP_GET_MAC_ADDRESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	CM_REQUEST_CHIP_GET_DP_VERSIONS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	CM_REQUEST_CHIP_ADSL_LINE_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	CM_REQUEST_CHIP_ADSL_LINE_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	CM_REQUEST_CHIP_ADSL_LINE_GET_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	CM_REQUEST_CHIP_ADSL_LINE_GET_SPEED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	CM_REQUEST_CARD_INFO_GET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	CM_REQUEST_CARD_DATA_GET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	CM_REQUEST_CARD_DATA_SET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	CM_REQUEST_COMMAND_HW_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	CM_REQUEST_INTERFACE_HW_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	CM_REQUEST_CARD_SERIAL_DATA_PATH_GET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	CM_REQUEST_CARD_SERIAL_DATA_PATH_SET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	CM_REQUEST_CARD_CONTROLLER_VERSION_GET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	CM_REQUEST_CARD_GET_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	CM_REQUEST_CARD_GET_MAC_ADDRESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	CM_REQUEST_CARD_GET_DATA_LINK_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	CM_REQUEST_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) /* commands for interaction with the flash memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96)  * read:  response is the contents of the first 60 bytes of flash memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97)  * write: request contains the 60 bytes of data to write to flash memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98)  *        response is the contents of the first 60 bytes of flash memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100)  * layout: PP PP VV VV  MM MM MM MM  MM MM ?? ??  SS SS SS SS  SS SS SS SS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101)  *         SS SS SS SS  SS SS SS SS  00 00 00 00  00 00 00 00  00 00 00 00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102)  *         00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)  *   P: le16  USB Product ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105)  *   V: le16  USB Vendor ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106)  *   M: be48  MAC Address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)  *   S: le16  ASCII Serial Number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) enum cxacru_cm_flash {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	CM_FLASH_READ = 0xa1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	CM_FLASH_WRITE = 0xa2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) /* reply codes to the commands above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) enum cxacru_cm_status {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	CM_STATUS_UNDEFINED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	CM_STATUS_SUCCESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	CM_STATUS_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	CM_STATUS_UNSUPPORTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	CM_STATUS_UNIMPLEMENTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	CM_STATUS_PARAMETER_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	CM_STATUS_DBG_LOOPBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	CM_STATUS_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) /* indices into CARD_INFO_GET return array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) enum cxacru_info_idx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	CXINF_DOWNSTREAM_RATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	CXINF_UPSTREAM_RATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	CXINF_LINK_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	CXINF_LINE_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	CXINF_MAC_ADDRESS_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	CXINF_MAC_ADDRESS_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	CXINF_UPSTREAM_SNR_MARGIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	CXINF_DOWNSTREAM_SNR_MARGIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	CXINF_UPSTREAM_ATTENUATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	CXINF_DOWNSTREAM_ATTENUATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	CXINF_TRANSMITTER_POWER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	CXINF_UPSTREAM_BITS_PER_FRAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	CXINF_DOWNSTREAM_BITS_PER_FRAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	CXINF_STARTUP_ATTEMPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	CXINF_UPSTREAM_CRC_ERRORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	CXINF_DOWNSTREAM_CRC_ERRORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	CXINF_UPSTREAM_FEC_ERRORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	CXINF_DOWNSTREAM_FEC_ERRORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	CXINF_UPSTREAM_HEC_ERRORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	CXINF_DOWNSTREAM_HEC_ERRORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	CXINF_LINE_STARTABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	CXINF_MODULATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	CXINF_ADSL_HEADEND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	CXINF_ADSL_HEADEND_ENVIRONMENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	CXINF_CONTROLLER_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	/* dunno what the missing two mean */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	CXINF_MAX = 0x1c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) enum cxacru_poll_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	CXPOLL_STOPPING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	CXPOLL_STOPPED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	CXPOLL_POLLING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	CXPOLL_SHUTDOWN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) struct cxacru_modem_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	u32 pll_f_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	u32 pll_b_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	int boot_rom_patch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) struct cxacru_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	struct usbatm_data *usbatm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	const struct cxacru_modem_type *modem_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	int line_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	struct mutex adsl_state_serialize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	int adsl_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	struct delayed_work poll_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	u32 card_info[CXINF_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	struct mutex poll_state_serialize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	enum cxacru_poll_state poll_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	/* contol handles */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	struct mutex cm_serialize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	u8 *rcv_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	u8 *snd_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	struct urb *rcv_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	struct urb *snd_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	struct completion rcv_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	struct completion snd_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	u8 *wdata, int wsize, u8 *rdata, int rsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) static void cxacru_poll_status(struct work_struct *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) /* Card info exported through sysfs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) #define CXACRU__ATTR_INIT(_name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) static DEVICE_ATTR_RO(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) #define CXACRU_CMD_INIT(_name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) static DEVICE_ATTR_RW(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) #define CXACRU_SET_INIT(_name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) static DEVICE_ATTR_WO(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) #define CXACRU_ATTR_INIT(_value, _type, _name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) static ssize_t _name##_show(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	struct device_attribute *attr, char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	struct cxacru_data *instance = to_usbatm_driver_data(\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 		to_usb_interface(dev)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	if (instance == NULL) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 		return -ENODEV; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	return cxacru_sysfs_showattr_##_type(instance->card_info[_value], buf); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) CXACRU__ATTR_INIT(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) #define CXACRU_ATTR_CREATE(_v, _t, _name) CXACRU_DEVICE_CREATE_FILE(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) #define CXACRU_CMD_CREATE(_name)          CXACRU_DEVICE_CREATE_FILE(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) #define CXACRU_SET_CREATE(_name)          CXACRU_DEVICE_CREATE_FILE(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) #define CXACRU__ATTR_CREATE(_name)        CXACRU_DEVICE_CREATE_FILE(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) #define CXACRU_ATTR_REMOVE(_v, _t, _name) CXACRU_DEVICE_REMOVE_FILE(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) #define CXACRU_CMD_REMOVE(_name)          CXACRU_DEVICE_REMOVE_FILE(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) #define CXACRU_SET_REMOVE(_name)          CXACRU_DEVICE_REMOVE_FILE(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) #define CXACRU__ATTR_REMOVE(_name)        CXACRU_DEVICE_REMOVE_FILE(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) static ssize_t cxacru_sysfs_showattr_u32(u32 value, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	return sprintf(buf, "%u\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) static ssize_t cxacru_sysfs_showattr_s8(s8 value, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	return sprintf(buf, "%d\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) static ssize_t cxacru_sysfs_showattr_dB(s16 value, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	if (likely(value >= 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 		return snprintf(buf, PAGE_SIZE, "%u.%02u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 					value / 100, value % 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 		value = -value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		return snprintf(buf, PAGE_SIZE, "-%u.%02u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 					value / 100, value % 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) static ssize_t cxacru_sysfs_showattr_bool(u32 value, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	static char *str[] = { "no", "yes" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	if (unlikely(value >= ARRAY_SIZE(str)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 		return sprintf(buf, "%u\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	return sprintf(buf, "%s\n", str[value]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) static ssize_t cxacru_sysfs_showattr_LINK(u32 value, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	static char *str[] = { NULL, "not connected", "connected", "lost" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	if (unlikely(value >= ARRAY_SIZE(str) || str[value] == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 		return sprintf(buf, "%u\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	return sprintf(buf, "%s\n", str[value]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) static ssize_t cxacru_sysfs_showattr_LINE(u32 value, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	static char *str[] = { "down", "attempting to activate",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 		"training", "channel analysis", "exchange", "up",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 		"waiting", "initialising"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	if (unlikely(value >= ARRAY_SIZE(str)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 		return sprintf(buf, "%u\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	return sprintf(buf, "%s\n", str[value]);
^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) static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	static char *str[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 			"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 			"ANSI T1.413",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 			"ITU-T G.992.1 (G.DMT)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 			"ITU-T G.992.2 (G.LITE)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	if (unlikely(value >= ARRAY_SIZE(str)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		return sprintf(buf, "%u\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	return sprintf(buf, "%s\n", str[value]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296)  * This could use MAC_ADDRESS_HIGH and MAC_ADDRESS_LOW, but since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297)  * this data is already in atm_dev there's no point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299)  * MAC_ADDRESS_HIGH = 0x????5544
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300)  * MAC_ADDRESS_LOW  = 0x33221100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301)  * Where 00-55 are bytes 0-5 of the MAC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) static ssize_t mac_address_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	struct cxacru_data *instance = to_usbatm_driver_data(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 			to_usb_interface(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	if (instance == NULL || instance->usbatm->atm_dev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	return sprintf(buf, "%pM\n", instance->usbatm->atm_dev->esi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) static ssize_t adsl_state_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	static char *str[] = { "running", "stopped" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	struct cxacru_data *instance = to_usbatm_driver_data(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 			to_usb_interface(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	u32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	if (instance == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	value = instance->card_info[CXINF_LINE_STARTABLE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	if (unlikely(value >= ARRAY_SIZE(str)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 		return sprintf(buf, "%u\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	return sprintf(buf, "%s\n", str[value]);
^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) static ssize_t adsl_state_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	struct cxacru_data *instance = to_usbatm_driver_data(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 			to_usb_interface(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	int poll = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	char str_cmd[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	int len = strlen(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	if (!capable(CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	ret = sscanf(buf, "%7s", str_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	if (ret != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	if (instance == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	if (mutex_lock_interruptible(&instance->adsl_state_serialize))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	if (!strcmp(str_cmd, "stop") || !strcmp(str_cmd, "restart")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 		ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_STOP, NULL, 0, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 			atm_err(instance->usbatm, "change adsl state:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 				" CHIP_ADSL_LINE_STOP returned %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 			ret = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 			poll = CXPOLL_STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	/* Line status is only updated every second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	 * and the device appears to only react to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	 * START/STOP every second too. Wait 1.5s to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	 * be sure that restart will have an effect. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	if (!strcmp(str_cmd, "restart"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 		msleep(1500);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	if (!strcmp(str_cmd, "start") || !strcmp(str_cmd, "restart")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 		ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 			atm_err(instance->usbatm, "change adsl state:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 				" CHIP_ADSL_LINE_START returned %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 			ret = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 			poll = CXPOLL_POLLING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	if (!strcmp(str_cmd, "poll")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		ret = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 		poll = CXPOLL_POLLING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 		poll = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	if (poll == CXPOLL_POLLING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		mutex_lock(&instance->poll_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		switch (instance->poll_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		case CXPOLL_STOPPED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 			/* start polling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 			instance->poll_state = CXPOLL_POLLING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		case CXPOLL_STOPPING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 			/* abort stop request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 			instance->poll_state = CXPOLL_POLLING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		case CXPOLL_POLLING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		case CXPOLL_SHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 			/* don't start polling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 			poll = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		mutex_unlock(&instance->poll_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	} else if (poll == CXPOLL_STOPPED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		mutex_lock(&instance->poll_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 		/* request stop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		if (instance->poll_state == CXPOLL_POLLING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 			instance->poll_state = CXPOLL_STOPPING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 		mutex_unlock(&instance->poll_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	mutex_unlock(&instance->adsl_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	if (poll == CXPOLL_POLLING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		cxacru_poll_status(&instance->poll_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) /* CM_REQUEST_CARD_DATA_GET times out, so no show attribute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) static ssize_t adsl_config_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	struct cxacru_data *instance = to_usbatm_driver_data(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 			to_usb_interface(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	int len = strlen(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	int ret, pos, num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	__le32 data[CMD_PACKET_SIZE / 4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	if (!capable(CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	if (instance == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	while (pos < len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		int tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		u32 index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		u32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		if (ret < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		if (index > 0x7f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 		if (tmp < 0 || tmp > len - pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		pos += tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		/* skip trailing newline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 		if (buf[pos] == '\n' && pos == len-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 			pos++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		data[num * 2 + 1] = cpu_to_le32(index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		data[num * 2 + 2] = cpu_to_le32(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		/* send config values when data buffer is full
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		 * or no more data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		if (pos >= len || num >= CMD_MAX_CONFIG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 			char log[CMD_MAX_CONFIG * 12 + 1]; /* %02x=%08x */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 			data[0] = cpu_to_le32(num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 			ret = cxacru_cm(instance, CM_REQUEST_CARD_DATA_SET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 				(u8 *) data, 4 + num * 8, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 			if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 				atm_err(instance->usbatm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 					"set card data returned %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 				return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 			for (tmp = 0; tmp < num; tmp++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 				snprintf(log + tmp*12, 13, " %02x=%08x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 					le32_to_cpu(data[tmp * 2 + 1]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 					le32_to_cpu(data[tmp * 2 + 2]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 			atm_info(instance->usbatm, "config%s\n", log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 			num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502)  * All device attributes are included in CXACRU_ALL_FILES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503)  * so that the same list can be used multiple times:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504)  *     INIT   (define the device attributes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505)  *     CREATE (create all the device files)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506)  *     REMOVE (remove all the device files)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508)  * With the last two being defined as needed in the functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509)  * they are used in before calling CXACRU_ALL_FILES()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) #define CXACRU_ALL_FILES(_action) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_RATE,           u32,  downstream_rate); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) CXACRU_ATTR_##_action(CXINF_UPSTREAM_RATE,             u32,  upstream_rate); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) CXACRU_ATTR_##_action(CXINF_LINK_STATUS,               LINK, link_status); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) CXACRU_ATTR_##_action(CXINF_LINE_STATUS,               LINE, line_status); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) CXACRU__ATTR_##_action(                                      mac_address); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) CXACRU_ATTR_##_action(CXINF_UPSTREAM_SNR_MARGIN,       dB,   upstream_snr_margin); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_SNR_MARGIN,     dB,   downstream_snr_margin); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) CXACRU_ATTR_##_action(CXINF_UPSTREAM_ATTENUATION,      dB,   upstream_attenuation); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_ATTENUATION,    dB,   downstream_attenuation); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) CXACRU_ATTR_##_action(CXINF_TRANSMITTER_POWER,         s8,   transmitter_power); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) CXACRU_ATTR_##_action(CXINF_UPSTREAM_BITS_PER_FRAME,   u32,  upstream_bits_per_frame); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_BITS_PER_FRAME, u32,  downstream_bits_per_frame); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) CXACRU_ATTR_##_action(CXINF_STARTUP_ATTEMPTS,          u32,  startup_attempts); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) CXACRU_ATTR_##_action(CXINF_UPSTREAM_CRC_ERRORS,       u32,  upstream_crc_errors); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_CRC_ERRORS,     u32,  downstream_crc_errors); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) CXACRU_ATTR_##_action(CXINF_UPSTREAM_FEC_ERRORS,       u32,  upstream_fec_errors); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_FEC_ERRORS,     u32,  downstream_fec_errors); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) CXACRU_ATTR_##_action(CXINF_UPSTREAM_HEC_ERRORS,       u32,  upstream_hec_errors); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_HEC_ERRORS,     u32,  downstream_hec_errors); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) CXACRU_ATTR_##_action(CXINF_LINE_STARTABLE,            bool, line_startable); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) CXACRU_ATTR_##_action(CXINF_MODULATION,                MODU, modulation); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND,              u32,  adsl_headend); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND_ENVIRONMENT,  u32,  adsl_headend_environment); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) CXACRU_ATTR_##_action(CXINF_CONTROLLER_VERSION,        u32,  adsl_controller_version); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) CXACRU_CMD_##_action(                                        adsl_state); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) CXACRU_SET_##_action(                                        adsl_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) CXACRU_ALL_FILES(INIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) static struct attribute *cxacru_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	&dev_attr_adsl_config.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	&dev_attr_adsl_state.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	&dev_attr_adsl_controller_version.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	&dev_attr_adsl_headend_environment.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	&dev_attr_adsl_headend.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	&dev_attr_modulation.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	&dev_attr_line_startable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	&dev_attr_downstream_hec_errors.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	&dev_attr_upstream_hec_errors.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	&dev_attr_downstream_fec_errors.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	&dev_attr_upstream_fec_errors.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	&dev_attr_downstream_crc_errors.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	&dev_attr_upstream_crc_errors.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	&dev_attr_startup_attempts.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	&dev_attr_downstream_bits_per_frame.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	&dev_attr_upstream_bits_per_frame.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	&dev_attr_transmitter_power.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	&dev_attr_downstream_attenuation.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	&dev_attr_upstream_attenuation.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	&dev_attr_downstream_snr_margin.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	&dev_attr_upstream_snr_margin.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	&dev_attr_mac_address.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	&dev_attr_line_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	&dev_attr_link_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	&dev_attr_upstream_rate.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	&dev_attr_downstream_rate.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) ATTRIBUTE_GROUPS(cxacru);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) /* the following three functions are stolen from drivers/usb/core/message.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) static void cxacru_blocking_completion(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	complete(urb->context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) struct cxacru_timer {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	struct timer_list timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) static void cxacru_timeout_kill(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	struct cxacru_timer *timer = from_timer(timer, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	usb_unlink_urb(timer->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) static int cxacru_start_wait_urb(struct urb *urb, struct completion *done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 				 int *actual_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	struct cxacru_timer timer = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		.urb = urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	timer_setup_on_stack(&timer.timer, cxacru_timeout_kill, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	mod_timer(&timer.timer, jiffies + msecs_to_jiffies(CMD_TIMEOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	wait_for_completion(done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	del_timer_sync(&timer.timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	destroy_timer_on_stack(&timer.timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	if (actual_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 		*actual_length = urb->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	return urb->status; /* must read status after completion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		     u8 *wdata, int wsize, u8 *rdata, int rsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	int ret, actlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	int offb, offd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	const int stride = CMD_PACKET_SIZE - 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	u8 *wbuf = instance->snd_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	u8 *rbuf = instance->rcv_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	int wbuflen = ((wsize - 1) / stride + 1) * CMD_PACKET_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	int rbuflen = ((rsize - 1) / stride + 1) * CMD_PACKET_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	if (wbuflen > PAGE_SIZE || rbuflen > PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		if (printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 			usb_err(instance->usbatm, "requested transfer size too large (%d, %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 				wbuflen, rbuflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	mutex_lock(&instance->cm_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	/* submit reading urb before the writing one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	init_completion(&instance->rcv_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	ret = usb_submit_urb(instance->rcv_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		if (printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 			usb_err(instance->usbatm, "submit of read urb for cm %#x failed (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 				cm, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		goto fail;
^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) 	memset(wbuf, 0, wbuflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	/* handle wsize == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	wbuf[0] = cm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	for (offb = offd = 0; offd < wsize; offd += stride, offb += CMD_PACKET_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		wbuf[offb] = cm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		memcpy(wbuf + offb + 4, wdata + offd, min_t(int, stride, wsize - offd));
^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) 	instance->snd_urb->transfer_buffer_length = wbuflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	init_completion(&instance->snd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	ret = usb_submit_urb(instance->snd_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 		if (printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 			usb_err(instance->usbatm, "submit of write urb for cm %#x failed (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 				cm, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	ret = cxacru_start_wait_urb(instance->snd_urb, &instance->snd_done, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		if (printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 			usb_err(instance->usbatm, "send of cm %#x failed (%d)\n", cm, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		goto fail;
^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) 	ret = cxacru_start_wait_urb(instance->rcv_urb, &instance->rcv_done, &actlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		if (printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 			usb_err(instance->usbatm, "receive of cm %#x failed (%d)\n", cm, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	if (actlen % CMD_PACKET_SIZE || !actlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		if (printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 			usb_err(instance->usbatm, "invalid response length to cm %#x: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 				cm, actlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		goto fail;
^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) 	/* check the return status and copy the data to the output buffer, if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	for (offb = offd = 0; offd < rsize && offb < actlen; offb += CMD_PACKET_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		if (rbuf[offb] != cm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 			if (printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 				usb_err(instance->usbatm, "wrong cm %#x in response to cm %#x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 					rbuf[offb], cm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		if (rbuf[offb + 1] != CM_STATUS_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 			if (printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 				usb_err(instance->usbatm, "response to cm %#x failed: %#x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 					cm, rbuf[offb + 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		if (offd >= rsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		memcpy(rdata + offd, rbuf + offb + 4, min_t(int, stride, rsize - offd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		offd += stride;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	ret = offd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	usb_dbg(instance->usbatm, "cm %#x\n", cm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	mutex_unlock(&instance->cm_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	return ret;
^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 int cxacru_cm_get_array(struct cxacru_data *instance, enum cxacru_cm_request cm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 			       u32 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	int ret, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	__le32 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	int offb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	unsigned int offd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	const int stride = CMD_PACKET_SIZE / (4 * 2) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	int buflen =  ((size - 1) / stride + 1 + size * 2) * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	buf = kmalloc(buflen, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	ret = cxacru_cm(instance, cm, NULL, 0, (u8 *) buf, buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	/* len > 0 && len % 4 == 0 guaranteed by cxacru_cm() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	len = ret / 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	for (offb = 0; offb < len; ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 		int l = le32_to_cpu(buf[offb++]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		if (l < 0 || l > stride || l > (len - offb) / 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 			if (printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 				usb_err(instance->usbatm, "invalid data length from cm %#x: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 					cm, l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 			goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		while (l--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 			offd = le32_to_cpu(buf[offb++]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 			if (offd >= size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 				if (printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 					usb_err(instance->usbatm, "wrong index %#x in response to cm %#x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 						offd, cm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 				ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 				goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 			data[offd] = le32_to_cpu(buf[offb++]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) static int cxacru_card_status(struct cxacru_data *instance)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	int ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	if (ret < 0) {		/* firmware not loaded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		usb_dbg(instance->usbatm, "cxacru_adsl_start: CARD_GET_STATUS returned %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) static int cxacru_atm_start(struct usbatm_data *usbatm_instance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		struct atm_dev *atm_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	struct cxacru_data *instance = usbatm_instance->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	struct usb_interface *intf = usbatm_instance->usb_intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	int start_polling = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	dev_dbg(&intf->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	/* Read MAC address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_MAC_ADDRESS, NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 			atm_dev->esi, sizeof(atm_dev->esi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 		atm_err(usbatm_instance, "cxacru_atm_start: CARD_GET_MAC_ADDRESS returned %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	/* start ADSL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	mutex_lock(&instance->adsl_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		atm_err(usbatm_instance, "cxacru_atm_start: CHIP_ADSL_LINE_START returned %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	/* Start status polling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	mutex_lock(&instance->poll_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	switch (instance->poll_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	case CXPOLL_STOPPED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		/* start polling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		instance->poll_state = CXPOLL_POLLING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	case CXPOLL_STOPPING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		/* abort stop request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		instance->poll_state = CXPOLL_POLLING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	case CXPOLL_POLLING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	case CXPOLL_SHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		/* don't start polling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		start_polling = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	mutex_unlock(&instance->poll_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	mutex_unlock(&instance->adsl_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	printk(KERN_INFO "%s%d: %s %pM\n", atm_dev->type, atm_dev->number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 			usbatm_instance->description, atm_dev->esi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	if (start_polling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		cxacru_poll_status(&instance->poll_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) static void cxacru_poll_status(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	struct cxacru_data *instance =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		container_of(work, struct cxacru_data, poll_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	u32 buf[CXINF_MAX] = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	struct usbatm_data *usbatm = instance->usbatm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	struct atm_dev *atm_dev = usbatm->atm_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	int keep_polling = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	ret = cxacru_cm_get_array(instance, CM_REQUEST_CARD_INFO_GET, buf, CXINF_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		if (ret != -ESHUTDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 			atm_warn(usbatm, "poll status: error %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		mutex_lock(&instance->poll_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		if (instance->poll_state != CXPOLL_SHUTDOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 			instance->poll_state = CXPOLL_STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 			if (ret != -ESHUTDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 				atm_warn(usbatm, "polling disabled, set adsl_state"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 						" to 'start' or 'poll' to resume\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		mutex_unlock(&instance->poll_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 		goto reschedule;
^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) 	memcpy(instance->card_info, buf, sizeof(instance->card_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	if (instance->adsl_status != buf[CXINF_LINE_STARTABLE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		instance->adsl_status = buf[CXINF_LINE_STARTABLE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		switch (instance->adsl_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 			atm_printk(KERN_INFO, usbatm, "ADSL state: running\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 			atm_printk(KERN_INFO, usbatm, "ADSL state: stopped\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 			atm_printk(KERN_INFO, usbatm, "Unknown adsl status %02x\n", instance->adsl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	if (instance->line_status == buf[CXINF_LINE_STATUS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 		goto reschedule;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	instance->line_status = buf[CXINF_LINE_STATUS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	switch (instance->line_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		atm_dev_signal_change(atm_dev, ATM_PHY_SIG_LOST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		atm_info(usbatm, "ADSL line: down\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 		atm_dev_signal_change(atm_dev, ATM_PHY_SIG_LOST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		atm_info(usbatm, "ADSL line: attempting to activate\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		atm_dev_signal_change(atm_dev, ATM_PHY_SIG_LOST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		atm_info(usbatm, "ADSL line: training\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		atm_dev_signal_change(atm_dev, ATM_PHY_SIG_LOST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		atm_info(usbatm, "ADSL line: channel analysis\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		atm_dev_signal_change(atm_dev, ATM_PHY_SIG_LOST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		atm_info(usbatm, "ADSL line: exchange\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		atm_dev->link_rate = buf[CXINF_DOWNSTREAM_RATE] * 1000 / 424;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		atm_dev_signal_change(atm_dev, ATM_PHY_SIG_FOUND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		atm_info(usbatm, "ADSL line: up (%d kb/s down | %d kb/s up)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		     buf[CXINF_DOWNSTREAM_RATE], buf[CXINF_UPSTREAM_RATE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 		atm_dev_signal_change(atm_dev, ATM_PHY_SIG_LOST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 		atm_info(usbatm, "ADSL line: waiting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	case 7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		atm_dev_signal_change(atm_dev, ATM_PHY_SIG_LOST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 		atm_info(usbatm, "ADSL line: initializing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 		atm_dev_signal_change(atm_dev, ATM_PHY_SIG_UNKNOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		atm_info(usbatm, "Unknown line state %02x\n", instance->line_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) reschedule:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	mutex_lock(&instance->poll_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	if (instance->poll_state == CXPOLL_STOPPING &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 				instance->adsl_status == 1 && /* stopped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 				instance->line_status == 0) /* down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 		instance->poll_state = CXPOLL_STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	if (instance->poll_state == CXPOLL_STOPPED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		keep_polling = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	mutex_unlock(&instance->poll_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	if (keep_polling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 		schedule_delayed_work(&instance->poll_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 				round_jiffies_relative(POLL_INTERVAL*HZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		     u8 code1, u8 code2, u32 addr, const u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	int offd, offb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	const int stride = CMD_PACKET_SIZE - 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	buf = (u8 *) __get_free_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	offb = offd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		int l = min_t(int, stride, size - offd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		buf[offb++] = fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 		buf[offb++] = l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		buf[offb++] = code1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		buf[offb++] = code2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 		put_unaligned(cpu_to_le32(addr), (__le32 *)(buf + offb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		offb += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 		addr += l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 		if (l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 			memcpy(buf + offb, data + offd, l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 		if (l < stride)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 			memset(buf + offb + l, 0, stride - l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 		offb += stride;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		offd += stride;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		if ((offb >= PAGE_SIZE) || (offd >= size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 			ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 					   buf, offb, NULL, CMD_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 			if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 				dev_dbg(&usb_dev->dev, "sending fw %#x failed\n", fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 				goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 			offb = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	} while (offd < size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	dev_dbg(&usb_dev->dev, "sent fw %#x\n", fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	free_page((unsigned long) buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) static void cxacru_upload_firmware(struct cxacru_data *instance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 				   const struct firmware *fw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 				   const struct firmware *bp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	struct usbatm_data *usbatm = instance->usbatm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	struct usb_device *usb_dev = usbatm->usb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	__le16 signature[] = { usb_dev->descriptor.idVendor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 			       usb_dev->descriptor.idProduct };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	__le32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	usb_dbg(usbatm, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	/* FirmwarePllFClkValue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	val = cpu_to_le32(instance->modem_type->pll_f_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLFCLK_ADDR, (u8 *) &val, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		usb_err(usbatm, "FirmwarePllFClkValue failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	/* FirmwarePllBClkValue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	val = cpu_to_le32(instance->modem_type->pll_b_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLBCLK_ADDR, (u8 *) &val, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		usb_err(usbatm, "FirmwarePllBClkValue failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	/* Enable SDRAM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	val = cpu_to_le32(SDRAM_ENA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SDRAMEN_ADDR, (u8 *) &val, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		usb_err(usbatm, "Enable SDRAM failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	/* Firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	usb_info(usbatm, "loading firmware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 		usb_err(usbatm, "Firmware upload failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	/* Boot ROM patch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	if (instance->modem_type->boot_rom_patch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		usb_info(usbatm, "loading boot ROM patch\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, bp->data, bp->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 			usb_err(usbatm, "Boot ROM patching failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	/* Signature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SIG_ADDR, (u8 *) signature, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		usb_err(usbatm, "Signature storing failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	usb_info(usbatm, "starting device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	if (instance->modem_type->boot_rom_patch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 		val = cpu_to_le32(BR_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 		ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		ret = cxacru_fw(usb_dev, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		usb_err(usbatm, "Passing control to firmware failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	/* Delay to allow firmware to start up. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	msleep_interruptible(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_CMD));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_DATA));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_DATA));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		usb_err(usbatm, "modem failed to initialize: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) static int cxacru_find_firmware(struct cxacru_data *instance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 				char *phase, const struct firmware **fw_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	struct usbatm_data *usbatm = instance->usbatm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	struct device *dev = &usbatm->usb_intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	char buf[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	sprintf(buf, "cxacru-%s.bin", phase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	usb_dbg(usbatm, "cxacru_find_firmware: looking for %s\n", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	if (request_firmware(fw_p, buf, dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 		usb_dbg(usbatm, "no stage %s firmware found\n", phase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	usb_info(usbatm, "found firmware %s\n", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) static int cxacru_heavy_init(struct usbatm_data *usbatm_instance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 			     struct usb_interface *usb_intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	const struct firmware *fw, *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	struct cxacru_data *instance = usbatm_instance->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	int ret = cxacru_find_firmware(instance, "fw", &fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		usb_warn(usbatm_instance, "firmware (cxacru-fw.bin) unavailable (system misconfigured?)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	if (instance->modem_type->boot_rom_patch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 		ret = cxacru_find_firmware(instance, "bp", &bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 			usb_warn(usbatm_instance, "boot ROM patch (cxacru-bp.bin) unavailable (system misconfigured?)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 			release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	cxacru_upload_firmware(instance, fw, bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	if (instance->modem_type->boot_rom_patch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 		release_firmware(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	ret = cxacru_card_status(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		usb_dbg(usbatm_instance, "modem initialisation failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 		usb_dbg(usbatm_instance, "done setting up the modem\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) static int cxacru_bind(struct usbatm_data *usbatm_instance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		       struct usb_interface *intf, const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	struct cxacru_data *instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	struct usb_device *usb_dev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	struct usb_host_endpoint *cmd_ep = usb_dev->ep_in[CXACRU_EP_CMD];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	/* instance init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	instance = kzalloc(sizeof(*instance), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	if (!instance)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	instance->usbatm = usbatm_instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	instance->modem_type = (struct cxacru_modem_type *) id->driver_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	mutex_init(&instance->poll_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	instance->poll_state = CXPOLL_STOPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	instance->line_status = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	instance->adsl_status = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	mutex_init(&instance->adsl_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	instance->rcv_buf = (u8 *) __get_free_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	if (!instance->rcv_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 		usb_dbg(usbatm_instance, "cxacru_bind: no memory for rcv_buf\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	instance->snd_buf = (u8 *) __get_free_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	if (!instance->snd_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 		usb_dbg(usbatm_instance, "cxacru_bind: no memory for snd_buf\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	instance->rcv_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	if (!instance->rcv_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	instance->snd_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	if (!instance->snd_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	if (!cmd_ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 		usb_dbg(usbatm_instance, "cxacru_bind: no command endpoint\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	if ((cmd_ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 			== USB_ENDPOINT_XFER_INT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 		usb_fill_int_urb(instance->rcv_urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 			usb_dev, usb_rcvintpipe(usb_dev, CXACRU_EP_CMD),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 			instance->rcv_buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 			cxacru_blocking_completion, &instance->rcv_done, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 		usb_fill_int_urb(instance->snd_urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 			usb_dev, usb_sndintpipe(usb_dev, CXACRU_EP_CMD),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 			instance->snd_buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 			cxacru_blocking_completion, &instance->snd_done, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 		usb_fill_bulk_urb(instance->rcv_urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 			usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_CMD),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 			instance->rcv_buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 			cxacru_blocking_completion, &instance->rcv_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 		usb_fill_bulk_urb(instance->snd_urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 			usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 			instance->snd_buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 			cxacru_blocking_completion, &instance->snd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	mutex_init(&instance->cm_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	INIT_DELAYED_WORK(&instance->poll_work, cxacru_poll_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	usbatm_instance->driver_data = instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	usbatm_instance->flags = (cxacru_card_status(instance) ? 0 : UDSL_SKIP_HEAVY_INIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)  fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	free_page((unsigned long) instance->snd_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	free_page((unsigned long) instance->rcv_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	usb_free_urb(instance->snd_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	usb_free_urb(instance->rcv_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	kfree(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) static void cxacru_unbind(struct usbatm_data *usbatm_instance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 		struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	struct cxacru_data *instance = usbatm_instance->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	int is_polling = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	usb_dbg(usbatm_instance, "cxacru_unbind entered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	if (!instance) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 		usb_dbg(usbatm_instance, "cxacru_unbind: NULL instance!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	mutex_lock(&instance->poll_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	BUG_ON(instance->poll_state == CXPOLL_SHUTDOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	/* ensure that status polling continues unless
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	 * it has already stopped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	if (instance->poll_state == CXPOLL_STOPPED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 		is_polling = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	/* stop polling from being stopped or started */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	instance->poll_state = CXPOLL_SHUTDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	mutex_unlock(&instance->poll_state_serialize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	if (is_polling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 		cancel_delayed_work_sync(&instance->poll_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	usb_kill_urb(instance->snd_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	usb_kill_urb(instance->rcv_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	usb_free_urb(instance->snd_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	usb_free_urb(instance->rcv_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	free_page((unsigned long) instance->snd_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	free_page((unsigned long) instance->rcv_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	kfree(instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	usbatm_instance->driver_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) static const struct cxacru_modem_type cxacru_cafe = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	.pll_f_clk = 0x02d874df,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	.pll_b_clk = 0x0196a51a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	.boot_rom_patch = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) static const struct cxacru_modem_type cxacru_cb00 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	.pll_f_clk = 0x5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	.pll_b_clk = 0x3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	.boot_rom_patch = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) static const struct usb_device_id cxacru_usb_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	{ /* V = Conexant			P = ADSL modem (Euphrates project)	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		USB_DEVICE(0x0572, 0xcafe),	.driver_info = (unsigned long) &cxacru_cafe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 	{ /* V = Conexant			P = ADSL modem (Hasbani project)	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 		USB_DEVICE(0x0572, 0xcb00),	.driver_info = (unsigned long) &cxacru_cb00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	{ /* V = Conexant			P = ADSL modem				*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 		USB_DEVICE(0x0572, 0xcb01),	.driver_info = (unsigned long) &cxacru_cb00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	{ /* V = Conexant			P = ADSL modem (Well PTI-800) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 		USB_DEVICE(0x0572, 0xcb02),	.driver_info = (unsigned long) &cxacru_cb00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	{ /* V = Conexant			P = ADSL modem				*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 		USB_DEVICE(0x0572, 0xcb06),	.driver_info = (unsigned long) &cxacru_cb00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	{ /* V = Conexant			P = ADSL modem (ZTE ZXDSL 852)		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 		USB_DEVICE(0x0572, 0xcb07),	.driver_info = (unsigned long) &cxacru_cb00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	{ /* V = Olitec				P = ADSL modem version 2		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 		USB_DEVICE(0x08e3, 0x0100),	.driver_info = (unsigned long) &cxacru_cafe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	{ /* V = Olitec				P = ADSL modem version 3		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 		USB_DEVICE(0x08e3, 0x0102),	.driver_info = (unsigned long) &cxacru_cb00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	{ /* V = Trust/Amigo Technology Co.	P = AMX-CA86U				*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		USB_DEVICE(0x0eb0, 0x3457),	.driver_info = (unsigned long) &cxacru_cafe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	{ /* V = Zoom				P = 5510				*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		USB_DEVICE(0x1803, 0x5510),	.driver_info = (unsigned long) &cxacru_cb00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	{ /* V = Draytek			P = Vigor 318				*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 		USB_DEVICE(0x0675, 0x0200),	.driver_info = (unsigned long) &cxacru_cb00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	{ /* V = Zyxel				P = 630-C1 aka OMNI ADSL USB (Annex A)	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 		USB_DEVICE(0x0586, 0x330a),	.driver_info = (unsigned long) &cxacru_cb00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	{ /* V = Zyxel				P = 630-C3 aka OMNI ADSL USB (Annex B)	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		USB_DEVICE(0x0586, 0x330b),	.driver_info = (unsigned long) &cxacru_cb00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	{ /* V = Aethra				P = Starmodem UM1020			*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 		USB_DEVICE(0x0659, 0x0020),	.driver_info = (unsigned long) &cxacru_cb00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	{ /* V = Aztech Systems			P = ? AKA Pirelli AUA-010		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		USB_DEVICE(0x0509, 0x0812),	.driver_info = (unsigned long) &cxacru_cb00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	{ /* V = Netopia			P = Cayman 3341(Annex A)/3351(Annex B)	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 		USB_DEVICE(0x100d, 0xcb01),	.driver_info = (unsigned long) &cxacru_cb00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	{ /* V = Netopia			P = Cayman 3342(Annex A)/3352(Annex B)	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 		USB_DEVICE(0x100d, 0x3342),	.driver_info = (unsigned long) &cxacru_cb00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) MODULE_DEVICE_TABLE(usb, cxacru_usb_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) static struct usbatm_driver cxacru_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	.driver_name	= cxacru_driver_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	.bind		= cxacru_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	.heavy_init	= cxacru_heavy_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	.unbind		= cxacru_unbind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	.atm_start	= cxacru_atm_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	.bulk_in	= CXACRU_EP_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	.bulk_out	= CXACRU_EP_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	.rx_padding	= 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	.tx_padding	= 11,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) static int cxacru_usb_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 		const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	struct usb_device *usb_dev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	char buf[15];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	/* Avoid ADSL routers (cx82310_eth).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	 * Abort if bDeviceClass is 0xff and iProduct is "USB NET CARD".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	if (usb_dev->descriptor.bDeviceClass == USB_CLASS_VENDOR_SPEC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 			&& usb_string(usb_dev, usb_dev->descriptor.iProduct,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 				buf, sizeof(buf)) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 		if (!strcmp(buf, "USB NET CARD")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 			dev_info(&intf->dev, "ignoring cx82310_eth device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 	return usbatm_usb_probe(intf, id, &cxacru_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) static struct usb_driver cxacru_usb_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	.name		= cxacru_driver_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	.probe		= cxacru_usb_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	.disconnect	= usbatm_usb_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	.id_table	= cxacru_usb_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	.dev_groups	= cxacru_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) module_usb_driver(cxacru_usb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) MODULE_AUTHOR(DRIVER_AUTHOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) MODULE_LICENSE("GPL");