Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee676cd5 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Kalle Valo
Browse files

mt76: add driver code for MT76x2u based devices



MT76x2u is a 2x2 USB 802.11ac chipset by MediaTek. This driver currently
support station mode

Tested-by: default avatar <cug_yangyuancong@hotmail.com>
Signed-off-by: default avatarLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent b40b15e1
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -17,3 +17,13 @@ config MT76x2E
	depends on PCI
	---help---
	  This adds support for MT7612/MT7602/MT7662-based wireless PCIe devices.

config MT76x2U
	tristate "MediaTek MT76x2U (USB) support"
	select MT76_CORE
	select MT76_USB
	select MT76x2_COMMON
	depends on MAC80211
	depends on USB
	help
	  This adds support for MT7612U-based wireless USB dongles.
+5 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ obj-$(CONFIG_MT76_CORE) += mt76.o
obj-$(CONFIG_MT76_USB) += mt76-usb.o
obj-$(CONFIG_MT76x2_COMMON) += mt76x2-common.o
obj-$(CONFIG_MT76x2E) += mt76x2e.o
obj-$(CONFIG_MT76x2U) += mt76x2u.o

mt76-y := \
	mmio.o util.o trace.o dma.o mac80211.o debugfs.o eeprom.o tx.o agg-rx.o
@@ -22,4 +23,8 @@ mt76x2e-y := \
	mt76x2_core.o mt76x2_mac.o mt76x2_mcu.o mt76x2_phy.o \
	mt76x2_dfs.o mt76x2_trace.o

mt76x2u-y := \
	mt76x2_usb.o mt76x2u_init.o mt76x2u_main.o mt76x2u_mac.o \
	mt76x2u_mcu.o mt76x2u_phy.o mt76x2u_core.o

CFLAGS_mt76x2_trace.o := -I$(src)
+4 −0
Original line number Diff line number Diff line
@@ -33,6 +33,9 @@
#define MT7662_ROM_PATCH	"mt7662_rom_patch.bin"
#define MT7662_EEPROM_SIZE	512

#define MT7662U_FIRMWARE	"mediatek/mt7662u.bin"
#define MT7662U_ROM_PATCH	"mediatek/mt7662u_rom_patch.bin"

#define MT76x2_RX_RING_SIZE	256
#define MT_RX_HEADROOM		32

@@ -55,6 +58,7 @@ struct mt76x2_mcu {

	wait_queue_head_t wait;
	struct sk_buff_head res_q;
	struct mt76u_buf res_u;

	u32 msg_seq;
};
+30 −0
Original line number Diff line number Diff line
@@ -75,6 +75,21 @@

#define MT_XO_CTRL7			0x011c

#define MT_USB_U3DMA_CFG		0x9018
#define MT_USB_DMA_CFG_RX_BULK_AGG_TOUT	GENMASK(7, 0)
#define MT_USB_DMA_CFG_RX_BULK_AGG_LMT	GENMASK(15, 8)
#define MT_USB_DMA_CFG_UDMA_TX_WL_DROP	BIT(16)
#define MT_USB_DMA_CFG_WAKE_UP_EN	BIT(17)
#define MT_USB_DMA_CFG_RX_DROP_OR_PAD	BIT(18)
#define MT_USB_DMA_CFG_TX_CLR		BIT(19)
#define MT_USB_DMA_CFG_TXOP_HALT	BIT(20)
#define MT_USB_DMA_CFG_RX_BULK_AGG_EN	BIT(21)
#define MT_USB_DMA_CFG_RX_BULK_EN	BIT(22)
#define MT_USB_DMA_CFG_TX_BULK_EN	BIT(23)
#define MT_USB_DMA_CFG_EP_OUT_VALID	GENMASK(29, 24)
#define MT_USB_DMA_CFG_RX_BUSY		BIT(30)
#define MT_USB_DMA_CFG_TX_BUSY		BIT(31)

