Skip to content

Commit 5f0456b

Browse files
joabreudavem330
authored andcommitted
net: stmmac: Implement logic to automatically select HW Interface
Move all the core version detection to a common place ("hwif.c") and implement a table which can be used to lookup the correct callbacks for each IP version. This simplifies the initialization flow of each IP version and eases future implementation of new IP versions. Signed-off-by: Jose Abreu <joabreu@synopsys.com> Cc: David S. Miller <davem@davemloft.net> Cc: Joao Pinto <jpinto@synopsys.com> Cc: Vitor Soares <soares@synopsys.com> Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com> Cc: Alexandre Torgue <alexandre.torgue@st.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 22148df commit 5f0456b

File tree

11 files changed

+279
-164
lines changed

11 files changed

+279
-164
lines changed

drivers/net/ethernet/stmicro/stmmac/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o ring_mode.o \
44
chain_mode.o dwmac_lib.o dwmac1000_core.o dwmac1000_dma.o \
55
dwmac100_core.o dwmac100_dma.o enh_desc.o norm_desc.o \
66
mmc_core.o stmmac_hwtstamp.o stmmac_ptp.o dwmac4_descs.o \
7-
dwmac4_dma.o dwmac4_lib.o dwmac4_core.o dwmac5.o $(stmmac-y)
7+
dwmac4_dma.o dwmac4_lib.o dwmac4_core.o dwmac5.o hwif.o \
8+
$(stmmac-y)
89

910
# Ordering matters. Generic driver must be last.
1011
obj-$(CONFIG_STMMAC_PLATFORM) += stmmac-platform.o

drivers/net/ethernet/stmicro/stmmac/common.h

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#define DWMAC_CORE_3_40 0x34
4040
#define DWMAC_CORE_3_50 0x35
4141
#define DWMAC_CORE_4_00 0x40
42+
#define DWMAC_CORE_4_10 0x41
4243
#define DWMAC_CORE_5_00 0x50
4344
#define DWMAC_CORE_5_10 0x51
4445
#define STMMAC_CHAN0 0 /* Always supported and default for all chips */
@@ -428,12 +429,9 @@ struct stmmac_rx_routing {
428429
u32 reg_shift;
429430
};
430431

431-
struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr, int mcbins,
432-
int perfect_uc_entries,
433-
int *synopsys_id);
434-
struct mac_device_info *dwmac100_setup(void __iomem *ioaddr, int *synopsys_id);
435-
struct mac_device_info *dwmac4_setup(void __iomem *ioaddr, int mcbins,
436-
int perfect_uc_entries, int *synopsys_id);
432+
int dwmac100_setup(struct stmmac_priv *priv);
433+
int dwmac1000_setup(struct stmmac_priv *priv);
434+
int dwmac4_setup(struct stmmac_priv *priv);
437435

438436
void stmmac_set_mac_addr(void __iomem *ioaddr, u8 addr[6],
439437
unsigned int high, unsigned int low);
@@ -453,24 +451,4 @@ extern const struct stmmac_mode_ops ring_mode_ops;
453451
extern const struct stmmac_mode_ops chain_mode_ops;
454452
extern const struct stmmac_desc_ops dwmac4_desc_ops;
455453

456-
/**
457-
* stmmac_get_synopsys_id - return the SYINID.
458-
* @priv: driver private structure
459-
* Description: this simple function is to decode and return the SYINID
460-
* starting from the HW core register.
461-
*/
462-
static inline u32 stmmac_get_synopsys_id(u32 hwid)
463-
{
464-
/* Check Synopsys Id (not available on old chips) */
465-
if (likely(hwid)) {
466-
u32 uid = ((hwid & 0x0000ff00) >> 8);
467-
u32 synid = (hwid & 0x000000ff);
468-
469-
pr_info("stmmac - user ID: 0x%x, Synopsys ID: 0x%x\n",
470-
uid, synid);
471-
472-
return synid;
473-
}
474-
return 0;
475-
}
476454
#endif /* __COMMON_H__ */

drivers/net/ethernet/stmicro/stmmac/dwmac1000.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#define GMAC_MII_DATA 0x00000014 /* MII Data */
3030
#define GMAC_FLOW_CTRL 0x00000018 /* Flow Control */
3131
#define GMAC_VLAN_TAG 0x0000001c /* VLAN Tag */
32-
#define GMAC_VERSION 0x00000020 /* GMAC CORE Version */
3332
#define GMAC_DEBUG 0x00000024 /* GMAC debug register */
3433
#define GMAC_WAKEUP_FILTER 0x00000028 /* Wake-up Frame Filter */
3534

drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/ethtool.h>
2828
#include <net/dsa.h>
2929
#include <asm/io.h>
30+
#include "stmmac.h"
3031
#include "stmmac_pcs.h"
3132
#include "dwmac1000.h"
3233

