Commit a6daf796 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt76: move mt76x02_beacon_offset in mt76x02_util.c

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: default avatarLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent b2eabd4c
...@@ -168,30 +168,13 @@ static int mt76x0_init_bbp(struct mt76x0_dev *dev) ...@@ -168,30 +168,13 @@ static int mt76x0_init_bbp(struct mt76x0_dev *dev)
return 0; 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) static void mt76x0_init_mac_registers(struct mt76x0_dev *dev)
{ {
u32 reg; u32 reg;
RANDOM_WRITE(dev, common_mac_reg_table); 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 */ /* Enable PBF and MAC clock SYS_CTRL[11:10] = 0x3 */
RANDOM_WRITE(dev, mt76x0_mac_reg_table); RANDOM_WRITE(dev, mt76x0_mac_reg_table);
...@@ -372,17 +355,8 @@ EXPORT_SYMBOL_GPL(mt76x0_mac_stop); ...@@ -372,17 +355,8 @@ EXPORT_SYMBOL_GPL(mt76x0_mac_stop);
int mt76x0_init_hardware(struct mt76x0_dev *dev) 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; int ret;
dev->beacon_offsets = beacon_offsets;
if (!mt76_poll_msec(dev, MT_WPDMA_GLO_CFG, if (!mt76_poll_msec(dev, MT_WPDMA_GLO_CFG,
MT_WPDMA_GLO_CFG_TX_DMA_BUSY | MT_WPDMA_GLO_CFG_TX_DMA_BUSY |
MT_WPDMA_GLO_CFG_RX_DMA_BUSY, 0, 100)) MT_WPDMA_GLO_CFG_RX_DMA_BUSY, 0, 100))
......
...@@ -87,8 +87,6 @@ struct mt76x0_dev { ...@@ -87,8 +87,6 @@ struct mt76x0_dev {
spinlock_t mac_lock; spinlock_t mac_lock;
const u16 *beacon_offsets;
struct mt76x0_caldata caldata; struct mt76x0_caldata caldata;
struct mutex reg_atomic_mutex; struct mutex reg_atomic_mutex;
......
...@@ -454,4 +454,42 @@ bool mt76x02_tx_status_data(struct mt76_dev *dev, u8 *update) ...@@ -454,4 +454,42 @@ bool mt76x02_tx_status_data(struct mt76_dev *dev, u8 *update)
} }
EXPORT_SYMBOL_GPL(mt76x02_tx_status_data); 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"); MODULE_LICENSE("Dual BSD/GPL");
...@@ -52,6 +52,8 @@ void mt76x02_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue *q, ...@@ -52,6 +52,8 @@ void mt76x02_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue *q,
struct mt76_queue_entry *e, bool flush); struct mt76_queue_entry *e, bool flush);
bool mt76x02_tx_status_data(struct mt76_dev *dev, u8 *update); 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); 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) static inline void mt76x02_irq_enable(struct mt76_dev *dev, u32 mask)
......
...@@ -78,8 +78,6 @@ struct mt76x2_dev { ...@@ -78,8 +78,6 @@ struct mt76x2_dev {
struct mutex mutex; struct mutex mutex;
const u16 *beacon_offsets;
u8 txdone_seq; u8 txdone_seq;
DECLARE_KFIFO_PTR(txstatus_fifo, struct mt76x02_tx_status); DECLARE_KFIFO_PTR(txstatus_fifo, struct mt76x02_tx_status);
......
...@@ -79,23 +79,6 @@ mt76x2_fixup_xtal(struct mt76x2_dev *dev) ...@@ -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 int mt76x2_mac_reset(struct mt76x2_dev *dev, bool hard)
{ {
static const u8 null_addr[ETH_ALEN] = {}; static const u8 null_addr[ETH_ALEN] = {};
...@@ -187,7 +170,7 @@ static int mt76x2_mac_reset(struct mt76x2_dev *dev, bool hard) ...@@ -187,7 +170,7 @@ static int mt76x2_mac_reset(struct mt76x2_dev *dev, bool hard)
MT_CH_TIME_CFG_EIFS_AS_BUSY | MT_CH_TIME_CFG_EIFS_AS_BUSY |
FIELD_PREP(MT_CH_TIME_CFG_CH_TIMER_CLR, 1)); 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); mt76x2_set_tx_ackto(dev);
...@@ -325,30 +308,8 @@ void mt76x2_set_tx_ackto(struct mt76x2_dev *dev) ...@@ -325,30 +308,8 @@ void mt76x2_set_tx_ackto(struct mt76x2_dev *dev)
int mt76x2_init_hardware(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; int ret;
dev->beacon_offsets = beacon_offsets;
tasklet_init(&dev->pre_tbtt_tasklet, mt76x2_pre_tbtt_tasklet, tasklet_init(&dev->pre_tbtt_tasklet, mt76x2_pre_tbtt_tasklet,
(unsigned long) dev); (unsigned long) dev);
......
...@@ -100,7 +100,7 @@ void mt76x2_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue *q, ...@@ -100,7 +100,7 @@ void mt76x2_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue *q,
static int static int
mt76_write_beacon(struct mt76x2_dev *dev, int offset, struct sk_buff *skb) 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; struct mt76x02_txwi txwi;
if (WARN_ON_ONCE(beacon_len < skb->len + sizeof(struct mt76x02_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) ...@@ -118,8 +118,8 @@ mt76_write_beacon(struct mt76x2_dev *dev, int offset, struct sk_buff *skb)
static int static int
__mt76x2_mac_set_beacon(struct mt76x2_dev *dev, u8 bcn_idx, struct sk_buff *skb) __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_len = mt76x02_beacon_offsets[1] - mt76x02_beacon_offsets[0];
int beacon_addr = dev->beacon_offsets[bcn_idx]; int beacon_addr = mt76x02_beacon_offsets[bcn_idx];
int ret = 0; int ret = 0;
int i; int i;
......
...@@ -165,21 +165,12 @@ static void mt76x2u_init_beacon_offsets(struct mt76x2_dev *dev) ...@@ -165,21 +165,12 @@ static void mt76x2u_init_beacon_offsets(struct mt76x2_dev *dev)
int mt76x2u_init_hardware(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 = { const struct mt76_wcid_addr addr = {
.macaddr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, .macaddr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
.ba_mask = 0, .ba_mask = 0,
}; };
int i, err; int i, err;
dev->beacon_offsets = beacon_offsets;
mt76x2_reset_wlan(dev, true); mt76x2_reset_wlan(dev, true);
mt76x2u_power_on(dev); mt76x2u_power_on(dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment