mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 10:49:33 +00:00
r8169: improve rtl8169_get_mac_version
Currently code snippet (RTL_R32(tp, TxConfig) >> 20) & 0xfcf is used in few places to extract the chip XID. Change the code to do the XID extraction only once. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
711463f834
commit
f1f9ca2875
1 changed files with 26 additions and 22 deletions
|
@ -2045,7 +2045,7 @@ static void rtl_enable_eee(struct rtl8169_private *tp)
|
||||||
phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, adv);
|
phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, adv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rtl8169_get_mac_version(struct rtl8169_private *tp)
|
static enum mac_version rtl8169_get_mac_version(u16 xid, bool gmii)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* The driver currently handles the 8168Bf and the 8168Be identically
|
* The driver currently handles the 8168Bf and the 8168Be identically
|
||||||
|
@ -2061,7 +2061,7 @@ static void rtl8169_get_mac_version(struct rtl8169_private *tp)
|
||||||
static const struct rtl_mac_info {
|
static const struct rtl_mac_info {
|
||||||
u16 mask;
|
u16 mask;
|
||||||
u16 val;
|
u16 val;
|
||||||
u16 mac_version;
|
enum mac_version ver;
|
||||||
} mac_info[] = {
|
} mac_info[] = {
|
||||||
/* 8125 family. */
|
/* 8125 family. */
|
||||||
{ 0x7cf, 0x608, RTL_GIGA_MAC_VER_60 },
|
{ 0x7cf, 0x608, RTL_GIGA_MAC_VER_60 },
|
||||||
|
@ -2148,22 +2148,22 @@ static void rtl8169_get_mac_version(struct rtl8169_private *tp)
|
||||||
{ 0x000, 0x000, RTL_GIGA_MAC_NONE }
|
{ 0x000, 0x000, RTL_GIGA_MAC_NONE }
|
||||||
};
|
};
|
||||||
const struct rtl_mac_info *p = mac_info;
|
const struct rtl_mac_info *p = mac_info;
|
||||||
u16 reg = RTL_R32(tp, TxConfig) >> 20;
|
enum mac_version ver;
|
||||||
|
|
||||||
while ((reg & p->mask) != p->val)
|
while ((xid & p->mask) != p->val)
|
||||||
p++;
|
p++;
|
||||||
tp->mac_version = p->mac_version;
|
ver = p->ver;
|
||||||
|
|
||||||
if (tp->mac_version == RTL_GIGA_MAC_NONE) {
|
if (ver != RTL_GIGA_MAC_NONE && !gmii) {
|
||||||
dev_err(tp_to_dev(tp), "unknown chip XID %03x\n", reg & 0xfcf);
|
if (ver == RTL_GIGA_MAC_VER_42)
|
||||||
} else if (!tp->supports_gmii) {
|
ver = RTL_GIGA_MAC_VER_43;
|
||||||
if (tp->mac_version == RTL_GIGA_MAC_VER_42)
|
else if (ver == RTL_GIGA_MAC_VER_45)
|
||||||
tp->mac_version = RTL_GIGA_MAC_VER_43;
|
ver = RTL_GIGA_MAC_VER_47;
|
||||||
else if (tp->mac_version == RTL_GIGA_MAC_VER_45)
|
else if (ver == RTL_GIGA_MAC_VER_46)
|
||||||
tp->mac_version = RTL_GIGA_MAC_VER_47;
|
ver = RTL_GIGA_MAC_VER_48;
|
||||||
else if (tp->mac_version == RTL_GIGA_MAC_VER_46)
|
|
||||||
tp->mac_version = RTL_GIGA_MAC_VER_48;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ver;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rtl_release_firmware(struct rtl8169_private *tp)
|
static void rtl_release_firmware(struct rtl8169_private *tp)
|
||||||
|
@ -5440,9 +5440,10 @@ static void rtl_init_mac_address(struct rtl8169_private *tp)
|
||||||
static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
|
static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||||
{
|
{
|
||||||
struct rtl8169_private *tp;
|
struct rtl8169_private *tp;
|
||||||
|
int jumbo_max, region, rc;
|
||||||
|
enum mac_version chipset;
|
||||||
struct net_device *dev;
|
struct net_device *dev;
|
||||||
int chipset, region;
|
u16 xid;
|
||||||
int jumbo_max, rc;
|
|
||||||
|
|
||||||
/* Some tools for creating an initramfs don't consider softdeps, then
|
/* Some tools for creating an initramfs don't consider softdeps, then
|
||||||
* r8169.ko may be in initramfs, but realtek.ko not. Then the generic
|
* r8169.ko may be in initramfs, but realtek.ko not. Then the generic
|
||||||
|
@ -5509,10 +5510,16 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||||
|
|
||||||
tp->mmio_addr = pcim_iomap_table(pdev)[region];
|
tp->mmio_addr = pcim_iomap_table(pdev)[region];
|
||||||
|
|
||||||
|
xid = (RTL_R32(tp, TxConfig) >> 20) & 0xfcf;
|
||||||
|
|
||||||
/* Identify chip attached to board */
|
/* Identify chip attached to board */
|
||||||
rtl8169_get_mac_version(tp);
|
chipset = rtl8169_get_mac_version(xid, tp->supports_gmii);
|
||||||
if (tp->mac_version == RTL_GIGA_MAC_NONE)
|
if (chipset == RTL_GIGA_MAC_NONE) {
|
||||||
|
dev_err(&pdev->dev, "unknown chip XID %03x\n", xid);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
tp->mac_version = chipset;
|
||||||
|
|
||||||
tp->cp_cmd = RTL_R16(tp, CPlusCmd);
|
tp->cp_cmd = RTL_R16(tp, CPlusCmd);
|
||||||
|
|
||||||
|
@ -5530,8 +5537,6 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||||
|
|
||||||
pci_set_master(pdev);
|
pci_set_master(pdev);
|
||||||
|
|
||||||
chipset = tp->mac_version;
|
|
||||||
|
|
||||||
rc = rtl_alloc_irq(tp);
|
rc = rtl_alloc_irq(tp);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
dev_err(&pdev->dev, "Can't allocate interrupt\n");
|
dev_err(&pdev->dev, "Can't allocate interrupt\n");
|
||||||
|
@ -5619,8 +5624,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||||
goto err_mdio_unregister;
|
goto err_mdio_unregister;
|
||||||
|
|
||||||
netif_info(tp, probe, dev, "%s, %pM, XID %03x, IRQ %d\n",
|
netif_info(tp, probe, dev, "%s, %pM, XID %03x, IRQ %d\n",
|
||||||
rtl_chip_infos[chipset].name, dev->dev_addr,
|
rtl_chip_infos[chipset].name, dev->dev_addr, xid,
|
||||||
(RTL_R32(tp, TxConfig) >> 20) & 0xfcf,
|
|
||||||
pci_irq_vector(pdev, 0));
|
pci_irq_vector(pdev, 0));
|
||||||
|
|
||||||
if (jumbo_max)
|
if (jumbo_max)
|
||||||
|
|
Loading…
Reference in a new issue