@@ -498,7 +499,7 @@ static void dwmac1000_debug(void __iomem *ioaddr, struct stmmac_extra_stats *x,
498499
x->mac_gmii_rx_proto_engine++;
499500
}
500501

501-
static const struct stmmac_ops dwmac1000_ops = {
502+
const struct stmmac_ops dwmac1000_ops = {
502503
.core_init = dwmac1000_core_init,
503504
.set_mac = stmmac_set_mac,
504505
.rx_ipc = dwmac1000_rx_ipc_enable,
@@ -519,28 +520,21 @@ static const struct stmmac_ops dwmac1000_ops = {
519520
.pcs_get_adv_lp = dwmac1000_get_adv_lp,
520521
};
521522

522-
struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr, int mcbins,
523-
int perfect_uc_entries,
524-
int *synopsys_id)
523+
int dwmac1000_setup(struct stmmac_priv *priv)
525524
{
526-
struct mac_device_info *mac;
527-
u32 hwid = readl(ioaddr + GMAC_VERSION);
525+
struct mac_device_info *mac = priv->hw;
528526

529-
mac = kzalloc(sizeof(const struct mac_device_info), GFP_KERNEL);
530-
if (!mac)
531-
return NULL;
527+
dev_info(priv->device, "\tDWMAC1000\n");
532528

533-
mac->pcsr = ioaddr;
534-
mac->multicast_filter_bins = mcbins;
535-
mac->unicast_filter_entries = perfect_uc_entries;
529+
priv->dev->priv_flags |= IFF_UNICAST_FLT;
530+
mac->pcsr = priv->ioaddr;
531+
mac->multicast_filter_bins = priv->plat->multicast_filter_bins;
532+
mac->unicast_filter_entries = priv->plat->unicast_filter_entries;
536533
mac->mcast_bits_log2 = 0;
537534

538535
if (mac->multicast_filter_bins)
539536
mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins);
540537

541-
mac->mac = &dwmac1000_ops;
542-
mac->dma = &dwmac1000_dma_ops;
543-
544538
mac->link.duplex = GMAC_CONTROL_DM;
545539
mac->link.speed10 = GMAC_CONTROL_PS;
546540
mac->link.speed100 = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
@@ -555,8 +549,5 @@ struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr, int mcbins,
555549
mac->mii.clk_csr_shift = 2;
556550
mac->mii.clk_csr_mask = GENMASK(5, 2);
557551

558-
/* Get and dump the chip ID */
559-
*synopsys_id = stmmac_get_synopsys_id(hwid);
560-
561-
return mac;
552+
return 0;
562553
}

drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/crc32.h>
2828
#include <net/dsa.h>
2929
#include <asm/io.h>
30+
#include "stmmac.h"
3031
#include "dwmac100.h"
3132

3233
static void dwmac100_core_init(struct mac_device_info *hw,
@@ -159,7 +160,7 @@ static void dwmac100_pmt(struct mac_device_info *hw, unsigned long mode)
159160
return;
160161
}
161162

