Skip to contentSkip to conversation

net: add new ar231x-eth driver

PATCH Superseded Oleksij Rempel 2 participants 2 messages Apr 22, 2013 Network drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 net: add new ar231x-eth driver

From: Oleksij Rempel <[email protected]>

This driver should work with some Atheros WiSoCs:
- ar2312, ar2313
- ar2315, ar2316 ...

---
 drivers/net/Kconfig  |    7 +
 drivers/net/Makefile |    1 +
 drivers/net/ar231x.c |  402 ++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/ar231x.h |  243 ++++++++++++++++++++++++++++++
 4 files changed, 653 insertions(+)
 create mode 100644 drivers/net/ar231x.c
 create mode 100644 drivers/net/ar231x.h
drivers/net/Kconfig +7 -0
index 43d5984..be7888f 100644
@@ -27,6 +27,13 @@ menu "Network drivers"
 
 source "drivers/net/phy/Kconfig"
 
+config DRIVER_NET_AR231X
+	bool "AR231X Ethernet support"
+	depends on MACH_MIPS_AR531X
+	select PHYLIB
+	help
+	  Support for the AR231x/531x ethernet controller
+
 config DRIVER_NET_CS8900
 	bool "cs8900 ethernet driver"
 	depends on HAS_CS8900
drivers/net/Makefile +1 -0
index 4e6b49b..1563e4f 100644
@@ -1,3 +1,4 @@
+obj-$(CONFIG_DRIVER_NET_AR231X)		+= ar231x.o
 obj-$(CONFIG_DRIVER_NET_CS8900)		+= cs8900.o
 obj-$(CONFIG_DRIVER_NET_SMC911X)	+= smc911x.o
 obj-$(CONFIG_DRIVER_NET_SMC91111)	+= smc91111.o
drivers/net/ar231x.c new file +402 -0

402 lines not on this page · raw message

drivers/net/ar231x.h new file +243 -0

243 lines not on this page · raw message

Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

Hi Oleksij,

The driver looks generally ok, but unfortunately contains some things which require some work to fix.

drivers/net/ar231x.c line 48

Quoted 9 lines · Oleksij Rempel

From: Oleksij Rempel <[email protected]>

drivers/net/ar231x.c new file +8 -0
+static int ar231x_set_ethaddr(struct eth_device *edev, unsigned char *addr);
+static void ar231x_reset_regs(struct eth_device *edev)
+{
+	struct ar231x_eth_priv *priv = edev->priv;
+	struct ar231x_eth_platform_data *cfg = priv->cfg;
+	u32 flags;
+
+	debug("%s\n", __func__);

Inside drivers you should generally use dev_dbg and friends. I think these 'I entered a function' kind of debug functions are often not useful for other people, so you should consider removing them completely.

drivers/net/ar231x.c line 57

Quoted 9 lines
drivers/net/ar231x.c new file +9 -0
+
+	*priv->int_regs |= cfg->reset_mac;
+	mdelay(10);
+	*priv->int_regs &= ~cfg->reset_mac;
+	mdelay(10);
+	*priv->int_regs |= cfg->reset_phy;
+	mdelay(10);
+	*priv->int_regs &= ~cfg->reset_phy;
+	mdelay(10);

Please use writel to access registers.

drivers/net/ar231x.c line 277

Quoted 13 lines
drivers/net/ar231x.c new file +13 -0
+static int ar231x_set_ethaddr(struct eth_device *edev, unsigned char *addr)
+{
+	struct ar231x_eth_priv *priv = edev->priv;
+
+	debug("%s\n", __func__);
+
+	priv->eth_regs->mac_addr[0] =
+			(addr[5] <<  8) | (addr[4]);
+	priv->eth_regs->mac_addr[1] =
+			(addr[3] << 24) | (addr[2] << 16) |
+			(addr[1] <<  8) | addr[0];
+
+	mdelay(10);

Is this needed?

Quoted 19 lines
drivers/net/ar231x.c new file +19 -0
+static int ar231x_eth_probe(struct device_d *dev)
+{
+	struct ar231x_eth_priv *priv;
+	struct eth_device *edev;
+	struct mii_bus *miibus;
+	struct ar231x_eth_platform_data *pdata;
+
+	debug("%s\n", __func__);
+
+	if (!dev->platform_data) {
+		dev_err(dev, "no platform data\n");
+		return -ENODEV;
+	}
+
+	pdata = dev->platform_data;
+
+	priv = xzalloc(sizeof(struct ar231x_eth_priv));
+	edev = &priv->edev;
+	miibus = &priv->miibus;

drivers/net/ar231x.c line 348

Quoted 10 lines
drivers/net/ar231x.c new file +10 -0
+	edev->priv = priv;
+
+	/* link all platform depended regs */
+	priv->mac = pdata->mac;
+
+	if (!pdata->base_eth) {
+		dev_err(dev, "no eth base defined\n");
+		return -ENODEV;
+	}
+	priv->eth_regs = (ETHERNET_STRUCT *)pdata->base_eth;

Please register a resource for the device like the other drivers do.

drivers/net/ar231x.c line 400

Quoted 13 lines
drivers/net/ar231x.c new file +13 -0
+
+static struct driver_d ar231x_eth_driver = {
+        .name = "ar231x_eth",
+        .probe = ar231x_eth_probe,
+        .remove = ar231x_eth_remove,
+};
+
+static int ar231x_eth_driver_init(void)
+{
+	debug("%s\n", __func__);
+
+	platform_driver_register(&ar231x_eth_driver);
+	return 0;

return platform_driver_register();

drivers/net/ar231x.h line 26

Quoted 4 lines
drivers/net/ar231x.h new file +4 -0
+/*
+ * probe link timer - 5 secs
+ */
+#define LINK_TIMER    (5*HZ)

This is unused.

drivers/net/ar231x.h line 32

Quoted 6 lines
drivers/net/ar231x.h new file +6 -0
+
+#define IS_DMA_TX_INT(X)   (((X) & (DMA_STATUS_TI)) != 0)
+#define IS_DMA_RX_INT(X)   (((X) & (DMA_STATUS_RI)) != 0)
+#define IS_DRIVER_OWNED(X) (((X) & (DMA_TX_OWN))    == 0)
+
+#define AR2313_TX_TIMEOUT (HZ/4)

also unused.

drivers/net/ar231x.h line 100

Quoted 2 lines
drivers/net/ar231x.h new file +2 -0
+
+#define RCVPKT_LENGTH(X)	(X  >> 16)	/* Received pkt Length */

It's good practice to protect variables in macros with braces, so:

#define RCVPKT_LENGTH(X) ((X) >> 16)

Otherwise surprises may happen...

drivers/net/ar231x.h line 162

Quoted 6 lines
drivers/net/ar231x.h new file +6 -0
+typedef struct {
+	volatile u32 status;		/* OWN, Device control and status. */
+	volatile u32 devcs;			/* Packet control bitmap + Length. */
+	volatile u32 buffer_ptr;	/* Pointer to packet buffer. */
+	volatile u32 next_dsc_ptr;	/* Pointer to next descriptor in chain. */
+} ar231x_descr_t;

No typedef struct please. Use the struct type directly. Also remove the volatile in favor of proper register accessors.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox