OSDN Git Service

mt76: move mt76x02_beacon_offset in mt76x02_util.c
authorLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Fri, 28 Sep 2018 11:38:49 +0000 (13:38 +0200)
committerFelix Fietkau <nbd@nbd.name>
Mon, 1 Oct 2018 10:34:23 +0000 (12:34 +0200)
Move mt76x02_beacon_offset utility routine in mt76x02-lib module
since it is shared between mt76x0 and mt76x2 driver and remove
duplicated code. Moreover move beacon_offset data structure in
mt76x02-lib module since it is shared between mt76x0 and mt76x2
drivers

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt76x0/init.c
drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h
drivers/net/wireless/mediatek/mt76/mt76x02_util.c
drivers/net/wireless/mediatek/mt76/mt76x02_util.h
drivers/net/wireless/mediatek/mt76/mt76x2.h
drivers/net/wireless/mediatek/mt76/mt76x2_init.c
drivers/net/wireless/mediatek/mt76/mt76x2_mac.c
drivers/net/wireless/mediatek/mt76/mt76x2u_init.c

index 5e3ec1b..3b4a67b 100644 (file)
@@ -168,30 +168,13 @@ static int mt76x0_init_bbp(struct mt76x0_dev *dev)
        return 0;
 }
 
-static void
-mt76_init_beacon_offsets(struct mt76x0_dev *dev)
-{
-       u16 base = MT_BEACON_BASE;
-       u32 regs[4] = {};
-       int i;
-
-       for (i = 0; i < 16; i++) {
-               u16 addr = dev->beacon_offsets[i];
-
-               regs[i / 4] |= ((addr - base) / 64) << (8 * (i % 4));
-       }
-
-       for (i = 0; i < 4; i++)
-               mt76_wr(dev, MT_BCN_OFFSET(i), regs[i]);
-}
-
 static void mt76x0_init_mac_registers(struct mt76x0_dev *dev)
 {
        u32 reg;
 
        RANDOM_WRITE(dev, common_mac_reg_table);
 
-       mt76_init_beacon_offsets(dev);
+       mt76x02_set_beacon_offsets(&dev->mt76);
 
        /* Enable PBF and MAC clock SYS_CTRL[11:10] = 0x3 */
        RANDOM_WRITE(dev, mt76x0_mac_reg_table);
@@ -372,17 +355,8 @@ EXPORT_SYMBOL_GPL(mt76x0_mac_stop);
 
 int mt76x0_init_hardware(struct mt76x0_dev *dev)
 {
-       static const u16 beacon_offsets[16] = {
-               /* 512 byte per beacon */
-               0xc000, 0xc200, 0xc400, 0xc600,
-               0xc800, 0xca00, 0xcc00, 0xce00,
-               0xd000, 0xd200, 0xd400, 0xd600,
-               0xd800, 0xda00, 0xdc00, 0xde00
-       };
        int ret;
 
-       dev->beacon_offsets = beacon_offsets;
-
        if (!mt76_poll_msec(dev, MT_WPDMA_GLO_CFG,
                            MT_WPDMA_GLO_CFG_TX_DMA_BUSY |
                            MT_WPDMA_GLO_CFG_RX_DMA_BUSY, 0, 100))
index 242abab..66fcb90 100644 (file)
@@ -87,8 +87,6 @@ struct mt76x0_dev {
 
        spinlock_t mac_lock;
 
-       const u16 *beacon_offsets;
-
        struct mt76x0_caldata caldata;
 
        struct mutex reg_atomic_mutex;
index 310720f..ec422c3 100644 (file)
@@ -454,4 +454,42 @@ bool mt76x02_tx_status_data(struct mt76_dev *dev, u8 *update)
 }
 EXPORT_SYMBOL_GPL(mt76x02_tx_status_data);
 
+const u16 mt76x02_beacon_offsets[16] = {
+       /* 1024 byte per beacon */
+       0xc000,
+       0xc400,
+       0xc800,
+       0xcc00,
+       0xd000,
+       0xd400,
+       0xd800,
+       0xdc00,
+       /* BSS idx 8-15 not used for beacons */
+       0xc000,
+       0xc000,
+       0xc000,
+       0xc000,
+       0xc000,
+       0xc000,
+       0xc000,
+       0xc000,
+};
+EXPORT_SYMBOL_GPL(mt76x02_beacon_offsets);
+
+void mt76x02_set_beacon_offsets(struct mt76_dev *dev)
+{
+       u16 val, base = MT_BEACON_BASE;
+       u32 regs[4] = {};
+       int i;
+
+       for (i = 0; i < 16; i++) {
+               val = mt76x02_beacon_offsets[i] - base;
+               regs[i / 4] |= (val / 64) << (8 * (i % 4));
+       }
+
+       for (i = 0; i < 4; i++)
+               __mt76_wr(dev, MT_BCN_OFFSET(i), regs[i]);
+}
+EXPORT_SYMBOL_GPL(mt76x02_set_beacon_offsets);
+
 MODULE_LICENSE("Dual BSD/GPL");
index 2c1ead8..479e7ff 100644 (file)
@@ -52,6 +52,8 @@ void mt76x02_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue *q,
                            struct mt76_queue_entry *e, bool flush);
 bool mt76x02_tx_status_data(struct mt76_dev *dev, u8 *update);
 
+extern const u16 mt76x02_beacon_offsets[16];
+void mt76x02_set_beacon_offsets(struct mt76_dev *dev);
 void mt76x02_set_irq_mask(struct mt76_dev *dev, u32 clear, u32 set);
 
 static inline void mt76x02_irq_enable(struct mt76_dev *dev, u32 mask)
index 1798f41..c51d6e2 100644 (file)
@@ -78,8 +78,6 @@ struct mt76x2_dev {
 
        struct mutex mutex;
 
-       const u16 *beacon_offsets;
-
        u8 txdone_seq;
        DECLARE_KFIFO_PTR(txstatus_fifo, struct mt76x02_tx_status);
 
index 98e40f6..37cbe55 100644 (file)
@@ -79,23 +79,6 @@ mt76x2_fixup_xtal(struct mt76x2_dev *dev)
        }
 }
 
