aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorHeiner Kallweit2019-05-29 21:15:06 +0200
committerDavid S. Miller2019-05-30 14:39:25 -0700
commitce8843abfa674350bf0f4f1b88d8e50a59401a46 (patch)
tree7c43c8864d48bf08cfe8320b1a3040642381e7af /drivers
parente95a7f30e1261f03487b15a8bd55bb812ceaa18b (diff)
r8169: decouple rtl_phy_write_fw from actual driver code
This patch is a further step towards decoupling firmware handling from the actual driver code. Firmware can be for PHY and/or MAC, and two pairs of read/write functions are needed for handling PHY firmware and MAC firmware respectively. Pass these functions via struct rtl_fw and avoid the ugly switching of mdio_ops behind the back of rtl_writephy(). Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/ethernet/realtek/r8169.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index 708df783c51f..ec9f98ad7490 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -626,6 +626,10 @@ struct rtl8169_stats {
struct u64_stats_sync syncp;
};
+struct rtl8169_private;
+typedef void (*rtl_fw_write_t)(struct rtl8169_private *tp, int reg, int val);
+typedef int (*rtl_fw_read_t)(struct rtl8169_private *tp, int reg);
+
struct rtl8169_private {
void __iomem *mmio_addr; /* memory map physical address */
struct pci_dev *pci_dev;
@@ -679,6 +683,10 @@ struct rtl8169_private {
const char *fw_name;
struct rtl_fw {
+ rtl_fw_write_t phy_write;
+ rtl_fw_read_t phy_read;
+ rtl_fw_write_t mac_mcu_write;
+ rtl_fw_read_t mac_mcu_read;
const struct firmware *fw;
#define RTL_VER_SIZE 32
@@ -1009,7 +1017,7 @@ static int r8168dp_2_mdio_read(struct rtl8169_private *tp, int reg)
return value;
}
-static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val)
+static void rtl_writephy(struct rtl8169_private *tp, int location, int val)
{
tp->mdio_ops.write(tp, location, val);
}
@@ -2427,17 +2435,15 @@ out:
return rc;
}
-static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
+static void rtl_fw_write_firmware(struct rtl8169_private *tp,
+ struct rtl_fw *rtl_fw)
{
struct rtl_fw_phy_action *pa = &rtl_fw->phy_action;
- struct mdio_ops org, *ops = &tp->mdio_ops;
- u32 predata, count;
+ rtl_fw_write_t fw_write = rtl_fw->phy_write;
+ rtl_fw_read_t fw_read = rtl_fw->phy_read;
+ int predata = 0, count = 0;
size_t index;
- predata = count = 0;
- org.write = ops->write;
- org.read = ops->read;
-
for (index = 0; index < pa->size; ) {
u32 action = le32_to_cpu(pa->code[index]);
u32 data = action & 0x0000ffff;
@@ -2448,7 +2454,7 @@ static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
switch(action & 0xf0000000) {
case PHY_READ:
- predata = rtl_readphy(tp, regno);
+ predata = fw_read(tp, regno);
count++;
index++;
break;
@@ -2465,11 +2471,11 @@ static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
break;
case PHY_MDIO_CHG:
if (data == 0) {
- ops->write = org.write;
- ops->read = org.read;
+ fw_write = rtl_fw->phy_write;
+ fw_read = rtl_fw->phy_read;
} else if (data == 1) {
- ops->write = mac_mcu_write;
- ops->read = mac_mcu_read;
+ fw_write = rtl_fw->mac_mcu_write;
+ fw_read = rtl_fw->mac_mcu_read;
}
index++;
@@ -2479,7 +2485,7 @@ static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
index++;
break;
case PHY_WRITE:
- rtl_writephy(tp, regno, data);
+ fw_write(tp, regno, data);
index++;
break;
case PHY_READCOUNT_EQ_SKIP:
@@ -2496,7 +2502,7 @@ static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
index++;
break;
case PHY_WRITE_PREVIOUS:
- rtl_writephy(tp, regno, predata);
+ fw_write(tp, regno, predata);
index++;
break;
case PHY_SKIPN:
@@ -2511,9 +2517,6 @@ static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
BUG();
}
}
-
- ops->write = org.write;
- ops->read = org.read;
}
static void rtl_release_firmware(struct rtl8169_private *tp)
@@ -2527,9 +2530,9 @@ static void rtl_release_firmware(struct rtl8169_private *tp)
static void rtl_apply_firmware(struct rtl8169_private *tp)
{
- /* TODO: release firmware once rtl_phy_write_fw signals failures. */
+ /* TODO: release firmware if rtl_fw_write_firmware signals failure. */
if (tp->rtl_fw)
- rtl_phy_write_fw(tp, tp->rtl_fw);
+ rtl_fw_write_firmware(tp, tp->rtl_fw);
}
static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val)
@@ -4359,6 +4362,11 @@ static void rtl_request_firmware(struct rtl8169_private *tp)
if (!rtl_fw)
goto err_warn;
+ rtl_fw->phy_write = rtl_writephy;
+ rtl_fw->phy_read = rtl_readphy;
+ rtl_fw->mac_mcu_write = mac_mcu_write;
+ rtl_fw->mac_mcu_read = mac_mcu_read;
+
rc = request_firmware(&rtl_fw->fw, tp->fw_name, tp_to_dev(tp));
if (rc < 0)
goto err_free;