From bfa0914afa95d44df9e1a1553e0c03a991223db3 Mon Sep 17 00:00:00 2001 From: Nicolas Ferre Date: Tue, 31 Mar 2015 15:01:59 +0200 Subject: [PATCH 1/8] net/macb: only probe queues once and use stored values When merging at91_ether and macb driver during 421d9df0628b (net/macb: merge at91_ether driver into macb driver) the probe function has been split. The code dealing with initialization of queues is now moved in macb_init() which needs information computed in the parent macb_probe() function. So, add the queue_mask information to the private structure and use it when needed in macb_init(). Signed-off-by: Nicolas Ferre Acked-by: Boris Brezillon Cc: Cyrille Pitchen Signed-off-by: David S. Miller --- drivers/net/ethernet/cadence/macb.c | 7 +++---- drivers/net/ethernet/cadence/macb.h | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c index a0a04b3638e6..ac1f18142f7e 100644 --- a/drivers/net/ethernet/cadence/macb.c +++ b/drivers/net/ethernet/cadence/macb.c @@ -2180,7 +2180,7 @@ static void macb_probe_queues(void __iomem *mem, static int macb_init(struct platform_device *pdev) { struct net_device *dev = platform_get_drvdata(pdev); - unsigned int hw_q, queue_mask, q, num_queues; + unsigned int hw_q, q; struct macb *bp = netdev_priv(dev); struct macb_queue *queue; int err; @@ -2226,10 +2226,8 @@ static int macb_init(struct platform_device *pdev) * register mapping but we don't want to test the queue index then * compute the corresponding register offset at run time. */ - macb_probe_queues(bp->regs, &queue_mask, &num_queues); - for (hw_q = 0, q = 0; hw_q < MACB_MAX_QUEUES; ++hw_q) { - if (!(queue_mask & (1 << hw_q))) + if (!(bp->queue_mask & (1 << hw_q))) continue; queue = &bp->queues[q]; @@ -2715,6 +2713,7 @@ static int macb_probe(struct platform_device *pdev) bp->dev = dev; bp->regs = mem; bp->num_queues = num_queues; + bp->queue_mask = queue_mask; spin_lock_init(&bp->lock); platform_set_drvdata(pdev, dev); diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h index bc6e35c40822..0b6afac91bfe 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -785,6 +785,7 @@ struct macb { size_t rx_buffer_size; unsigned int num_queues; + unsigned int queue_mask; struct macb_queue queues[MACB_MAX_QUEUES]; spinlock_t lock; From da120112493460332b5b430070ca0ea205c37632 Mon Sep 17 00:00:00 2001 From: Nicolas Ferre Date: Tue, 31 Mar 2015 15:02:00 +0200 Subject: [PATCH 2/8] net/macb: add comment in macb_probe_queues As we access the MID register directly, we need to tell why we don't use the macb_is_gem() dedicated function. Signed-off-by: Nicolas Ferre Signed-off-by: David S. Miller --- drivers/net/ethernet/cadence/macb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c index ac1f18142f7e..68d59b3900b1 100644 --- a/drivers/net/ethernet/cadence/macb.c +++ b/drivers/net/ethernet/cadence/macb.c @@ -2161,9 +2161,13 @@ static void macb_probe_queues(void __iomem *mem, *queue_mask = 0x1; *num_queues = 1; - /* is it macb or gem ? */ + /* is it macb or gem ? + * + * We need to read directly from the hardware here because + * we are early in the probe process and don't have the + * MACB_CAPS_MACB_IS_GEM flag positioned + */ mid = readl_relaxed(mem + MACB_MID); - if (MACB_BFEXT(IDNUM, mid) < 0x2) return; From f6970505defd0e7bb5dea9606939bb3b32e51768 Mon Sep 17 00:00:00 2001 From: Nicolas Ferre Date: Tue, 31 Mar 2015 15:02:01 +0200 Subject: [PATCH 3/8] net/macb: fix capabilities configuration Capabilities configuration by macb_configure_caps() was moved far too late by 421d9df0628b (net/macb: merge at91_ether driver into macb driver) which would lead to badly configured hardware. So, move this function to early probe and modify its prototype to re-gain its original behavior. DT data retrieval is also moved to simplify the probe code flow. Signed-off-by: Nicolas Ferre Cc: Cyrille Pitchen Cc: Boris Brezillon Signed-off-by: David S. Miller --- drivers/net/ethernet/cadence/macb.c | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c index 68d59b3900b1..680e1eebb7ea 100644 --- a/drivers/net/ethernet/cadence/macb.c +++ b/drivers/net/ethernet/cadence/macb.c @@ -2132,10 +2132,13 @@ static const struct net_device_ops macb_netdev_ops = { * Configure peripheral capacities according to device tree * and integration options used */ -static void macb_configure_caps(struct macb *bp) +static void macb_configure_caps(struct macb *bp, const struct macb_config *dt_conf) { u32 dcfg; + if (dt_conf) + bp->caps = dt_conf->caps; + if (MACB_BFEXT(IDNUM, macb_readl(bp, MID)) == 0x2) bp->caps |= MACB_CAPS_MACB_IS_GEM; @@ -2313,9 +2316,6 @@ static int macb_init(struct platform_device *pdev) macb_or_gem_writel(bp, USRIO, val); - /* setup capacities */ - macb_configure_caps(bp); - /* Set MII management clock divider */ val = macb_mdc_clk_div(bp); val |= macb_dbw(bp); @@ -2720,6 +2720,20 @@ static int macb_probe(struct platform_device *pdev) bp->queue_mask = queue_mask; spin_lock_init(&bp->lock); + if (np) { + const struct of_device_id *match; + + match = of_match_node(macb_dt_ids, np); + if (match && match->data) { + macb_config = match->data; + bp->dma_burst_length = macb_config->dma_burst_length; + init = macb_config->init; + } + } + + /* setup capacities */ + macb_configure_caps(bp, macb_config); + platform_set_drvdata(pdev, dev); dev->irq = platform_get_irq(pdev, 0); @@ -2743,20 +2757,6 @@ static int macb_probe(struct platform_device *pdev) bp->phy_interface = err; } - if (np) { - const struct of_device_id *match; - - match = of_match_node(macb_dt_ids, np); - if (match) - macb_config = match->data; - } - - if (macb_config) { - bp->caps = macb_config->caps; - bp->dma_burst_length = macb_config->dma_burst_length; - init = macb_config->init; - } - /* IP specific init */ err = init(pdev); if (err) From ad78347f06581e445790343bc1d9e34375f11fd4 Mon Sep 17 00:00:00 2001 From: Nicolas Ferre Date: Tue, 31 Mar 2015 15:02:02 +0200 Subject: [PATCH 4/8] net/macb: trivial: correct wording for caps As a non-native English speaker, I would correct "capacities" of the macb peripheral to "capabilities": correct me if I'm wrong! Signed-off-by: Nicolas Ferre Signed-off-by: David S. Miller --- drivers/net/ethernet/cadence/macb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c index 680e1eebb7ea..e27bc6964402 100644 --- a/drivers/net/ethernet/cadence/macb.c +++ b/drivers/net/ethernet/cadence/macb.c @@ -2129,7 +2129,7 @@ static const struct net_device_ops macb_netdev_ops = { }; /* - * Configure peripheral capacities according to device tree + * Configure peripheral capabilities according to device tree * and integration options used */ static void macb_configure_caps(struct macb *bp, const struct macb_config *dt_conf) @@ -2731,7 +2731,7 @@ static int macb_probe(struct platform_device *pdev) } } - /* setup capacities */ + /* setup capabilities */ macb_configure_caps(bp, macb_config); platform_set_drvdata(pdev, dev); From c69618b3e4f220f4990b91596d40ea3c4cdc938a Mon Sep 17 00:00:00 2001 From: Nicolas Ferre Date: Tue, 31 Mar 2015 15:02:03 +0200 Subject: [PATCH 5/8] net/macb: fix probe sequence to setup clocks earlier As accessing the peripheral registers need the clocks to be set, we have to enable them as soon as possible. Their configuration depend on the type of device used and determined by the DT compatible string. That lead to add another initialization function in the DT configuration structure. As the device private structure length depend on an information read in the registers, we have to store the clock pointers in temporary variables before feeding the structure fields. Signed-off-by: Nicolas Ferre Signed-off-by: David S. Miller --- drivers/net/ethernet/cadence/macb.c | 209 ++++++++++++++++------------ drivers/net/ethernet/cadence/macb.h | 2 + 2 files changed, 124 insertions(+), 87 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c index e27bc6964402..205f4b86d9da 100644 --- a/drivers/net/ethernet/cadence/macb.c +++ b/drivers/net/ethernet/cadence/macb.c @@ -2184,6 +2184,58 @@ static void macb_probe_queues(void __iomem *mem, (*num_queues)++; } +static int macb_clk_init(struct platform_device *pdev, struct clk **pclk, + struct clk **hclk, struct clk **tx_clk) +{ + int err; + + *pclk = devm_clk_get(&pdev->dev, "pclk"); + if (IS_ERR(*pclk)) { + err = PTR_ERR(*pclk); + dev_err(&pdev->dev, "failed to get macb_clk (%u)\n", err); + return err; + } + + *hclk = devm_clk_get(&pdev->dev, "hclk"); + if (IS_ERR(*hclk)) { + err = PTR_ERR(*hclk); + dev_err(&pdev->dev, "failed to get hclk (%u)\n", err); + return err; + } + + *tx_clk = devm_clk_get(&pdev->dev, "tx_clk"); + if (IS_ERR(*tx_clk)) + *tx_clk = NULL; + + err = clk_prepare_enable(*pclk); + if (err) { + dev_err(&pdev->dev, "failed to enable pclk (%u)\n", err); + return err; + } + + err = clk_prepare_enable(*hclk); + if (err) { + dev_err(&pdev->dev, "failed to enable hclk (%u)\n", err); + goto err_disable_pclk; + } + + err = clk_prepare_enable(*tx_clk); + if (err) { + dev_err(&pdev->dev, "failed to enable tx_clk (%u)\n", err); + goto err_disable_hclk; + } + + return 0; + +err_disable_hclk: + clk_disable_unprepare(*hclk); + +err_disable_pclk: + clk_disable_unprepare(*pclk); + + return err; +} + static int macb_init(struct platform_device *pdev) { struct net_device *dev = platform_get_drvdata(pdev); @@ -2193,42 +2245,6 @@ static int macb_init(struct platform_device *pdev) int err; u32 val; - bp->pclk = devm_clk_get(&pdev->dev, "pclk"); - if (IS_ERR(bp->pclk)) { - err = PTR_ERR(bp->pclk); - dev_err(&pdev->dev, "failed to get macb_clk (%u)\n", err); - return err; - } - - bp->hclk = devm_clk_get(&pdev->dev, "hclk"); - if (IS_ERR(bp->hclk)) { - err = PTR_ERR(bp->hclk); - dev_err(&pdev->dev, "failed to get hclk (%u)\n", err); - return err; - } - - bp->tx_clk = devm_clk_get(&pdev->dev, "tx_clk"); - if (IS_ERR(bp->tx_clk)) - bp->tx_clk = NULL; - - err = clk_prepare_enable(bp->pclk); - if (err) { - dev_err(&pdev->dev, "failed to enable pclk (%u)\n", err); - return err; - } - - err = clk_prepare_enable(bp->hclk); - if (err) { - dev_err(&pdev->dev, "failed to enable hclk (%u)\n", err); - goto err_disable_pclk; - } - - err = clk_prepare_enable(bp->tx_clk); - if (err) { - dev_err(&pdev->dev, "failed to enable tx_clk (%u)\n", err); - goto err_disable_hclk; - } - /* set the queue register mapping once for all: queue0 has a special * register mapping but we don't want to test the queue index then * compute the corresponding register offset at run time. @@ -2266,7 +2282,7 @@ static int macb_init(struct platform_device *pdev) dev_err(&pdev->dev, "Unable to request IRQ %d (error %d)\n", queue->irq, err); - goto err_disable_tx_clk; + return err; } INIT_WORK(&queue->tx_error_task, macb_tx_error_task); @@ -2322,17 +2338,6 @@ static int macb_init(struct platform_device *pdev) macb_writel(bp, NCFGR, val); return 0; - -err_disable_tx_clk: - clk_disable_unprepare(bp->tx_clk); - -err_disable_hclk: - clk_disable_unprepare(bp->hclk); - -err_disable_pclk: - clk_disable_unprepare(bp->pclk); - - return err; } #if defined(CONFIG_OF) @@ -2600,6 +2605,27 @@ static const struct net_device_ops at91ether_netdev_ops = { #endif }; +static int at91ether_clk_init(struct platform_device *pdev, struct clk **pclk, + struct clk **hclk, struct clk **tx_clk) +{ + int err; + + *hclk = NULL; + *tx_clk = NULL; + + *pclk = devm_clk_get(&pdev->dev, "ether_clk"); + if (IS_ERR(*pclk)) + return PTR_ERR(*pclk); + + err = clk_prepare_enable(*pclk); + if (err) { + dev_err(&pdev->dev, "failed to enable pclk (%u)\n", err); + return err; + } + + return 0; +} + static int at91ether_init(struct platform_device *pdev) { struct net_device *dev = platform_get_drvdata(pdev); @@ -2607,23 +2633,13 @@ static int at91ether_init(struct platform_device *pdev) int err; u32 reg; - bp->pclk = devm_clk_get(&pdev->dev, "ether_clk"); - if (IS_ERR(bp->pclk)) - return PTR_ERR(bp->pclk); - - err = clk_prepare_enable(bp->pclk); - if (err) { - dev_err(&pdev->dev, "failed to enable pclk (%u)\n", err); - return err; - } - dev->netdev_ops = &at91ether_netdev_ops; dev->ethtool_ops = &macb_ethtool_ops; err = devm_request_irq(&pdev->dev, dev->irq, at91ether_interrupt, 0, dev->name, dev); if (err) - goto err_disable_clk; + return err; macb_writel(bp, NCR, 0); @@ -2634,37 +2650,37 @@ static int at91ether_init(struct platform_device *pdev) macb_writel(bp, NCFGR, reg); return 0; - -err_disable_clk: - clk_disable_unprepare(bp->pclk); - - return err; } static const struct macb_config at91sam9260_config = { .caps = MACB_CAPS_USRIO_HAS_CLKEN | MACB_CAPS_USRIO_DEFAULT_IS_MII, + .clk_init = macb_clk_init, .init = macb_init, }; static const struct macb_config pc302gem_config = { .caps = MACB_CAPS_SG_DISABLED | MACB_CAPS_GIGABIT_MODE_AVAILABLE, .dma_burst_length = 16, + .clk_init = macb_clk_init, .init = macb_init, }; static const struct macb_config sama5d3_config = { .caps = MACB_CAPS_SG_DISABLED | MACB_CAPS_GIGABIT_MODE_AVAILABLE, .dma_burst_length = 16, + .clk_init = macb_clk_init, .init = macb_init, }; static const struct macb_config sama5d4_config = { .caps = 0, .dma_burst_length = 4, + .clk_init = macb_clk_init, .init = macb_init, }; static const struct macb_config emac_config = { + .clk_init = at91ether_clk_init, .init = at91ether_init, }; @@ -2685,9 +2701,13 @@ MODULE_DEVICE_TABLE(of, macb_dt_ids); static int macb_probe(struct platform_device *pdev) { + int (*clk_init)(struct platform_device *, struct clk **, + struct clk **, struct clk **) + = macb_clk_init; int (*init)(struct platform_device *) = macb_init; struct device_node *np = pdev->dev.of_node; const struct macb_config *macb_config = NULL; + struct clk *pclk, *hclk, *tx_clk; unsigned int queue_mask, num_queues; struct macb_platform_data *pdata; struct phy_device *phydev; @@ -2698,15 +2718,34 @@ static int macb_probe(struct platform_device *pdev) struct macb *bp; int err; + if (np) { + const struct of_device_id *match; + + match = of_match_node(macb_dt_ids, np); + if (match && match->data) { + macb_config = match->data; + clk_init = macb_config->clk_init; + init = macb_config->init; + } + } + + err = clk_init(pdev, &pclk, &hclk, &tx_clk); + if (err) + return err; + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); mem = devm_ioremap_resource(&pdev->dev, regs); - if (IS_ERR(mem)) - return PTR_ERR(mem); + if (IS_ERR(mem)) { + err = PTR_ERR(mem); + goto err_disable_clocks; + } macb_probe_queues(mem, &queue_mask, &num_queues); dev = alloc_etherdev_mq(sizeof(*bp), num_queues); - if (!dev) - return -ENOMEM; + if (!dev) { + err = -ENOMEM; + goto err_disable_clocks; + } dev->base_addr = regs->start; @@ -2718,27 +2757,23 @@ static int macb_probe(struct platform_device *pdev) bp->regs = mem; bp->num_queues = num_queues; bp->queue_mask = queue_mask; + if (macb_config) + bp->dma_burst_length = macb_config->dma_burst_length; + bp->pclk = pclk; + bp->hclk = hclk; + bp->tx_clk = tx_clk; spin_lock_init(&bp->lock); - if (np) { - const struct of_device_id *match; - - match = of_match_node(macb_dt_ids, np); - if (match && match->data) { - macb_config = match->data; - bp->dma_burst_length = macb_config->dma_burst_length; - init = macb_config->init; - } - } - /* setup capabilities */ macb_configure_caps(bp, macb_config); platform_set_drvdata(pdev, dev); dev->irq = platform_get_irq(pdev, 0); - if (dev->irq < 0) - return dev->irq; + if (dev->irq < 0) { + err = dev->irq; + goto err_disable_clocks; + } mac = of_get_mac_address(np); if (mac) @@ -2765,7 +2800,7 @@ static int macb_probe(struct platform_device *pdev) err = register_netdev(dev); if (err) { dev_err(&pdev->dev, "Cannot register net device, aborting.\n"); - goto err_disable_clocks; + goto err_out_unregister_netdev; } err = macb_mii_init(bp); @@ -2787,14 +2822,14 @@ static int macb_probe(struct platform_device *pdev) err_out_unregister_netdev: unregister_netdev(dev); -err_disable_clocks: - clk_disable_unprepare(bp->tx_clk); - clk_disable_unprepare(bp->hclk); - clk_disable_unprepare(bp->pclk); - err_out_free_netdev: free_netdev(dev); +err_disable_clocks: + clk_disable_unprepare(tx_clk); + clk_disable_unprepare(hclk); + clk_disable_unprepare(pclk); + return err; } diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h index 0b6afac91bfe..5f9950e84c5e 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -754,6 +754,8 @@ struct macb_or_gem_ops { struct macb_config { u32 caps; unsigned int dma_burst_length; + int (*clk_init)(struct platform_device *pdev, struct clk **pclk, + struct clk **hclk, struct clk **tx_clk); int (*init)(struct platform_device *pdev); }; From 7c39994fc1e2b6a1bb5cb207a88e88a6b1ac1694 Mon Sep 17 00:00:00 2001 From: Nicolas Ferre Date: Tue, 31 Mar 2015 15:02:04 +0200 Subject: [PATCH 6/8] net/macb: add the user i/o to ethtool register dump User i/o register EMAC_USRIO or GMAC_UR can be found on both macb and gem flavors of the peripheral. By using the proper accessor, we can add it to the register dump feature of ethtool. Increment the version of this API so it can be noticed from user space. Signed-off-by: Nicolas Ferre Signed-off-by: David S. Miller --- drivers/net/ethernet/cadence/macb.c | 2 +- drivers/net/ethernet/cadence/macb.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c index 205f4b86d9da..babe972a7c32 100644 --- a/drivers/net/ethernet/cadence/macb.c +++ b/drivers/net/ethernet/cadence/macb.c @@ -2037,8 +2037,8 @@ static void macb_get_regs(struct net_device *dev, struct ethtool_regs *regs, regs_buff[10] = macb_tx_dma(&bp->queues[0], tail); regs_buff[11] = macb_tx_dma(&bp->queues[0], head); + regs_buff[12] = macb_or_gem_readl(bp, USRIO); if (macb_is_gem(bp)) { - regs_buff[12] = gem_readl(bp, USRIO); regs_buff[13] = gem_readl(bp, DMACFG); } } diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h index 5f9950e84c5e..fd0a22157a88 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -11,7 +11,7 @@ #define _MACB_H #define MACB_GREGS_NBR 16 -#define MACB_GREGS_VERSION 1 +#define MACB_GREGS_VERSION 2 #define MACB_MAX_QUEUES 8 /* MACB register offsets */ From 361918970b7426bba97a64678ef2b2679c37199b Mon Sep 17 00:00:00 2001 From: Nicolas Ferre Date: Tue, 31 Mar 2015 15:02:05 +0200 Subject: [PATCH 7/8] net/macb: fix the peripheral version test We currently need two checks of the peripheral version in MACB_MID register. One of them got out of sync after modification by 8a013a9c71b2 (net: macb: Include multi queue support for xilinx ZynqMP ethernet version). Fix this in macb_configure_caps() so that xilinx ZynqMP will be considered as a GEM flavor. Fixes: 8a013a9c71b2 ("net: macb: Include multi queue support for xilinx ZynqMP ethernet version") Signed-off-by: Nicolas Ferre Cc: Michal Simek Cc: Punnaiah Choudary Kalluri Cc: #4.0 (if it doesn't make it for -final) Signed-off-by: David S. Miller --- drivers/net/ethernet/cadence/macb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c index babe972a7c32..4412895cf4a8 100644 --- a/drivers/net/ethernet/cadence/macb.c +++ b/drivers/net/ethernet/cadence/macb.c @@ -2139,7 +2139,7 @@ static void macb_configure_caps(struct macb *bp, const struct macb_config *dt_co if (dt_conf) bp->caps = dt_conf->caps; - if (MACB_BFEXT(IDNUM, macb_readl(bp, MID)) == 0x2) + if (MACB_BFEXT(IDNUM, macb_readl(bp, MID)) >= 0x2) bp->caps |= MACB_CAPS_MACB_IS_GEM; if (macb_is_gem(bp)) { From fa6935981af81706f363df4b6f1285a20dc7ae17 Mon Sep 17 00:00:00 2001 From: Nicolas Ferre Date: Tue, 31 Mar 2015 15:02:06 +0200 Subject: [PATCH 8/8] net/macb: unify peripheral version testing As we need to check peripheral version from the hardware during probe, I introduce a little helper to unify these tests. It would prevent to de-synchronize the test like previously observed. Signed-off-by: Nicolas Ferre Signed-off-by: David S. Miller --- drivers/net/ethernet/cadence/macb.c | 7 ++----- drivers/net/ethernet/cadence/macb.h | 5 +++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c index 4412895cf4a8..448a32309dd0 100644 --- a/drivers/net/ethernet/cadence/macb.c +++ b/drivers/net/ethernet/cadence/macb.c @@ -2139,10 +2139,9 @@ static void macb_configure_caps(struct macb *bp, const struct macb_config *dt_co if (dt_conf) bp->caps = dt_conf->caps; - if (MACB_BFEXT(IDNUM, macb_readl(bp, MID)) >= 0x2) + if (macb_is_gem_hw(bp->regs)) { bp->caps |= MACB_CAPS_MACB_IS_GEM; - if (macb_is_gem(bp)) { dcfg = gem_readl(bp, DCFG1); if (GEM_BFEXT(IRQCOR, dcfg) == 0) bp->caps |= MACB_CAPS_ISR_CLEAR_ON_WRITE; @@ -2159,7 +2158,6 @@ static void macb_probe_queues(void __iomem *mem, unsigned int *num_queues) { unsigned int hw_q; - u32 mid; *queue_mask = 0x1; *num_queues = 1; @@ -2170,8 +2168,7 @@ static void macb_probe_queues(void __iomem *mem, * we are early in the probe process and don't have the * MACB_CAPS_MACB_IS_GEM flag positioned */ - mid = readl_relaxed(mem + MACB_MID); - if (MACB_BFEXT(IDNUM, mid) < 0x2) + if (!macb_is_gem_hw(mem)) return; /* bit 0 is never set but queue 0 always exists */ diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h index fd0a22157a88..eb7d76f7bf6a 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -833,4 +833,9 @@ static inline bool macb_is_gem(struct macb *bp) return !!(bp->caps & MACB_CAPS_MACB_IS_GEM); } +static inline bool macb_is_gem_hw(void __iomem *addr) +{ + return !!(MACB_BFEXT(IDNUM, readl_relaxed(addr + MACB_MID)) >= 0x2); +} + #endif /* _MACB_H */