#define MT_WLAN_MTC_CTRL		0x10148
#define MT_WLAN_MTC_CTRL_MTCMOS_PWR_UP	BIT(0)
#define MT_WLAN_MTC_CTRL_PWR_ACK	BIT(12)
@@ -150,6 +165,9 @@
#define MT_TX_HW_QUEUE_MCU		8
#define MT_TX_HW_QUEUE_MGMT		9

#define MT_US_CYC_CFG			0x02a4
#define MT_US_CYC_CNT			GENMASK(7, 0)

#define MT_PBF_SYS_CTRL			0x0400
#define MT_PBF_SYS_CTRL_MCU_RESET	BIT(0)
#define MT_PBF_SYS_CTRL_DMA_RESET	BIT(1)
@@ -202,6 +220,11 @@

#define MT_FCE_WLAN_FLOW_CONTROL1	0x0824

#define MT_TX_CPU_FROM_FCE_BASE_PTR	0x09a0
#define MT_TX_CPU_FROM_FCE_MAX_COUNT	0x09a4
#define MT_FCE_PDMA_GLOBAL_CONF		0x09c4
#define MT_FCE_SKIP_FS			0x0a6c

#define MT_PAUSE_ENABLE_CONTROL1	0x0a38

#define MT_MAC_CSR0			0x1000
@@ -214,6 +237,7 @@

#define MT_MAC_ADDR_DW0			0x1008
#define MT_MAC_ADDR_DW1			0x100c
#define MT_MAC_ADDR_DW1_U2ME_MASK	GENMASK(23, 16)

#define MT_MAC_BSSID_DW0		0x1010
#define MT_MAC_BSSID_DW1		0x1014
@@ -351,6 +375,7 @@
#define MT_TX_TIMEOUT_CFG_ACKTO		GENMASK(15, 8)

#define MT_TX_RETRY_CFG			0x134c
#define MT_TX_LINK_CFG			0x1350
#define MT_VHT_HT_FBK_CFG1		0x1358

#define MT_PROT_CFG_RATE		GENMASK(15, 0)
@@ -425,6 +450,7 @@
#define MT_RX_FILTR_CFG_BAR		BIT(15)
#define MT_RX_FILTR_CFG_CTRL_RSV	BIT(16)

#define MT_AUTO_RSP_CFG			0x1404
#define MT_LEGACY_BASIC_RATE		0x1408
#define MT_HT_BASIC_RATE		0x140c

@@ -460,6 +486,10 @@
#define MT_RX_STAT_2_DUP_ERRORS		GENMASK(15, 0)
#define MT_RX_STAT_2_OVERFLOW_ERRORS	GENMASK(31, 16)

#define MT_TX_STA_0			0x170c
#define MT_TX_STA_1			0x1710
#define MT_TX_STA_2			0x1714

#define MT_TX_STAT_FIFO			0x1718
#define MT_TX_STAT_FIFO_VALID		BIT(0)
#define MT_TX_STAT_FIFO_SUCCESS		BIT(5)
+142 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
 *
 * 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 <linux/kernel.h>
#include <linux/module.h>

#include "mt76x2u.h"

static const struct usb_device_id mt76x2u_device_table[] = {
	{ USB_DEVICE(0x0b05, 0x1833) },	/* Asus USB-AC54 */
	{ USB_DEVICE(0x0b05, 0x17eb) },	/* Asus USB-AC55 */
	{ USB_DEVICE(0x0b05, 0x180b) },	/* Asus USB-N53 B1 */
	{ USB_DEVICE(0x0e8d, 0x7612) },	/* Aukey USB-AC1200 */
	{ USB_DEVICE(0x057c, 0x8503) },	/* Avm FRITZ!WLAN AC860 */
	{ USB_DEVICE(0x7392, 0xb711) },	/* Edimax EW 7722 UAC */
	{ USB_DEVICE(0x0846, 0x9053) },	/* Netgear A6210 */
	{ USB_DEVICE(0x045e, 0x02e6) },	/* XBox One Wireless Adapter */
	{ },
};