162-
static const struct stmmac_ops dwmac100_ops = {
163+
const struct stmmac_ops dwmac100_ops = {
163164
.core_init = dwmac100_core_init,
164165
.set_mac = stmmac_set_mac,
165166
.rx_ipc = dwmac100_rx_ipc_enable,
@@ -172,20 +173,13 @@ static const struct stmmac_ops dwmac100_ops = {
172173
.get_umac_addr = dwmac100_get_umac_addr,
173174
};
174175

175-
struct mac_device_info *dwmac100_setup(void __iomem *ioaddr, int *synopsys_id)
176+
int dwmac100_setup(struct stmmac_priv *priv)
176177
{
177-
struct mac_device_info *mac;
178+
struct mac_device_info *mac = priv->hw;
178179

179-
mac = kzalloc(sizeof(const struct mac_device_info), GFP_KERNEL);
180-
if (!mac)
181-
return NULL;
182-
183-
pr_info("\tDWMAC100\n");
184-
185-
mac->pcsr = ioaddr;
186-
mac->mac = &dwmac100_ops;
187-
mac->dma = &dwmac100_dma_ops;
180+
dev_info(priv->device, "\tDWMAC100\n");
188181

182+
mac->pcsr = priv->ioaddr;
189183
mac->link.duplex = MAC_CONTROL_F;
190184
mac->link.speed10 = 0;
191185
mac->link.speed100 = 0;
@@ -200,8 +194,5 @@ struct mac_device_info *dwmac100_setup(void __iomem *ioaddr, int *synopsys_id)
200194
mac->mii.clk_csr_shift = 2;
201195
mac->mii.clk_csr_mask = GENMASK(5, 2);
202196

203-
/* Synopsys Id is not available on old chips */
204-
*synopsys_id = 0;
205-
206-
return mac;
197+
return 0;
207198
}

drivers/net/ethernet/stmicro/stmmac/dwmac4.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#define GMAC_PCS_BASE 0x000000e0
3535
#define GMAC_PHYIF_CONTROL_STATUS 0x000000f8
3636
#define GMAC_PMT 0x000000c0
37-
#define GMAC_VERSION 0x00000110
3837
#define GMAC_DEBUG 0x00000114
3938
#define GMAC_HW_FEATURE0 0x0000011c
4039
#define GMAC_HW_FEATURE1 0x00000120

drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/ethtool.h>
1919
#include <linux/io.h>
2020
#include <net/dsa.h>
21+
#include "stmmac.h"
2122
#include "stmmac_pcs.h"
2223
#include "dwmac4.h"
2324
#include "dwmac5.h"
@@ -700,7 +701,7 @@ static void dwmac4_debug(void __iomem *ioaddr, struct stmmac_extra_stats *x,
700701
x->mac_gmii_rx_proto_engine++;
701702
}
702703

703-
static const struct stmmac_ops dwmac4_ops = {
704+
const struct stmmac_ops dwmac4_ops = {
704705
.core_init = dwmac4_core_init,
705706
.set_mac = stmmac_set_mac,
706707
.rx_ipc = dwmac4_rx_ipc_enable,
@@ -731,7 +732,7 @@ static const struct stmmac_ops dwmac4_ops = {
731732
.set_filter = dwmac4_set_filter,
732733
};
733734

734-
static const struct stmmac_ops dwmac410_ops = {
735+
const struct stmmac_ops dwmac410_ops = {
735736
.core_init = dwmac4_core_init,
736737
.set_mac = stmmac_dwmac4_set_mac,
737738
.rx_ipc = dwmac4_rx_ipc_enable,
@@ -762,7 +763,7 @@ static const struct stmmac_ops dwmac410_ops = {
762763
.set_filter = dwmac4_set_filter,
763764
};
764765

765-
static const struct stmmac_ops dwmac510_ops = {
766+
const struct stmmac_ops dwmac510_ops = {
766767
.core_init = dwmac4_core_init,
767768
.set_mac = stmmac_dwmac4_set_mac,
768769
.rx_ipc = dwmac4_rx_ipc_enable,
@@ -796,19 +797,16 @@ static const struct stmmac_ops dwmac510_ops = {
796797
.safety_feat_dump = dwmac5_safety_feat_dump,
797798
};
798799

799-
struct mac_device_info *dwmac4_setup(void __iomem *ioaddr, int mcbins,
800-
int perfect_uc_entries, int *synopsys_id)
800+
int dwmac4_setup(struct stmmac_priv *priv)
801801
{
802-
struct mac_device_info *mac;
803-
u32 hwid = readl(ioaddr + GMAC_VERSION);
802+
struct mac_device_info *mac = priv->hw;
804803

805-
mac = kzalloc(sizeof(const struct mac_device_info), GFP_KERNEL);
806-
if (!mac)
807-
return NULL;
804+
dev_info(priv->device, "\tDWMAC4/5\n");
808805

809-
mac->pcsr = ioaddr;
810-
mac->multicast_filter_bins = mcbins;
811-
mac->unicast_filter_entries = perfect_uc_entries;
806+
priv->dev->priv_flags |= IFF_UNICAST_FLT;
807+
mac->pcsr = priv->ioaddr;
808+
mac->multicast_filter_bins = priv->plat->multicast_filter_bins;
809+
mac->unicast_filter_entries = priv->plat->unicast_filter_entries;
812810
mac->mcast_bits_log2 = 0;
813811

814812
if (mac->multicast_filter_bins)
@@ -828,20 +826,5 @@ struct mac_device_info *dwmac4_setup(void __iomem *ioaddr, int mcbins,
828826
mac->mii.clk_csr_shift = 8;
829827
mac->mii.clk_csr_mask = GENMASK(11, 8);
830828

831-
/* Get and dump the chip ID */
832-
*synopsys_id = stmmac_get_synopsys_id(hwid);
833-
834-
if (*synopsys_id > DWMAC_CORE_4_00)
835-
mac->dma = &dwmac410_dma_ops;
836-
else
837-
mac->dma = &dwmac4_dma_ops;
838-
839-
if (*synopsys_id >= DWMAC_CORE_5_10)
840-
mac->mac = &dwmac510_ops;
841-
else if (*synopsys_id >= DWMAC_CORE_4_00)
842-
mac->mac = &dwmac410_ops;
843-
else
844-
mac->mac = &dwmac4_ops;
845-
846-
return mac;
829+
return 0;
847830
}

0 commit comments

Comments
 (0)