Changes in 4.9.337 mm/khugepaged: fix GUP-fast interaction by sending IPI mm/khugepaged: invoke MMU notifiers in shmem/file collapse paths block: unhash blkdev part inode when the part is deleted ASoC: ops: Check bounds for second channel in snd_soc_put_volsw_sx() can: sja1000: fix size of OCR_MODE_MASK define ASoC: ops: Correct bounds check for second channel on SX controls udf: Discard preallocation before extending file with a hole udf: Drop unused arguments of udf_delete_aext() udf: Fix preallocation discarding at indirect extent boundary udf: Do not bother looking for prealloc extents if i_lenExtents matches i_size udf: Fix extending file within last block usb: gadget: uvc: Prevent buffer overflow in setup handler USB: serial: cp210x: add Kamstrup RF sniffer PIDs Bluetooth: L2CAP: Fix u8 overflow net: loopback: use NET_NAME_PREDICTABLE for name_assign_type drivers: soc: ti: knav_qmss_queue: Mark knav_acc_firmwares as static arm: dts: spear600: Fix clcd interrupt soc: ti: smartreflex: Fix PM disable depth imbalance in omap_sr_probe ARM: dts: dove: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-370: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-xp: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-375: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-38x: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-39x: Fix assigned-addresses for every PCIe Root Port ARM: mmp: fix timer_read delay pstore: Avoid kcore oops by vmap()ing with VM_IOREMAP cpuidle: dt: Return the correct numbers of parsed idle states alpha: fix syscall entry in !AUDUT_SYSCALL case PM: hibernate: Fix mistake in kerneldoc comment fs: don't audit the capability check in simple_xattr_list() perf: Fix possible memleak in pmu_dev_alloc() timerqueue: Use rb_entry_safe() in timerqueue_getnext() ocfs2: fix memory leak in ocfs2_stack_glue_init() MIPS: vpe-mt: fix possible memory leak while module exiting MIPS: vpe-cmp: fix possible memory leak while module exiting PNP: fix name memory leak in pnp_alloc_dev() irqchip: gic-pm: Use pm_runtime_resume_and_get() in gic_probe() libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value lib/notifier-error-inject: fix error when writing -errno to debugfs file rapidio: fix possible name leaks when rio_add_device() fails rapidio: rio: fix possible name leak in rio_register_mport() ACPICA: Fix use-after-free in acpi_ut_copy_ipackage_to_ipackage() uprobes/x86: Allow to probe a NOP instruction with 0x66 prefix x86/xen: Fix memory leak in xen_init_lock_cpu() MIPS: BCM63xx: Add check for NULL for clk in clk_enable fs: sysv: Fix sysv_nblocks() returns wrong value rapidio: fix possible UAF when kfifo_alloc() fails eventfd: change int to __u64 in eventfd_signal() ifndef CONFIG_EVENTFD hfs: Fix OOB Write in hfs_asc2mac rapidio: devices: fix missing put_device in mport_cdev_open wifi: ath9k: hif_usb: fix memory leak of urbs in ath9k_hif_usb_dealloc_tx_urbs() wifi: ath9k: hif_usb: Fix use-after-free in ath9k_hif_usb_reg_in_cb() media: i2c: ad5820: Fix error path media: vivid: fix compose size exceed boundary mtd: Fix device name leak when register device failed in add_mtd_device() ASoC: pxa: fix null-pointer dereference in filter() regulator: core: fix unbalanced of node refcount in regulator_dev_lookup() ima: Fix misuse of dereference of pointer in template_desc_init_fields() wifi: ath10k: Fix return value in ath10k_pci_init() mtd: lpddr2_nvm: Fix possible null-ptr-deref Input: elants_i2c - properly handle the reset GPIO when power is off media: solo6x10: fix possible memory leak in solo_sysfs_init() media: platform: exynos4-is: Fix error handling in fimc_md_init() HID: hid-sensor-custom: set fixed size for custom attributes ALSA: seq: fix undefined behavior in bit shift for SNDRV_SEQ_FILTER_USE_EVENT clk: rockchip: Fix memory leak in rockchip_clk_register_pll() mtd: maps: pxa2xx-flash: fix memory leak in probe media: imon: fix a race condition in send_packet() pinctrl: pinconf-generic: add missing of_node_put() media: dvb-usb: az6027: fix null-ptr-deref in az6027_i2c_xfer() NFSv4.2: Fix a memory stomp in decode_attr_security_label NFSv4: Fix a deadlock between nfs4_open_recover_helper() and delegreturn ALSA: asihpi: fix missing pci_disable_device() drm/radeon: Fix PCI device refcount leak in radeon_atrm_get_bios() drm/amdgpu: Fix PCI device refcount leak in amdgpu_atrm_get_bios() ASoC: pcm512x: Fix PM disable depth imbalance in pcm512x_probe bonding: uninitialized variable in bond_miimon_inspect() regulator: core: fix module refcount leak in set_supply() media: saa7164: fix missing pci_disable_device() ALSA: mts64: fix possible null-ptr-defer in snd_mts64_interrupt SUNRPC: Fix missing release socket in rpc_sockname() mmc: moxart: fix return value check of mmc_add_host() mmc: mxcmmc: fix return value check of mmc_add_host() mmc: rtsx_usb_sdmmc: fix return value check of mmc_add_host() mmc: toshsd: fix return value check of mmc_add_host() mmc: vub300: fix return value check of mmc_add_host() mmc: via-sdmmc: fix return value check of mmc_add_host() mmc: wbsd: fix return value check of mmc_add_host() mmc: mmci: fix return value check of mmc_add_host() media: c8sectpfe: Add of_node_put() when breaking out of loop media: coda: Add check for dcoda_iram_alloc media: coda: Add check for kmalloc wifi: rtl8xxxu: Add __packed to struct rtl8723bu_c2h wifi: brcmfmac: Fix error return code in brcmf_sdio_download_firmware() blktrace: Fix output non-blktrace event when blk_classic option enabled net: vmw_vsock: vmci: Check memcpy_from_msg() net: defxx: Fix missing err handling in dfx_init() drivers: net: qlcnic: Fix potential memory leak in qlcnic_sriov_init() ethernet: s2io: don't call dev_kfree_skb() under spin_lock_irqsave() net: farsync: Fix kmemleak when rmmods farsync net/tunnel: wait until all sk_user_data reader finish before releasing the sock net: apple: mace: don't call dev_kfree_skb() under spin_lock_irqsave() net: apple: bmac: don't call dev_kfree_skb() under spin_lock_irqsave() net: emaclite: don't call dev_kfree_skb() under spin_lock_irqsave() net: ethernet: dnet: don't call dev_kfree_skb() under spin_lock_irqsave() hamradio: don't call dev_kfree_skb() under spin_lock_irqsave() net: amd: lance: don't call dev_kfree_skb() under spin_lock_irqsave() ntb_netdev: Use dev_kfree_skb_any() in interrupt context Bluetooth: btusb: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_qca: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_h5: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_bcsp: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_core: don't call kfree_skb() under spin_lock_irqsave() stmmac: fix potential division by 0 scsi: hpsa: Fix error handling in hpsa_add_sas_host() scsi: hpsa: Fix possible memory leak in hpsa_add_sas_device() scsi: fcoe: Fix possible name leak when device_register() fails scsi: ipr: Fix WARNING in ipr_init() scsi: fcoe: Fix transport not deattached when fcoe_if_init() fails scsi: snic: Fix possible UAF in snic_tgt_create() orangefs: Fix sysfs not cleanup when dev init failed crypto: img-hash - Fix variable dereferenced before check 'hdev->req' hwrng: amd - Fix PCI device refcount leak hwrng: geode - Fix PCI device refcount leak IB/IPoIB: Fix queue count inconsistency for PKEY child interfaces drivers: dio: fix possible memory leak in dio_init() vfio: platform: Do not pass return buffer to ACPI _RST method uio: uio_dmem_genirq: Fix missing unlock in irq configuration uio: uio_dmem_genirq: Fix deadlock between irq config and handling usb: fotg210-udc: Fix ages old endianness issues staging: vme_user: Fix possible UAF in tsi148_dma_list_add serial: amba-pl011: avoid SBSA UART accessing DMACR register serial: pch: Fix PCI device refcount leak in pch_request_dma() serial: sunsab: Fix error handling in sunsab_init() misc: tifm: fix possible memory leak in tifm_7xx1_switch_media() misc: sgi-gru: fix use-after-free error in gru_set_context_option, gru_fault and gru_handle_user_call_os cxl: fix possible null-ptr-deref in cxl_guest_init_afu|adapter() cxl: fix possible null-ptr-deref in cxl_pci_init_afu|adapter() drivers: mcb: fix resource leak in mcb_probe() mcb: mcb-parse: fix error handing in chameleon_parse_gdd() chardev: fix error handling in cdev_device_add() i2c: pxa-pci: fix missing pci_disable_device() on error in ce4100_i2c_probe staging: rtl8192u: Fix use after free in ieee80211_rx() staging: rtl8192e: Fix potential use-after-free in rtllib_rx_Monitor() vme: Fix error not catched in fake_init() i2c: ismt: Fix an out-of-bounds bug in ismt_access() usb: storage: Add check for kcalloc fbdev: ssd1307fb: Drop optional dependency fbdev: pm2fb: fix missing pci_disable_device() fbdev: via: Fix error in via_core_init() fbdev: vermilion: decrease reference count in error path fbdev: uvesafb: Fixes an error handling path in uvesafb_probe() HSI: omap_ssi_core: fix unbalanced pm_runtime_disable() HSI: omap_ssi_core: fix possible memory leak in ssi_probe() power: supply: fix residue sysfs file in error handle route of __power_supply_register() HSI: omap_ssi_core: Fix error handling in ssi_init() include/uapi/linux/swab: Fix potentially missing __always_inline rtc: snvs: Allow a time difference on clock register read iommu/fsl_pamu: Fix resource leak in fsl_pamu_probe() macintosh: fix possible memory leak in macio_add_one_device() macintosh/macio-adb: check the return value of ioremap() powerpc/52xx: Fix a resource leak in an error handling path powerpc/perf: callchain validate kernel stack pointer bounds powerpc/83xx/mpc832x_rdb: call platform_device_put() in error case in of_fsl_spi_probe() powerpc/hv-gpci: Fix hv_gpci event list selftests/powerpc: Fix resource leaks rtc: st-lpc: Add missing clk_disable_unprepare in st_rtc_probe() nfsd: under NFSv4.1, fix double svc_xprt_put on rpc_create failure mISDN: hfcsusb: don't call dev_kfree_skb/kfree_skb() under spin_lock_irqsave() mISDN: hfcpci: don't call dev_kfree_skb/kfree_skb() under spin_lock_irqsave() mISDN: hfcmulti: don't call dev_kfree_skb/kfree_skb() under spin_lock_irqsave() nfc: pn533: Clear nfc_target before being used r6040: Fix kmemleak in probe and remove openvswitch: Fix flow lookup to use unmasked key skbuff: Account for tail adjustment during pull operations net_sched: reject TCF_EM_SIMPLE case for complex ematch module myri10ge: Fix an error handling path in myri10ge_probe() net: stream: purge sk_error_queue in sk_stream_kill_queues() binfmt_misc: fix shift-out-of-bounds in check_special_flags fs: jfs: fix shift-out-of-bounds in dbAllocAG udf: Avoid double brelse() in udf_rename() fs: jfs: fix shift-out-of-bounds in dbDiscardAG ACPICA: Fix error code path in acpi_ds_call_control_method() nilfs2: fix shift-out-of-bounds/overflow in nilfs_sb2_bad_offset() acct: fix potential integer overflow in encode_comp_t() hfs: fix OOB Read in __hfs_brec_find wifi: ath9k: verify the expected usb_endpoints are present wifi: ar5523: Fix use-after-free on ar5523_cmd() timed out ipmi: fix memleak when unload ipmi driver net: ethernet: ti: Fix return type of netcp_ndo_start_xmit() hamradio: baycom_epp: Fix return type of baycom_send_packet() wifi: brcmfmac: Fix potential shift-out-of-bounds in brcmf_fw_alloc_request() igb: Do not free q_vector unless new one was allocated s390/ctcm: Fix return type of ctc{mp,}m_tx() s390/netiucv: Fix return type of netiucv_tx() s390/lcs: Fix return type of lcs_start_xmit() drm/sti: Use drm_mode_copy() md/raid1: stop mdx_raid1 thread when raid1 array run failed mrp: introduce active flags to prevent UAF when applicant uninit ppp: associate skb with a device at tx media: dvb-frontends: fix leak of memory fw media: dvb-usb: fix memory leak in dvb_usb_adapter_init() blk-mq: fix possible memleak when register 'hctx' failed mmc: f-sdh30: Add quirks for broken timeout clock capability media: si470x: Fix use-after-free in si470x_int_in_callback() clk: st: Fix memory leak in st_of_quadfs_setup() drm/fsl-dcu: Fix return type of fsl_dcu_drm_connector_mode_valid() drm/sti: Fix return type of sti_{dvo,hda,hdmi}_connector_mode_valid() orangefs: Fix kmemleak in orangefs_prepare_debugfs_help_string() ASoC: mediatek: mt8173-rt5650-rt5514: fix refcount leak in mt8173_rt5650_rt5514_dev_probe() ASoC: wm8994: Fix potential deadlock ASoC: rockchip: spdif: Add missing clk_disable_unprepare() in rk_spdif_runtime_resume() ASoC: rt5670: Remove unbalanced pm_runtime_put() HID: wacom: Ensure bootloader PID is usable in hidraw mode reiserfs: Add missing calls to reiserfs_security_free() iio: adc: ad_sigma_delta: do not use internal iio_dev lock gcov: add support for checksum field powerpc/rtas: avoid scheduling in rtas_os_term() HID: plantronics: Additional PIDs for double volume key presses quirk hfsplus: fix bug causing custom uid and gid being unable to be assigned with mount ALSA: line6: correct midi status byte when receiving data from podxt ALSA: line6: fix stack overflow in line6_midi_transmit pnode: terminate at peers of source md: fix a crash in mempool_free mmc: vub300: fix warning - do not call blocking ops when !TASK_RUNNING media: stv0288: use explicitly signed char ktest.pl minconfig: Unset configs instead of just removing them ARM: ux500: do not directly dereference __iomem dm cache: Fix ABBA deadlock between shrink_slab and dm_cache_metadata_abort dm thin: Use last transaction's pmd->root when commit failed dm thin: Fix UAF in run_timer_softirq() dm cache: Fix UAF in destroy() dm cache: set needs_check flag after aborting metadata tracing: Fix infinite loop in tracing_read_pipe on overflowed print_trace_line ARM: 9256/1: NWFPE: avoid compiler-generated __aeabi_uldivmod media: dvb-core: Fix double free in dvb_register_device() cifs: fix confusing debug message PCI/sysfs: Fix double free in error path crypto: n2 - add missing hash statesize iommu/amd: Fix ivrs_acpihid cmdline parsing code parisc: led: Fix potential null-ptr-deref in start_task() device_cgroup: Roll back to original exceptions after copy failure drm/connector: send hotplug uevent on connector cleanup drm/vmwgfx: Validate the box size for the snooped cursor ext4: add inode table check in __ext4_get_inode_loc to aovid possible infinite loop ext4: fix undefined behavior in bit shift for ext4_check_flag_values ext4: fix bug_on in __es_tree_search caused by bad boot loader inode ext4: init quota for 'old.inode' in 'ext4_rename' ext4: fix error code return to user-space in ext4_get_branch() ext4: avoid BUG_ON when creating xattrs ext4: initialize quota before expanding inode in setproject ioctl Linux 4.9.337 Change-Id: I923e3fef499ae1688b25c70a1a805b55a9f4f027 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
1518 lines
34 KiB
C
1518 lines
34 KiB
C
/*
|
|
* Copyright (c) 2010-2011 Atheros Communications Inc.
|
|
*
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
* copyright notice and this permission notice appear in all copies.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
|
|
#include <asm/unaligned.h>
|
|
#include "htc.h"
|
|
|
|
MODULE_FIRMWARE(HTC_7010_MODULE_FW);
|
|
MODULE_FIRMWARE(HTC_9271_MODULE_FW);
|
|
|
|
static struct usb_device_id ath9k_hif_usb_ids[] = {
|
|
{ USB_DEVICE(0x0cf3, 0x9271) }, /* Atheros */
|
|
{ USB_DEVICE(0x0cf3, 0x1006) }, /* Atheros */
|
|
{ USB_DEVICE(0x0846, 0x9030) }, /* Netgear N150 */
|
|
{ USB_DEVICE(0x07D1, 0x3A10) }, /* Dlink Wireless 150 */
|
|
{ USB_DEVICE(0x13D3, 0x3327) }, /* Azurewave */
|
|
{ USB_DEVICE(0x13D3, 0x3328) }, /* Azurewave */
|
|
{ USB_DEVICE(0x13D3, 0x3346) }, /* IMC Networks */
|
|
{ USB_DEVICE(0x13D3, 0x3348) }, /* Azurewave */
|
|
{ USB_DEVICE(0x13D3, 0x3349) }, /* Azurewave */
|
|
{ USB_DEVICE(0x13D3, 0x3350) }, /* Azurewave */
|
|
{ USB_DEVICE(0x04CA, 0x4605) }, /* Liteon */
|
|
{ USB_DEVICE(0x040D, 0x3801) }, /* VIA */
|
|
{ USB_DEVICE(0x0cf3, 0xb003) }, /* Ubiquiti WifiStation Ext */
|
|
{ USB_DEVICE(0x0cf3, 0xb002) }, /* Ubiquiti WifiStation */
|
|
{ USB_DEVICE(0x057c, 0x8403) }, /* AVM FRITZ!WLAN 11N v2 USB */
|
|
{ USB_DEVICE(0x0471, 0x209e) }, /* Philips (or NXP) PTA01 */
|
|
{ USB_DEVICE(0x1eda, 0x2315) }, /* AirTies */
|
|
|
|
{ USB_DEVICE(0x0cf3, 0x7015),
|
|
.driver_info = AR9287_USB }, /* Atheros */
|
|
{ USB_DEVICE(0x1668, 0x1200),
|
|
.driver_info = AR9287_USB }, /* Verizon */
|
|
|
|
{ USB_DEVICE(0x0cf3, 0x7010),
|
|
.driver_info = AR9280_USB }, /* Atheros */
|
|
{ USB_DEVICE(0x0846, 0x9018),
|
|
.driver_info = AR9280_USB }, /* Netgear WNDA3200 */
|
|
{ USB_DEVICE(0x083A, 0xA704),
|
|
.driver_info = AR9280_USB }, /* SMC Networks */
|
|
{ USB_DEVICE(0x0411, 0x017f),
|
|
.driver_info = AR9280_USB }, /* Sony UWA-BR100 */
|
|
{ USB_DEVICE(0x0411, 0x0197),
|
|
.driver_info = AR9280_USB }, /* Buffalo WLI-UV-AG300P */
|
|
{ USB_DEVICE(0x04da, 0x3904),
|
|
.driver_info = AR9280_USB },
|
|
{ USB_DEVICE(0x0930, 0x0a08),
|
|
.driver_info = AR9280_USB }, /* Toshiba WLM-20U2 and GN-1080 */
|
|
|
|
{ USB_DEVICE(0x0cf3, 0x20ff),
|
|
.driver_info = STORAGE_DEVICE },
|
|
|
|
{ },
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(usb, ath9k_hif_usb_ids);
|
|
|
|
static int __hif_usb_tx(struct hif_device_usb *hif_dev);
|
|
|
|
static void hif_usb_regout_cb(struct urb *urb)
|
|
{
|
|
struct cmd_buf *cmd = (struct cmd_buf *)urb->context;
|
|
|
|
switch (urb->status) {
|
|
case 0:
|
|
break;
|
|
case -ENOENT:
|
|
case -ECONNRESET:
|
|
case -ENODEV:
|
|
case -ESHUTDOWN:
|
|
goto free;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (cmd) {
|
|
ath9k_htc_txcompletion_cb(cmd->hif_dev->htc_handle,
|
|
cmd->skb, true);
|
|
kfree(cmd);
|
|
}
|
|
|
|
return;
|
|
free:
|
|
kfree_skb(cmd->skb);
|
|
kfree(cmd);
|
|
}
|
|
|
|
static int hif_usb_send_regout(struct hif_device_usb *hif_dev,
|
|
struct sk_buff *skb)
|
|
{
|
|
struct urb *urb;
|
|
struct cmd_buf *cmd;
|
|
int ret = 0;
|
|
|
|
urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
if (urb == NULL)
|
|
return -ENOMEM;
|
|
|
|
cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
|
|
if (cmd == NULL) {
|
|
usb_free_urb(urb);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
cmd->skb = skb;
|
|
cmd->hif_dev = hif_dev;
|
|
|
|
usb_fill_int_urb(urb, hif_dev->udev,
|
|
usb_sndintpipe(hif_dev->udev, USB_REG_OUT_PIPE),
|
|
skb->data, skb->len,
|
|
hif_usb_regout_cb, cmd, 1);
|
|
|
|
usb_anchor_urb(urb, &hif_dev->regout_submitted);
|
|
ret = usb_submit_urb(urb, GFP_KERNEL);
|
|
if (ret) {
|
|
usb_unanchor_urb(urb);
|
|
kfree(cmd);
|
|
}
|
|
usb_free_urb(urb);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void hif_usb_mgmt_cb(struct urb *urb)
|
|
{
|
|
struct cmd_buf *cmd = (struct cmd_buf *)urb->context;
|
|
struct hif_device_usb *hif_dev;
|
|
bool txok = true;
|
|
|
|
if (!cmd || !cmd->skb || !cmd->hif_dev)
|
|
return;
|
|
|
|
hif_dev = cmd->hif_dev;
|
|
|
|
switch (urb->status) {
|
|
case 0:
|
|
break;
|
|
case -ENOENT:
|
|
case -ECONNRESET:
|
|
case -ENODEV:
|
|
case -ESHUTDOWN:
|
|
txok = false;
|
|
|
|
/*
|
|
* If the URBs are being flushed, no need to complete
|
|
* this packet.
|
|
*/
|
|
spin_lock(&hif_dev->tx.tx_lock);
|
|
if (hif_dev->tx.flags & HIF_USB_TX_FLUSH) {
|
|
spin_unlock(&hif_dev->tx.tx_lock);
|
|
dev_kfree_skb_any(cmd->skb);
|
|
kfree(cmd);
|
|
return;
|
|
}
|
|
spin_unlock(&hif_dev->tx.tx_lock);
|
|
|
|
break;
|
|
default:
|
|
txok = false;
|
|
break;
|
|
}
|
|
|
|
skb_pull(cmd->skb, 4);
|
|
ath9k_htc_txcompletion_cb(cmd->hif_dev->htc_handle,
|
|
cmd->skb, txok);
|
|
kfree(cmd);
|
|
}
|
|
|
|
static int hif_usb_send_mgmt(struct hif_device_usb *hif_dev,
|
|
struct sk_buff *skb)
|
|
{
|
|
struct urb *urb;
|
|
struct cmd_buf *cmd;
|
|
int ret = 0;
|
|
__le16 *hdr;
|
|
|
|
urb = usb_alloc_urb(0, GFP_ATOMIC);
|
|
if (urb == NULL)
|
|
return -ENOMEM;
|
|
|
|
cmd = kzalloc(sizeof(*cmd), GFP_ATOMIC);
|
|
if (cmd == NULL) {
|
|
usb_free_urb(urb);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
cmd->skb = skb;
|
|
cmd->hif_dev = hif_dev;
|
|
|
|
hdr = (__le16 *) skb_push(skb, 4);
|
|
*hdr++ = cpu_to_le16(skb->len - 4);
|
|
*hdr++ = cpu_to_le16(ATH_USB_TX_STREAM_MODE_TAG);
|
|
|
|
usb_fill_bulk_urb(urb, hif_dev->udev,
|
|
usb_sndbulkpipe(hif_dev->udev, USB_WLAN_TX_PIPE),
|
|
skb->data, skb->len,
|
|
hif_usb_mgmt_cb, cmd);
|
|
|
|
usb_anchor_urb(urb, &hif_dev->mgmt_submitted);
|
|
ret = usb_submit_urb(urb, GFP_ATOMIC);
|
|
if (ret) {
|
|
usb_unanchor_urb(urb);
|
|
kfree(cmd);
|
|
}
|
|
usb_free_urb(urb);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static inline void ath9k_skb_queue_purge(struct hif_device_usb *hif_dev,
|
|
struct sk_buff_head *list)
|
|
{
|
|
struct sk_buff *skb;
|
|
|
|
while ((skb = __skb_dequeue(list)) != NULL) {
|
|
dev_kfree_skb_any(skb);
|
|
}
|
|
}
|
|
|
|
static inline void ath9k_skb_queue_complete(struct hif_device_usb *hif_dev,
|
|
struct sk_buff_head *queue,
|
|
bool txok)
|
|
{
|
|
struct sk_buff *skb;
|
|
|
|
while ((skb = __skb_dequeue(queue)) != NULL) {
|
|
#ifdef CONFIG_ATH9K_HTC_DEBUGFS
|
|
int ln = skb->len;
|
|
#endif
|
|
ath9k_htc_txcompletion_cb(hif_dev->htc_handle,
|
|
skb, txok);
|
|
if (txok) {
|
|
TX_STAT_INC(skb_success);
|
|
TX_STAT_ADD(skb_success_bytes, ln);
|
|
}
|
|
else
|
|
TX_STAT_INC(skb_failed);
|
|
}
|
|
}
|
|
|
|
static void hif_usb_tx_cb(struct urb *urb)
|
|
{
|
|
struct tx_buf *tx_buf = (struct tx_buf *) urb->context;
|
|
struct hif_device_usb *hif_dev;
|
|
bool txok = true;
|
|
|
|
if (!tx_buf || !tx_buf->hif_dev)
|
|
return;
|
|
|
|
hif_dev = tx_buf->hif_dev;
|
|
|
|
switch (urb->status) {
|
|
case 0:
|
|
break;
|
|
case -ENOENT:
|
|
case -ECONNRESET:
|
|
case -ENODEV:
|
|
case -ESHUTDOWN:
|
|
txok = false;
|
|
|
|
/*
|
|
* If the URBs are being flushed, no need to add this
|
|
* URB to the free list.
|
|
*/
|
|
spin_lock(&hif_dev->tx.tx_lock);
|
|
if (hif_dev->tx.flags & HIF_USB_TX_FLUSH) {
|
|
spin_unlock(&hif_dev->tx.tx_lock);
|
|
ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue);
|
|
return;
|
|
}
|
|
spin_unlock(&hif_dev->tx.tx_lock);
|
|
|
|
break;
|
|
default:
|
|
txok = false;
|
|
break;
|
|
}
|
|
|
|
ath9k_skb_queue_complete(hif_dev, &tx_buf->skb_queue, txok);
|
|
|
|
/* Re-initialize the SKB queue */
|
|
tx_buf->len = tx_buf->offset = 0;
|
|
__skb_queue_head_init(&tx_buf->skb_queue);
|
|
|
|
/* Add this TX buffer to the free list */
|
|
spin_lock(&hif_dev->tx.tx_lock);
|
|
list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
|
|
hif_dev->tx.tx_buf_cnt++;
|
|
if (!(hif_dev->tx.flags & HIF_USB_TX_STOP))
|
|
__hif_usb_tx(hif_dev); /* Check for pending SKBs */
|
|
TX_STAT_INC(buf_completed);
|
|
spin_unlock(&hif_dev->tx.tx_lock);
|
|
}
|
|
|
|
/* TX lock has to be taken */
|
|
static int __hif_usb_tx(struct hif_device_usb *hif_dev)
|
|
{
|
|
struct tx_buf *tx_buf = NULL;
|
|
struct sk_buff *nskb = NULL;
|
|
int ret = 0, i;
|
|
u16 tx_skb_cnt = 0;
|
|
u8 *buf;
|
|
__le16 *hdr;
|
|
|
|
if (hif_dev->tx.tx_skb_cnt == 0)
|
|
return 0;
|
|
|
|
/* Check if a free TX buffer is available */
|
|
if (list_empty(&hif_dev->tx.tx_buf))
|
|
return 0;
|
|
|
|
tx_buf = list_first_entry(&hif_dev->tx.tx_buf, struct tx_buf, list);
|
|
list_move_tail(&tx_buf->list, &hif_dev->tx.tx_pending);
|
|
hif_dev->tx.tx_buf_cnt--;
|
|
|
|
tx_skb_cnt = min_t(u16, hif_dev->tx.tx_skb_cnt, MAX_TX_AGGR_NUM);
|
|
|
|
for (i = 0; i < tx_skb_cnt; i++) {
|
|
nskb = __skb_dequeue(&hif_dev->tx.tx_skb_queue);
|
|
|
|
/* Should never be NULL */
|
|
BUG_ON(!nskb);
|
|
|
|
hif_dev->tx.tx_skb_cnt--;
|
|
|
|
buf = tx_buf->buf;
|
|
buf += tx_buf->offset;
|
|
hdr = (__le16 *)buf;
|
|
*hdr++ = cpu_to_le16(nskb->len);
|
|
*hdr++ = cpu_to_le16(ATH_USB_TX_STREAM_MODE_TAG);
|
|
buf += 4;
|
|
memcpy(buf, nskb->data, nskb->len);
|
|
tx_buf->len = nskb->len + 4;
|
|
|
|
if (i < (tx_skb_cnt - 1))
|
|
tx_buf->offset += (((tx_buf->len - 1) / 4) + 1) * 4;
|
|
|
|
if (i == (tx_skb_cnt - 1))
|
|
tx_buf->len += tx_buf->offset;
|
|
|
|
__skb_queue_tail(&tx_buf->skb_queue, nskb);
|
|
TX_STAT_INC(skb_queued);
|
|
}
|
|
|
|
usb_fill_bulk_urb(tx_buf->urb, hif_dev->udev,
|
|
usb_sndbulkpipe(hif_dev->udev, USB_WLAN_TX_PIPE),
|
|
tx_buf->buf, tx_buf->len,
|
|
hif_usb_tx_cb, tx_buf);
|
|
|
|
ret = usb_submit_urb(tx_buf->urb, GFP_ATOMIC);
|
|
if (ret) {
|
|
tx_buf->len = tx_buf->offset = 0;
|
|
ath9k_skb_queue_complete(hif_dev, &tx_buf->skb_queue, false);
|
|
__skb_queue_head_init(&tx_buf->skb_queue);
|
|
list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
|
|
hif_dev->tx.tx_buf_cnt++;
|
|
}
|
|
|
|
if (!ret)
|
|
TX_STAT_INC(buf_queued);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int hif_usb_send_tx(struct hif_device_usb *hif_dev, struct sk_buff *skb)
|
|
{
|
|
struct ath9k_htc_tx_ctl *tx_ctl;
|
|
unsigned long flags;
|
|
int ret = 0;
|
|
|
|
spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
|
|
|
|
if (hif_dev->tx.flags & HIF_USB_TX_STOP) {
|
|
spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
|
|
return -ENODEV;
|
|
}
|
|
|
|
/* Check if the max queue count has been reached */
|
|
if (hif_dev->tx.tx_skb_cnt > MAX_TX_BUF_NUM) {
|
|
spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
|
|
|
|
tx_ctl = HTC_SKB_CB(skb);
|
|
|
|
/* Mgmt/Beacon frames don't use the TX buffer pool */
|
|
if ((tx_ctl->type == ATH9K_HTC_MGMT) ||
|
|
(tx_ctl->type == ATH9K_HTC_BEACON)) {
|
|
ret = hif_usb_send_mgmt(hif_dev, skb);
|
|
}
|
|
|
|
spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
|
|
|
|
if ((tx_ctl->type == ATH9K_HTC_NORMAL) ||
|
|
(tx_ctl->type == ATH9K_HTC_AMPDU)) {
|
|
__skb_queue_tail(&hif_dev->tx.tx_skb_queue, skb);
|
|
hif_dev->tx.tx_skb_cnt++;
|
|
}
|
|
|
|
/* Check if AMPDUs have to be sent immediately */
|
|
if ((hif_dev->tx.tx_buf_cnt == MAX_TX_URB_NUM) &&
|
|
(hif_dev->tx.tx_skb_cnt < 2)) {
|
|
__hif_usb_tx(hif_dev);
|
|
}
|
|
|
|
spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void hif_usb_start(void *hif_handle)
|
|
{
|
|
struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
|
|
unsigned long flags;
|
|
|
|
hif_dev->flags |= HIF_USB_START;
|
|
|
|
spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
|
|
hif_dev->tx.flags &= ~HIF_USB_TX_STOP;
|
|
spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
|
|
}
|
|
|
|
static void hif_usb_stop(void *hif_handle)
|
|
{
|
|
struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
|
|
struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL;
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
|
|
ath9k_skb_queue_complete(hif_dev, &hif_dev->tx.tx_skb_queue, false);
|
|
hif_dev->tx.tx_skb_cnt = 0;
|
|
hif_dev->tx.flags |= HIF_USB_TX_STOP;
|
|
spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
|
|
|
|
/* The pending URBs have to be canceled. */
|
|
spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
|
|
list_for_each_entry_safe(tx_buf, tx_buf_tmp,
|
|
&hif_dev->tx.tx_pending, list) {
|
|
usb_get_urb(tx_buf->urb);
|
|
spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
|
|
usb_kill_urb(tx_buf->urb);
|
|
list_del(&tx_buf->list);
|
|
usb_free_urb(tx_buf->urb);
|
|
kfree(tx_buf->buf);
|
|
kfree(tx_buf);
|
|
spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
|
|
}
|
|
spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
|
|
|
|
usb_kill_anchored_urbs(&hif_dev->mgmt_submitted);
|
|
}
|
|
|
|
static int hif_usb_send(void *hif_handle, u8 pipe_id, struct sk_buff *skb)
|
|
{
|
|
struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
|
|
int ret = 0;
|
|
|
|
switch (pipe_id) {
|
|
case USB_WLAN_TX_PIPE:
|
|
ret = hif_usb_send_tx(hif_dev, skb);
|
|
break;
|
|
case USB_REG_OUT_PIPE:
|
|
ret = hif_usb_send_regout(hif_dev, skb);
|
|
break;
|
|
default:
|
|
dev_err(&hif_dev->udev->dev,
|
|
"ath9k_htc: Invalid TX pipe: %d\n", pipe_id);
|
|
ret = -EINVAL;
|
|
break;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static inline bool check_index(struct sk_buff *skb, u8 idx)
|
|
{
|
|
struct ath9k_htc_tx_ctl *tx_ctl;
|
|
|
|
tx_ctl = HTC_SKB_CB(skb);
|
|
|
|
if ((tx_ctl->type == ATH9K_HTC_AMPDU) &&
|
|
(tx_ctl->sta_idx == idx))
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
static void hif_usb_sta_drain(void *hif_handle, u8 idx)
|
|
{
|
|
struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
|
|
struct sk_buff *skb, *tmp;
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
|
|
|
|
skb_queue_walk_safe(&hif_dev->tx.tx_skb_queue, skb, tmp) {
|
|
if (check_index(skb, idx)) {
|
|
__skb_unlink(skb, &hif_dev->tx.tx_skb_queue);
|
|
ath9k_htc_txcompletion_cb(hif_dev->htc_handle,
|
|
skb, false);
|
|
hif_dev->tx.tx_skb_cnt--;
|
|
TX_STAT_INC(skb_failed);
|
|
}
|
|
}
|
|
|
|
spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
|
|
}
|
|
|
|
static struct ath9k_htc_hif hif_usb = {
|
|
.transport = ATH9K_HIF_USB,
|
|
.name = "ath9k_hif_usb",
|
|
|
|
.control_ul_pipe = USB_REG_OUT_PIPE,
|
|
.control_dl_pipe = USB_REG_IN_PIPE,
|
|
|
|
.start = hif_usb_start,
|
|
.stop = hif_usb_stop,
|
|
.sta_drain = hif_usb_sta_drain,
|
|
.send = hif_usb_send,
|
|
};
|
|
|
|
static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev,
|
|
struct sk_buff *skb)
|
|
{
|
|
struct sk_buff *nskb, *skb_pool[MAX_PKT_NUM_IN_TRANSFER];
|
|
int index = 0, i, len = skb->len;
|
|
int rx_remain_len, rx_pkt_len;
|
|
u16 pool_index = 0;
|
|
u8 *ptr;
|
|
|
|
spin_lock(&hif_dev->rx_lock);
|
|
|
|
rx_remain_len = hif_dev->rx_remain_len;
|
|
rx_pkt_len = hif_dev->rx_transfer_len;
|
|
|
|
if (rx_remain_len != 0) {
|
|
struct sk_buff *remain_skb = hif_dev->remain_skb;
|
|
|
|
if (remain_skb) {
|
|
ptr = (u8 *) remain_skb->data;
|
|
|
|
index = rx_remain_len;
|
|
rx_remain_len -= hif_dev->rx_pad_len;
|
|
ptr += rx_pkt_len;
|
|
|
|
memcpy(ptr, skb->data, rx_remain_len);
|
|
|
|
rx_pkt_len += rx_remain_len;
|
|
hif_dev->rx_remain_len = 0;
|
|
skb_put(remain_skb, rx_pkt_len);
|
|
|
|
skb_pool[pool_index++] = remain_skb;
|
|
|
|
} else {
|
|
index = rx_remain_len;
|
|
}
|
|
}
|
|
|
|
spin_unlock(&hif_dev->rx_lock);
|
|
|
|
while (index < len) {
|
|
u16 pkt_len;
|
|
u16 pkt_tag;
|
|
u16 pad_len;
|
|
int chk_idx;
|
|
|
|
ptr = (u8 *) skb->data;
|
|
|
|
pkt_len = get_unaligned_le16(ptr + index);
|
|
pkt_tag = get_unaligned_le16(ptr + index + 2);
|
|
|
|
if (pkt_tag != ATH_USB_RX_STREAM_MODE_TAG) {
|
|
RX_STAT_INC(skb_dropped);
|
|
return;
|
|
}
|
|
|
|
if (pkt_len > 2 * MAX_RX_BUF_SIZE) {
|
|
dev_err(&hif_dev->udev->dev,
|
|
"ath9k_htc: invalid pkt_len (%x)\n", pkt_len);
|
|
RX_STAT_INC(skb_dropped);
|
|
return;
|
|
}
|
|
|
|
pad_len = 4 - (pkt_len & 0x3);
|
|
if (pad_len == 4)
|
|
pad_len = 0;
|
|
|
|
chk_idx = index;
|
|
index = index + 4 + pkt_len + pad_len;
|
|
|
|
if (index > MAX_RX_BUF_SIZE) {
|
|
spin_lock(&hif_dev->rx_lock);
|
|
hif_dev->rx_remain_len = index - MAX_RX_BUF_SIZE;
|
|
hif_dev->rx_transfer_len =
|
|
MAX_RX_BUF_SIZE - chk_idx - 4;
|
|
hif_dev->rx_pad_len = pad_len;
|
|
|
|
nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC);
|
|
if (!nskb) {
|
|
dev_err(&hif_dev->udev->dev,
|
|
"ath9k_htc: RX memory allocation error\n");
|
|
spin_unlock(&hif_dev->rx_lock);
|
|
goto err;
|
|
}
|
|
skb_reserve(nskb, 32);
|
|
RX_STAT_INC(skb_allocated);
|
|
|
|
memcpy(nskb->data, &(skb->data[chk_idx+4]),
|
|
hif_dev->rx_transfer_len);
|
|
|
|
/* Record the buffer pointer */
|
|
hif_dev->remain_skb = nskb;
|
|
spin_unlock(&hif_dev->rx_lock);
|
|
} else {
|
|
if (pool_index == MAX_PKT_NUM_IN_TRANSFER) {
|
|
dev_err(&hif_dev->udev->dev,
|
|
"ath9k_htc: over RX MAX_PKT_NUM\n");
|
|
goto err;
|
|
}
|
|
nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC);
|
|
if (!nskb) {
|
|
dev_err(&hif_dev->udev->dev,
|
|
"ath9k_htc: RX memory allocation error\n");
|
|
goto err;
|
|
}
|
|
skb_reserve(nskb, 32);
|
|
RX_STAT_INC(skb_allocated);
|
|
|
|
memcpy(nskb->data, &(skb->data[chk_idx+4]), pkt_len);
|
|
skb_put(nskb, pkt_len);
|
|
skb_pool[pool_index++] = nskb;
|
|
}
|
|
}
|
|
|
|
err:
|
|
for (i = 0; i < pool_index; i++) {
|
|
RX_STAT_ADD(skb_completed_bytes, skb_pool[i]->len);
|
|
ath9k_htc_rx_msg(hif_dev->htc_handle, skb_pool[i],
|
|
skb_pool[i]->len, USB_WLAN_RX_PIPE);
|
|
RX_STAT_INC(skb_completed);
|
|
}
|
|
}
|
|
|
|
static void ath9k_hif_usb_rx_cb(struct urb *urb)
|
|
{
|
|
struct rx_buf *rx_buf = (struct rx_buf *)urb->context;
|
|
struct hif_device_usb *hif_dev = rx_buf->hif_dev;
|
|
struct sk_buff *skb = rx_buf->skb;
|
|
int ret;
|
|
|
|
if (!skb)
|
|
return;
|
|
|
|
if (!hif_dev)
|
|
goto free;
|
|
|
|
switch (urb->status) {
|
|
case 0:
|
|
break;
|
|
case -ENOENT:
|
|
case -ECONNRESET:
|
|
case -ENODEV:
|
|
case -ESHUTDOWN:
|
|
goto free;
|
|
default:
|
|
goto resubmit;
|
|
}
|
|
|
|
if (likely(urb->actual_length != 0)) {
|
|
skb_put(skb, urb->actual_length);
|
|
ath9k_hif_usb_rx_stream(hif_dev, skb);
|
|
}
|
|
|
|
resubmit:
|
|
skb_reset_tail_pointer(skb);
|
|
skb_trim(skb, 0);
|
|
|
|
usb_anchor_urb(urb, &hif_dev->rx_submitted);
|
|
ret = usb_submit_urb(urb, GFP_ATOMIC);
|
|
if (ret) {
|
|
usb_unanchor_urb(urb);
|
|
goto free;
|
|
}
|
|
|
|
return;
|
|
free:
|
|
kfree_skb(skb);
|
|
kfree(rx_buf);
|
|
}
|
|
|
|
static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
|
|
{
|
|
struct rx_buf *rx_buf = (struct rx_buf *)urb->context;
|
|
struct hif_device_usb *hif_dev = rx_buf->hif_dev;
|
|
struct sk_buff *skb = rx_buf->skb;
|
|
int ret;
|
|
|
|
if (!skb)
|
|
return;
|
|
|
|
if (!hif_dev)
|
|
goto free_skb;
|
|
|
|
switch (urb->status) {
|
|
case 0:
|
|
break;
|
|
case -ENOENT:
|
|
case -ECONNRESET:
|
|
case -ENODEV:
|
|
case -ESHUTDOWN:
|
|
goto free_skb;
|
|
default:
|
|
skb_reset_tail_pointer(skb);
|
|
skb_trim(skb, 0);
|
|
|
|
goto resubmit;
|
|
}
|
|
|
|
if (likely(urb->actual_length != 0)) {
|
|
skb_put(skb, urb->actual_length);
|
|
|
|
/*
|
|
* Process the command first.
|
|
* skb is either freed here or passed to be
|
|
* managed to another callback function.
|
|
*/
|
|
ath9k_htc_rx_msg(hif_dev->htc_handle, skb,
|
|
skb->len, USB_REG_IN_PIPE);
|
|
|
|
skb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC);
|
|
if (!skb) {
|
|
dev_err(&hif_dev->udev->dev,
|
|
"ath9k_htc: REG_IN memory allocation failure\n");
|
|
goto free_rx_buf;
|
|
}
|
|
|
|
rx_buf->skb = skb;
|
|
|
|
usb_fill_int_urb(urb, hif_dev->udev,
|
|
usb_rcvintpipe(hif_dev->udev,
|
|
USB_REG_IN_PIPE),
|
|
skb->data, MAX_REG_IN_BUF_SIZE,
|
|
ath9k_hif_usb_reg_in_cb, rx_buf, 1);
|
|
}
|
|
|
|
resubmit:
|
|
usb_anchor_urb(urb, &hif_dev->reg_in_submitted);
|
|
ret = usb_submit_urb(urb, GFP_ATOMIC);
|
|
if (ret) {
|
|
usb_unanchor_urb(urb);
|
|
goto free_skb;
|
|
}
|
|
|
|
return;
|
|
free_skb:
|
|
kfree_skb(skb);
|
|
free_rx_buf:
|
|
kfree(rx_buf);
|
|
urb->context = NULL;
|
|
}
|
|
|
|
static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev)
|
|
{
|
|
struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL;
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
|
|
list_for_each_entry_safe(tx_buf, tx_buf_tmp,
|
|
&hif_dev->tx.tx_buf, list) {
|
|
list_del(&tx_buf->list);
|
|
usb_free_urb(tx_buf->urb);
|
|
kfree(tx_buf->buf);
|
|
kfree(tx_buf);
|
|
}
|
|
spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
|
|
|
|
spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
|
|
hif_dev->tx.flags |= HIF_USB_TX_FLUSH;
|
|
spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
|
|
|
|
spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
|
|
list_for_each_entry_safe(tx_buf, tx_buf_tmp,
|
|
&hif_dev->tx.tx_pending, list) {
|
|
usb_get_urb(tx_buf->urb);
|
|
spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
|
|
usb_kill_urb(tx_buf->urb);
|
|
list_del(&tx_buf->list);
|
|
usb_free_urb(tx_buf->urb);
|
|
kfree(tx_buf->buf);
|
|
kfree(tx_buf);
|
|
spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
|
|
}
|
|
spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
|
|
|
|
usb_kill_anchored_urbs(&hif_dev->mgmt_submitted);
|
|
}
|
|
|
|
static int ath9k_hif_usb_alloc_tx_urbs(struct hif_device_usb *hif_dev)
|
|
{
|
|
struct tx_buf *tx_buf;
|
|
int i;
|
|
|
|
INIT_LIST_HEAD(&hif_dev->tx.tx_buf);
|
|
INIT_LIST_HEAD(&hif_dev->tx.tx_pending);
|
|
spin_lock_init(&hif_dev->tx.tx_lock);
|
|
__skb_queue_head_init(&hif_dev->tx.tx_skb_queue);
|
|
init_usb_anchor(&hif_dev->mgmt_submitted);
|
|
|
|
for (i = 0; i < MAX_TX_URB_NUM; i++) {
|
|
tx_buf = kzalloc(sizeof(*tx_buf), GFP_KERNEL);
|
|
if (!tx_buf)
|
|
goto err;
|
|
|
|
tx_buf->buf = kzalloc(MAX_TX_BUF_SIZE, GFP_KERNEL);
|
|
if (!tx_buf->buf)
|
|
goto err;
|
|
|
|
tx_buf->urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
if (!tx_buf->urb)
|
|
goto err;
|
|
|
|
tx_buf->hif_dev = hif_dev;
|
|
__skb_queue_head_init(&tx_buf->skb_queue);
|
|
|
|
list_add_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
|
|
}
|
|
|
|
hif_dev->tx.tx_buf_cnt = MAX_TX_URB_NUM;
|
|
|
|
return 0;
|
|
err:
|
|
if (tx_buf) {
|
|
kfree(tx_buf->buf);
|
|
kfree(tx_buf);
|
|
}
|
|
ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
static void ath9k_hif_usb_dealloc_rx_urbs(struct hif_device_usb *hif_dev)
|
|
{
|
|
usb_kill_anchored_urbs(&hif_dev->rx_submitted);
|
|
}
|
|
|
|
static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb *hif_dev)
|
|
{
|
|
struct rx_buf *rx_buf = NULL;
|
|
struct sk_buff *skb = NULL;
|
|
struct urb *urb = NULL;
|
|
int i, ret;
|
|
|
|
init_usb_anchor(&hif_dev->rx_submitted);
|
|
spin_lock_init(&hif_dev->rx_lock);
|
|
|
|
for (i = 0; i < MAX_RX_URB_NUM; i++) {
|
|
|
|
rx_buf = kzalloc(sizeof(*rx_buf), GFP_KERNEL);
|
|
if (!rx_buf) {
|
|
ret = -ENOMEM;
|
|
goto err_rxb;
|
|
}
|
|
|
|
/* Allocate URB */
|
|
urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
if (urb == NULL) {
|
|
ret = -ENOMEM;
|
|
goto err_urb;
|
|
}
|
|
|
|
/* Allocate buffer */
|
|
skb = alloc_skb(MAX_RX_BUF_SIZE, GFP_KERNEL);
|
|
if (!skb) {
|
|
ret = -ENOMEM;
|
|
goto err_skb;
|
|
}
|
|
|
|
rx_buf->hif_dev = hif_dev;
|
|
rx_buf->skb = skb;
|
|
|
|
usb_fill_bulk_urb(urb, hif_dev->udev,
|
|
usb_rcvbulkpipe(hif_dev->udev,
|
|
USB_WLAN_RX_PIPE),
|
|
skb->data, MAX_RX_BUF_SIZE,
|
|
ath9k_hif_usb_rx_cb, rx_buf);
|
|
|
|
/* Anchor URB */
|
|
usb_anchor_urb(urb, &hif_dev->rx_submitted);
|
|
|
|
/* Submit URB */
|
|
ret = usb_submit_urb(urb, GFP_KERNEL);
|
|
if (ret) {
|
|
usb_unanchor_urb(urb);
|
|
goto err_submit;
|
|
}
|
|
|
|
/*
|
|
* Drop reference count.
|
|
* This ensures that the URB is freed when killing them.
|
|
*/
|
|
usb_free_urb(urb);
|
|
}
|
|
|
|
return 0;
|
|
|
|
err_submit:
|
|
kfree_skb(skb);
|
|
err_skb:
|
|
usb_free_urb(urb);
|
|
err_urb:
|
|
kfree(rx_buf);
|
|
err_rxb:
|
|
ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
|
|
return ret;
|
|
}
|
|
|
|
static void ath9k_hif_usb_dealloc_reg_in_urbs(struct hif_device_usb *hif_dev)
|
|
{
|
|
usb_kill_anchored_urbs(&hif_dev->reg_in_submitted);
|
|
}
|
|
|
|
static int ath9k_hif_usb_alloc_reg_in_urbs(struct hif_device_usb *hif_dev)
|
|
{
|
|
struct rx_buf *rx_buf = NULL;
|
|
struct sk_buff *skb = NULL;
|
|
struct urb *urb = NULL;
|
|
int i, ret;
|
|
|
|
init_usb_anchor(&hif_dev->reg_in_submitted);
|
|
|
|
for (i = 0; i < MAX_REG_IN_URB_NUM; i++) {
|
|
|
|
rx_buf = kzalloc(sizeof(*rx_buf), GFP_KERNEL);
|
|
if (!rx_buf) {
|
|
ret = -ENOMEM;
|
|
goto err_rxb;
|
|
}
|
|
|
|
/* Allocate URB */
|
|
urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
if (urb == NULL) {
|
|
ret = -ENOMEM;
|
|
goto err_urb;
|
|
}
|
|
|
|
/* Allocate buffer */
|
|
skb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_KERNEL);
|
|
if (!skb) {
|
|
ret = -ENOMEM;
|
|
goto err_skb;
|
|
}
|
|
|
|
rx_buf->hif_dev = hif_dev;
|
|
rx_buf->skb = skb;
|
|
|
|
usb_fill_int_urb(urb, hif_dev->udev,
|
|
usb_rcvintpipe(hif_dev->udev,
|
|
USB_REG_IN_PIPE),
|
|
skb->data, MAX_REG_IN_BUF_SIZE,
|
|
ath9k_hif_usb_reg_in_cb, rx_buf, 1);
|
|
|
|
/* Anchor URB */
|
|
usb_anchor_urb(urb, &hif_dev->reg_in_submitted);
|
|
|
|
/* Submit URB */
|
|
ret = usb_submit_urb(urb, GFP_KERNEL);
|
|
if (ret) {
|
|
usb_unanchor_urb(urb);
|
|
goto err_submit;
|
|
}
|
|
|
|
/*
|
|
* Drop reference count.
|
|
* This ensures that the URB is freed when killing them.
|
|
*/
|
|
usb_free_urb(urb);
|
|
}
|
|
|
|
return 0;
|
|
|
|
err_submit:
|
|
kfree_skb(skb);
|
|
err_skb:
|
|
usb_free_urb(urb);
|
|
err_urb:
|
|
kfree(rx_buf);
|
|
err_rxb:
|
|
ath9k_hif_usb_dealloc_reg_in_urbs(hif_dev);
|
|
return ret;
|
|
}
|
|
|
|
static int ath9k_hif_usb_alloc_urbs(struct hif_device_usb *hif_dev)
|
|
{
|
|
/* Register Write */
|
|
init_usb_anchor(&hif_dev->regout_submitted);
|
|
|
|
/* TX */
|
|
if (ath9k_hif_usb_alloc_tx_urbs(hif_dev) < 0)
|
|
goto err;
|
|
|
|
/* RX */
|
|
if (ath9k_hif_usb_alloc_rx_urbs(hif_dev) < 0)
|
|
goto err_rx;
|
|
|
|
/* Register Read */
|
|
if (ath9k_hif_usb_alloc_reg_in_urbs(hif_dev) < 0)
|
|
goto err_reg;
|
|
|
|
return 0;
|
|
err_reg:
|
|
ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
|
|
err_rx:
|
|
ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
|
|
err:
|
|
return -ENOMEM;
|
|
}
|
|
|
|
void ath9k_hif_usb_dealloc_urbs(struct hif_device_usb *hif_dev)
|
|
{
|
|
usb_kill_anchored_urbs(&hif_dev->regout_submitted);
|
|
ath9k_hif_usb_dealloc_reg_in_urbs(hif_dev);
|
|
ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
|
|
ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
|
|
}
|
|
|
|
static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev)
|
|
{
|
|
int transfer, err;
|
|
const void *data = hif_dev->fw_data;
|
|
size_t len = hif_dev->fw_size;
|
|
u32 addr = AR9271_FIRMWARE;
|
|
u8 *buf = kzalloc(4096, GFP_KERNEL);
|
|
u32 firm_offset;
|
|
|
|
if (!buf)
|
|
return -ENOMEM;
|
|
|
|
while (len) {
|
|
transfer = min_t(size_t, len, 4096);
|
|
memcpy(buf, data, transfer);
|
|
|
|
err = usb_control_msg(hif_dev->udev,
|
|
usb_sndctrlpipe(hif_dev->udev, 0),
|
|
FIRMWARE_DOWNLOAD, 0x40 | USB_DIR_OUT,
|
|
addr >> 8, 0, buf, transfer, HZ);
|
|
if (err < 0) {
|
|
kfree(buf);
|
|
return err;
|
|
}
|
|
|
|
len -= transfer;
|
|
data += transfer;
|
|
addr += transfer;
|
|
}
|
|
kfree(buf);
|
|
|
|
if (IS_AR7010_DEVICE(hif_dev->usb_device_id->driver_info))
|
|
firm_offset = AR7010_FIRMWARE_TEXT;
|
|
else
|
|
firm_offset = AR9271_FIRMWARE_TEXT;
|
|
|
|
/*
|
|
* Issue FW download complete command to firmware.
|
|
*/
|
|
err = usb_control_msg(hif_dev->udev, usb_sndctrlpipe(hif_dev->udev, 0),
|
|
FIRMWARE_DOWNLOAD_COMP,
|
|
0x40 | USB_DIR_OUT,
|
|
firm_offset >> 8, 0, NULL, 0, HZ);
|
|
if (err)
|
|
return -EIO;
|
|
|
|
dev_info(&hif_dev->udev->dev, "ath9k_htc: Transferred FW: %s, size: %ld\n",
|
|
hif_dev->fw_name, (unsigned long) hif_dev->fw_size);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev)
|
|
{
|
|
int ret;
|
|
|
|
ret = ath9k_hif_usb_download_fw(hif_dev);
|
|
if (ret) {
|
|
dev_err(&hif_dev->udev->dev,
|
|
"ath9k_htc: Firmware - %s download failed\n",
|
|
hif_dev->fw_name);
|
|
return ret;
|
|
}
|
|
|
|
/* Alloc URBs */
|
|
ret = ath9k_hif_usb_alloc_urbs(hif_dev);
|
|
if (ret) {
|
|
dev_err(&hif_dev->udev->dev,
|
|
"ath9k_htc: Unable to allocate URBs\n");
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void ath9k_hif_usb_dev_deinit(struct hif_device_usb *hif_dev)
|
|
{
|
|
ath9k_hif_usb_dealloc_urbs(hif_dev);
|
|
}
|
|
|
|
/*
|
|
* If initialization fails or the FW cannot be retrieved,
|
|
* detach the device.
|
|
*/
|
|
static void ath9k_hif_usb_firmware_fail(struct hif_device_usb *hif_dev)
|
|
{
|
|
struct device *dev = &hif_dev->udev->dev;
|
|
struct device *parent = dev->parent;
|
|
|
|
complete_all(&hif_dev->fw_done);
|
|
|
|
if (parent)
|
|
device_lock(parent);
|
|
|
|
device_release_driver(dev);
|
|
|
|
if (parent)
|
|
device_unlock(parent);
|
|
}
|
|
|
|
static void ath9k_hif_usb_firmware_cb(const struct firmware *fw, void *context);
|
|
|
|
/* taken from iwlwifi */
|
|
static int ath9k_hif_request_firmware(struct hif_device_usb *hif_dev,
|
|
bool first)
|
|
{
|
|
char index[8], *chip;
|
|
int ret;
|
|
|
|
if (first) {
|
|
if (htc_use_dev_fw) {
|
|
hif_dev->fw_minor_index = FIRMWARE_MINOR_IDX_MAX + 1;
|
|
sprintf(index, "%s", "dev");
|
|
} else {
|
|
hif_dev->fw_minor_index = FIRMWARE_MINOR_IDX_MAX;
|
|
sprintf(index, "%d", hif_dev->fw_minor_index);
|
|
}
|
|
} else {
|
|
hif_dev->fw_minor_index--;
|
|
sprintf(index, "%d", hif_dev->fw_minor_index);
|
|
}
|
|
|
|
/* test for FW 1.3 */
|
|
if (MAJOR_VERSION_REQ == 1 && hif_dev->fw_minor_index == 3) {
|
|
const char *filename;
|
|
|
|
if (IS_AR7010_DEVICE(hif_dev->usb_device_id->driver_info))
|
|
filename = FIRMWARE_AR7010_1_1;
|
|
else
|
|
filename = FIRMWARE_AR9271;
|
|
|
|
/* expected fw locations:
|
|
* - htc_9271.fw (stable version 1.3, depricated)
|
|
*/
|
|
snprintf(hif_dev->fw_name, sizeof(hif_dev->fw_name),
|
|
"%s", filename);
|
|
|
|
} else if (hif_dev->fw_minor_index < FIRMWARE_MINOR_IDX_MIN) {
|
|
dev_err(&hif_dev->udev->dev, "no suitable firmware found!\n");
|
|
|
|
return -ENOENT;
|
|
} else {
|
|
if (IS_AR7010_DEVICE(hif_dev->usb_device_id->driver_info))
|
|
chip = "7010";
|
|
else
|
|
chip = "9271";
|
|
|
|
/* expected fw locations:
|
|
* - ath9k_htc/htc_9271-1.dev.0.fw (development version)
|
|
* - ath9k_htc/htc_9271-1.4.0.fw (stable version)
|
|
*/
|
|
snprintf(hif_dev->fw_name, sizeof(hif_dev->fw_name),
|
|
"%s/htc_%s-%d.%s.0.fw", HTC_FW_PATH,
|
|
chip, MAJOR_VERSION_REQ, index);
|
|
}
|
|
|
|
ret = request_firmware_nowait(THIS_MODULE, true, hif_dev->fw_name,
|
|
&hif_dev->udev->dev, GFP_KERNEL,
|
|
hif_dev, ath9k_hif_usb_firmware_cb);
|
|
if (ret) {
|
|
dev_err(&hif_dev->udev->dev,
|
|
"ath9k_htc: Async request for firmware %s failed\n",
|
|
hif_dev->fw_name);
|
|
return ret;
|
|
}
|
|
|
|
dev_info(&hif_dev->udev->dev, "ath9k_htc: Firmware %s requested\n",
|
|
hif_dev->fw_name);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void ath9k_hif_usb_firmware_cb(const struct firmware *fw, void *context)
|
|
{
|
|
struct hif_device_usb *hif_dev = context;
|
|
int ret;
|
|
|
|
if (!fw) {
|
|
ret = ath9k_hif_request_firmware(hif_dev, false);
|
|
if (!ret)
|
|
return;
|
|
|
|
dev_err(&hif_dev->udev->dev,
|
|
"ath9k_htc: Failed to get firmware %s\n",
|
|
hif_dev->fw_name);
|
|
goto err_fw;
|
|
}
|
|
|
|
hif_dev->htc_handle = ath9k_htc_hw_alloc(hif_dev, &hif_usb,
|
|
&hif_dev->udev->dev);
|
|
if (hif_dev->htc_handle == NULL)
|
|
goto err_dev_alloc;
|
|
|
|
hif_dev->fw_data = fw->data;
|
|
hif_dev->fw_size = fw->size;
|
|
|
|
/* Proceed with initialization */
|
|
|
|
ret = ath9k_hif_usb_dev_init(hif_dev);
|
|
if (ret)
|
|
goto err_dev_init;
|
|
|
|
ret = ath9k_htc_hw_init(hif_dev->htc_handle,
|
|
&hif_dev->interface->dev,
|
|
hif_dev->usb_device_id->idProduct,
|
|
hif_dev->udev->product,
|
|
hif_dev->usb_device_id->driver_info);
|
|
if (ret) {
|
|
ret = -EINVAL;
|
|
goto err_htc_hw_init;
|
|
}
|
|
|
|
release_firmware(fw);
|
|
hif_dev->flags |= HIF_USB_READY;
|
|
complete_all(&hif_dev->fw_done);
|
|
|
|
return;
|
|
|
|
err_htc_hw_init:
|
|
ath9k_hif_usb_dev_deinit(hif_dev);
|
|
err_dev_init:
|
|
ath9k_htc_hw_free(hif_dev->htc_handle);
|
|
err_dev_alloc:
|
|
release_firmware(fw);
|
|
err_fw:
|
|
ath9k_hif_usb_firmware_fail(hif_dev);
|
|
}
|
|
|
|
/*
|
|
* An exact copy of the function from zd1211rw.
|
|
*/
|
|
static int send_eject_command(struct usb_interface *interface)
|
|
{
|
|
struct usb_device *udev = interface_to_usbdev(interface);
|
|
struct usb_host_interface *iface_desc = interface->cur_altsetting;
|
|
struct usb_endpoint_descriptor *endpoint;
|
|
unsigned char *cmd;
|
|
u8 bulk_out_ep;
|
|
int r;
|
|
|
|
if (iface_desc->desc.bNumEndpoints < 2)
|
|
return -ENODEV;
|
|
|
|
/* Find bulk out endpoint */
|
|
for (r = 1; r >= 0; r--) {
|
|
endpoint = &iface_desc->endpoint[r].desc;
|
|
if (usb_endpoint_dir_out(endpoint) &&
|
|
usb_endpoint_xfer_bulk(endpoint)) {
|
|
bulk_out_ep = endpoint->bEndpointAddress;
|
|
break;
|
|
}
|
|
}
|
|
if (r == -1) {
|
|
dev_err(&udev->dev,
|
|
"ath9k_htc: Could not find bulk out endpoint\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
cmd = kzalloc(31, GFP_KERNEL);
|
|
if (cmd == NULL)
|
|
return -ENODEV;
|
|
|
|
/* USB bulk command block */
|
|
cmd[0] = 0x55; /* bulk command signature */
|
|
cmd[1] = 0x53; /* bulk command signature */
|
|
cmd[2] = 0x42; /* bulk command signature */
|
|
cmd[3] = 0x43; /* bulk command signature */
|
|
cmd[14] = 6; /* command length */
|
|
|
|
cmd[15] = 0x1b; /* SCSI command: START STOP UNIT */
|
|
cmd[19] = 0x2; /* eject disc */
|
|
|
|
dev_info(&udev->dev, "Ejecting storage device...\n");
|
|
r = usb_bulk_msg(udev, usb_sndbulkpipe(udev, bulk_out_ep),
|
|
cmd, 31, NULL, 2000);
|
|
kfree(cmd);
|
|
if (r)
|
|
return r;
|
|
|
|
/* At this point, the device disconnects and reconnects with the real
|
|
* ID numbers. */
|
|
|
|
usb_set_intfdata(interface, NULL);
|
|
return 0;
|
|
}
|
|
|
|
static int ath9k_hif_usb_probe(struct usb_interface *interface,
|
|
const struct usb_device_id *id)
|
|
{
|
|
struct usb_endpoint_descriptor *bulk_in, *bulk_out, *int_in, *int_out;
|
|
struct usb_device *udev = interface_to_usbdev(interface);
|
|
struct usb_host_interface *alt;
|
|
struct hif_device_usb *hif_dev;
|
|
int ret = 0;
|
|
|
|
/* Verify the expected endpoints are present */
|
|
alt = interface->cur_altsetting;
|
|
if (usb_find_common_endpoints(alt, &bulk_in, &bulk_out, &int_in, &int_out) < 0 ||
|
|
usb_endpoint_num(bulk_in) != USB_WLAN_RX_PIPE ||
|
|
usb_endpoint_num(bulk_out) != USB_WLAN_TX_PIPE ||
|
|
usb_endpoint_num(int_in) != USB_REG_IN_PIPE ||
|
|
usb_endpoint_num(int_out) != USB_REG_OUT_PIPE) {
|
|
dev_err(&udev->dev,
|
|
"ath9k_htc: Device endpoint numbers are not the expected ones\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
if (id->driver_info == STORAGE_DEVICE)
|
|
return send_eject_command(interface);
|
|
|
|
hif_dev = kzalloc(sizeof(struct hif_device_usb), GFP_KERNEL);
|
|
if (!hif_dev) {
|
|
ret = -ENOMEM;
|
|
goto err_alloc;
|
|
}
|
|
|
|
usb_get_dev(udev);
|
|
|
|
hif_dev->udev = udev;
|
|
hif_dev->interface = interface;
|
|
hif_dev->usb_device_id = id;
|
|
#ifdef CONFIG_PM
|
|
udev->reset_resume = 1;
|
|
#endif
|
|
usb_set_intfdata(interface, hif_dev);
|
|
|
|
init_completion(&hif_dev->fw_done);
|
|
|
|
ret = ath9k_hif_request_firmware(hif_dev, true);
|
|
if (ret)
|
|
goto err_fw_req;
|
|
|
|
return ret;
|
|
|
|
err_fw_req:
|
|
usb_set_intfdata(interface, NULL);
|
|
kfree(hif_dev);
|
|
usb_put_dev(udev);
|
|
err_alloc:
|
|
return ret;
|
|
}
|
|
|
|
static void ath9k_hif_usb_reboot(struct usb_device *udev)
|
|
{
|
|
u32 reboot_cmd = 0xffffffff;
|
|
void *buf;
|
|
int ret;
|
|
|
|
buf = kmemdup(&reboot_cmd, 4, GFP_KERNEL);
|
|
if (!buf)
|
|
return;
|
|
|
|
ret = usb_interrupt_msg(udev, usb_sndintpipe(udev, USB_REG_OUT_PIPE),
|
|
buf, 4, NULL, HZ);
|
|
if (ret)
|
|
dev_err(&udev->dev, "ath9k_htc: USB reboot failed\n");
|
|
|
|
kfree(buf);
|
|
}
|
|
|
|
static void ath9k_hif_usb_disconnect(struct usb_interface *interface)
|
|
{
|
|
struct usb_device *udev = interface_to_usbdev(interface);
|
|
struct hif_device_usb *hif_dev = usb_get_intfdata(interface);
|
|
bool unplugged = (udev->state == USB_STATE_NOTATTACHED) ? true : false;
|
|
|
|
if (!hif_dev)
|
|
return;
|
|
|
|
wait_for_completion(&hif_dev->fw_done);
|
|
|
|
if (hif_dev->flags & HIF_USB_READY) {
|
|
ath9k_htc_hw_deinit(hif_dev->htc_handle, unplugged);
|
|
ath9k_hif_usb_dev_deinit(hif_dev);
|
|
ath9k_destoy_wmi(hif_dev->htc_handle->drv_priv);
|
|
ath9k_htc_hw_free(hif_dev->htc_handle);
|
|
}
|
|
|
|
usb_set_intfdata(interface, NULL);
|
|
|
|
/* If firmware was loaded we should drop it
|
|
* go back to first stage bootloader. */
|
|
if (!unplugged && (hif_dev->flags & HIF_USB_READY))
|
|
ath9k_hif_usb_reboot(udev);
|
|
|
|
kfree(hif_dev);
|
|
dev_info(&udev->dev, "ath9k_htc: USB layer deinitialized\n");
|
|
usb_put_dev(udev);
|
|
}
|
|
|
|
#ifdef CONFIG_PM
|
|
static int ath9k_hif_usb_suspend(struct usb_interface *interface,
|
|
pm_message_t message)
|
|
{
|
|
struct hif_device_usb *hif_dev = usb_get_intfdata(interface);
|
|
|
|
/*
|
|
* The device has to be set to FULLSLEEP mode in case no
|
|
* interface is up.
|
|
*/
|
|
if (!(hif_dev->flags & HIF_USB_START))
|
|
ath9k_htc_suspend(hif_dev->htc_handle);
|
|
|
|
wait_for_completion(&hif_dev->fw_done);
|
|
|
|
if (hif_dev->flags & HIF_USB_READY)
|
|
ath9k_hif_usb_dealloc_urbs(hif_dev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int ath9k_hif_usb_resume(struct usb_interface *interface)
|
|
{
|
|
struct hif_device_usb *hif_dev = usb_get_intfdata(interface);
|
|
struct htc_target *htc_handle = hif_dev->htc_handle;
|
|
int ret;
|
|
const struct firmware *fw;
|
|
|
|
ret = ath9k_hif_usb_alloc_urbs(hif_dev);
|
|
if (ret)
|
|
return ret;
|
|
|
|
if (hif_dev->flags & HIF_USB_READY) {
|
|
/* request cached firmware during suspend/resume cycle */
|
|
ret = request_firmware(&fw, hif_dev->fw_name,
|
|
&hif_dev->udev->dev);
|
|
if (ret)
|
|
goto fail_resume;
|
|
|
|
hif_dev->fw_data = fw->data;
|
|
hif_dev->fw_size = fw->size;
|
|
ret = ath9k_hif_usb_download_fw(hif_dev);
|
|
release_firmware(fw);
|
|
if (ret)
|
|
goto fail_resume;
|
|
} else {
|
|
ath9k_hif_usb_dealloc_urbs(hif_dev);
|
|
return -EIO;
|
|
}
|
|
|
|
mdelay(100);
|
|
|
|
ret = ath9k_htc_resume(htc_handle);
|
|
|
|
if (ret)
|
|
goto fail_resume;
|
|
|
|
return 0;
|
|
|
|
fail_resume:
|
|
ath9k_hif_usb_dealloc_urbs(hif_dev);
|
|
|
|
return ret;
|
|
}
|
|
#endif
|
|
|
|
static struct usb_driver ath9k_hif_usb_driver = {
|
|
.name = KBUILD_MODNAME,
|
|
.probe = ath9k_hif_usb_probe,
|
|
.disconnect = ath9k_hif_usb_disconnect,
|
|
#ifdef CONFIG_PM
|
|
.suspend = ath9k_hif_usb_suspend,
|
|
.resume = ath9k_hif_usb_resume,
|
|
.reset_resume = ath9k_hif_usb_resume,
|
|
#endif
|
|
.id_table = ath9k_hif_usb_ids,
|
|
.soft_unbind = 1,
|
|
.disable_hub_initiated_lpm = 1,
|
|
};
|
|
|
|
int ath9k_hif_usb_init(void)
|
|
{
|
|
return usb_register(&ath9k_hif_usb_driver);
|
|
}
|
|
|
|
void ath9k_hif_usb_exit(void)
|
|
{
|
|
usb_deregister(&ath9k_hif_usb_driver);
|
|
}
|