-static void
-mt76x2_init_beacon_offsets(struct mt76x2_dev *dev)
-{
-       u16 base = MT_BEACON_BASE;
-       u32 regs[4] = {};
-       int i;
-
-       for (i = 0; i < 16; i++) {
-               u16 addr = dev->beacon_offsets[i];
-
-               regs[i / 4] |= ((addr - base) / 64) << (8 * (i % 4));
-       }
-
-       for (i = 0; i < 4; i++)
-               mt76_wr(dev, MT_BCN_OFFSET(i), regs[i]);
-}
-
 static int mt76x2_mac_reset(struct mt76x2_dev *dev, bool hard)
 {
        static const u8 null_addr[ETH_ALEN] = {};
@@ -187,7 +170,7 @@ static int mt76x2_mac_reset(struct mt76x2_dev *dev, bool hard)
                MT_CH_TIME_CFG_EIFS_AS_BUSY |
                FIELD_PREP(MT_CH_TIME_CFG_CH_TIMER_CLR, 1));
 
-       mt76x2_init_beacon_offsets(dev);
+       mt76x02_set_beacon_offsets(&dev->mt76);
 
        mt76x2_set_tx_ackto(dev);
 
@@ -325,30 +308,8 @@ void mt76x2_set_tx_ackto(struct mt76x2_dev *dev)
 
 int mt76x2_init_hardware(struct mt76x2_dev *dev)
 {
-       static const u16 beacon_offsets[16] = {
-               /* 1024 byte per beacon */
-               0xc000,
-               0xc400,
-               0xc800,
-               0xcc00,
-               0xd000,
-               0xd400,
-               0xd800,
-               0xdc00,
-
-               /* BSS idx 8-15 not used for beacons */
-               0xc000,
-               0xc000,
-               0xc000,
-               0xc000,
-               0xc000,
-               0xc000,
-               0xc000,
-               0xc000,
-       };
        int ret;
 
-       dev->beacon_offsets = beacon_offsets;
        tasklet_init(&dev->pre_tbtt_tasklet, mt76x2_pre_tbtt_tasklet,
                     (unsigned long) dev);
 
index 5fff086..25ce8fc 100644 (file)
@@ -100,7 +100,7 @@ void mt76x2_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue *q,
 static int
 mt76_write_beacon(struct mt76x2_dev *dev, int offset, struct sk_buff *skb)
 {
-       int beacon_len = dev->beacon_offsets[1] - dev->beacon_offsets[0];
+       int beacon_len = mt76x02_beacon_offsets[1] - mt76x02_beacon_offsets[0];
        struct mt76x02_txwi txwi;
 
        if (WARN_ON_ONCE(beacon_len < skb->len + sizeof(struct mt76x02_txwi)))
@@ -118,8 +118,8 @@ mt76_write_beacon(struct mt76x2_dev *dev, int offset, struct sk_buff *skb)
 static int
 __mt76x2_mac_set_beacon(struct mt76x2_dev *dev, u8 bcn_idx, struct sk_buff *skb)
 {
-       int beacon_len = dev->beacon_offsets[1] - dev->beacon_offsets[0];
-       int beacon_addr = dev->beacon_offsets[bcn_idx];
+       int beacon_len = mt76x02_beacon_offsets[1] - mt76x02_beacon_offsets[0];
+       int beacon_addr = mt76x02_beacon_offsets[bcn_idx];
        int ret = 0;
        int i;
 
index 9ba0294..4eb3fe6 100644 (file)
@@ -165,21 +165,12 @@ static void mt76x2u_init_beacon_offsets(struct mt76x2_dev *dev)
 
 int mt76x2u_init_hardware(struct mt76x2_dev *dev)
 {
-       static const u16 beacon_offsets[] = {
-               /* 512 byte per beacon */
-               0xc000, 0xc200, 0xc400, 0xc600,
-               0xc800, 0xca00, 0xcc00, 0xce00,
-               0xd000, 0xd200, 0xd400, 0xd600,
-               0xd800, 0xda00, 0xdc00, 0xde00
-       };
        const struct mt76_wcid_addr addr = {
                .macaddr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
                .ba_mask = 0,
        };
        int i, err;
 
-       dev->beacon_offsets = beacon_offsets;
-
        mt76x2_reset_wlan(dev, true);
        mt76x2u_power_on(dev);