mt76: move mt76x02_mac_setaddr in mt76x02-lib module
Move mt76x02_mac_setaddr utility routine in mt76x02-lib module and remove duplicated code. This is a preliminary patch to unify eeprom code between mt76x2 and mt76x0 driver Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
parent
b27823a774
commit
89a8607c49
|
@ -131,28 +131,6 @@ mt76x0_set_chip_cap(struct mt76x0_dev *dev, u8 *eeprom)
|
||||||
dev_dbg(dev->mt76.dev, "PA Type %d\n", dev->ee->pa_type);
|
dev_dbg(dev->mt76.dev, "PA Type %d\n", dev->ee->pa_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
mt76x0_set_macaddr(struct mt76x0_dev *dev, const u8 *eeprom)
|
|
||||||
{
|
|
||||||
const void *src = eeprom + MT_EE_MAC_ADDR;
|
|
||||||
u8 *dst = dev->mt76.macaddr;
|
|
||||||
|
|
||||||
ether_addr_copy(dev->mt76.macaddr, src);
|
|
||||||
|
|
||||||
if (!is_valid_ether_addr(dst)) {
|
|
||||||
eth_random_addr(dst);
|
|
||||||
dev_info(dev->mt76.dev,
|
|
||||||
"Invalid MAC address, using random address %pM\n",
|
|
||||||
dst);
|
|
||||||
}
|
|
||||||
|
|
||||||
mt76_wr(dev, MT_MAC_ADDR_DW0, get_unaligned_le32(dst));
|
|
||||||
mt76_wr(dev, MT_MAC_ADDR_DW1, get_unaligned_le16(dst + 4) |
|
|
||||||
FIELD_PREP(MT_MAC_ADDR_DW1_U2ME_MASK, 0xff));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mt76x0_set_temp_offset(struct mt76x0_dev *dev, u8 *eeprom)
|
mt76x0_set_temp_offset(struct mt76x0_dev *dev, u8 *eeprom)
|
||||||
{
|
{
|
||||||
|
@ -409,7 +387,7 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev)
|
||||||
dev_info(dev->mt76.dev, "EEPROM ver:%02hhx fae:%02hhx\n",
|
dev_info(dev->mt76.dev, "EEPROM ver:%02hhx fae:%02hhx\n",
|
||||||
eeprom[MT_EE_VERSION + 1], eeprom[MT_EE_VERSION]);
|
eeprom[MT_EE_VERSION + 1], eeprom[MT_EE_VERSION]);
|
||||||
|
|
||||||
mt76x0_set_macaddr(dev, eeprom);
|
mt76x02_mac_setaddr(&dev->mt76, eeprom + MT_EE_MAC_ADDR);
|
||||||
mt76x0_set_chip_cap(dev, eeprom);
|
mt76x0_set_chip_cap(dev, eeprom);
|
||||||
mt76x0_set_country_reg(dev, eeprom);
|
mt76x0_set_country_reg(dev, eeprom);
|
||||||
mt76x0_set_rf_freq_off(dev, eeprom);
|
mt76x0_set_rf_freq_off(dev, eeprom);
|
||||||
|
|
|
@ -502,3 +502,21 @@ mt76x02_mac_process_rate(struct mt76_rx_status *status, u16 rate)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(mt76x02_mac_process_rate);
|
EXPORT_SYMBOL_GPL(mt76x02_mac_process_rate);
|
||||||
|
|
||||||
|
void mt76x02_mac_setaddr(struct mt76_dev *dev, u8 *addr)
|
||||||
|
{
|
||||||
|
ether_addr_copy(dev->macaddr, addr);
|
||||||
|
|
||||||
|
if (!is_valid_ether_addr(dev->macaddr)) {
|
||||||
|
eth_random_addr(dev->macaddr);
|
||||||
|
dev_info(dev->dev,
|
||||||
|
"Invalid MAC address, using random address %pM\n",
|
||||||
|
dev->macaddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
__mt76_wr(dev, MT_MAC_ADDR_DW0, get_unaligned_le32(dev->macaddr));
|
||||||
|
__mt76_wr(dev, MT_MAC_ADDR_DW1,
|
||||||
|
get_unaligned_le16(dev->macaddr + 4) |
|
||||||
|
FIELD_PREP(MT_MAC_ADDR_DW1_U2ME_MASK, 0xff));
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(mt76x02_mac_setaddr);
|
||||||
|
|
|
@ -202,4 +202,5 @@ void mt76x02_send_tx_status(struct mt76_dev *dev,
|
||||||
struct mt76x02_tx_status *stat, u8 *update);
|
struct mt76x02_tx_status *stat, u8 *update);
|
||||||
int
|
int
|
||||||
mt76x02_mac_process_rate(struct mt76_rx_status *status, u16 rate);
|
mt76x02_mac_process_rate(struct mt76_rx_status *status, u16 rate);
|
||||||
|
void mt76x02_mac_setaddr(struct mt76_dev *dev, u8 *addr);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,7 +36,6 @@ int mt76x2u_init_hardware(struct mt76x2_dev *dev);
|
||||||
void mt76x2u_cleanup(struct mt76x2_dev *dev);
|
void mt76x2u_cleanup(struct mt76x2_dev *dev);
|
||||||
void mt76x2u_stop_hw(struct mt76x2_dev *dev);
|
void mt76x2u_stop_hw(struct mt76x2_dev *dev);
|
||||||
|
|
||||||
void mt76x2u_mac_setaddr(struct mt76x2_dev *dev, u8 *addr);
|
|
||||||
int mt76x2u_mac_reset(struct mt76x2_dev *dev);
|
int mt76x2u_mac_reset(struct mt76x2_dev *dev);
|
||||||
void mt76x2u_mac_resume(struct mt76x2_dev *dev);
|
void mt76x2u_mac_resume(struct mt76x2_dev *dev);
|
||||||
int mt76x2u_mac_start(struct mt76x2_dev *dev);
|
int mt76x2u_mac_start(struct mt76x2_dev *dev);
|
||||||
|
|
|
@ -212,7 +212,8 @@ int mt76x2u_init_hardware(struct mt76x2_dev *dev)
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
mt76x2u_mac_setaddr(dev, dev->mt76.eeprom.data + MT_EE_MAC_ADDR);
|
mt76x02_mac_setaddr(&dev->mt76,
|
||||||
|
dev->mt76.eeprom.data + MT_EE_MAC_ADDR);
|
||||||
dev->mt76.rxfilter = mt76_rr(dev, MT_RX_FILTR_CFG);
|
dev->mt76.rxfilter = mt76_rr(dev, MT_RX_FILTR_CFG);
|
||||||
|
|
||||||
mt76x2u_init_beacon_offsets(dev);
|
mt76x2u_init_beacon_offsets(dev);
|
||||||
|
|
|
@ -220,21 +220,3 @@ void mt76x2u_mac_resume(struct mt76x2_dev *dev)
|
||||||
mt76_set(dev, MT_TXOP_CTRL_CFG, BIT(20));
|
mt76_set(dev, MT_TXOP_CTRL_CFG, BIT(20));
|
||||||
mt76_set(dev, MT_TXOP_HLDR_ET, BIT(1));
|
mt76_set(dev, MT_TXOP_HLDR_ET, BIT(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mt76x2u_mac_setaddr(struct mt76x2_dev *dev, u8 *addr)
|
|
||||||
{
|
|
||||||
ether_addr_copy(dev->mt76.macaddr, addr);
|
|
||||||
|
|
||||||
if (!is_valid_ether_addr(dev->mt76.macaddr)) {
|
|
||||||
eth_random_addr(dev->mt76.macaddr);
|
|
||||||
dev_info(dev->mt76.dev,
|
|
||||||
"Invalid MAC address, using random address %pM\n",
|
|
||||||
dev->mt76.macaddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
mt76_wr(dev, MT_MAC_ADDR_DW0, get_unaligned_le32(dev->mt76.macaddr));
|
|
||||||
mt76_wr(dev, MT_MAC_ADDR_DW1,
|
|
||||||
get_unaligned_le16(dev->mt76.macaddr + 4) |
|
|
||||||
FIELD_PREP(MT_MAC_ADDR_DW1_U2ME_MASK, 0xff));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ static int mt76x2u_add_interface(struct ieee80211_hw *hw,
|
||||||
struct mt76x2_dev *dev = hw->priv;
|
struct mt76x2_dev *dev = hw->priv;
|
||||||
|
|
||||||
if (!ether_addr_equal(dev->mt76.macaddr, vif->addr))
|
if (!ether_addr_equal(dev->mt76.macaddr, vif->addr))
|
||||||
mt76x2u_mac_setaddr(dev, vif->addr);
|
mt76x02_mac_setaddr(&dev->mt76, vif->addr);
|
||||||
|
|
||||||
mt76x02_vif_init(&dev->mt76, vif, 0);
|
mt76x02_vif_init(&dev->mt76, vif, 0);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue