From e635c4aa89f395139da15f6cbce77daa49a90304 Mon Sep 17 00:00:00 2001 From: Alexandros Couloumbis Date: Mon, 1 Jun 2020 12:15:49 +0300 Subject: [PATCH] target/linux/adm5120: update ethernet modernization, ok on 4.14, still not-ok on 4.19 --- .../730-struct_device_DMA_API.patch | 182 +++++++++++++----- .../730-struct_device_DMA_API.patch | 182 +++++++++++++----- 2 files changed, 262 insertions(+), 102 deletions(-) diff --git a/target/linux/adm5120/patches-4.14/730-struct_device_DMA_API.patch b/target/linux/adm5120/patches-4.14/730-struct_device_DMA_API.patch index 4c04c46cf8..90b9d0421c 100644 --- a/target/linux/adm5120/patches-4.14/730-struct_device_DMA_API.patch +++ b/target/linux/adm5120/patches-4.14/730-struct_device_DMA_API.patch @@ -1,76 +1,132 @@ diff --git a/drivers/net/adm5120sw.c b/drivers/net/adm5120sw.c -index eb17a0d..024551f 100644 +index eb17a0d..56c015c 100644 --- a/drivers/net/adm5120sw.c +++ b/drivers/net/adm5120sw.c -@@ -428,11 +428,12 @@ static void adm5120_switch_rx_ring_reset(struct dma_desc *desc, +@@ -91,6 +91,7 @@ struct adm5120_if_priv { + unsigned int vlan_no; + unsigned int port_mask; + struct napi_struct napi; ++ struct device *d; + }; + + struct dma_desc { +@@ -428,12 +429,18 @@ static void adm5120_switch_rx_ring_reset(struct dma_desc *desc, dirty_rxl = 0; } -static int adm5120_switch_tx_ring_alloc(void) +static int adm5120_switch_tx_ring_alloc(struct net_device *dev) { -+ struct adm5120_if_priv *priv = netdev_priv(dev); int err; - txl_descs = dma_alloc_coherent(NULL, TX_DESCS_SIZE, &txl_descs_dma, -+ txl_descs = dma_alloc_coherent(&priv->dev->dev, TX_DESCS_SIZE, &txl_descs_dma, - GFP_DMA | GFP_KERNEL); +- GFP_DMA | GFP_KERNEL); ++ if (!dev) { ++ txl_descs = dma_alloc_coherent(NULL, TX_DESCS_SIZE, &txl_descs_dma, ++ GFP_KERNEL); ++ } else { ++ txl_descs = dma_alloc_coherent(dev->dev.parent, TX_DESCS_SIZE, &txl_descs_dma, ++ GFP_KERNEL); ++ } ++ if (!txl_descs) { err = -ENOMEM; -@@ -451,8 +452,9 @@ static int adm5120_switch_tx_ring_alloc(void) + goto err; +@@ -451,7 +458,7 @@ err: return err; } -static void adm5120_switch_tx_ring_free(void) +static void adm5120_switch_tx_ring_free(struct net_device *dev) { -+ struct adm5120_if_priv *priv = netdev_priv(dev); int i; - if (txl_skbuff) { -@@ -463,17 +465,18 @@ static void adm5120_switch_tx_ring_free(void) +@@ -462,27 +469,40 @@ static void adm5120_switch_tx_ring_free(void) + kfree(txl_skbuff); } - if (txl_descs) +- if (txl_descs) - dma_free_coherent(NULL, TX_DESCS_SIZE, txl_descs, -+ dma_free_coherent(&priv->dev->dev, TX_DESCS_SIZE, txl_descs, - txl_descs_dma); +- txl_descs_dma); ++ if (!dev) { ++ if (txl_descs) ++ dma_free_coherent(NULL, TX_DESCS_SIZE, txl_descs, ++ txl_descs_dma); ++ } else { ++ if (txl_descs) ++ dma_free_coherent(dev->dev.parent, TX_DESCS_SIZE, txl_descs, ++ txl_descs_dma); ++ } } -static int adm5120_switch_rx_ring_alloc(void) +static int adm5120_switch_rx_ring_alloc(struct net_device *dev) { -+ struct adm5120_if_priv *priv = netdev_priv(dev); - int err; - int i; +- int err; +- int i; ++ int i, err; /* init RX ring */ - rxl_descs = dma_alloc_coherent(NULL, RX_DESCS_SIZE, &rxl_descs_dma, -+ rxl_descs = dma_alloc_coherent(&priv->dev->dev, RX_DESCS_SIZE, &rxl_descs_dma, - GFP_DMA | GFP_KERNEL); +- GFP_DMA | GFP_KERNEL); ++ if (!dev) { ++ rxl_descs = dma_alloc_coherent(NULL, RX_DESCS_SIZE, &rxl_descs_dma, ++ GFP_KERNEL); ++ } else { ++ SW_INFO("rx_dma_alloc_coherent init\n"); ++ rxl_descs = dma_alloc_coherent(dev->dev.parent, RX_DESCS_SIZE, &rxl_descs_dma, ++ GFP_KERNEL); ++ } if (!rxl_descs) { err = -ENOMEM; -@@ -503,8 +506,9 @@ static int adm5120_switch_rx_ring_alloc(void) ++ SW_ERR("rx_dma_alloc_coherent failed\n"); + goto err; + } + + rxl_skbuff = kzalloc(RX_SKBS_SIZE, GFP_KERNEL); + if (!rxl_skbuff) { + err = -ENOMEM; ++ SW_ERR("rx_kzalloc failed\n"); + goto err; + } + +@@ -491,6 +511,7 @@ static int adm5120_switch_rx_ring_alloc(void) + skb = alloc_skb(SKB_ALLOC_LEN, GFP_ATOMIC); + if (!skb) { + err = -ENOMEM; ++ SW_ERR("rx_alloc_skb failed\n"); + goto err; + } + rxl_skbuff[i] = skb; +@@ -503,7 +524,7 @@ err: return err; } -static void adm5120_switch_rx_ring_free(void) +static void adm5120_switch_rx_ring_free(struct net_device *dev) { -+ struct adm5120_if_priv *priv = netdev_priv(dev); int i; - if (rxl_skbuff) { -@@ -515,7 +519,7 @@ static void adm5120_switch_rx_ring_free(void) +@@ -514,9 +535,15 @@ static void adm5120_switch_rx_ring_free(void) + kfree(rxl_skbuff); } - if (rxl_descs) +- if (rxl_descs) - dma_free_coherent(NULL, RX_DESCS_SIZE, rxl_descs, -+ dma_free_coherent(&priv->dev->dev, RX_DESCS_SIZE, rxl_descs, - rxl_descs_dma); +- rxl_descs_dma); ++ if (!dev) { ++ if (rxl_descs) ++ dma_free_coherent(NULL, RX_DESCS_SIZE, rxl_descs, ++ rxl_descs_dma); ++ } else { ++ if (rxl_descs) ++ dma_free_coherent(dev->dev.parent, RX_DESCS_SIZE, rxl_descs, ++ rxl_descs_dma); ++ } } -@@ -809,8 +813,10 @@ static struct net_device *adm5120_if_alloc(void) + static void adm5120_write_mac(struct net_device *dev) +@@ -809,8 +836,10 @@ static struct net_device *adm5120_if_alloc(void) struct adm5120_if_priv *priv; dev = alloc_etherdev(sizeof(*priv)); @@ -82,7 +138,7 @@ index eb17a0d..024551f 100644 priv = netdev_priv(dev); priv->dev = dev; -@@ -824,7 +830,7 @@ static struct net_device *adm5120_if_alloc(void) +@@ -824,7 +853,7 @@ static struct net_device *adm5120_if_alloc(void) return dev; } @@ -91,7 +147,7 @@ index eb17a0d..024551f 100644 { int i; -@@ -839,12 +845,13 @@ static void adm5120_switch_cleanup(void) +@@ -839,15 +868,21 @@ static void adm5120_switch_cleanup(void) } } @@ -103,39 +159,65 @@ index eb17a0d..024551f 100644 static int adm5120_switch_probe(struct platform_device *pdev) { -+ struct net_device *dev; ++ struct net_device *ndev = adm5120_if_alloc(); u32 t; int i, err; -@@ -879,11 +886,17 @@ static int adm5120_switch_probe(struct platform_device *pdev) ++ if (!ndev) { ++ SW_ERR("probe_adm5120_if_alloc failed\n"); ++ goto err; ++ } ++ + adm5120_nrdevs = adm5120_eth_num_ports; + + t = CPUP_CONF_DCPUP | CPUP_CONF_CRCP | +@@ -879,13 +914,17 @@ static int adm5120_switch_probe(struct platform_device *pdev) sw_int_mask(SWITCH_INTS_ALL); sw_int_ack(SWITCH_INTS_ALL); - err = adm5120_switch_rx_ring_alloc(); -+ dev = platform_get_drvdata(pdev); -+ if (!dev) { -+ err = -ENOMEM; -+ return err; -+ } -+ -+ err = adm5120_switch_rx_ring_alloc(dev); - if (err) +- if (err) ++ err = adm5120_switch_rx_ring_alloc(ndev); ++ if (err) { ++ SW_ERR("probe_rx_ring_alloc failed\n"); goto err; ++ } - err = adm5120_switch_tx_ring_alloc(); -+ err = adm5120_switch_tx_ring_alloc(dev); - if (err) +- if (err) ++ err = adm5120_switch_tx_ring_alloc(ndev); ++ if (err) { ++ SW_ERR("probe_tx_ring_alloc failed\n"); goto err; ++ } + + adm5120_switch_tx_ring_reset(txl_descs, txl_skbuff, TX_RING_SIZE); + adm5120_switch_rx_ring_reset(rxl_descs, rxl_skbuff, RX_RING_SIZE); +@@ -902,6 +941,7 @@ static int adm5120_switch_probe(struct platform_device *pdev) + dev = adm5120_if_alloc(); + if (!dev) { + err = -ENOMEM; ++ SW_ERR("probe_for_if_alloc failed\n"); + goto err; + } + +@@ -916,7 +956,7 @@ static int adm5120_switch_probe(struct platform_device *pdev) -@@ -933,16 +946,29 @@ static int adm5120_switch_probe(struct platform_device *pdev) + err = register_netdev(dev); + if (err) { +- SW_INFO("%s register failed, error=%d\n", ++ SW_INFO("%s for_register failed, error=%d\n", + dev->name, err); + goto err; + } +@@ -933,16 +973,26 @@ static int adm5120_switch_probe(struct platform_device *pdev) return 0; err: - adm5120_switch_cleanup(); -+ adm5120_switch_cleanup(dev); ++ adm5120_switch_cleanup(ndev); - SW_ERR("init failed\n"); -+ SW_ERR("probe_init failed\n"); return err; } @@ -143,19 +225,17 @@ index eb17a0d..024551f 100644 { - adm5120_switch_cleanup(); - return 0; -+ struct net_device *dev; ++ struct net_device *ndev = ndev = adm5120_if_alloc(); + int err; + -+ dev = platform_get_drvdata(pdev); -+ if (!dev) { -+ err = -ENOMEM; ++ if (!ndev) { ++ err = -ENOMEM; + -+ adm5120_switch_cleanup(dev); -+ SW_ERR("remove_init failed\n"); ++ SW_ERR("probe_adm5120_if_alloc failed\n"); + -+ return err; -+ } else { -+ adm5120_switch_cleanup(dev); ++ return err; ++ } else { ++ adm5120_switch_cleanup(ndev); + return 0; + } } diff --git a/target/linux/adm5120/patches-4.19/730-struct_device_DMA_API.patch b/target/linux/adm5120/patches-4.19/730-struct_device_DMA_API.patch index 4c04c46cf8..90b9d0421c 100644 --- a/target/linux/adm5120/patches-4.19/730-struct_device_DMA_API.patch +++ b/target/linux/adm5120/patches-4.19/730-struct_device_DMA_API.patch @@ -1,76 +1,132 @@ diff --git a/drivers/net/adm5120sw.c b/drivers/net/adm5120sw.c -index eb17a0d..024551f 100644 +index eb17a0d..56c015c 100644 --- a/drivers/net/adm5120sw.c +++ b/drivers/net/adm5120sw.c -@@ -428,11 +428,12 @@ static void adm5120_switch_rx_ring_reset(struct dma_desc *desc, +@@ -91,6 +91,7 @@ struct adm5120_if_priv { + unsigned int vlan_no; + unsigned int port_mask; + struct napi_struct napi; ++ struct device *d; + }; + + struct dma_desc { +@@ -428,12 +429,18 @@ static void adm5120_switch_rx_ring_reset(struct dma_desc *desc, dirty_rxl = 0; } -static int adm5120_switch_tx_ring_alloc(void) +static int adm5120_switch_tx_ring_alloc(struct net_device *dev) { -+ struct adm5120_if_priv *priv = netdev_priv(dev); int err; - txl_descs = dma_alloc_coherent(NULL, TX_DESCS_SIZE, &txl_descs_dma, -+ txl_descs = dma_alloc_coherent(&priv->dev->dev, TX_DESCS_SIZE, &txl_descs_dma, - GFP_DMA | GFP_KERNEL); +- GFP_DMA | GFP_KERNEL); ++ if (!dev) { ++ txl_descs = dma_alloc_coherent(NULL, TX_DESCS_SIZE, &txl_descs_dma, ++ GFP_KERNEL); ++ } else { ++ txl_descs = dma_alloc_coherent(dev->dev.parent, TX_DESCS_SIZE, &txl_descs_dma, ++ GFP_KERNEL); ++ } ++ if (!txl_descs) { err = -ENOMEM; -@@ -451,8 +452,9 @@ static int adm5120_switch_tx_ring_alloc(void) + goto err; +@@ -451,7 +458,7 @@ err: return err; } -static void adm5120_switch_tx_ring_free(void) +static void adm5120_switch_tx_ring_free(struct net_device *dev) { -+ struct adm5120_if_priv *priv = netdev_priv(dev); int i; - if (txl_skbuff) { -@@ -463,17 +465,18 @@ static void adm5120_switch_tx_ring_free(void) +@@ -462,27 +469,40 @@ static void adm5120_switch_tx_ring_free(void) + kfree(txl_skbuff); } - if (txl_descs) +- if (txl_descs) - dma_free_coherent(NULL, TX_DESCS_SIZE, txl_descs, -+ dma_free_coherent(&priv->dev->dev, TX_DESCS_SIZE, txl_descs, - txl_descs_dma); +- txl_descs_dma); ++ if (!dev) { ++ if (txl_descs) ++ dma_free_coherent(NULL, TX_DESCS_SIZE, txl_descs, ++ txl_descs_dma); ++ } else { ++ if (txl_descs) ++ dma_free_coherent(dev->dev.parent, TX_DESCS_SIZE, txl_descs, ++ txl_descs_dma); ++ } } -static int adm5120_switch_rx_ring_alloc(void) +static int adm5120_switch_rx_ring_alloc(struct net_device *dev) { -+ struct adm5120_if_priv *priv = netdev_priv(dev); - int err; - int i; +- int err; +- int i; ++ int i, err; /* init RX ring */ - rxl_descs = dma_alloc_coherent(NULL, RX_DESCS_SIZE, &rxl_descs_dma, -+ rxl_descs = dma_alloc_coherent(&priv->dev->dev, RX_DESCS_SIZE, &rxl_descs_dma, - GFP_DMA | GFP_KERNEL); +- GFP_DMA | GFP_KERNEL); ++ if (!dev) { ++ rxl_descs = dma_alloc_coherent(NULL, RX_DESCS_SIZE, &rxl_descs_dma, ++ GFP_KERNEL); ++ } else { ++ SW_INFO("rx_dma_alloc_coherent init\n"); ++ rxl_descs = dma_alloc_coherent(dev->dev.parent, RX_DESCS_SIZE, &rxl_descs_dma, ++ GFP_KERNEL); ++ } if (!rxl_descs) { err = -ENOMEM; -@@ -503,8 +506,9 @@ static int adm5120_switch_rx_ring_alloc(void) ++ SW_ERR("rx_dma_alloc_coherent failed\n"); + goto err; + } + + rxl_skbuff = kzalloc(RX_SKBS_SIZE, GFP_KERNEL); + if (!rxl_skbuff) { + err = -ENOMEM; ++ SW_ERR("rx_kzalloc failed\n"); + goto err; + } + +@@ -491,6 +511,7 @@ static int adm5120_switch_rx_ring_alloc(void) + skb = alloc_skb(SKB_ALLOC_LEN, GFP_ATOMIC); + if (!skb) { + err = -ENOMEM; ++ SW_ERR("rx_alloc_skb failed\n"); + goto err; + } + rxl_skbuff[i] = skb; +@@ -503,7 +524,7 @@ err: return err; } -static void adm5120_switch_rx_ring_free(void) +static void adm5120_switch_rx_ring_free(struct net_device *dev) { -+ struct adm5120_if_priv *priv = netdev_priv(dev); int i; - if (rxl_skbuff) { -@@ -515,7 +519,7 @@ static void adm5120_switch_rx_ring_free(void) +@@ -514,9 +535,15 @@ static void adm5120_switch_rx_ring_free(void) + kfree(rxl_skbuff); } - if (rxl_descs) +- if (rxl_descs) - dma_free_coherent(NULL, RX_DESCS_SIZE, rxl_descs, -+ dma_free_coherent(&priv->dev->dev, RX_DESCS_SIZE, rxl_descs, - rxl_descs_dma); +- rxl_descs_dma); ++ if (!dev) { ++ if (rxl_descs) ++ dma_free_coherent(NULL, RX_DESCS_SIZE, rxl_descs, ++ rxl_descs_dma); ++ } else { ++ if (rxl_descs) ++ dma_free_coherent(dev->dev.parent, RX_DESCS_SIZE, rxl_descs, ++ rxl_descs_dma); ++ } } -@@ -809,8 +813,10 @@ static struct net_device *adm5120_if_alloc(void) + static void adm5120_write_mac(struct net_device *dev) +@@ -809,8 +836,10 @@ static struct net_device *adm5120_if_alloc(void) struct adm5120_if_priv *priv; dev = alloc_etherdev(sizeof(*priv)); @@ -82,7 +138,7 @@ index eb17a0d..024551f 100644 priv = netdev_priv(dev); priv->dev = dev; -@@ -824,7 +830,7 @@ static struct net_device *adm5120_if_alloc(void) +@@ -824,7 +853,7 @@ static struct net_device *adm5120_if_alloc(void) return dev; } @@ -91,7 +147,7 @@ index eb17a0d..024551f 100644 { int i; -@@ -839,12 +845,13 @@ static void adm5120_switch_cleanup(void) +@@ -839,15 +868,21 @@ static void adm5120_switch_cleanup(void) } } @@ -103,39 +159,65 @@ index eb17a0d..024551f 100644 static int adm5120_switch_probe(struct platform_device *pdev) { -+ struct net_device *dev; ++ struct net_device *ndev = adm5120_if_alloc(); u32 t; int i, err; -@@ -879,11 +886,17 @@ static int adm5120_switch_probe(struct platform_device *pdev) ++ if (!ndev) { ++ SW_ERR("probe_adm5120_if_alloc failed\n"); ++ goto err; ++ } ++ + adm5120_nrdevs = adm5120_eth_num_ports; + + t = CPUP_CONF_DCPUP | CPUP_CONF_CRCP | +@@ -879,13 +914,17 @@ static int adm5120_switch_probe(struct platform_device *pdev) sw_int_mask(SWITCH_INTS_ALL); sw_int_ack(SWITCH_INTS_ALL); - err = adm5120_switch_rx_ring_alloc(); -+ dev = platform_get_drvdata(pdev); -+ if (!dev) { -+ err = -ENOMEM; -+ return err; -+ } -+ -+ err = adm5120_switch_rx_ring_alloc(dev); - if (err) +- if (err) ++ err = adm5120_switch_rx_ring_alloc(ndev); ++ if (err) { ++ SW_ERR("probe_rx_ring_alloc failed\n"); goto err; ++ } - err = adm5120_switch_tx_ring_alloc(); -+ err = adm5120_switch_tx_ring_alloc(dev); - if (err) +- if (err) ++ err = adm5120_switch_tx_ring_alloc(ndev); ++ if (err) { ++ SW_ERR("probe_tx_ring_alloc failed\n"); goto err; ++ } + + adm5120_switch_tx_ring_reset(txl_descs, txl_skbuff, TX_RING_SIZE); + adm5120_switch_rx_ring_reset(rxl_descs, rxl_skbuff, RX_RING_SIZE); +@@ -902,6 +941,7 @@ static int adm5120_switch_probe(struct platform_device *pdev) + dev = adm5120_if_alloc(); + if (!dev) { + err = -ENOMEM; ++ SW_ERR("probe_for_if_alloc failed\n"); + goto err; + } + +@@ -916,7 +956,7 @@ static int adm5120_switch_probe(struct platform_device *pdev) -@@ -933,16 +946,29 @@ static int adm5120_switch_probe(struct platform_device *pdev) + err = register_netdev(dev); + if (err) { +- SW_INFO("%s register failed, error=%d\n", ++ SW_INFO("%s for_register failed, error=%d\n", + dev->name, err); + goto err; + } +@@ -933,16 +973,26 @@ static int adm5120_switch_probe(struct platform_device *pdev) return 0; err: - adm5120_switch_cleanup(); -+ adm5120_switch_cleanup(dev); ++ adm5120_switch_cleanup(ndev); - SW_ERR("init failed\n"); -+ SW_ERR("probe_init failed\n"); return err; } @@ -143,19 +225,17 @@ index eb17a0d..024551f 100644 { - adm5120_switch_cleanup(); - return 0; -+ struct net_device *dev; ++ struct net_device *ndev = ndev = adm5120_if_alloc(); + int err; + -+ dev = platform_get_drvdata(pdev); -+ if (!dev) { -+ err = -ENOMEM; ++ if (!ndev) { ++ err = -ENOMEM; + -+ adm5120_switch_cleanup(dev); -+ SW_ERR("remove_init failed\n"); ++ SW_ERR("probe_adm5120_if_alloc failed\n"); + -+ return err; -+ } else { -+ adm5120_switch_cleanup(dev); ++ return err; ++ } else { ++ adm5120_switch_cleanup(ndev); + return 0; + } } -- 2.35.1