NET: ethernet/netlogic: Netlogic XLR/XLS GMAC driver
Subsystems (3)
PATCH v2 1/2 NET: ethernet/netlogic: Netlogic XLR/XLS GMAC driver
From: Ganesan Ramalingam <[email protected]>
Add support for the Network Accelerator Engine on Netlogic XLR/XLS MIPS SoCs. The XLR/XLS NAE blocks can be configured as one 10G interface or four 1G interfaces. This driver supports blocks with 1G ports.
---
This patch has to be merged through netdev tree.
Changes since v1:
* Implementing ethtool using phylib
* Free skb buf incase of nlm_fmn_send() fail
* Use of ndo_get_stats64 instead of ndo_get_stats
* Watchdog timeo fix
drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/netlogic/Kconfig | 8 + drivers/net/ethernet/netlogic/Makefile | 1 + drivers/net/ethernet/netlogic/xlr_net.c | 1109 +++++++++++++++++++++++++++++++ drivers/net/ethernet/netlogic/xlr_net.h | 1099 ++++++++++++++++++++++++++++++ 6 files changed, 2219 insertions(+), 0 deletions(-) create mode 100644 drivers/net/ethernet/netlogic/Kconfig create mode 100644 drivers/net/ethernet/netlogic/Makefile create mode 100644 drivers/net/ethernet/netlogic/xlr_net.c create mode 100644 drivers/net/ethernet/netlogic/xlr_net.h
drivers/net/ethernet/Kconfig +1 -0
@@ -168,5 +168,6 @@ source "drivers/net/ethernet/via/Kconfig" source "drivers/net/ethernet/wiznet/Kconfig" source "drivers/net/ethernet/xilinx/Kconfig" source "drivers/net/ethernet/xircom/Kconfig" +source "drivers/net/ethernet/netlogic/Kconfig" endif # ETHERNET
drivers/net/ethernet/Makefile +1 -0
@@ -75,3 +75,4 @@ obj-$(CONFIG_NET_VENDOR_VIA) += via/ obj-$(CONFIG_NET_VENDOR_WIZNET) += wiznet/ obj-$(CONFIG_NET_VENDOR_XILINX) += xilinx/ obj-$(CONFIG_NET_VENDOR_XIRCOM) += xircom/ +obj-$(CONFIG_NETLOGIC_XLR_NET) += netlogic/
drivers/net/ethernet/netlogic/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +config NETLOGIC_XLR_NET + tristate "Netlogic XLR/XLS network device" + default y + select PHYLIB + depends on CPU_XLR + ---help--- + This driver support Netlogic XLR/XLS on chip gigabit + Ethernet.
drivers/net/ethernet/netlogic/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_NETLOGIC_XLR_NET) += xlr_net.o
drivers/net/ethernet/netlogic/xlr_net.c new file +1109 -0
1,109 lines not on this page · raw message
drivers/net/ethernet/netlogic/xlr_net.h new file +1099 -0
1,099 lines not on this page · raw message
Signature · 1 line
1.7.6
Quoted 16 lines · On Tue, 2013-02-05 at 17:00 +0530, [email protected] wrote:
From: Ganesan Ramalingam <[email protected]>
Add support for the Network Accelerator Engine on Netlogic XLR/XLS MIPS SoCs. The XLR/XLS NAE blocks can be configured as one 10G interface or four 1G interfaces. This driver supports blocks with 1G ports.
Signed-off-by Ganesan Ramalingam <[email protected]>---
This patch has to be merged through netdev tree.Changes since v1:
* Implementing ethtool using phylib
* Free skb buf incase ofnlm_fmn_send()fail
* Use ofndo_get_stats64instead ofndo_get_stats
* Watchdog timeo fix
[...]
drivers/net/ethernet/netlogic/xlr_net.c line 378
Quoted 13 lines
drivers/net/ethernet/netlogic/xlr_net.c new file +13
-0+static void xlr_stats (struct net_device *ndev,struct rtnl_link_stats64 *stats) +{ +struct xlr_net_priv *priv =netdev_priv (ndev); + + stats->rx_packets =xlr_nae_rdreg (priv->base_addr,RX_PACKET_COUNTER ); + stats->tx_packets =xlr_nae_rdreg (priv->base_addr,TX_PACKET_COUNTER ); + stats->rx_bytes =xlr_nae_rdreg (priv->base_addr,RX_BYTE_COUNTER ); + stats->tx_bytes =xlr_nae_rdreg (priv->base_addr,TX_BYTE_COUNTER ); + stats->tx_errors =xlr_nae_rdreg (priv->base_addr,TX_FCS_ERROR_COUNTER ); + stats->rx_dropped =xlr_nae_rdreg (priv->base_addr, +RX_DROP_PACKET_COUNTER ); + stats->tx_dropped =xlr_nae_rdreg (priv->base_addr, +TX_DROP_FRAME_COUNTER );
[...]
But these are still 32-bit counters in hardware, yes? So I think you need to arrange to poll at least the byte counters every few seconds and maintain the higher bits in software e.g.:
struct xlr_stats {
spinlock_t lock;
struct timer timer;
u64 rx_bytes;
u64 tx_bytes;
...
};static void xlr_poll_stats(struct xlr_net_priv *priv)
{
struct xlr_stats = &priv->stats;
u32 counter;
spin_lock_bh(&stats->lock);
counter = xlr_nae_rdreg(priv->base_addr, RX_BYTE_COUNTER);
stats->rx_bytes += (u32)(counter - stats->rx_bytes);
counter = xlr_nae_rdreg(priv->base_addr, TX_BYTE_COUNTER);
stats->tx_bytes += (u32)(counter - stats->tx_bytes);
...
spin_unlock_bh(&stats->lock);
}static void xlr_poll_stats_timer(void *data)
{
struct xlr_net_priv *priv = data;
xlr_poll_stats(priv);
mod_timer(&priv->stats.timer, jiffies + 2 * HZ);
}static void xlr_stats(struct net_device *ndev, struct rtnl_link_stats64 *stats)
{
struct xlr_net_priv *priv = netdev_priv(ndev);
xlr_poll_stats(priv);
...
}static int xlr_net_probe(struct platform_device *pdev)
{
...
spin_lock_init(&priv->stats.lock);
setup_timer(&priv->stats.timer, xlr_poll_stats_timer, priv);
...
}Plus add_timer() and del_timer_sync() when starting/stopping the interface. Also you need to clear the software stats if you have to reset the hardware. All of which is a fair amount of work but you can't avoid it if the hardware counters just aren't wide enough.
Ben.
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
David Miller
maintainerFrom: [email protected]
Date: Tue, 5 Feb 2013 17:00:19 +0530
drivers/net/ethernet/netlogic/Kconfig line 8
Quoted 8 lines
drivers/net/ethernet/netlogic/Kconfig new file +8
-0+config NETLOGIC_XLR_NET + tristate "Netlogic XLR/XLS network device" + default y + select PHYLIB + depends on CPU_XLR + ---help--- + This driver support Netlogic XLR/XLS on chip gigabit + Ethernet.
No individual device driver should default to 'y'. Vendor guards, yes, can
default to 'y', but not individual drivers.
Quoted 5 lines
+/*
+ * The readl/writel implementation byteswaps on XLR/XLS, so
+ * we need to use__raw_IO to read the NAE registers
+ * because they are in the big-endian MMIO area on the SoC.
+ */
Comments in the networking are to be formatted:
/* Like * this. */
Please fix this up in your entire driver.
drivers/net/ethernet/netlogic/xlr_net.c line 82
Quoted 7 lines
drivers/net/ethernet/netlogic/xlr_net.c new file +7
-0+/* +* Table of net_device pointers indexed by port, this will be used to +* lookup the net_device corresponding to a port by the message ring handler. +* +* Maximum ports in XLR/XLS is 8(8 GMAC on XLS, 4 GMAC + 2 XGMAC on XLR) +*/ +static struct net_device *mac_to_ndev[8 ];
Make this a dynamic data structure, a parent device that the individual netdevs are hung off of, it can still be an array. That way you can have a bonafide struct device instance and associated hierarchy of devices in the kernel device list.
Also avoid this strange and non-standard usage of "MAC" as an integer port index. The canonical meaning of MAC is the link-layer address of the device.
drivers/net/ethernet/netlogic/xlr_net.c line 94
Quoted 12 lines
drivers/net/ethernet/netlogic/xlr_net.c new file +12
-0+ +static inline struct sk_buff *mac_get_skb_back_ptr (void *addr) +{ +struct sk_buff **back_ptr; + +/* this function should be used only for newly allocated packets. +* It assumes the first cacheline is for the back pointer related +* book keeping info. +*/ + back_ptr = (struct sk_buff **)(addr -MAC_SKB_BACK_PTR_SIZE ); +return *back_ptr; +}
Use the skb->cb[] control block rather than mis-using the skb data area for storing internal driver state.
drivers/net/ethernet/netlogic/xlr_net.c line 114
Quoted 1 line
drivers/net/ethernet/netlogic/xlr_net.c new file +1
-0+ paddr =virt_to_bus (addr);
virt_to_bus() is verboten, use the proper DMA APIs. I don't care if this is a specialized driver for a special platform.
drivers/net/ethernet/netlogic/xlr_net.c line 157
Quoted 1 line
drivers/net/ethernet/netlogic/xlr_net.c new file +1
-0+ addr =bus_to_virt (msg->msg0 &0xffffffffffULL );
bus_to_virt() is verbotten, use the proper DMA APIs and store correct references to packets in a translation data structure in your per-netdev software state.
Quoted 1 line
+static void
__maybe_unusedxlr_wakeup_queue(unsigned long dev)
This is really unused, just delete it.
That's enough for me, this driver needs a lot of work.