From patchwork Fri Dec 22 19:33:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Enrico Mioso X-Patchwork-Id: 10131025 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 694D56038F for ; Fri, 22 Dec 2017 19:33:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B00B2995B for ; Fri, 22 Dec 2017 19:33:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FD0C29E3D; Fri, 22 Dec 2017 19:33:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 157AA29EFC for ; Fri, 22 Dec 2017 19:33:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756167AbdLVTdz (ORCPT ); Fri, 22 Dec 2017 14:33:55 -0500 Received: from mail-wr0-f169.google.com ([209.85.128.169]:34662 "EHLO mail-wr0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752224AbdLVTdy (ORCPT ); Fri, 22 Dec 2017 14:33:54 -0500 Received: by mail-wr0-f169.google.com with SMTP id y21so28756010wrc.1 for ; Fri, 22 Dec 2017 11:33:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version; bh=v1HOIhS8lgwqHZPTB8Rg+hQAcKKagTWkrCJ4SMnS+aU=; b=XodxM8nn7r7b+s6gDHHlATBnvTd0ggkecypPgv94ozdIE6g8bbRTjBkCT3wPRlnCJB +daAfkclQofqqB/TRidg7yxSsmmfqZFVeP1bFUKq/cLgyypbiHKew9uCuaAOBXHKFWBJ RzF/TE0corSgEg9roJTOpffpVrnTbiIPOI6Ow97CG6QMxa2o+9QX+Qh8/N35L3NTPyCS 4nhto7aALANVvwFG1o7X8lLdW0yL2WAnRi4RVE2pc+6HUwiZoj2hrQbOn5AlVr+LOozG LGDDngsc/bPvPO/3qcqqcA2tgM3KjZyDyKKUGmSh4Z0k8u4Sinolxrw7W2LFuA/HOf8z TXRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version; bh=v1HOIhS8lgwqHZPTB8Rg+hQAcKKagTWkrCJ4SMnS+aU=; b=hzKnBDGn2onlw5ITm7gPjeafPyvm3PbUQL7P9B7UZBG6JrdmYlAjajkXQR7RzMpbSq AZyuL7z+7oAapsVpIeVJhC0s7Mpc5eHvZCxrB+0UiaNT1bg/g88DTe8f3U9I/XMsuwRI o8Qm4gIwd3M6Z7ooWNbhJbvbPMJpCEuU0fzuE4GOPnLtvfYnkjcg0w7OiRGIqaG2dwZA VwFCWEwwdlJiCUwoPlehO2ixLL1v3gecheprc+9KpBRBIZ0HTFSd6paFGiaT8/hwBQHN 7cNRGgEGDEfbDDEsZbZaHIVizd0eNFZp4tpL/PKre9MS0j2eDKUFoZyN97ZZISBjL38q CzRA== X-Gm-Message-State: AKGB3mJttElucyDxDsRCw5BifPO07TG9DNRi3Z7ssksU/paZ4+JryQKR TvNXZDApdmhvM8QWdrnblhg= X-Google-Smtp-Source: ACJfBovstvMQOVz670/aZIIw0aL2u0+IMA3NAUhQNe52FqyHYBMHLyYq5F8TfHmdhDA03/46KnlqXw== X-Received: by 10.223.190.12 with SMTP id n12mr8016553wrh.34.1513971233263; Fri, 22 Dec 2017 11:33:53 -0800 (PST) Received: from localhost.localdomain (host248-105-dynamic.50-82-r.retail.telecomitalia.it. [82.50.105.248]) by smtp.gmail.com with ESMTPSA id j77sm29609218wmf.36.2017.12.22.11.33.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Dec 2017 11:33:52 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by localhost.localdomain (OpenSMTPD) with ESMTP id d4525738; Fri, 22 Dec 2017 19:33:49 +0000 (UTC) Date: Fri, 22 Dec 2017 20:33:49 +0100 (CET) From: Enrico Mioso X-X-Sender: mrkiko@localhost.localdomain To: linux-wireless@vger.kernel.org cc: Stanislaw Gruszka , Felix Fietkau Subject: mt76x0 support Message-ID: MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hello Felix, Stanislaw, linux-wireless list, and everybody reading this message. So I am trying to see if it's possible to get an MT7630 device to a "workable" state. So I used this https://github.com/neurobin/MT7630E as a reference, the MT7601u to look how things where done (upstream version in drivers/net/wireless/mediatek/mt7601u ). Here is the diff I came up with. The diff is relative to mt76.git. Any idea and / or hint would be greatly apreciated. I have some difficulties in understanding how to access the EEPROM to read e.g.: the MAC address and other data if needed (calibration etc). The device is on a MIPS device, so unfortunately I will have to test my code there, since opening up the device and desoldering / removing the card is not easily done. Is there some way I can debug things, get more infos on the device? Thank you very much for your help and patience, and hints. They allowed me to get here, try this new approach. For now I am modifying the code, but the palan would be to clean up things at the end a create a new module, and mark common functions as such. Enrico diff --git a/mt76x2_init.c b/mt76x2_init.c index 6f942e5..1b321e2 100644 --- a/mt76x2_init.c +++ b/mt76x2_init.c @@ -330,6 +330,14 @@ int mt76x2_mac_reset(struct mt76x2_dev *dev, bool hard) return 0; } +int mt76x0_mac_reset(struct mt76x2_dev *dev) +{ + mt76_set(dev, MT_MAC_SYS_CTRL, MT_MAC_SYS_CTRL_RESET_CSR); + udelay(50); + mt76_clear(dev, MT_MAC_SYS_CTRL, MT_MAC_SYS_CTRL_RESET_CSR); + return 0; +} + int mt76x2_mac_start(struct mt76x2_dev *dev) { int i; @@ -364,6 +372,34 @@ int mt76x2_mac_start(struct mt76x2_dev *dev) return 0; } +int mt76x0_mac_start(struct mt76x2_dev *dev) +{ + mt76_wr(dev, MT_MAC_SYS_CTRL, MT_MAC_SYS_CTRL_ENABLE_TX); + + if (!mt76_poll(dev, MT_WPDMA_GLO_CFG, MT_WPDMA_GLO_CFG_TX_DMA_BUSY | + MT_WPDMA_GLO_CFG_RX_DMA_BUSY, 0, 200000)) + return -ETIMEDOUT; + + dev->rxfilter = MT_RX_FILTR_CFG_CRC_ERR | + MT_RX_FILTR_CFG_PHY_ERR | MT_RX_FILTR_CFG_PROMISC | + MT_RX_FILTR_CFG_VER_ERR | MT_RX_FILTR_CFG_DUP | + MT_RX_FILTR_CFG_CFACK | MT_RX_FILTR_CFG_CFEND | + MT_RX_FILTR_CFG_ACK | MT_RX_FILTR_CFG_CTS | + MT_RX_FILTR_CFG_RTS | MT_RX_FILTR_CFG_PSPOLL | + MT_RX_FILTR_CFG_BA | MT_RX_FILTR_CFG_CTRL_RSV; + + mt76_wr(dev, MT_RX_FILTR_CFG, dev->rxfilter); + + mt76_wr(dev, MT_MAC_SYS_CTRL, + MT_MAC_SYS_CTRL_ENABLE_TX | MT_MAC_SYS_CTRL_ENABLE_RX); + + if (!mt76_poll(dev, MT_WPDMA_GLO_CFG, MT_WPDMA_GLO_CFG_TX_DMA_BUSY | + MT_WPDMA_GLO_CFG_RX_DMA_BUSY, 0, 50)) + return -ETIMEDOUT; + + return 0; +} + void mt76x2_mac_stop(struct mt76x2_dev *dev, bool force) { bool stopped = false; @@ -399,6 +435,38 @@ void mt76x2_mac_stop(struct mt76x2_dev *dev, bool force) mt76_wr(dev, MT_TX_RTS_CFG, rts_cfg); } +void mt76x0_mac_stop(struct mt76x2_dev *dev) { + int i, ok; + + mt76_clear(dev, MT_BEACON_TIME_CFG, MT_BEACON_TIME_CFG_TIMER_EN | + MT_BEACON_TIME_CFG_SYNC_MODE | MT_BEACON_TIME_CFG_TBTT_EN | + MT_BEACON_TIME_CFG_BEACON_TX); + + /* Page count on TxQ */ + i = 200; + while (i-- && ((mt76_rr(dev, 0x0438) & 0xffffffff) || + (mt76_rr(dev, 0x0a30) & 0x000000ff) || + (mt76_rr(dev, 0x0a34) & 0x00ff00ff))) + msleep(10); + + mt76_clear(dev, MT_MAC_SYS_CTRL, MT_MAC_SYS_CTRL_ENABLE_RX | + MT_MAC_SYS_CTRL_ENABLE_TX); + + /* Page count on RxQ */ + ok = 0; + i = 200; + while (i--) { + if (!(mt76_rr(dev, MT_RXQ_STA) & 0x00ff0000) && + !mt76_rr(dev, 0x0a30) && + !mt76_rr(dev, 0x0a34)) { + if (ok++ > 5) + break; + continue; + } + msleep(1); + } +} + void mt76x2_mac_resume(struct mt76x2_dev *dev) { mt76_wr(dev, MT_MAC_SYS_CTRL, @@ -485,6 +553,34 @@ mt76x2_power_on(struct mt76x2_dev *dev) mt76x2_power_on_rf(dev, 1); } +/* Big thanks to the author(s?) of mt7601U, upstream version */ +static void +mt76x2_power_on_76x0(struct mt76x2_dev *dev) +{ + int i; + u32 val; + + val = mt76_rr(dev, MT_WLAN_FUN_CTRL); + + /* Note: we don't turn off WLAN_CLK because that may make the device not responsive. */ + val |= (MT_WLAN_FUN_CTRL_WLAN_EN | + MT_WLAN_FUN_CTRL_WLAN_CLK_EN); + + mt76_wr(dev, MT_WLAN_FUN_CTRL, val); + udelay(50); + + for (i = 200; i; i--) { + val = mt76_rr(dev, MT_CMB_CTRL); + if (val & MT_CMB_CTRL_XTAL_RDY && val & MT_CMB_CTRL_PLL_LD) + break; + + udelay(50); + } + + if (!i) + dev_err(dev->mt76.dev, "Error: PLL and XTAL check failed!\n"); +} + void mt76x2_set_tx_ackto(struct mt76x2_dev *dev) { u8 ackto, sifs, slottime = dev->slottime; @@ -543,23 +639,21 @@ int mt76x2_init_hardware(struct mt76x2_dev *dev) static const u16 beacon_offsets[16] = { /* 1024 byte per beacon */ 0xc000, + 0xc200, 0xc400, + 0xc600, 0xc800, + 0xca00, 0xcc00, + 0xce00, 0xd000, + 0xd200, 0xd400, + 0xd600, 0xd800, + 0xda00, 0xdc00, - - /* BSS idx 8-15 not used for beacons */ - 0xc000, - 0xc000, - 0xc000, - 0xc000, - 0xc000, - 0xc000, - 0xc000, - 0xc000, + 0xde00, }; u32 val; int ret; @@ -581,24 +675,28 @@ int mt76x2_init_hardware(struct mt76x2_dev *dev) mt76_wr(dev, MT_WPDMA_GLO_CFG, val); mt76x2_reset_wlan(dev, true); - mt76x2_power_on(dev); + mt76x2_power_on_76x0(dev); - ret = mt76x2_eeprom_init(dev); + /* Note: at this point the vendor driver does write some things to MT_CMB_CTRL; we aren't. */ + + /* Note: at this point the vendor driver does write some things to MT_CMB_CTRL; we aren't. */ + + /* ret = mt76x2_eeprom_init(dev); if (ret) - return ret; + return ret; */ - ret = mt76x2_mac_reset(dev, true); + ret = mt76x0_mac_reset(dev); if (ret) return ret; dev->rxfilter = mt76_rr(dev, MT_RX_FILTR_CFG); - ret = mt76x2_dma_init(dev); + //ret = mt76x0_dma_init(dev); XXX MISSING BUT NEEDED if (ret) return ret; set_bit(MT76_STATE_INITIALIZED, &dev->mt76.state); - ret = mt76x2_mac_start(dev); + ret = mt76x0_mac_start(dev); if (ret) return ret; diff --git a/mt76x2_regs.h b/mt76x2_regs.h index 95c1e95..ca2bca4 100644 --- a/mt76x2_regs.h +++ b/mt76x2_regs.h @@ -47,6 +47,7 @@ #define MT_WLAN_FUN_CTRL_WLAN_RESET_RF BIT(2) #define MT_WLAN_FUN_CTRL_WLAN_RESET BIT(3) /* MT76x0 */ +#define MT_RXQ_STA 0x0430 #define MT_WLAN_FUN_CTRL_CSR_F20M_CKEN BIT(3) /* MT76x2 */ #define MT_WLAN_FUN_CTRL_PCIE_CLK_REQ BIT(4)