^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * at76c503/at76c505 USB driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2002 - 2003 Oliver Kurth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2004 Joerg Albert <joerg.albert@gmx.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (c) 2004 Nick Jones
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (c) 2004 Balint Seeber <n0_5p4m_p13453@hotmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (c) 2007 Guido Guenther <agx@sigxcpu.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (c) 2007 Kalle Valo <kalle.valo@iki.fi>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright (c) 2010 Sebastian Smolorz <sesmo@gmx.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * This file is part of the Berlios driver for WLAN USB devices based on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Atmel AT76C503A/505/505A.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Some iw_handler code was taken from airo.c, (C) 1999 Benjamin Reed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * TODO list is at the wiki:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * https://wireless.wiki.kernel.org/en/users/Drivers/at76c50x-usb#TODO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/ethtool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/wireless.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <net/iw_handler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <net/ieee80211_radiotap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <net/mac80211.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include "at76c50x-usb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* Version information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define DRIVER_NAME "at76c50x-usb"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define DRIVER_VERSION "0.17"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define DRIVER_DESC "Atmel at76x USB Wireless LAN Driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* at76_debug bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define DBG_PROGRESS 0x00000001 /* authentication/accociation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define DBG_BSS_TABLE 0x00000002 /* show BSS table after scans */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define DBG_IOCTL 0x00000004 /* ioctl calls / settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define DBG_MAC_STATE 0x00000008 /* MAC state transitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define DBG_TX_DATA 0x00000010 /* tx header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define DBG_TX_DATA_CONTENT 0x00000020 /* tx content */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define DBG_TX_MGMT 0x00000040 /* tx management */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define DBG_RX_DATA 0x00000080 /* rx data header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define DBG_RX_DATA_CONTENT 0x00000100 /* rx data content */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define DBG_RX_MGMT 0x00000200 /* rx mgmt frame headers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define DBG_RX_BEACON 0x00000400 /* rx beacon */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define DBG_RX_CTRL 0x00000800 /* rx control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define DBG_RX_MGMT_CONTENT 0x00001000 /* rx mgmt content */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define DBG_RX_FRAGS 0x00002000 /* rx data fragment handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define DBG_DEVSTART 0x00004000 /* fw download, device start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define DBG_URB 0x00008000 /* rx urb status, ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define DBG_RX_ATMEL_HDR 0x00010000 /* Atmel-specific Rx headers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define DBG_PROC_ENTRY 0x00020000 /* procedure entries/exits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define DBG_PM 0x00040000 /* power management settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define DBG_BSS_MATCH 0x00080000 /* BSS match failures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define DBG_PARAMS 0x00100000 /* show configured parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define DBG_WAIT_COMPLETE 0x00200000 /* command completion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define DBG_RX_FRAGS_SKB 0x00400000 /* skb header of Rx fragments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define DBG_BSS_TABLE_RM 0x00800000 /* purging bss table entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define DBG_MONITOR_MODE 0x01000000 /* monitor mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define DBG_MIB 0x02000000 /* dump all MIBs on startup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define DBG_MGMT_TIMER 0x04000000 /* dump mgmt_timer ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define DBG_WE_EVENTS 0x08000000 /* dump wireless events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define DBG_FW 0x10000000 /* firmware download */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define DBG_DFU 0x20000000 /* device firmware upgrade */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define DBG_CMD 0x40000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define DBG_MAC80211 0x80000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define DBG_DEFAULTS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* Use our own dbg macro */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define at76_dbg(bits, format, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (at76_debug & (bits)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) printk(KERN_DEBUG DRIVER_NAME ": " format "\n", ##arg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define at76_dbg_dump(bits, buf, len, format, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (at76_debug & (bits)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) printk(KERN_DEBUG DRIVER_NAME ": " format "\n", ##arg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, len); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static uint at76_debug = DBG_DEFAULTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /* Protect against concurrent firmware loading and parsing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static struct mutex fw_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static struct fwentry firmwares[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) [0] = { "" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) [BOARD_503_ISL3861] = { "atmel_at76c503-i3861.bin" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) [BOARD_503_ISL3863] = { "atmel_at76c503-i3863.bin" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) [BOARD_503] = { "atmel_at76c503-rfmd.bin" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) [BOARD_503_ACC] = { "atmel_at76c503-rfmd-acc.bin" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) [BOARD_505] = { "atmel_at76c505-rfmd.bin" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) [BOARD_505_2958] = { "atmel_at76c505-rfmd2958.bin" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) [BOARD_505A] = { "atmel_at76c505a-rfmd2958.bin" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) [BOARD_505AMX] = { "atmel_at76c505amx-rfmd.bin" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) MODULE_FIRMWARE("atmel_at76c503-i3861.bin");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) MODULE_FIRMWARE("atmel_at76c503-i3863.bin");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) MODULE_FIRMWARE("atmel_at76c503-rfmd.bin");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) MODULE_FIRMWARE("atmel_at76c503-rfmd-acc.bin");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) MODULE_FIRMWARE("atmel_at76c505-rfmd.bin");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) MODULE_FIRMWARE("atmel_at76c505-rfmd2958.bin");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) MODULE_FIRMWARE("atmel_at76c505a-rfmd2958.bin");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) MODULE_FIRMWARE("atmel_at76c505amx-rfmd.bin");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #define USB_DEVICE_DATA(__ops) .driver_info = (kernel_ulong_t)(__ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static const struct usb_device_id dev_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * at76c503-i3861
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /* Generic AT76C503/3861 device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) { USB_DEVICE(0x03eb, 0x7603), USB_DEVICE_DATA(BOARD_503_ISL3861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* Linksys WUSB11 v2.1/v2.6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) { USB_DEVICE(0x066b, 0x2211), USB_DEVICE_DATA(BOARD_503_ISL3861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /* Netgear MA101 rev. A */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) { USB_DEVICE(0x0864, 0x4100), USB_DEVICE_DATA(BOARD_503_ISL3861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /* Tekram U300C / Allnet ALL0193 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) { USB_DEVICE(0x0b3b, 0x1612), USB_DEVICE_DATA(BOARD_503_ISL3861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /* HP HN210W J7801A */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) { USB_DEVICE(0x03f0, 0x011c), USB_DEVICE_DATA(BOARD_503_ISL3861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /* Sitecom/Z-Com/Zyxel M4Y-750 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) { USB_DEVICE(0x0cde, 0x0001), USB_DEVICE_DATA(BOARD_503_ISL3861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* Dynalink/Askey WLL013 (intersil) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) { USB_DEVICE(0x069a, 0x0320), USB_DEVICE_DATA(BOARD_503_ISL3861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /* EZ connect 11Mpbs Wireless USB Adapter SMC2662W v1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) { USB_DEVICE(0x0d5c, 0xa001), USB_DEVICE_DATA(BOARD_503_ISL3861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /* BenQ AWL300 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) { USB_DEVICE(0x04a5, 0x9000), USB_DEVICE_DATA(BOARD_503_ISL3861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /* Addtron AWU-120, Compex WLU11 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) { USB_DEVICE(0x05dd, 0xff31), USB_DEVICE_DATA(BOARD_503_ISL3861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /* Intel AP310 AnyPoint II USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) { USB_DEVICE(0x8086, 0x0200), USB_DEVICE_DATA(BOARD_503_ISL3861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* Dynalink L11U */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) { USB_DEVICE(0x0d8e, 0x7100), USB_DEVICE_DATA(BOARD_503_ISL3861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* Arescom WL-210, FCC id 07J-GL2411USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) { USB_DEVICE(0x0d8e, 0x7110), USB_DEVICE_DATA(BOARD_503_ISL3861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* I-O DATA WN-B11/USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) { USB_DEVICE(0x04bb, 0x0919), USB_DEVICE_DATA(BOARD_503_ISL3861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /* BT Voyager 1010 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) { USB_DEVICE(0x069a, 0x0821), USB_DEVICE_DATA(BOARD_503_ISL3861) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * at76c503-i3863
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /* Generic AT76C503/3863 device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) { USB_DEVICE(0x03eb, 0x7604), USB_DEVICE_DATA(BOARD_503_ISL3863) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /* Samsung SWL-2100U */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) { USB_DEVICE(0x055d, 0xa000), USB_DEVICE_DATA(BOARD_503_ISL3863) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * at76c503-rfmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* Generic AT76C503/RFMD device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) { USB_DEVICE(0x03eb, 0x7605), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* Dynalink/Askey WLL013 (rfmd) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) { USB_DEVICE(0x069a, 0x0321), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /* Linksys WUSB11 v2.6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) { USB_DEVICE(0x077b, 0x2219), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /* Network Everywhere NWU11B */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) { USB_DEVICE(0x077b, 0x2227), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /* Netgear MA101 rev. B */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) { USB_DEVICE(0x0864, 0x4102), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* D-Link DWL-120 rev. E */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) { USB_DEVICE(0x2001, 0x3200), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /* Actiontec 802UAT1, HWU01150-01UK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) { USB_DEVICE(0x1668, 0x7605), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /* AirVast W-Buddie WN210 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) { USB_DEVICE(0x03eb, 0x4102), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /* Dick Smith Electronics XH1153 802.11b USB adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) { USB_DEVICE(0x1371, 0x5743), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /* CNet CNUSB611 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) { USB_DEVICE(0x1371, 0x0001), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /* FiberLine FL-WL200U */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) { USB_DEVICE(0x1371, 0x0002), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* BenQ AWL400 USB stick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) { USB_DEVICE(0x04a5, 0x9001), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /* 3Com 3CRSHEW696 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) { USB_DEVICE(0x0506, 0x0a01), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /* Siemens Santis ADSL WLAN USB adapter WLL 013 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) { USB_DEVICE(0x0681, 0x001b), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /* Belkin F5D6050, version 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) { USB_DEVICE(0x050d, 0x0050), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* iBlitzz, BWU613 (not *B or *SB) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) { USB_DEVICE(0x07b8, 0xb000), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* Gigabyte GN-WLBM101 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) { USB_DEVICE(0x1044, 0x8003), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* Planex GW-US11S */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) { USB_DEVICE(0x2019, 0x3220), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* Internal WLAN adapter in h5[4,5]xx series iPAQs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) { USB_DEVICE(0x049f, 0x0032), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /* Corega Wireless LAN USB-11 mini */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) { USB_DEVICE(0x07aa, 0x0011), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* Corega Wireless LAN USB-11 mini2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) { USB_DEVICE(0x07aa, 0x0018), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /* Uniden PCW100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) { USB_DEVICE(0x05dd, 0xff35), USB_DEVICE_DATA(BOARD_503) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * at76c503-rfmd-acc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* SMC2664W */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) { USB_DEVICE(0x083a, 0x3501), USB_DEVICE_DATA(BOARD_503_ACC) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* Belkin F5D6050, SMC2662W v2, SMC2662W-AR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) { USB_DEVICE(0x0d5c, 0xa002), USB_DEVICE_DATA(BOARD_503_ACC) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * at76c505-rfmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /* Generic AT76C505/RFMD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) { USB_DEVICE(0x03eb, 0x7606), USB_DEVICE_DATA(BOARD_505) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * at76c505-rfmd2958
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /* Generic AT76C505/RFMD, OvisLink WL-1130USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) { USB_DEVICE(0x03eb, 0x7613), USB_DEVICE_DATA(BOARD_505_2958) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /* Fiberline FL-WL240U */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) { USB_DEVICE(0x1371, 0x0014), USB_DEVICE_DATA(BOARD_505_2958) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /* CNet CNUSB-611G */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) { USB_DEVICE(0x1371, 0x0013), USB_DEVICE_DATA(BOARD_505_2958) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /* Linksys WUSB11 v2.8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) { USB_DEVICE(0x1915, 0x2233), USB_DEVICE_DATA(BOARD_505_2958) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /* Xterasys XN-2122B, IBlitzz BWU613B/BWU613SB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) { USB_DEVICE(0x12fd, 0x1001), USB_DEVICE_DATA(BOARD_505_2958) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /* Corega WLAN USB Stick 11 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) { USB_DEVICE(0x07aa, 0x7613), USB_DEVICE_DATA(BOARD_505_2958) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /* Microstar MSI Box MS6978 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) { USB_DEVICE(0x0db0, 0x1020), USB_DEVICE_DATA(BOARD_505_2958) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * at76c505a-rfmd2958
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /* Generic AT76C505A device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) { USB_DEVICE(0x03eb, 0x7614), USB_DEVICE_DATA(BOARD_505A) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /* Generic AT76C505AS device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) { USB_DEVICE(0x03eb, 0x7617), USB_DEVICE_DATA(BOARD_505A) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* Siemens Gigaset USB WLAN Adapter 11 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) { USB_DEVICE(0x1690, 0x0701), USB_DEVICE_DATA(BOARD_505A) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /* OQO Model 01+ Internal Wi-Fi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) { USB_DEVICE(0x1557, 0x0002), USB_DEVICE_DATA(BOARD_505A) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * at76c505amx-rfmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) /* Generic AT76C505AMX device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) { USB_DEVICE(0x03eb, 0x7615), USB_DEVICE_DATA(BOARD_505AMX) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) MODULE_DEVICE_TABLE(usb, dev_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* Supported rates of this hardware, bit 7 marks basic rates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static const u8 hw_rates[] = { 0x82, 0x84, 0x0b, 0x16 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static const char *const preambles[] = { "long", "short", "auto" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /* Firmware download */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /* DFU states */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) #define STATE_IDLE 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) #define STATE_DETACH 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #define STATE_DFU_IDLE 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #define STATE_DFU_DOWNLOAD_SYNC 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #define STATE_DFU_DOWNLOAD_BUSY 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) #define STATE_DFU_DOWNLOAD_IDLE 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #define STATE_DFU_MANIFEST_SYNC 0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #define STATE_DFU_MANIFEST 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) #define STATE_DFU_MANIFEST_WAIT_RESET 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) #define STATE_DFU_UPLOAD_IDLE 0x09
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) #define STATE_DFU_ERROR 0x0a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /* DFU commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) #define DFU_DETACH 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #define DFU_DNLOAD 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) #define DFU_UPLOAD 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #define DFU_GETSTATUS 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) #define DFU_CLRSTATUS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) #define DFU_GETSTATE 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) #define DFU_ABORT 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) #define FW_BLOCK_SIZE 1024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct dfu_status {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) unsigned char status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) unsigned char poll_timeout[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) unsigned char state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) unsigned char string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static inline int at76_is_intersil(enum board_type board)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) return (board == BOARD_503_ISL3861 || board == BOARD_503_ISL3863);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static inline int at76_is_503rfmd(enum board_type board)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return (board == BOARD_503 || board == BOARD_503_ACC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static inline int at76_is_505a(enum board_type board)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) return (board == BOARD_505A || board == BOARD_505AMX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /* Load a block of the first (internal) part of the firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static int at76_load_int_fw_block(struct usb_device *udev, int blockno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) void *block, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), DFU_DNLOAD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) USB_TYPE_CLASS | USB_DIR_OUT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) USB_RECIP_INTERFACE, blockno, 0, block, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) USB_CTRL_GET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static int at76_dfu_get_status(struct usb_device *udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) struct dfu_status *status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), DFU_GETSTATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) USB_TYPE_CLASS | USB_DIR_IN | USB_RECIP_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 0, 0, status, sizeof(struct dfu_status),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) USB_CTRL_GET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), DFU_GETSTATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) USB_TYPE_CLASS | USB_DIR_IN | USB_RECIP_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 0, 0, state, 1, USB_CTRL_GET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) /* Convert timeout from the DFU status to jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) static inline unsigned long at76_get_timeout(struct dfu_status *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) return msecs_to_jiffies((s->poll_timeout[2] << 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) | (s->poll_timeout[1] << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) | (s->poll_timeout[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /* Load internal firmware from the buffer. If manifest_sync_timeout > 0, use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * its value in jiffies in the MANIFEST_SYNC state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static int at76_usbdfu_download(struct usb_device *udev, u8 *buf, u32 size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) int manifest_sync_timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int need_dfu_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) int is_done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) u32 dfu_timeout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) int bsize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) int blockno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct dfu_status *dfu_stat_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) u8 *dfu_state = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) u8 *block = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) at76_dbg(DBG_DFU, "%s( %p, %u, %d)", __func__, buf, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) manifest_sync_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (!size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) dev_err(&udev->dev, "FW buffer length invalid!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) dfu_stat_buf = kmalloc(sizeof(struct dfu_status), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (!dfu_stat_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) block = kmalloc(FW_BLOCK_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) if (!block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) dfu_state = kmalloc(sizeof(u8), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (!dfu_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) *dfu_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (need_dfu_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) ret = at76_dfu_get_state(udev, dfu_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) dev_err(&udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) "cannot get DFU state: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) need_dfu_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) switch (*dfu_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) case STATE_DFU_DOWNLOAD_SYNC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) at76_dbg(DBG_DFU, "STATE_DFU_DOWNLOAD_SYNC");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) ret = at76_dfu_get_status(udev, dfu_stat_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (ret >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) *dfu_state = dfu_stat_buf->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) dfu_timeout = at76_get_timeout(dfu_stat_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) need_dfu_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) dev_err(&udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) "at76_dfu_get_status returned %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) case STATE_DFU_DOWNLOAD_BUSY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) at76_dbg(DBG_DFU, "STATE_DFU_DOWNLOAD_BUSY");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) need_dfu_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) at76_dbg(DBG_DFU, "DFU: Resetting device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) schedule_timeout_interruptible(dfu_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) case STATE_DFU_DOWNLOAD_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) at76_dbg(DBG_DFU, "DOWNLOAD...");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) case STATE_DFU_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) at76_dbg(DBG_DFU, "DFU IDLE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) bsize = min_t(int, size, FW_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) memcpy(block, buf, bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) at76_dbg(DBG_DFU, "int fw, size left = %5d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) "bsize = %4d, blockno = %2d", size, bsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) blockno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) ret =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) at76_load_int_fw_block(udev, blockno, block, bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) buf += bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) size -= bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) blockno++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (ret != bsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) dev_err(&udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) "at76_load_int_fw_block returned %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) need_dfu_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) case STATE_DFU_MANIFEST_SYNC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) at76_dbg(DBG_DFU, "STATE_DFU_MANIFEST_SYNC");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) ret = at76_dfu_get_status(udev, dfu_stat_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) *dfu_state = dfu_stat_buf->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) dfu_timeout = at76_get_timeout(dfu_stat_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) need_dfu_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) /* override the timeout from the status response,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) needed for AT76C505A */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (manifest_sync_timeout > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) dfu_timeout = manifest_sync_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) at76_dbg(DBG_DFU, "DFU: Waiting for manifest phase");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) schedule_timeout_interruptible(dfu_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) case STATE_DFU_MANIFEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) at76_dbg(DBG_DFU, "STATE_DFU_MANIFEST");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) is_done = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) case STATE_DFU_MANIFEST_WAIT_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) at76_dbg(DBG_DFU, "STATE_DFU_MANIFEST_WAIT_RESET");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) is_done = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) case STATE_DFU_UPLOAD_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) at76_dbg(DBG_DFU, "STATE_DFU_UPLOAD_IDLE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) case STATE_DFU_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) at76_dbg(DBG_DFU, "STATE_DFU_ERROR");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) ret = -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) at76_dbg(DBG_DFU, "DFU UNKNOWN STATE (%d)", *dfu_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) } while (!is_done && (ret >= 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) kfree(dfu_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) kfree(block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) kfree(dfu_stat_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) /* LED trigger */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) static int tx_activity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) static void at76_ledtrig_tx_timerfunc(struct timer_list *unused);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) static DEFINE_TIMER(ledtrig_tx_timer, at76_ledtrig_tx_timerfunc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) DEFINE_LED_TRIGGER(ledtrig_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) static void at76_ledtrig_tx_timerfunc(struct timer_list *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) static int tx_lastactivity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) if (tx_lastactivity != tx_activity) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) tx_lastactivity = tx_activity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) led_trigger_event(ledtrig_tx, LED_FULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) mod_timer(&ledtrig_tx_timer, jiffies + HZ / 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) led_trigger_event(ledtrig_tx, LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) static void at76_ledtrig_tx_activity(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) tx_activity++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) if (!timer_pending(&ledtrig_tx_timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) mod_timer(&ledtrig_tx_timer, jiffies + HZ / 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) static int at76_remap(struct usb_device *udev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x0a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) USB_TYPE_VENDOR | USB_DIR_OUT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) USB_RECIP_INTERFACE, 0, 0, NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) USB_CTRL_GET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) static int at76_get_op_mode(struct usb_device *udev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) u8 saved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) u8 *op_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) op_mode = kmalloc(1, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (!op_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x33,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) USB_TYPE_VENDOR | USB_DIR_IN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) USB_RECIP_INTERFACE, 0x01, 0, op_mode, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) USB_CTRL_GET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) saved = *op_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) kfree(op_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) else if (ret < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) return saved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) /* Load a block of the second ("external") part of the firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static inline int at76_load_ext_fw_block(struct usb_device *udev, int blockno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) void *block, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x0e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 0x0802, blockno, block, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) USB_CTRL_GET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) static inline int at76_get_hw_cfg(struct usb_device *udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) union at76_hwcfg *buf, int buf_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x33,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) USB_TYPE_VENDOR | USB_DIR_IN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) USB_RECIP_INTERFACE, 0x0a02, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) buf, buf_size, USB_CTRL_GET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) /* Intersil boards use a different "value" for GetHWConfig requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) static inline int at76_get_hw_cfg_intersil(struct usb_device *udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) union at76_hwcfg *buf, int buf_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) return usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x33,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) USB_TYPE_VENDOR | USB_DIR_IN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) USB_RECIP_INTERFACE, 0x0902, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) buf, buf_size, USB_CTRL_GET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) /* Get the hardware configuration for the adapter and put it to the appropriate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) * fields of 'priv' (the GetHWConfig request and interpretation of the result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) * depends on the board type) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) static int at76_get_hw_config(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) union at76_hwcfg *hwcfg = kmalloc(sizeof(*hwcfg), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) if (!hwcfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) if (at76_is_intersil(priv->board_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) ret = at76_get_hw_cfg_intersil(priv->udev, hwcfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) sizeof(hwcfg->i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) memcpy(priv->mac_addr, hwcfg->i.mac_addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) priv->regulatory_domain = hwcfg->i.regulatory_domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) } else if (at76_is_503rfmd(priv->board_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) ret = at76_get_hw_cfg(priv->udev, hwcfg, sizeof(hwcfg->r3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) memcpy(priv->mac_addr, hwcfg->r3.mac_addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) priv->regulatory_domain = hwcfg->r3.regulatory_domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) ret = at76_get_hw_cfg(priv->udev, hwcfg, sizeof(hwcfg->r5));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) memcpy(priv->mac_addr, hwcfg->r5.mac_addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) priv->regulatory_domain = hwcfg->r5.regulatory_domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) kfree(hwcfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) wiphy_err(priv->hw->wiphy, "cannot get HW Config (error %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) static struct reg_domain const *at76_get_reg_domain(u16 code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) static struct reg_domain const fd_tab[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) { 0x10, "FCC (USA)", 0x7ff }, /* ch 1-11 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) { 0x20, "IC (Canada)", 0x7ff }, /* ch 1-11 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) { 0x30, "ETSI (most of Europe)", 0x1fff }, /* ch 1-13 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) { 0x31, "Spain", 0x600 }, /* ch 10-11 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) { 0x32, "France", 0x1e00 }, /* ch 10-13 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) { 0x40, "MKK (Japan)", 0x2000 }, /* ch 14 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) { 0x41, "MKK1 (Japan)", 0x3fff }, /* ch 1-14 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) { 0x50, "Israel", 0x3fc }, /* ch 3-9 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) { 0x00, "<unknown>", 0xffffffff } /* ch 1-32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) /* Last entry is fallback for unknown domain code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) for (i = 0; i < ARRAY_SIZE(fd_tab) - 1; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (code == fd_tab[i].code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) return &fd_tab[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) static inline int at76_get_mib(struct usb_device *udev, u16 mib, void *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) int buf_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x33,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) USB_TYPE_VENDOR | USB_DIR_IN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) USB_RECIP_INTERFACE, mib << 8, 0, buf, buf_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) USB_CTRL_GET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) if (ret >= 0 && ret != buf_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) /* Return positive number for status, negative for an error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) static inline int at76_get_cmd_status(struct usb_device *udev, u8 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) u8 *stat_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) stat_buf = kmalloc(40, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) if (!stat_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x22,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) USB_TYPE_VENDOR | USB_DIR_IN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) USB_RECIP_INTERFACE, cmd, 0, stat_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 40, USB_CTRL_GET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) ret = stat_buf[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) kfree(stat_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) #define MAKE_CMD_CASE(c) case (c): return #c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) static const char *at76_get_cmd_string(u8 cmd_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) switch (cmd_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) MAKE_CMD_CASE(CMD_SET_MIB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) MAKE_CMD_CASE(CMD_GET_MIB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) MAKE_CMD_CASE(CMD_SCAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) MAKE_CMD_CASE(CMD_JOIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) MAKE_CMD_CASE(CMD_START_IBSS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) MAKE_CMD_CASE(CMD_RADIO_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) MAKE_CMD_CASE(CMD_RADIO_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) MAKE_CMD_CASE(CMD_STARTUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) return "UNKNOWN";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) static int at76_set_card_command(struct usb_device *udev, u8 cmd, void *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) int buf_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) struct at76_command *cmd_buf = kmalloc(sizeof(struct at76_command) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) buf_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) if (!cmd_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) cmd_buf->cmd = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) cmd_buf->reserved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) cmd_buf->size = cpu_to_le16(buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) memcpy(cmd_buf->data, buf, buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) at76_dbg_dump(DBG_CMD, cmd_buf, sizeof(struct at76_command) + buf_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) "issuing command %s (0x%02x)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) at76_get_cmd_string(cmd), cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x0e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 0, 0, cmd_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) sizeof(struct at76_command) + buf_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) USB_CTRL_GET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) kfree(cmd_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) #define MAKE_CMD_STATUS_CASE(c) case (c): return #c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) static const char *at76_get_cmd_status_string(u8 cmd_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) switch (cmd_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) MAKE_CMD_STATUS_CASE(CMD_STATUS_IDLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) MAKE_CMD_STATUS_CASE(CMD_STATUS_COMPLETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) MAKE_CMD_STATUS_CASE(CMD_STATUS_UNKNOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) MAKE_CMD_STATUS_CASE(CMD_STATUS_INVALID_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) MAKE_CMD_STATUS_CASE(CMD_STATUS_FUNCTION_NOT_SUPPORTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) MAKE_CMD_STATUS_CASE(CMD_STATUS_TIME_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) MAKE_CMD_STATUS_CASE(CMD_STATUS_IN_PROGRESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) MAKE_CMD_STATUS_CASE(CMD_STATUS_HOST_FAILURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) MAKE_CMD_STATUS_CASE(CMD_STATUS_SCAN_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) return "UNKNOWN";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) /* Wait until the command is completed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) static int at76_wait_completion(struct at76_priv *priv, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) unsigned long timeout = jiffies + CMD_COMPLETION_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) status = at76_get_cmd_status(priv->udev, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) "at76_get_cmd_status failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) at76_dbg(DBG_WAIT_COMPLETE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) "%s: Waiting on cmd %d, status = %d (%s)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) wiphy_name(priv->hw->wiphy), cmd, status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) at76_get_cmd_status_string(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) if (status != CMD_STATUS_IN_PROGRESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) && status != CMD_STATUS_IDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) schedule_timeout_interruptible(HZ / 10); /* 100 ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) if (time_after(jiffies, timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) "completion timeout for command %d\n", cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) status = -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) } while (1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) static int at76_set_mib(struct at76_priv *priv, struct set_mib_buffer *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) ret = at76_set_card_command(priv->udev, CMD_SET_MIB, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) offsetof(struct set_mib_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) data) + buf->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) ret = at76_wait_completion(priv, CMD_SET_MIB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) if (ret != CMD_STATUS_COMPLETE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) wiphy_info(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) "set_mib: at76_wait_completion failed with %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) /* Return < 0 on error, == 0 if no command sent, == 1 if cmd sent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) static int at76_set_radio(struct at76_priv *priv, int enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) int cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) if (priv->radio_on == enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) cmd = enable ? CMD_RADIO_ON : CMD_RADIO_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) ret = at76_set_card_command(priv->udev, cmd, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) "at76_set_card_command(%d) failed: %d\n", cmd, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) priv->radio_on = enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) /* Set current power save mode (AT76_PM_OFF/AT76_PM_ON/AT76_PM_SMART) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) static int at76_set_pm_mode(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) priv->mib_buf.type = MIB_MAC_MGMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) priv->mib_buf.size = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) priv->mib_buf.index = offsetof(struct mib_mac_mgmt, power_mgmt_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) priv->mib_buf.data.byte = priv->pm_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) ret = at76_set_mib(priv, &priv->mib_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) wiphy_err(priv->hw->wiphy, "set_mib (pm_mode) failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) static int at76_set_preamble(struct at76_priv *priv, u8 type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) priv->mib_buf.type = MIB_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) priv->mib_buf.size = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) priv->mib_buf.index = offsetof(struct mib_local, preamble_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) priv->mib_buf.data.byte = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) ret = at76_set_mib(priv, &priv->mib_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) wiphy_err(priv->hw->wiphy, "set_mib (preamble) failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) static int at76_set_frag(struct at76_priv *priv, u16 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) priv->mib_buf.type = MIB_MAC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) priv->mib_buf.size = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) priv->mib_buf.index = offsetof(struct mib_mac, frag_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) priv->mib_buf.data.word = cpu_to_le16(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) ret = at76_set_mib(priv, &priv->mib_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) "set_mib (frag threshold) failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) static int at76_set_rts(struct at76_priv *priv, u16 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) priv->mib_buf.type = MIB_MAC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) priv->mib_buf.size = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) priv->mib_buf.index = offsetof(struct mib_mac, rts_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) priv->mib_buf.data.word = cpu_to_le16(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) ret = at76_set_mib(priv, &priv->mib_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) wiphy_err(priv->hw->wiphy, "set_mib (rts) failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) static int at76_set_autorate_fallback(struct at76_priv *priv, int onoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) priv->mib_buf.type = MIB_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) priv->mib_buf.size = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) priv->mib_buf.index = offsetof(struct mib_local, txautorate_fallback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) priv->mib_buf.data.byte = onoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) ret = at76_set_mib(priv, &priv->mib_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) "set_mib (autorate fallback) failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) static void at76_dump_mib_mac_addr(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) struct mib_mac_addr *m = kmalloc(sizeof(struct mib_mac_addr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) if (!m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) ret = at76_get_mib(priv->udev, MIB_MAC_ADDR, m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) sizeof(struct mib_mac_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) "at76_get_mib (MAC_ADDR) failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) at76_dbg(DBG_MIB, "%s: MIB MAC_ADDR: mac_addr %pM res 0x%x 0x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) wiphy_name(priv->hw->wiphy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) m->mac_addr, m->res[0], m->res[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) for (i = 0; i < ARRAY_SIZE(m->group_addr); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) at76_dbg(DBG_MIB, "%s: MIB MAC_ADDR: group addr %d: %pM, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) "status %d", wiphy_name(priv->hw->wiphy), i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) m->group_addr[i], m->group_addr_status[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) kfree(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) static void at76_dump_mib_mac_wep(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) int key_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) struct mib_mac_wep *m = kmalloc(sizeof(struct mib_mac_wep), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) if (!m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) ret = at76_get_mib(priv->udev, MIB_MAC_WEP, m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) sizeof(struct mib_mac_wep));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) "at76_get_mib (MAC_WEP) failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: priv_invoked %u def_key_id %u "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) "key_len %u excl_unencr %u wep_icv_err %u wep_excluded %u "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) "encr_level %u key %d", wiphy_name(priv->hw->wiphy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) m->privacy_invoked, m->wep_default_key_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) m->wep_key_mapping_len, m->exclude_unencrypted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) le32_to_cpu(m->wep_icv_error_count),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) le32_to_cpu(m->wep_excluded_count), m->encryption_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) m->wep_default_key_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) key_len = (m->encryption_level == 1) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) for (i = 0; i < WEP_KEYS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %*phD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) wiphy_name(priv->hw->wiphy), i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) key_len, m->wep_default_keyvalue[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) kfree(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) static void at76_dump_mib_mac_mgmt(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) struct mib_mac_mgmt *m = kmalloc(sizeof(struct mib_mac_mgmt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) if (!m)
^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) ret = at76_get_mib(priv->udev, MIB_MAC_MGMT, m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) sizeof(struct mib_mac_mgmt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) "at76_get_mib (MAC_MGMT) failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) at76_dbg(DBG_MIB, "%s: MIB MAC_MGMT: beacon_period %d CFP_max_duration "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) "%d medium_occupancy_limit %d station_id 0x%x ATIM_window %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) "CFP_mode %d privacy_opt_impl %d DTIM_period %d CFP_period %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) "current_bssid %pM current_essid %*phD current_bss_type %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) "pm_mode %d ibss_change %d res %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) "multi_domain_capability_implemented %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) "international_roaming %d country_string %.3s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) wiphy_name(priv->hw->wiphy), le16_to_cpu(m->beacon_period),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) le16_to_cpu(m->CFP_max_duration),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) le16_to_cpu(m->medium_occupancy_limit),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) le16_to_cpu(m->station_id), le16_to_cpu(m->ATIM_window),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) m->CFP_mode, m->privacy_option_implemented, m->DTIM_period,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) m->CFP_period, m->current_bssid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) IW_ESSID_MAX_SIZE, m->current_essid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) m->current_bss_type, m->power_mgmt_mode, m->ibss_change,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) m->res, m->multi_domain_capability_implemented,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) m->multi_domain_capability_enabled, m->country_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) kfree(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) static void at76_dump_mib_mac(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) struct mib_mac *m = kmalloc(sizeof(struct mib_mac), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) if (!m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) ret = at76_get_mib(priv->udev, MIB_MAC, m, sizeof(struct mib_mac));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) "at76_get_mib (MAC) failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) at76_dbg(DBG_MIB, "%s: MIB MAC: max_tx_msdu_lifetime %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) "max_rx_lifetime %d frag_threshold %d rts_threshold %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) "cwmin %d cwmax %d short_retry_time %d long_retry_time %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) "scan_type %d scan_channel %d probe_delay %u "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) "min_channel_time %d max_channel_time %d listen_int %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) "desired_ssid %*phD desired_bssid %pM desired_bsstype %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) wiphy_name(priv->hw->wiphy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) le32_to_cpu(m->max_tx_msdu_lifetime),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) le32_to_cpu(m->max_rx_lifetime),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) le16_to_cpu(m->frag_threshold), le16_to_cpu(m->rts_threshold),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) le16_to_cpu(m->cwmin), le16_to_cpu(m->cwmax),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) m->short_retry_time, m->long_retry_time, m->scan_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) m->scan_channel, le16_to_cpu(m->probe_delay),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) le16_to_cpu(m->min_channel_time),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) le16_to_cpu(m->max_channel_time),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) le16_to_cpu(m->listen_interval),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) IW_ESSID_MAX_SIZE, m->desired_ssid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) m->desired_bssid, m->desired_bsstype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) kfree(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) static void at76_dump_mib_phy(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) struct mib_phy *m = kmalloc(sizeof(struct mib_phy), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) if (!m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) ret = at76_get_mib(priv->udev, MIB_PHY, m, sizeof(struct mib_phy));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) "at76_get_mib (PHY) failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) at76_dbg(DBG_MIB, "%s: MIB PHY: ed_threshold %d slot_time %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) "sifs_time %d preamble_length %d plcp_header_length %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) "mpdu_max_length %d cca_mode_supported %d operation_rate_set "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) "0x%x 0x%x 0x%x 0x%x channel_id %d current_cca_mode %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) "phy_type %d current_reg_domain %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) wiphy_name(priv->hw->wiphy), le32_to_cpu(m->ed_threshold),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) le16_to_cpu(m->slot_time), le16_to_cpu(m->sifs_time),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) le16_to_cpu(m->preamble_length),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) le16_to_cpu(m->plcp_header_length),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) le16_to_cpu(m->mpdu_max_length),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) le16_to_cpu(m->cca_mode_supported), m->operation_rate_set[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) m->operation_rate_set[1], m->operation_rate_set[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) m->operation_rate_set[3], m->channel_id, m->current_cca_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) m->phy_type, m->current_reg_domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) kfree(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) static void at76_dump_mib_local(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) struct mib_local *m = kmalloc(sizeof(*m), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) if (!m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) ret = at76_get_mib(priv->udev, MIB_LOCAL, m, sizeof(*m));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) "at76_get_mib (LOCAL) failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) at76_dbg(DBG_MIB, "%s: MIB LOCAL: beacon_enable %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) "txautorate_fallback %d ssid_size %d promiscuous_mode %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) "preamble_type %d", wiphy_name(priv->hw->wiphy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) m->beacon_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) m->txautorate_fallback, m->ssid_size, m->promiscuous_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) m->preamble_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) kfree(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) static void at76_dump_mib_mdomain(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) struct mib_mdomain *m = kmalloc(sizeof(struct mib_mdomain), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) if (!m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) ret = at76_get_mib(priv->udev, MIB_MDOMAIN, m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) sizeof(struct mib_mdomain));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) "at76_get_mib (MDOMAIN) failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %*phD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) wiphy_name(priv->hw->wiphy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) (int)sizeof(m->channel_list), m->channel_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %*phD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) wiphy_name(priv->hw->wiphy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) (int)sizeof(m->tx_powerlevel), m->tx_powerlevel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) kfree(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) /* Enable monitor mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) static int at76_start_monitor(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) struct at76_req_scan scan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) memset(&scan, 0, sizeof(struct at76_req_scan));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) eth_broadcast_addr(scan.bssid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) scan.channel = priv->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) scan.scan_type = SCAN_TYPE_PASSIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) scan.international_scan = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) scan.min_channel_time = cpu_to_le16(priv->scan_min_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) scan.max_channel_time = cpu_to_le16(priv->scan_max_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) scan.probe_delay = cpu_to_le16(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) ret = at76_set_card_command(priv->udev, CMD_SCAN, &scan, sizeof(scan));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) ret = at76_get_cmd_status(priv->udev, CMD_SCAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) /* Calculate padding from txbuf->wlength (which excludes the USB TX header),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) likely to compensate a flaw in the AT76C503A USB part ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) static inline int at76_calc_padding(int wlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) /* add the USB TX header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) wlen += AT76_TX_HDRLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) wlen = wlen % 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) if (wlen < 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) return 50 - wlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) if (wlen >= 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) return 64 + 50 - wlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) static void at76_rx_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) struct at76_priv *priv = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) tasklet_schedule(&priv->rx_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) static int at76_submit_rx_urb(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) struct sk_buff *skb = priv->rx_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) if (!priv->rx_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) wiphy_err(priv->hw->wiphy, "%s: priv->rx_urb is NULL\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) skb = dev_alloc_skb(sizeof(struct at76_rx_buffer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) "cannot allocate rx skbuff\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) priv->rx_skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) skb_push(skb, skb_headroom(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) skb_trim(skb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) size = skb_tailroom(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) usb_fill_bulk_urb(priv->rx_urb, priv->udev, priv->rx_pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) skb_put(skb, size), size, at76_rx_callback, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) ret = usb_submit_urb(priv->rx_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) if (ret == -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) at76_dbg(DBG_DEVSTART,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) "usb_submit_urb returned -ENODEV");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) "rx, usb_submit_urb failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) if (ret < 0 && ret != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) "cannot submit rx urb - please unload the driver and/or power cycle the device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) /* Download external firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) static int at76_load_external_fw(struct usb_device *udev, struct fwentry *fwe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) int op_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) int blockno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) int bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) u8 *block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) u8 *buf = fwe->extfw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) int size = fwe->extfw_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) if (!buf || !size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) op_mode = at76_get_op_mode(udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) at76_dbg(DBG_DEVSTART, "opmode %d", op_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) if (op_mode != OPMODE_NORMAL_NIC_WITHOUT_FLASH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) dev_err(&udev->dev, "unexpected opmode %d\n", op_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) block = kmalloc(FW_BLOCK_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) if (!block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) at76_dbg(DBG_DEVSTART, "downloading external firmware");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) /* for fw >= 0.100, the device needs an extra empty block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) bsize = min_t(int, size, FW_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) memcpy(block, buf, bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) at76_dbg(DBG_DEVSTART,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) "ext fw, size left = %5d, bsize = %4d, blockno = %2d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) size, bsize, blockno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) ret = at76_load_ext_fw_block(udev, blockno, block, bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) if (ret != bsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) dev_err(&udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) "loading %dth firmware block failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) blockno, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) buf += bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) size -= bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) blockno++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) } while (bsize > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) if (at76_is_505a(fwe->board_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) at76_dbg(DBG_DEVSTART, "200 ms delay for 505a");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) schedule_timeout_interruptible(HZ / 5 + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) kfree(block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) dev_err(&udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) "downloading external firmware failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) /* Download internal firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) static int at76_load_internal_fw(struct usb_device *udev, struct fwentry *fwe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) int need_remap = !at76_is_505a(fwe->board_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) ret = at76_usbdfu_download(udev, fwe->intfw, fwe->intfw_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) need_remap ? 0 : 2 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) dev_err(&udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) "downloading internal fw failed with %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) at76_dbg(DBG_DEVSTART, "sending REMAP");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) /* no REMAP for 505A (see SF driver) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) if (need_remap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) ret = at76_remap(udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) dev_err(&udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) "sending REMAP failed with %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) at76_dbg(DBG_DEVSTART, "sleeping for 2 seconds");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) schedule_timeout_interruptible(2 * HZ + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) usb_reset_device(udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) return ret;
^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 at76_startup_device(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) struct at76_card_config *ccfg = &priv->card_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) at76_dbg(DBG_PARAMS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) "%s param: ssid %.*s (%*phD) mode %s ch %d wep %s key %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) "keylen %d", wiphy_name(priv->hw->wiphy), priv->essid_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) priv->essid, IW_ESSID_MAX_SIZE, priv->essid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) priv->iw_mode == IW_MODE_ADHOC ? "adhoc" : "infra",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) priv->channel, priv->wep_enabled ? "enabled" : "disabled",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) priv->wep_key_id, priv->wep_keys_len[priv->wep_key_id]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) at76_dbg(DBG_PARAMS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) "%s param: preamble %s rts %d retry %d frag %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) "txrate %s auth_mode %d", wiphy_name(priv->hw->wiphy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) preambles[priv->preamble_type], priv->rts_threshold,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) priv->short_retry_limit, priv->frag_threshold,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) priv->txrate == TX_RATE_1MBIT ? "1MBit" : priv->txrate ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) TX_RATE_2MBIT ? "2MBit" : priv->txrate ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) TX_RATE_5_5MBIT ? "5.5MBit" : priv->txrate ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) TX_RATE_11MBIT ? "11MBit" : priv->txrate ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) TX_RATE_AUTO ? "auto" : "<invalid>", priv->auth_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) at76_dbg(DBG_PARAMS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) "%s param: pm_mode %d pm_period %d auth_mode %s "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) "scan_times %d %d scan_mode %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) wiphy_name(priv->hw->wiphy), priv->pm_mode, priv->pm_period,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) priv->auth_mode == WLAN_AUTH_OPEN ? "open" : "shared_secret",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) priv->scan_min_time, priv->scan_max_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) priv->scan_mode == SCAN_TYPE_ACTIVE ? "active" : "passive");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) memset(ccfg, 0, sizeof(struct at76_card_config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) ccfg->promiscuous_mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) ccfg->short_retry_limit = priv->short_retry_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) if (priv->wep_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) if (priv->wep_keys_len[priv->wep_key_id] > WEP_SMALL_KEY_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) ccfg->encryption_type = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) ccfg->encryption_type = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) /* jal: always exclude unencrypted if WEP is active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) ccfg->exclude_unencrypted = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) ccfg->exclude_unencrypted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) ccfg->encryption_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) ccfg->rts_threshold = cpu_to_le16(priv->rts_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) ccfg->fragmentation_threshold = cpu_to_le16(priv->frag_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) memcpy(ccfg->basic_rate_set, hw_rates, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) /* jal: really needed, we do a set_mib for autorate later ??? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) ccfg->auto_rate_fallback = (priv->txrate == TX_RATE_AUTO ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) ccfg->channel = priv->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) ccfg->privacy_invoked = priv->wep_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) memcpy(ccfg->current_ssid, priv->essid, IW_ESSID_MAX_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) ccfg->ssid_len = priv->essid_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) ccfg->wep_default_key_id = priv->wep_key_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) memcpy(ccfg->wep_default_key_value, priv->wep_keys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) sizeof(priv->wep_keys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) ccfg->short_preamble = priv->preamble_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) ccfg->beacon_period = cpu_to_le16(priv->beacon_period);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) ret = at76_set_card_command(priv->udev, CMD_STARTUP, &priv->card_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) sizeof(struct at76_card_config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) wiphy_err(priv->hw->wiphy, "at76_set_card_command failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) at76_wait_completion(priv, CMD_STARTUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) /* remove BSSID from previous run */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) eth_zero_addr(priv->bssid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) priv->scanning = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) if (at76_set_radio(priv, 1) == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) at76_wait_completion(priv, CMD_RADIO_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) ret = at76_set_preamble(priv, priv->preamble_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) ret = at76_set_frag(priv, priv->frag_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) ret = at76_set_rts(priv, priv->rts_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) ret = at76_set_autorate_fallback(priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) priv->txrate == TX_RATE_AUTO ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) ret = at76_set_pm_mode(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) if (at76_debug & DBG_MIB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) at76_dump_mib_mac(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) at76_dump_mib_mac_addr(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) at76_dump_mib_mac_mgmt(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) at76_dump_mib_mac_wep(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) at76_dump_mib_mdomain(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) at76_dump_mib_phy(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) at76_dump_mib_local(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) /* Enable or disable promiscuous mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) static void at76_work_set_promisc(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) struct at76_priv *priv = container_of(work, struct at76_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) work_set_promisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) if (priv->device_unplugged)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) mutex_lock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) priv->mib_buf.type = MIB_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) priv->mib_buf.size = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) priv->mib_buf.index = offsetof(struct mib_local, promiscuous_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) priv->mib_buf.data.byte = priv->promisc ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) ret = at76_set_mib(priv, &priv->mib_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) "set_mib (promiscuous_mode) failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) mutex_unlock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) /* Submit Rx urb back to the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) static void at76_work_submit_rx(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) struct at76_priv *priv = container_of(work, struct at76_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) work_submit_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) mutex_lock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) at76_submit_rx_urb(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) mutex_unlock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) /* This is a workaround to make scan working:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) * currently mac80211 does not process frames with no frequency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) * information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) * However during scan the HW performs a sweep by itself, and we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) * are unable to know where the radio is actually tuned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) * This function tries to do its best to guess this information..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) * During scan, If the current frame is a beacon or a probe response,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) * the channel information is extracted from it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) * When not scanning, for other frames, or if it happens that for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) * whatever reason we fail to parse beacons and probe responses, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) * function returns the priv->channel information, that should be correct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) * at least when we are not scanning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) static inline int at76_guess_freq(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) size_t el_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) const u8 *el;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) int channel = priv->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) int len = priv->rx_skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) struct ieee80211_hdr *hdr = (void *)priv->rx_skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) if (!priv->scanning)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) if (len < 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) if (ieee80211_is_probe_resp(hdr->frame_control)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) el_off = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) el = ((struct ieee80211_mgmt *)hdr)->u.probe_resp.variable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) } else if (ieee80211_is_beacon(hdr->frame_control)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) el_off = offsetof(struct ieee80211_mgmt, u.beacon.variable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) el = ((struct ieee80211_mgmt *)hdr)->u.beacon.variable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) len -= el_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) el = cfg80211_find_ie(WLAN_EID_DS_PARAMS, el, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) if (el && el[1] > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) channel = el[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) return ieee80211_channel_to_frequency(channel, NL80211_BAND_2GHZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) static void at76_rx_tasklet(struct tasklet_struct *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) struct at76_priv *priv = from_tasklet(priv, t, rx_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) struct urb *urb = priv->rx_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) struct at76_rx_buffer *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) struct ieee80211_rx_status rx_status = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) if (priv->device_unplugged) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) at76_dbg(DBG_DEVSTART, "device unplugged");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) at76_dbg(DBG_DEVSTART, "urb status %d", urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) if (!priv->rx_skb || !priv->rx_skb->data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) buf = (struct at76_rx_buffer *)priv->rx_skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) if (urb->status != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) if (urb->status != -ENOENT && urb->status != -ECONNRESET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) at76_dbg(DBG_URB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) "%s %s: - nonzero Rx bulk status received: %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) __func__, wiphy_name(priv->hw->wiphy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) at76_dbg(DBG_RX_ATMEL_HDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) "%s: rx frame: rate %d rssi %d noise %d link %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) wiphy_name(priv->hw->wiphy), buf->rx_rate, buf->rssi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) buf->noise_level, buf->link_quality);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) skb_pull(priv->rx_skb, AT76_RX_HDRLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) skb_trim(priv->rx_skb, le16_to_cpu(buf->wlength));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) at76_dbg_dump(DBG_RX_DATA, priv->rx_skb->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) priv->rx_skb->len, "RX: len=%d", priv->rx_skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) rx_status.signal = buf->rssi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) rx_status.flag |= RX_FLAG_DECRYPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) rx_status.flag |= RX_FLAG_IV_STRIPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) rx_status.band = NL80211_BAND_2GHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) rx_status.freq = at76_guess_freq(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) at76_dbg(DBG_MAC80211, "calling ieee80211_rx_irqsafe(): %d/%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) priv->rx_skb->len, priv->rx_skb->data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) memcpy(IEEE80211_SKB_RXCB(priv->rx_skb), &rx_status, sizeof(rx_status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) ieee80211_rx_irqsafe(priv->hw, priv->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) /* Use a new skb for the next receive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) priv->rx_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) at76_submit_rx_urb(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) /* Load firmware into kernel memory and parse it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) static struct fwentry *at76_load_firmware(struct usb_device *udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) enum board_type board_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) char *str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) struct at76_fw_header *fwh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) struct fwentry *fwe = &firmwares[board_type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) mutex_lock(&fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) if (fwe->loaded) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) at76_dbg(DBG_FW, "re-using previously loaded fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) at76_dbg(DBG_FW, "downloading firmware %s", fwe->fwname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) ret = request_firmware(&fwe->fw, fwe->fwname, &udev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) dev_err(&udev->dev, "firmware %s not found!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) fwe->fwname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) dev_err(&udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) "you may need to download the firmware from http://developer.berlios.de/projects/at76c503a/\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) at76_dbg(DBG_FW, "got it.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) fwh = (struct at76_fw_header *)(fwe->fw->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) if (fwe->fw->size <= sizeof(*fwh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) dev_err(&udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) "firmware is too short (0x%zx)\n", fwe->fw->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) /* CRC currently not checked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) fwe->board_type = le32_to_cpu(fwh->board_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) if (fwe->board_type != board_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) dev_err(&udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) "board type mismatch, requested %u, got %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) board_type, fwe->board_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) fwe->fw_version.major = fwh->major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) fwe->fw_version.minor = fwh->minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) fwe->fw_version.patch = fwh->patch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) fwe->fw_version.build = fwh->build;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) str = (char *)fwh + le32_to_cpu(fwh->str_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) fwe->intfw = (u8 *)fwh + le32_to_cpu(fwh->int_fw_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) fwe->intfw_size = le32_to_cpu(fwh->int_fw_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) fwe->extfw = (u8 *)fwh + le32_to_cpu(fwh->ext_fw_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) fwe->extfw_size = le32_to_cpu(fwh->ext_fw_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) fwe->loaded = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) dev_printk(KERN_DEBUG, &udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) "using firmware %s (version %d.%d.%d-%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) fwe->fwname, fwh->major, fwh->minor, fwh->patch, fwh->build);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) at76_dbg(DBG_DEVSTART, "board %u, int %d:%d, ext %d:%d", board_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) le32_to_cpu(fwh->int_fw_offset), le32_to_cpu(fwh->int_fw_len),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) le32_to_cpu(fwh->ext_fw_offset), le32_to_cpu(fwh->ext_fw_len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) at76_dbg(DBG_DEVSTART, "firmware id %s", str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) mutex_unlock(&fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) if (fwe->loaded)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) return fwe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) static int at76_join(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) struct at76_req_join join;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) memset(&join, 0, sizeof(struct at76_req_join));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) memcpy(join.essid, priv->essid, priv->essid_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) join.essid_size = priv->essid_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) memcpy(join.bssid, priv->bssid, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) join.bss_type = INFRASTRUCTURE_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) join.channel = priv->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) join.timeout = cpu_to_le16(2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) at76_dbg(DBG_MAC80211, "%s: sending CMD_JOIN", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) ret = at76_set_card_command(priv->udev, CMD_JOIN, &join,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) sizeof(struct at76_req_join));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) wiphy_err(priv->hw->wiphy, "at76_set_card_command failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) ret = at76_wait_completion(priv, CMD_JOIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) at76_dbg(DBG_MAC80211, "%s: CMD_JOIN returned: 0x%02x", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) if (ret != CMD_STATUS_COMPLETE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) wiphy_err(priv->hw->wiphy, "at76_wait_completion failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) at76_set_pm_mode(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) static void at76_work_join_bssid(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) struct at76_priv *priv = container_of(work, struct at76_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) work_join_bssid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) if (priv->device_unplugged)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) mutex_lock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) if (is_valid_ether_addr(priv->bssid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) at76_join(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) mutex_unlock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) static void at76_mac80211_tx_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) struct at76_priv *priv = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) struct ieee80211_tx_info *info = IEEE80211_SKB_CB(priv->tx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) at76_dbg(DBG_MAC80211, "%s()", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) switch (urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) /* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) info->flags |= IEEE80211_TX_STAT_ACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) /* fail, urb has been unlinked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) /* FIXME: add error message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) at76_dbg(DBG_URB, "%s - nonzero tx status received: %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) __func__, urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) memset(&info->status, 0, sizeof(info->status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) ieee80211_tx_status_irqsafe(priv->hw, priv->tx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) priv->tx_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) ieee80211_wake_queues(priv->hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) static void at76_mac80211_tx(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) struct ieee80211_tx_control *control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) struct at76_priv *priv = hw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) struct at76_tx_buffer *tx_buffer = priv->bulk_out_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) int padding, submit_len, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) at76_dbg(DBG_MAC80211, "%s()", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) if (priv->tx_urb->status == -EINPROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) "%s called while tx urb is pending\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) dev_kfree_skb_any(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) /* The following code lines are important when the device is going to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) * authenticate with a new bssid. The driver must send CMD_JOIN before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) * an authentication frame is transmitted. For this to succeed, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) * correct bssid of the AP must be known. As mac80211 does not inform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) * drivers about the bssid prior to the authentication process the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) * following workaround is necessary. If the TX frame is an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) * authentication frame extract the bssid and send the CMD_JOIN. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) if (mgmt->frame_control & cpu_to_le16(IEEE80211_STYPE_AUTH)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) if (!ether_addr_equal_64bits(priv->bssid, mgmt->bssid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) memcpy(priv->bssid, mgmt->bssid, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) ieee80211_queue_work(hw, &priv->work_join_bssid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) dev_kfree_skb_any(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) ieee80211_stop_queues(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) at76_ledtrig_tx_activity(); /* tell ledtrigger we send a packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) WARN_ON(priv->tx_skb != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) priv->tx_skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) padding = at76_calc_padding(skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) submit_len = AT76_TX_HDRLEN + skb->len + padding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) /* setup 'Atmel' header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) memset(tx_buffer, 0, sizeof(*tx_buffer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) tx_buffer->padding = padding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) tx_buffer->wlength = cpu_to_le16(skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) tx_buffer->tx_rate = ieee80211_get_tx_rate(hw, info)->hw_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) memset(tx_buffer->reserved, 0, sizeof(tx_buffer->reserved));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) memcpy(tx_buffer->packet, skb->data, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) at76_dbg(DBG_TX_DATA, "%s tx: wlen 0x%x pad 0x%x rate %d hdr",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) wiphy_name(priv->hw->wiphy), le16_to_cpu(tx_buffer->wlength),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) tx_buffer->padding, tx_buffer->tx_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) /* send stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) at76_dbg_dump(DBG_TX_DATA_CONTENT, tx_buffer, submit_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) "%s(): tx_buffer %d bytes:", __func__, submit_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) usb_fill_bulk_urb(priv->tx_urb, priv->udev, priv->tx_pipe, tx_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) submit_len, at76_mac80211_tx_callback, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) ret = usb_submit_urb(priv->tx_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) wiphy_err(priv->hw->wiphy, "error in tx submit urb: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) if (ret == -EINVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) "-EINVAL: tx urb %p hcpriv %p complete %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) priv->tx_urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) priv->tx_urb->hcpriv, priv->tx_urb->complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) static int at76_mac80211_start(struct ieee80211_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) struct at76_priv *priv = hw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) at76_dbg(DBG_MAC80211, "%s()", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) mutex_lock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) ret = at76_submit_rx_urb(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) wiphy_err(priv->hw->wiphy, "open: submit_rx_urb failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) at76_startup_device(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) at76_start_monitor(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) mutex_unlock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) static void at76_mac80211_stop(struct ieee80211_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) struct at76_priv *priv = hw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) at76_dbg(DBG_MAC80211, "%s()", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) cancel_delayed_work(&priv->dwork_hw_scan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) cancel_work_sync(&priv->work_join_bssid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) cancel_work_sync(&priv->work_set_promisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) mutex_lock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) if (!priv->device_unplugged) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) /* We are called by "ifconfig ethX down", not because the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) * device is not available anymore. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) at76_set_radio(priv, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) /* We unlink rx_urb because at76_open() re-submits it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) * If unplugged, at76_delete_device() takes care of it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) usb_kill_urb(priv->rx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) mutex_unlock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) static int at76_add_interface(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) struct ieee80211_vif *vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) struct at76_priv *priv = hw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) at76_dbg(DBG_MAC80211, "%s()", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) mutex_lock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) switch (vif->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) priv->iw_mode = IW_MODE_INFRA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) mutex_unlock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) static void at76_remove_interface(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) struct ieee80211_vif *vif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) at76_dbg(DBG_MAC80211, "%s()", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) static void at76_dwork_hw_scan(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) struct at76_priv *priv = container_of(work, struct at76_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) dwork_hw_scan.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) struct cfg80211_scan_info info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) .aborted = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) if (priv->device_unplugged)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) mutex_lock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) ret = at76_get_cmd_status(priv->udev, CMD_SCAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) at76_dbg(DBG_MAC80211, "%s: CMD_SCAN status 0x%02x", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) /* FIXME: add maximum time for scan to complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) if (ret != CMD_STATUS_COMPLETE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) ieee80211_queue_delayed_work(priv->hw, &priv->dwork_hw_scan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) SCAN_POLL_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) mutex_unlock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) if (is_valid_ether_addr(priv->bssid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) at76_join(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) priv->scanning = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) mutex_unlock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) ieee80211_scan_completed(priv->hw, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) ieee80211_wake_queues(priv->hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) static int at76_hw_scan(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) struct ieee80211_vif *vif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) struct ieee80211_scan_request *hw_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) struct cfg80211_scan_request *req = &hw_req->req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) struct at76_priv *priv = hw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) struct at76_req_scan scan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) u8 *ssid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) int ret, len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) at76_dbg(DBG_MAC80211, "%s():", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) if (priv->device_unplugged)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) mutex_lock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) ieee80211_stop_queues(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) memset(&scan, 0, sizeof(struct at76_req_scan));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) eth_broadcast_addr(scan.bssid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) if (req->n_ssids) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) scan.scan_type = SCAN_TYPE_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) ssid = req->ssids[0].ssid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) len = req->ssids[0].ssid_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) scan.scan_type = SCAN_TYPE_PASSIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) if (len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) memcpy(scan.essid, ssid, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) scan.essid_size = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) scan.min_channel_time = cpu_to_le16(priv->scan_min_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) scan.max_channel_time = cpu_to_le16(priv->scan_max_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) scan.probe_delay = cpu_to_le16(priv->scan_min_time * 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) scan.international_scan = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) at76_dbg(DBG_MAC80211, "%s: sending CMD_SCAN", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) ret = at76_set_card_command(priv->udev, CMD_SCAN, &scan, sizeof(scan));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) wiphy_err(priv->hw->wiphy, "CMD_SCAN failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) priv->scanning = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) ieee80211_queue_delayed_work(priv->hw, &priv->dwork_hw_scan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) SCAN_POLL_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) mutex_unlock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) static int at76_config(struct ieee80211_hw *hw, u32 changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) struct at76_priv *priv = hw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) at76_dbg(DBG_MAC80211, "%s(): channel %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) __func__, hw->conf.chandef.chan->hw_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) at76_dbg_dump(DBG_MAC80211, priv->bssid, ETH_ALEN, "bssid:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) mutex_lock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) priv->channel = hw->conf.chandef.chan->hw_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) if (is_valid_ether_addr(priv->bssid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) at76_join(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) at76_start_monitor(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) mutex_unlock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) static void at76_bss_info_changed(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) struct ieee80211_vif *vif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) struct ieee80211_bss_conf *conf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) u32 changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) struct at76_priv *priv = hw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) at76_dbg(DBG_MAC80211, "%s():", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) if (!(changed & BSS_CHANGED_BSSID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) at76_dbg_dump(DBG_MAC80211, conf->bssid, ETH_ALEN, "bssid:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) mutex_lock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) memcpy(priv->bssid, conf->bssid, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) if (is_valid_ether_addr(priv->bssid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) /* mac80211 is joining a bss */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) at76_join(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) mutex_unlock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) /* must be atomic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) static void at76_configure_filter(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) unsigned int changed_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) unsigned int *total_flags, u64 multicast)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) struct at76_priv *priv = hw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) at76_dbg(DBG_MAC80211, "%s(): changed_flags=0x%08x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) "total_flags=0x%08x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) __func__, changed_flags, *total_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) flags = changed_flags & AT76_SUPPORTED_FILTERS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) *total_flags = AT76_SUPPORTED_FILTERS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) /* Bail out after updating flags to prevent a WARN_ON in mac80211. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) if (priv->device_unplugged)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) /* FIXME: access to priv->promisc should be protected with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) * priv->mtx, but it's impossible because this function needs to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) * atomic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) if (flags && !priv->promisc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) /* mac80211 wants us to enable promiscuous mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) priv->promisc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) } else if (!flags && priv->promisc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) /* we need to disable promiscuous mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) priv->promisc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) ieee80211_queue_work(hw, &priv->work_set_promisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) static int at76_set_wep(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) struct mib_mac_wep *mib_data = &priv->mib_buf.data.wep_mib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) priv->mib_buf.type = MIB_MAC_WEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) priv->mib_buf.size = sizeof(struct mib_mac_wep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) priv->mib_buf.index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) memset(mib_data, 0, sizeof(*mib_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) if (priv->wep_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) if (priv->wep_keys_len[priv->wep_key_id] > WEP_SMALL_KEY_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) mib_data->encryption_level = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) mib_data->encryption_level = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) /* always exclude unencrypted if WEP is active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) mib_data->exclude_unencrypted = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) mib_data->exclude_unencrypted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) mib_data->encryption_level = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) mib_data->privacy_invoked = priv->wep_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) mib_data->wep_default_key_id = priv->wep_key_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) memcpy(mib_data->wep_default_keyvalue, priv->wep_keys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) sizeof(priv->wep_keys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) ret = at76_set_mib(priv, &priv->mib_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) wiphy_err(priv->hw->wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) "set_mib (wep) failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) static int at76_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) struct ieee80211_vif *vif, struct ieee80211_sta *sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) struct ieee80211_key_conf *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) struct at76_priv *priv = hw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) at76_dbg(DBG_MAC80211, "%s(): cmd %d key->cipher %d key->keyidx %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) "key->keylen %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) __func__, cmd, key->cipher, key->keyidx, key->keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) if ((key->cipher != WLAN_CIPHER_SUITE_WEP40) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) (key->cipher != WLAN_CIPHER_SUITE_WEP104))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) key->hw_key_idx = key->keyidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) mutex_lock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) case SET_KEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) memcpy(priv->wep_keys[key->keyidx], key->key, key->keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) priv->wep_keys_len[key->keyidx] = key->keylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) /* FIXME: find out how to do this properly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) priv->wep_key_id = key->keyidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) case DISABLE_KEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) priv->wep_keys_len[key->keyidx] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) priv->wep_enabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) for (i = 0; i < WEP_KEYS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) if (priv->wep_keys_len[i] != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) priv->wep_enabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) at76_set_wep(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) mutex_unlock(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) static const struct ieee80211_ops at76_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) .tx = at76_mac80211_tx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) .add_interface = at76_add_interface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) .remove_interface = at76_remove_interface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) .config = at76_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) .bss_info_changed = at76_bss_info_changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) .configure_filter = at76_configure_filter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) .start = at76_mac80211_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) .stop = at76_mac80211_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) .hw_scan = at76_hw_scan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) .set_key = at76_set_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) /* Allocate network device and initialize private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) static struct at76_priv *at76_alloc_new_device(struct usb_device *udev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) struct ieee80211_hw *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) struct at76_priv *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) hw = ieee80211_alloc_hw(sizeof(struct at76_priv), &at76_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) if (!hw) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) printk(KERN_ERR DRIVER_NAME ": could not register"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) " ieee80211_hw\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) priv = hw->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) priv->hw = hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) priv->udev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) mutex_init(&priv->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) INIT_WORK(&priv->work_set_promisc, at76_work_set_promisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) INIT_WORK(&priv->work_submit_rx, at76_work_submit_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) INIT_WORK(&priv->work_join_bssid, at76_work_join_bssid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) INIT_DELAYED_WORK(&priv->dwork_hw_scan, at76_dwork_hw_scan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) tasklet_setup(&priv->rx_tasklet, at76_rx_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) priv->pm_mode = AT76_PM_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) priv->pm_period = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) /* unit us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) return priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) static int at76_alloc_urbs(struct at76_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) struct usb_endpoint_descriptor *endpoint, *ep_in, *ep_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) int buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) struct usb_host_interface *iface_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) at76_dbg(DBG_PROC_ENTRY, "%s: ENTER", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) at76_dbg(DBG_URB, "%s: NumEndpoints %d ", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) interface->cur_altsetting->desc.bNumEndpoints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) ep_in = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) ep_out = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) iface_desc = interface->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) endpoint = &iface_desc->endpoint[i].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) at76_dbg(DBG_URB, "%s: %d. endpoint: addr 0x%x attr 0x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) __func__, i, endpoint->bEndpointAddress,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) endpoint->bmAttributes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) if (!ep_in && usb_endpoint_is_bulk_in(endpoint))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) ep_in = endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) if (!ep_out && usb_endpoint_is_bulk_out(endpoint))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) ep_out = endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) if (!ep_in || !ep_out) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) dev_err(&interface->dev, "bulk endpoints missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) priv->rx_pipe = usb_rcvbulkpipe(priv->udev, ep_in->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) priv->tx_pipe = usb_sndbulkpipe(priv->udev, ep_out->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) priv->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) priv->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) if (!priv->rx_urb || !priv->tx_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) dev_err(&interface->dev, "cannot allocate URB\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) buffer_size = sizeof(struct at76_tx_buffer) + MAX_PADDING_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) priv->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) if (!priv->bulk_out_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) at76_dbg(DBG_PROC_ENTRY, "%s: EXIT", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) static struct ieee80211_rate at76_rates[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) { .bitrate = 10, .hw_value = TX_RATE_1MBIT, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) { .bitrate = 20, .hw_value = TX_RATE_2MBIT, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) { .bitrate = 55, .hw_value = TX_RATE_5_5MBIT, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) { .bitrate = 110, .hw_value = TX_RATE_11MBIT, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) static struct ieee80211_channel at76_channels[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) { .center_freq = 2412, .hw_value = 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) { .center_freq = 2417, .hw_value = 2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) { .center_freq = 2422, .hw_value = 3 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) { .center_freq = 2427, .hw_value = 4 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) { .center_freq = 2432, .hw_value = 5 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) { .center_freq = 2437, .hw_value = 6 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) { .center_freq = 2442, .hw_value = 7 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) { .center_freq = 2447, .hw_value = 8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) { .center_freq = 2452, .hw_value = 9 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) { .center_freq = 2457, .hw_value = 10 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) { .center_freq = 2462, .hw_value = 11 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) { .center_freq = 2467, .hw_value = 12 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) { .center_freq = 2472, .hw_value = 13 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) { .center_freq = 2484, .hw_value = 14 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) static struct ieee80211_supported_band at76_supported_band = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) .channels = at76_channels,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) .n_channels = ARRAY_SIZE(at76_channels),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) .bitrates = at76_rates,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) .n_bitrates = ARRAY_SIZE(at76_rates),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) /* Register network device and initialize the hardware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) static int at76_init_new_device(struct at76_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) struct wiphy *wiphy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) /* set up the endpoint information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) /* check out the endpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) at76_dbg(DBG_DEVSTART, "USB interface: %d endpoints",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) interface->cur_altsetting->desc.bNumEndpoints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) ret = at76_alloc_urbs(priv, interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) /* MAC address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) ret = at76_get_hw_config(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) dev_err(&interface->dev, "cannot get MAC address\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) priv->domain = at76_get_reg_domain(priv->regulatory_domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) priv->channel = DEF_CHANNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) priv->iw_mode = IW_MODE_INFRA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) priv->rts_threshold = DEF_RTS_THRESHOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) priv->frag_threshold = DEF_FRAG_THRESHOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) priv->short_retry_limit = DEF_SHORT_RETRY_LIMIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) priv->txrate = TX_RATE_AUTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) priv->preamble_type = PREAMBLE_TYPE_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) priv->beacon_period = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) priv->auth_mode = WLAN_AUTH_OPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) priv->scan_min_time = DEF_SCAN_MIN_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) priv->scan_max_time = DEF_SCAN_MAX_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) priv->scan_mode = SCAN_TYPE_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) priv->device_unplugged = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) /* mac80211 initialisation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) wiphy = priv->hw->wiphy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) priv->hw->wiphy->max_scan_ssids = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) priv->hw->wiphy->max_scan_ie_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) priv->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) priv->hw->wiphy->bands[NL80211_BAND_2GHZ] = &at76_supported_band;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) ieee80211_hw_set(priv->hw, RX_INCLUDES_FCS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) ieee80211_hw_set(priv->hw, SIGNAL_UNSPEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) priv->hw->max_signal = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) SET_IEEE80211_DEV(priv->hw, &interface->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) len = sizeof(wiphy->fw_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) snprintf(wiphy->fw_version, len, "%d.%d.%d-%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) priv->fw_version.major, priv->fw_version.minor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) priv->fw_version.patch, priv->fw_version.build);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) wiphy->hw_version = priv->board_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) ret = ieee80211_register_hw(priv->hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) printk(KERN_ERR "cannot register mac80211 hw (status %d)!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) priv->mac80211_registered = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) wiphy_info(priv->hw->wiphy, "USB %s, MAC %pM, firmware %d.%d.%d-%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) dev_name(&interface->dev), priv->mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) priv->fw_version.major, priv->fw_version.minor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) priv->fw_version.patch, priv->fw_version.build);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) wiphy_info(priv->hw->wiphy, "regulatory domain 0x%02x: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) priv->regulatory_domain, priv->domain->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) static void at76_delete_device(struct at76_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) at76_dbg(DBG_PROC_ENTRY, "%s: ENTER", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) /* The device is gone, don't bother turning it off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) priv->device_unplugged = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) tasklet_kill(&priv->rx_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) if (priv->mac80211_registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) ieee80211_unregister_hw(priv->hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) if (priv->tx_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) usb_kill_urb(priv->tx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) usb_free_urb(priv->tx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) if (priv->rx_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) usb_kill_urb(priv->rx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) usb_free_urb(priv->rx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) at76_dbg(DBG_PROC_ENTRY, "%s: unlinked urbs", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) kfree(priv->bulk_out_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) del_timer_sync(&ledtrig_tx_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) kfree_skb(priv->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) at76_dbg(DBG_PROC_ENTRY, "%s: before freeing priv/ieee80211_hw",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) ieee80211_free_hw(priv->hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) at76_dbg(DBG_PROC_ENTRY, "%s: EXIT", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) static int at76_probe(struct usb_interface *interface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) struct at76_priv *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) struct fwentry *fwe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) int op_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) int need_ext_fw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) struct mib_fw_version *fwv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) int board_type = (int)id->driver_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) udev = usb_get_dev(interface_to_usbdev(interface));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) fwv = kmalloc(sizeof(*fwv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) if (!fwv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) /* Load firmware into kernel memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) fwe = at76_load_firmware(udev, board_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) if (!fwe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) op_mode = at76_get_op_mode(udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) at76_dbg(DBG_DEVSTART, "opmode %d", op_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) /* we get OPMODE_NONE with 2.4.23, SMC2662W-AR ???
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) we get 204 with 2.4.23, Fiberline FL-WL240u (505A+RFMD2958) ??? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) if (op_mode == OPMODE_HW_CONFIG_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) dev_err(&interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) "cannot handle a device in HW_CONFIG_MODE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) if (op_mode != OPMODE_NORMAL_NIC_WITH_FLASH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) && op_mode != OPMODE_NORMAL_NIC_WITHOUT_FLASH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) /* download internal firmware part */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) dev_printk(KERN_DEBUG, &interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) "downloading internal firmware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) ret = at76_load_internal_fw(udev, fwe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) dev_err(&interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) "error %d downloading internal firmware\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) /* Internal firmware already inside the device. Get firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) * version to test if external firmware is loaded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) * This works only for newer firmware, e.g. the Intersil 0.90.x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) * says "control timeout on ep0in" and subsequent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) * at76_get_op_mode() fail too :-( */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) /* if version >= 0.100.x.y or device with built-in flash we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) * query the device for the fw version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) if ((fwe->fw_version.major > 0 || fwe->fw_version.minor >= 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) || (op_mode == OPMODE_NORMAL_NIC_WITH_FLASH)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) ret = at76_get_mib(udev, MIB_FW_VERSION, fwv, sizeof(*fwv));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) if (ret < 0 || (fwv->major | fwv->minor) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) need_ext_fw = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) /* No way to check firmware version, reload to be sure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) need_ext_fw = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) if (need_ext_fw) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) dev_printk(KERN_DEBUG, &interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) "downloading external firmware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) ret = at76_load_external_fw(udev, fwe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) /* Re-check firmware version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) ret = at76_get_mib(udev, MIB_FW_VERSION, fwv, sizeof(*fwv));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) dev_err(&interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) "error %d getting firmware version\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) priv = at76_alloc_new_device(udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) if (!priv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) usb_set_intfdata(interface, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) memcpy(&priv->fw_version, fwv, sizeof(struct mib_fw_version));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) priv->board_type = board_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) ret = at76_init_new_device(priv, interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) at76_delete_device(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) kfree(fwv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) usb_put_dev(udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) static void at76_disconnect(struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) struct at76_priv *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) priv = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) usb_set_intfdata(interface, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) /* Disconnect after loading internal firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) if (!priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) wiphy_info(priv->hw->wiphy, "disconnecting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) at76_delete_device(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) usb_put_dev(priv->udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) dev_info(&interface->dev, "disconnected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) /* Structure for registering this driver with the USB subsystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) static struct usb_driver at76_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) .name = DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) .probe = at76_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) .disconnect = at76_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) .id_table = dev_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) .disable_hub_initiated_lpm = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) static int __init at76_mod_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION " loading\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) mutex_init(&fw_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) /* register this driver with the USB subsystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) result = usb_register(&at76_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) printk(KERN_ERR DRIVER_NAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) ": usb_register failed (status %d)\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) led_trigger_register_simple("at76_usb-tx", &ledtrig_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) static void __exit at76_mod_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION " unloading\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) usb_deregister(&at76_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) for (i = 0; i < ARRAY_SIZE(firmwares); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) release_firmware(firmwares[i].fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) led_trigger_unregister_simple(ledtrig_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) module_param_named(debug, at76_debug, uint, 0600);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) MODULE_PARM_DESC(debug, "Debugging level");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) module_init(at76_mod_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) module_exit(at76_mod_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) MODULE_AUTHOR("Oliver Kurth <oku@masqmail.cx>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) MODULE_AUTHOR("Joerg Albert <joerg.albert@gmx.de>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) MODULE_AUTHOR("Alex <alex@foogod.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) MODULE_AUTHOR("Nick Jones");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) MODULE_AUTHOR("Balint Seeber <n0_5p4m_p13453@hotmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) MODULE_AUTHOR("Guido Guenther <agx@sigxcpu.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) MODULE_AUTHOR("Kalle Valo <kalle.valo@iki.fi>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) MODULE_AUTHOR("Sebastian Smolorz <sesmo@gmx.net>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) MODULE_LICENSE("GPL");