bgmac: driver for GBit MAC core on BCMA bus
Subsystems (4)
Rafał Miłecki
maintainerRFC PATCH 1/1 bgmac: driver for GBit MAC core on BCMA bus
BCMA is a Broadcom specific bus with devices AKA cores. All recent BCMA based SoCs have gigabit ethernet provided by the GBit MAC core. This patch adds driver for such a cores registering itself as a netdev. It has been tested on a BCM4706 and BCM4718 chipsets.
In the kernel tree there is already b44 driver which has some common things with bgmac, however there are many differences that has led to the decision or writing a new driver:
1) GBit MAC cores appear on BCMA bus (not SSB as in case of b44)
2) There is 64bit DMA engine which differs from 32bit one
3) There is no CAM (Content Addressable Memory) in GBit MAC
4) We have 4 TX queues on GBit MAC devices (instead of 1)
5) Many registers have different addresses/values
6) RX header flags are also different
The driver in it's state is functional how, however there is of course place for improvements:
1) Supporting more net_device_ops
2) SUpporting more ethtool_ops
3) Unaligned addressing in DMA
4) Writing separated PHY driver
It's just a RFC, so be aware of two ugly parts in this version:
1) bgmac_stop doesn't stop device and free resources
2) bgmac_dma_rx_read doesn't check for alloc result
--- drivers/bcma/driver_chipcommon_pmu.c | 3 +- drivers/net/ethernet/broadcom/Kconfig | 9 + drivers/net/ethernet/broadcom/Makefile | 1 + drivers/net/ethernet/broadcom/bgmac.c | 1396 +++++++++++++++++++++++++++ drivers/net/ethernet/broadcom/bgmac.h | 425 ++++++++ include/linux/bcma/bcma_driver_chipcommon.h | 2 + 6 files changed, 1835 insertions(+), 1 deletions(-) create mode 100644 drivers/net/ethernet/broadcom/bgmac.c create mode 100644 drivers/net/ethernet/broadcom/bgmac.h
drivers/bcma/driver_chipcommon_pmu.c +2 -1
@@ -264,7 +264,7 @@ static u32 bcma_pmu_pll_clock_bcm4706(struct bcma_drv_cc *cc, u32 pll0, u32 m) }/* query bus clock frequency for PMU-enabled chipcommon */ -static u32 bcma_pmu_get_bus_clock (struct bcma_drv_cc *cc) +u32 bcma_pmu_get_bus_clock (struct bcma_drv_cc *cc) {struct bcma_bus *bus = cc->core->bus;
@@ -293,6 +293,7 @@ static u32 bcma_pmu_get_bus_clock(struct bcma_drv_cc *cc) }return BCMA_CC_PMU_HT_CLOCK ; } +EXPORT_SYMBOL_GPL (bcma_pmu_get_bus_clock);/* query cpu clock frequency for PMU-enabled chipcommon */ u32 bcma_pmu_get_cpu_clock (struct bcma_drv_cc *cc)
drivers/net/ethernet/broadcom/Kconfig +9 -0
@@ -120,4 +120,13 @@ config BNX2X To compile this driver as a module, choose M here: the module will be called bnx2x. This is recommended. +config BGMAC + tristate "BCMA bus GBit core support" + depends on BCMA_HOST_SOC && HAS_DMA + ---help--- + This driver supports GBit MAC and BCM4706 GBit MAC cores on BCMA bus. + They can be found on BCM47xx SoCs and provide gigabit ethernet. + In case of using this driver on BCM4706 it's also requires to enable + BCMA_DRIVER_GMAC_CMN to make it work. + endif # NET_VENDOR_BROADCOM
drivers/net/ethernet/broadcom/Makefile +1 -0
@@ -9,3 +9,4 @@ obj-$(CONFIG_CNIC) += cnic.o obj-$(CONFIG_BNX2X) += bnx2x/ obj-$(CONFIG_SB1250_MAC) += sb1250-mac.o obj-$(CONFIG_TIGON3) += tg3.o +obj-$(CONFIG_BGMAC) += bgmac.o
drivers/net/ethernet/broadcom/bgmac.c new file +1396 -0
1,396 lines not on this page · raw message
drivers/net/ethernet/broadcom/bgmac.h new file +425 -0
425 lines not on this page · raw message
include/linux/bcma/bcma_driver_chipcommon.h +2 -0
@@ -638,4 +638,6 @@ extern void bcma_chipco_regctl_maskset(struct bcma_drv_cc *cc, u32 offset, u32 mask, u32 set);extern void bcma_pmu_spuravoid_pllupdate (struct bcma_drv_cc *cc,int spuravoid); +extern u32 bcma_pmu_get_bus_clock (struct bcma_drv_cc *cc); +#endif /* LINUX_BCMA_DRIVER_CC_H_ */
Signature · 1 line
1.7.7
Quoted 4 lines · Rafał Miłecki
BCMA is a Broadcom specific bus with devices AKA cores. All recent BCMA based SoCs have gigabit ethernet provided by the GBit MAC core. This patch adds driver for such a cores registering itself as a netdev. It has been tested on a BCM4706 and BCM4718 chipsets.
[]
Quoted 1 line
It's just a RFC, so be aware of two ugly parts in this version:
Just some trivial notes. Feel free to ignore.
drivers/net/ethernet/broadcom/bgmac.c
Quoted 1 line
drivers/net/ethernet/broadcom/bgmac.c +0
-0
[]
drivers/net/ethernet/broadcom/bgmac.c line 19
Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac.c +10
-0+#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#define bgmac_err (bgmac, fmt, ...) \ + pr_err("u%d: " fmt, (bgmac)->core->core_unit, ##__VA_ARGS__) +#define bgmac_warn (bgmac, fmt, ...) \ + pr_warn("u%d: " fmt, (bgmac)->core->core_unit, ##__VA_ARGS__) +#define bgmac_info (bgmac, fmt, ...) \ + pr_info("u%d: " fmt, (bgmac)->core->core_unit, ##__VA_ARGS__) +#define bgmac_debug (bgmac, fmt, ...) \ + pr_debug("u%d: " fmt, (bgmac)->core->core_unit, ##__VA_ARGS__)
Most subsystems use prefix_dbg now instead of prefix_debug. Why not change these from pr_<level> to dev_<level>? Maybe these should be in the bgmac.h file.
drivers/net/ethernet/broadcom/bgmac.c line 45
Quoted 3 lines
drivers/net/ethernet/broadcom/bgmac.c +3
-0+static bool bgmac_wait_value (struct bcma_device *core,u16 reg,u32 mask, +u32 value,int timeout) +{
[]
drivers/net/ethernet/broadcom/bgmac.c line 55
Quoted 1 line
drivers/net/ethernet/broadcom/bgmac.c +1
-0+pr_err ("Timeout waiting for reg 0x%X\n" , reg);
Maybe add new bmca_dev_(err|warn|info|dbg) macros too?
Quoted 23 lines
drivers/net/ethernet/broadcom/bgmac.c +23
-0+/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyinit */ +static void bgmac_phy_init (struct bgmac *bgmac) +{ +struct bcma_chipinfo *ci = &bgmac->core->bus->chipinfo; +struct bcma_drv_cc *cc = &bgmac->core->bus->drv_cc; +u8 i; + +if (ci->id ==BCMA_CHIP_ID_BCM5356 ) { +for (i =0 ; i <5 ; i++) { +bgmac_phy_write (bgmac, i,0x1f ,0x008b ); +bgmac_phy_write (bgmac, i,0x15 ,0x0100 ); +bgmac_phy_write (bgmac, i,0x1f ,0x000f ); +bgmac_phy_write (bgmac, i,0x12 ,0x2aaa ); +bgmac_phy_write (bgmac, i,0x1f ,0x000b ); + } + } +if ((ci->id ==BCMA_CHIP_ID_BCM5357 && ci->pkg !=10 ) || + (ci->id ==BCMA_CHIP_ID_BCM4749 && ci->pkg !=10 ) || + (ci->id ==BCMA_CHIP_ID_BCM53572 && ci->pkg !=9 )) { +bcma_chipco_chipctl_maskset (cc,2 , ~0xc0000000 ,0 ); +bcma_chipco_chipctl_maskset (cc,4 , ~0x80000000 ,0 ); +for (i =0 ; i <5 ; i++) { +bgmac_phy_write (bgmac, i,0x1f ,0x000f );
drivers/net/ethernet/broadcom/bgmac.c line 709
Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac.c +10
-0+bgmac_phy_write (bgmac, i,0x16 ,0x5284 ); +bgmac_phy_write (bgmac, i,0x1f ,0x000b ); +bgmac_phy_write (bgmac, i,0x17 ,0x0010 ); +bgmac_phy_write (bgmac, i,0x1f ,0x000f ); +bgmac_phy_write (bgmac, i,0x16 ,0x5296 ); +bgmac_phy_write (bgmac, i,0x17 ,0x1073 ); +bgmac_phy_write (bgmac, i,0x17 ,0x9073 ); +bgmac_phy_write (bgmac, i,0x16 ,0x52b6 ); +bgmac_phy_write (bgmac, i,0x17 ,0x9273 ); +bgmac_phy_write (bgmac, i,0x1f ,0x000b );
That's a lot of magic numbers.
drivers/net/ethernet/broadcom/bgmac.c line 756
Quoted 5 lines
drivers/net/ethernet/broadcom/bgmac.c +5
-0+static void bgmac_chip_stats_update (struct bgmac *bgmac) +{ +int i; + +if (bgmac->core->id.id !=BCMA_CORE_4706_MAC_GBIT ) {
Save an indent level by returning a call to
a new bgmac_4706_chip_stats_update instead?
if (bgmac->core->id.id == BCMA_CORE_4706_MAC_GBIT) return bgmac_407_chip_stats_update(bgmac);
drivers/net/ethernet/broadcom/bgmac.c line 765
Quoted 9 lines
drivers/net/ethernet/broadcom/bgmac.c +9
-0+for (i =0 ; i <BGMAC_NUM_MIB_TX_REGS ; i++) + bgmac->mib_tx_regs[i] = +bgmac_read (bgmac, +BGMAC_TX_GOOD_OCTETS + (i *4 )); +for (i =0 ; i <BGMAC_NUM_MIB_RX_REGS ; i++) + bgmac->mib_rx_regs[i] = +bgmac_read (bgmac, +BGMAC_RX_GOOD_OCTETS + (i *4 )); + }
unindent
drivers/net/ethernet/broadcom/bgmac.c line 767
Quoted 2 lines
drivers/net/ethernet/broadcom/bgmac.c +2
-0+ +/* TODO: what else? how to handle BCM4706? */
and delete?
drivers/net/ethernet/broadcom/bgmac.c line 775
Quoted 8 lines
drivers/net/ethernet/broadcom/bgmac.c +8
-0+} + +static void bgmac_clear_mib (struct bgmac *bgmac) +{ +int i; + +if (bgmac->core->id.id ==BCMA_CORE_4706_MAC_GBIT ) +return ;
Something like what this function does.
[]
drivers/net/ethernet/broadcom/bgmac.h
Quoted 1 line
drivers/net/ethernet/broadcom/bgmac.h +0
-0
[]
Quoted 17 lines
drivers/net/ethernet/broadcom/bgmac.h +17
-0+struct bgmac { +struct bcma_device *core; +struct bcma_device *cmn;/* Reference to CMN core for BCM4706 */ +struct net_device *net_dev; +struct napi_struct napi; + +u8 phyaddr; +bool has_robosw; + +u32 int_mask; +u32 int_status; + +bool loopback; + +bool autoneg; +bool full_duplex; +int speed;
drivers/net/ethernet/broadcom/bgmac.h line 394
Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac.h +10
-0+ +/* DMA */ +struct bgmac_dma_ring tx_ring[BGMAC_MAX_TX_RINGS ]; +struct bgmac_dma_ring rx_ring[BGMAC_MAX_RX_RINGS ]; + +/* Stats */ +bool stats_grabbed; +u32 mib_tx_regs[BGMAC_NUM_MIB_TX_REGS ]; +u32 mib_rx_regs[BGMAC_NUM_MIB_RX_REGS ]; +};
Maybe some minor reordering of the u8/bools to reduce padding.
Rafał Miłecki
maintainer2012/12/13 Joe Perches <[email protected]>:
Quoted 9 lines · Rafał Miłecki
Quoted 4 lines
BCMA is a Broadcom specific bus with devices AKA cores. All recent BCMA based SoCs have gigabit ethernet provided by the GBit MAC core. This patch adds driver for such a cores registering itself as a netdev. It has been tested on a BCM4706 and BCM4718 chipsets.
[]
Quoted 1 line
It's just a RFC, so be aware of two ugly parts in this version:
Just some trivial notes. Feel free to ignore.
Thanks :) I can always try to discuss some points, but I appreciate every review!
Quoted 4 lines
drivers/net/ethernet/broadcom/bgmac.c
Quoted 1 line
drivers/net/ethernet/broadcom/bgmac.c +0
-0[]
Quoted 12 lines
drivers/net/ethernet/broadcom/bgmac.c line 19
Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac.c +10
-0+#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#define bgmac_err (bgmac, fmt, ...) \ + pr_err("u%d: " fmt, (bgmac)->core->core_unit, ##__VA_ARGS__) +#define bgmac_warn (bgmac, fmt, ...) \ + pr_warn("u%d: " fmt, (bgmac)->core->core_unit, ##__VA_ARGS__) +#define bgmac_info (bgmac, fmt, ...) \ + pr_info("u%d: " fmt, (bgmac)->core->core_unit, ##__VA_ARGS__) +#define bgmac_debug (bgmac, fmt, ...) \ + pr_debug("u%d: " fmt, (bgmac)->core->core_unit, ##__VA_ARGS__)Most subsystems use
prefix_dbgnow instead ofprefix_debug.
Thanks, I didn't know about that. Seeing "pr_debug" suggested I also should use *_debug.
Quoted 1 line
Why not change these from pr_<level> to dev_<level>?
One more thing I didn't know/think about (dev_*).
Quoted 1 line
Maybe these should be in the
bgmac.hfile.
OK.
Quoted 7 lines
drivers/net/ethernet/broadcom/bgmac.c line 45
Quoted 3 lines
drivers/net/ethernet/broadcom/bgmac.c +3
-0+static bool bgmac_wait_value (struct bcma_device *core,u16 reg,u32 mask, +u32 value,int timeout) +{[]
Quoted 1 line
+
pr_err("Timeout waiting for reg 0x%X\n", reg);Maybe add new
bmca_dev_(err|warn|info|dbg)macros too?
It's the only place where we are working on a specific coreunit, but I didn't bother to print that. Was too lazy to add special code for this single case, ups ;)
Quoted 27 lines
Quoted 27 lines
drivers/net/ethernet/broadcom/bgmac.c +27
-0+/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyinit */ +static void bgmac_phy_init (struct bgmac *bgmac) +{ +struct bcma_chipinfo *ci = &bgmac->core->bus->chipinfo; +struct bcma_drv_cc *cc = &bgmac->core->bus->drv_cc; +u8 i; + +if (ci->id ==BCMA_CHIP_ID_BCM5356 ) { +for (i =0 ; i <5 ; i++) { +bgmac_phy_write (bgmac, i,0x1f ,0x008b ); +bgmac_phy_write (bgmac, i,0x15 ,0x0100 ); +bgmac_phy_write (bgmac, i,0x1f ,0x000f ); +bgmac_phy_write (bgmac, i,0x12 ,0x2aaa ); +bgmac_phy_write (bgmac, i,0x1f ,0x000b ); + } + } +if ((ci->id ==BCMA_CHIP_ID_BCM5357 && ci->pkg !=10 ) || + (ci->id ==BCMA_CHIP_ID_BCM4749 && ci->pkg !=10 ) || + (ci->id ==BCMA_CHIP_ID_BCM53572 && ci->pkg !=9 )) { +bcma_chipco_chipctl_maskset (cc,2 , ~0xc0000000 ,0 ); +bcma_chipco_chipctl_maskset (cc,4 , ~0x80000000 ,0 ); +for (i =0 ; i <5 ; i++) { +bgmac_phy_write (bgmac, i,0x1f ,0x000f ); +bgmac_phy_write (bgmac, i,0x16 ,0x5284 ); +bgmac_phy_write (bgmac, i,0x1f ,0x000b ); +bgmac_phy_write (bgmac, i,0x17 ,0x0010 ); +bgmac_phy_write (bgmac, i,0x1f ,0x000f );
Quoted 8 lines
drivers/net/ethernet/broadcom/bgmac.c line 709
Quoted 6 lines
drivers/net/ethernet/broadcom/bgmac.c +6
-0+bgmac_phy_write (bgmac, i,0x16 ,0x5296 ); +bgmac_phy_write (bgmac, i,0x17 ,0x1073 ); +bgmac_phy_write (bgmac, i,0x17 ,0x9073 ); +bgmac_phy_write (bgmac, i,0x16 ,0x52b6 ); +bgmac_phy_write (bgmac, i,0x17 ,0x9273 ); +bgmac_phy_write (bgmac, i,0x1f ,0x000b );That's a lot of magic numbers.
I agree, unfortunately there's nothing I can do :( I don't know names for that registers not to mention the values (bits). We don't have datasheets for that devices and I don't think we will ever have.
Quoted 22 lines
drivers/net/ethernet/broadcom/bgmac.c line 756
Quoted 5 lines
drivers/net/ethernet/broadcom/bgmac.c +5
-0+static void bgmac_chip_stats_update (struct bgmac *bgmac) +{ +int i; + +if (bgmac->core->id.id !=BCMA_CORE_4706_MAC_GBIT ) {Save an indent level by returning a call to
a newbgmac_4706_chip_stats_updateinstead?if (bgmac->core->id.id == BCMA_CORE_4706_MAC_GBIT) return bgmac_407_chip_stats_update(bgmac);drivers/net/ethernet/broadcom/bgmac.c line 765
Quoted 9 lines
drivers/net/ethernet/broadcom/bgmac.c +9
-0+for (i =0 ; i <BGMAC_NUM_MIB_TX_REGS ; i++) + bgmac->mib_tx_regs[i] = +bgmac_read (bgmac, +BGMAC_TX_GOOD_OCTETS + (i *4 )); +for (i =0 ; i <BGMAC_NUM_MIB_RX_REGS ; i++) + bgmac->mib_rx_regs[i] = +bgmac_read (bgmac, +BGMAC_RX_GOOD_OCTETS + (i *4 )); + }
Quoted 6 lines
unindent
drivers/net/ethernet/broadcom/bgmac.c line 767
Quoted 2 lines
drivers/net/ethernet/broadcom/bgmac.c +2
-0+ +/* TODO: what else? how to handle BCM4706? */ and delete?
I got an info from Hauke that we can still do/read sth on BCM4706. It's just not documented yet, that's why I left "TODO". I can note the specs are lacking to make it clearer.
Quoted 12 lines
drivers/net/ethernet/broadcom/bgmac.c line 775
Quoted 8 lines
drivers/net/ethernet/broadcom/bgmac.c +8
-0+} + +static void bgmac_clear_mib (struct bgmac *bgmac) +{ +int i; + +if (bgmac->core->id.id ==BCMA_CORE_4706_MAC_GBIT ) +return ;Something like what this function does.
Quoted 7 lines
drivers/net/ethernet/broadcom/bgmac.c
Quoted 5 lines
drivers/net/ethernet/broadcom/bgmac.c +5
-0+/* Stats */ +bool stats_grabbed; +u32 mib_tx_regs[BGMAC_NUM_MIB_TX_REGS ]; +u32 mib_rx_regs[BGMAC_NUM_MIB_RX_REGS ]; +};Maybe some minor reordering of the u8/bools to reduce padding.
Really? Compiler won't do that for me? I hope that compiler optimizes structs (until using __packed) :(
Signature · 1 line
Rafał
Quoted 6 lines · Rafał Miłecki
2012/12/13 Joe Perches <[email protected]>:
Quoted 5 lines · Rafał Miłecki
Quoted 4 lines
BCMA is a Broadcom specific bus with devices AKA cores. All recent BCMA based SoCs have gigabit ethernet provided by the GBit MAC core. This patch adds driver for such a cores registering itself as a netdev. It has been tested on a BCM4706 and BCM4718 chipsets.
[]
Quoted 10 lines
Quoted 7 lines
drivers/net/ethernet/broadcom/bgmac.h line 394
Quoted 5 lines
drivers/net/ethernet/broadcom/bgmac.h new file +5
-0+/* Stats */ +bool stats_grabbed; +u32 mib_tx_regs[BGMAC_NUM_MIB_TX_REGS ]; +u32 mib_rx_regs[BGMAC_NUM_MIB_RX_REGS ]; +};Maybe some minor reordering of the u8/bools to reduce padding.
Really? Compiler won't do that for me? I hope that compiler optimizes structs (until using
__packed) :(
The compiler is not allowed to reorder struct members. Perhaps you bundle together all the u8/bools. Maybe not when/where cachelines are crossed.