From 7ae912385bbc2c47f02957bffe0f52aa54771711 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 8 Dec 2015 11:18:54 +0100 Subject: [PATCH] mt7603: register device with mac80211 Signed-off-by: Felix Fietkau --- mt7603.h | 4 +++- mt7603_init.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++- mt7603_pci.c | 7 +----- 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/mt7603.h b/mt7603.h index 9fb9bea9..f42b377c 100644 --- a/mt7603.h +++ b/mt7603.h @@ -50,6 +50,8 @@ struct mt7603_mcu { struct mt7603_dev { struct mt76_dev mt76; + struct cfg80211_chan_def chandef; + u32 irqmask; spinlock_t irq_lock; @@ -69,7 +71,7 @@ extern const struct ieee80211_ops mt7603_ops; struct mt7603_dev *mt7603_alloc_device(struct device *pdev); irqreturn_t mt7603_irq_handler(int irq, void *dev_instance); -int mt7603_init_hardware(struct mt7603_dev *dev); +int mt7603_register_device(struct mt7603_dev *dev); int mt7603_dma_init(struct mt7603_dev *dev); void mt7603_dma_cleanup(struct mt7603_dev *dev); int mt7603_mcu_init(struct mt7603_dev *dev); diff --git a/mt7603_init.c b/mt7603_init.c index d60267a2..d34aec64 100644 --- a/mt7603_init.c +++ b/mt7603_init.c @@ -79,7 +79,8 @@ int mt7603_mac_start(struct mt7603_dev *dev) return 0; } -int mt7603_init_hardware(struct mt7603_dev *dev) +static int +mt7603_init_hardware(struct mt7603_dev *dev) { int ret; @@ -108,3 +109,63 @@ int mt7603_init_hardware(struct mt7603_dev *dev) return 0; } + +#define CCK_RATE(_idx, _rate) { \ + .bitrate = _rate, \ + .flags = IEEE80211_RATE_SHORT_PREAMBLE, \ + .hw_value = (MT_PHY_TYPE_CCK << 8) | _idx, \ + .hw_value_short = (MT_PHY_TYPE_CCK << 8) | (4 + _idx), \ +} + +#define OFDM_RATE(_idx, _rate) { \ + .bitrate = _rate, \ + .hw_value = (MT_PHY_TYPE_OFDM << 8) | _idx, \ + .hw_value_short = (MT_PHY_TYPE_OFDM << 8) | _idx, \ +} + +static struct ieee80211_rate mt76x2_rates[] = { + CCK_RATE(0, 10), + CCK_RATE(1, 20), + CCK_RATE(2, 55), + CCK_RATE(3, 110), + OFDM_RATE(11, 60), + OFDM_RATE(15, 90), + OFDM_RATE(10, 120), + OFDM_RATE(14, 180), + OFDM_RATE(9, 240), + OFDM_RATE(13, 360), + OFDM_RATE(8, 480), + OFDM_RATE(12, 540), +}; + + +int mt7603_register_device(struct mt7603_dev *dev) +{ + static u8 macaddr[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }; + struct ieee80211_hw *hw = mt76_hw(dev); + struct ieee80211_supported_band *sband; + struct wiphy *wiphy = hw->wiphy; + int ret; + + ret = mt7603_init_hardware(dev); + if (ret) + return ret; + + hw->queues = 4; + hw->max_rates = 1; + hw->max_report_rates = 7; + hw->max_rate_tries = 1; + hw->extra_tx_headroom = 2; + + SET_IEEE80211_PERM_ADDR(hw, macaddr); + + ret = mt76_register_device(&dev->mt76, BIT(IEEE80211_BAND_2GHZ), true, + mt76x2_rates, ARRAY_SIZE(mt76x2_rates)); + if (ret) + return ret; + + sband = wiphy->bands[IEEE80211_BAND_2GHZ]; + dev->chandef.chan = &sband->channels[0]; + + return 0; +} diff --git a/mt7603_pci.c b/mt7603_pci.c index dc8a718b..ce4e787e 100644 --- a/mt7603_pci.c +++ b/mt7603_pci.c @@ -59,15 +59,10 @@ mt76pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (ret) goto error; - ret = mt7603_init_hardware(dev); + ret = mt7603_register_device(dev); if (ret) goto error; - if (1) { - ret = -EINVAL; - goto error; - } - return 0; error: ieee80211_free_hw(mt76_hw(dev));