static int mt76x2u_probe(struct usb_interface *intf,
			 const struct usb_device_id *id)
{
	struct usb_device *udev = interface_to_usbdev(intf);
	struct mt76x2_dev *dev;
	int err;

	dev = mt76x2u_alloc_device(&intf->dev);
	if (!dev)
		return -ENOMEM;

	udev = usb_get_dev(udev);
	usb_reset_device(udev);

	err = mt76u_init(&dev->mt76, intf);
	if (err < 0)
		goto err;

	dev->mt76.rev = mt76_rr(dev, MT_ASIC_VERSION);
	dev_info(dev->mt76.dev, "ASIC revision: %08x\n", dev->mt76.rev);

	err = mt76x2u_register_device(dev);
	if (err < 0)
		goto err;

	return 0;

err:
	ieee80211_free_hw(mt76_hw(dev));
	usb_set_intfdata(intf, NULL);
	usb_put_dev(udev);

	return err;
}

static void mt76x2u_disconnect(struct usb_interface *intf)
{
	struct usb_device *udev = interface_to_usbdev(intf);
	struct mt76x2_dev *dev = usb_get_intfdata(intf);
	struct ieee80211_hw *hw = mt76_hw(dev);

	set_bit(MT76_REMOVED, &dev->mt76.state);
	ieee80211_unregister_hw(hw);
	mt76x2u_cleanup(dev);

	ieee80211_free_hw(hw);
	usb_set_intfdata(intf, NULL);
	usb_put_dev(udev);
}

static int __maybe_unused mt76x2u_suspend(struct usb_interface *intf,
					  pm_message_t state)
{
	struct mt76x2_dev *dev = usb_get_intfdata(intf);
	struct mt76_usb *usb = &dev->mt76.usb;

	mt76u_stop_queues(&dev->mt76);
	mt76x2u_stop_hw(dev);
	usb_kill_urb(usb->mcu.res.urb);

	return 0;
}

static int __maybe_unused mt76x2u_resume(struct usb_interface *intf)
{
	struct mt76x2_dev *dev = usb_get_intfdata(intf);
	struct mt76_usb *usb = &dev->mt76.usb;
	int err;

	reinit_completion(&usb->mcu.cmpl);
	err = mt76u_submit_buf(&dev->mt76, USB_DIR_IN,
			       MT_EP_IN_CMD_RESP,
			       &usb->mcu.res, GFP_KERNEL,
			       mt76u_mcu_complete_urb,
			       &usb->mcu.cmpl);
	if (err < 0)
		return err;

	err = mt76u_submit_rx_buffers(&dev->mt76);
	if (err < 0)
		return err;

	tasklet_enable(&usb->rx_tasklet);
	tasklet_enable(&usb->tx_tasklet);

	return mt76x2u_init_hardware(dev);
}

MODULE_DEVICE_TABLE(usb, mt76x2u_device_table);
MODULE_FIRMWARE(MT7662U_FIRMWARE);
MODULE_FIRMWARE(MT7662U_ROM_PATCH);

static struct usb_driver mt76x2u_driver = {
	.name		= KBUILD_MODNAME,
	.id_table	= mt76x2u_device_table,
	.probe		= mt76x2u_probe,
	.disconnect	= mt76x2u_disconnect,
#ifdef CONFIG_PM
	.suspend	= mt76x2u_suspend,
	.resume		= mt76x2u_resume,
	.reset_resume	= mt76x2u_resume,
#endif /* CONFIG_PM */
	.soft_unbind	= 1,
	.disable_hub_initiated_lpm = 1,
};
module_usb_driver(mt76x2u_driver);

MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>");
MODULE_LICENSE("Dual BSD/GPL");
Loading