Skip to contentSkip to conversation

Amiga XSurf100 patch series, to be submitted to linux-net

PATCH In review Michael Schmitz 3 participants 17 messages Nov 16, 2015 – Nov 18, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Amiga XSurf100 patch series, to be submitted to linux-net

Geert,

just as a heads-up, I've been working on getting this series ready for submission to -net. The first six patches will need to be taken through -net, the last two are m68k specific and might be equally well placed in arch/m68k/amiga for preference.

Patch 6 and 8 are optional - the interrupts are handled just fine inside ei_interrupt if generated by other users of IRQ_AMIGA_PORTS.

If you know of some other hardware currently using IRQ_AMIGA_PORTS that cannot handle shared interupts, give me a shout and I'll look into handling this through a new interrupt controller for IRQ_AMIGA_PORTS.

There's a typo in #7 that gets fixed in #8, will be cleaned up before submission.

Any other badness, just let me know what you'd like to see handled differently.

Cheers,

Michael

#1 lore raw

PATCH 1/8 aX88796: Fix MAC address reading

From: Michael Karcher <[email protected]>

To read the MAC address from the (virtual) SAprom. the remote DMA unit needs to be set up like for every other process access to card-local memory.

---
 drivers/net/ethernet/8390/ax88796.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
drivers/net/ethernet/8390/ax88796.c +6 -0
index 0443654..7963e1d 100644
@@ -709,10 +709,16 @@ static int ax_init_dev(struct net_device *dev)
 	if (ax->plat->flags & AXFLG_HAS_EEPROM) {
 		unsigned char SA_prom[32];
 
+		ei_outb(6, ioaddr + EN0_RCNTLO);
+		ei_outb(0, ioaddr + EN0_RCNTHI);
+		ei_outb(0, ioaddr + EN0_RSARLO);
+		ei_outb(0, ioaddr + EN0_RSARHI);
+		ei_outb(E8390_RREAD+E8390_START, ioaddr + NE_CMD);
 		for (i = 0; i < sizeof(SA_prom); i += 2) {
 			SA_prom[i] = ei_inb(ioaddr + NE_DATAPORT);
 			SA_prom[i + 1] = ei_inb(ioaddr + NE_DATAPORT);
 		}
+		ei_outb(ENISR_RDC, ioaddr + EN0_ISR);	/* Ack intr. */
 
 		if (ax->plat->wordlength == 2)
 			for (i = 0; i < 16; i++)
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH 2/8 ax88796: Attach MII bus only when open

In reply to Michael Schmitz

From: Michael Karcher <[email protected]>

This is needed to be able to unload the module, as the module is busy while the MII bus is attached.

---
 drivers/net/ethernet/8390/ax88796.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
drivers/net/ethernet/8390/ax88796.c +10 -4
index 7963e1d..f76753b 100644
@@ -79,6 +79,8 @@ static unsigned char version[] = "ax88796.c: Copyright 2005,2007 Simtec Electron
 
 static u32 ax_msg_enable;
 
+static int ax_mii_init(struct net_device *dev);
+
 /* device private data */
 
 struct ax_device {
@@ -399,6 +401,10 @@ static int ax_open(struct net_device *dev)
 
 	netdev_dbg(dev, "open\n");
 
+	ret = ax_mii_init(dev);
+	if (ret)
+		goto failed_request_irq;
+
 	ret = request_irq(dev->irq, ax_ei_interrupt, ax->irqflags,
 			  dev->name, dev);
 	if (ret)
@@ -445,6 +451,10 @@ static int ax_close(struct net_device *dev)
 	phy_disconnect(ax->phy_dev);
 
 	free_irq(dev->irq, dev);
+
+	mdiobus_unregister(ax->mii_bus);
+	kfree(ax->mii_bus->irq);
+	free_mdio_bitbang(ax->mii_bus);
 	return 0;
 }
 
@@ -790,10 +800,6 @@ static int ax_init_dev(struct net_device *dev)
 	dev->netdev_ops = &ax_netdev_ops;
 	dev->ethtool_ops = &ax_ethtool_ops;
 
-	ret = ax_mii_init(dev);
-	if (ret)
-		goto out_irq;
-
 	ax_NS8390_init(dev, 0);
 
 	ret = register_netdev(dev);
Signature · 1 line
1.7.0.4
#3 lore raw

PATCH 3/8 ax88796: Move mii support functions upwards to prevent need of forward declaration

In reply to Michael Schmitz

From: Michael Karcher <[email protected]>

This commit contains nothing but moving of code lines inside ax88796.c

---
 drivers/net/ethernet/8390/ax88796.c |  192 +++++++++++++++++------------------
 1 files changed, 95 insertions(+), 97 deletions(-)
drivers/net/ethernet/8390/ax88796.c +95 -97
index f76753b..544f3ba 100644
@@ -79,8 +79,6 @@ static unsigned char version[] = "ax88796.c: Copyright 2005,2007 Simtec Electron
 
 static u32 ax_msg_enable;
 
-static int ax_mii_init(struct net_device *dev);
-
 /* device private data */
 
 struct ax_device {
@@ -319,6 +317,101 @@ static void ax_block_output(struct net_device *dev, int count,
 #define AX_MEMR_EEO		BIT(6)
 #define AX_MEMR_EECLK		BIT(7)
 
+static void ax_bb_mdc(struct mdiobb_ctrl *ctrl, int level)
+{
+	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
+
+	if (level)
+		ax->reg_memr |= AX_MEMR_MDC;
+	else
+		ax->reg_memr &= ~AX_MEMR_MDC;
+
+	ei_outb(ax->reg_memr, ax->addr_memr);
+}
+
+static void ax_bb_dir(struct mdiobb_ctrl *ctrl, int output)
+{
+	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
+
+	if (output)
+		ax->reg_memr &= ~AX_MEMR_MDIR;
+	else
+		ax->reg_memr |= AX_MEMR_MDIR;
+
+	ei_outb(ax->reg_memr, ax->addr_memr);
+}
+
+static void ax_bb_set_data(struct mdiobb_ctrl *ctrl, int value)
+{
+	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
+
+	if (value)
+		ax->reg_memr |= AX_MEMR_MDO;
+	else
+		ax->reg_memr &= ~AX_MEMR_MDO;
+
+	ei_outb(ax->reg_memr, ax->addr_memr);
+}
+
+static int ax_bb_get_data(struct mdiobb_ctrl *ctrl)
+{
+	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
+	int reg_memr = ei_inb(ax->addr_memr);
+
+	return reg_memr & AX_MEMR_MDI ? 1 : 0;
+}
+
+static struct mdiobb_ops bb_ops = {
+	.owner = THIS_MODULE,
+	.set_mdc = ax_bb_mdc,
+	.set_mdio_dir = ax_bb_dir,
+	.set_mdio_data = ax_bb_set_data,
+	.get_mdio_data = ax_bb_get_data,
+};
+
+static int ax_mii_init(struct net_device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev->dev.parent);
+	struct ei_device *ei_local = netdev_priv(dev);
+	struct ax_device *ax = to_ax_dev(dev);
+	int err, i;
+
+	ax->bb_ctrl.ops = &bb_ops;
+	ax->addr_memr = ei_local->mem + AX_MEMR;
+	ax->mii_bus = alloc_mdio_bitbang(&ax->bb_ctrl);
+	if (!ax->mii_bus) {
+		err = -ENOMEM;
+		goto out;
+	}
+
+	ax->mii_bus->name = "ax88796_mii_bus";
+	ax->mii_bus->parent = dev->dev.parent;
+	snprintf(ax->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
+		pdev->name, pdev->id);
+
+	ax->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
+	if (!ax->mii_bus->irq) {
+		err = -ENOMEM;
+		goto out_free_mdio_bitbang;
+	}
+
+	for (i = 0; i < PHY_MAX_ADDR; i++)
+		ax->mii_bus->irq[i] = PHY_POLL;
+
+	err = mdiobus_register(ax->mii_bus);
+	if (err)
+		goto out_free_irq;
+
+	return 0;
+
+ out_free_irq:
+	kfree(ax->mii_bus->irq);
+ out_free_mdio_bitbang:
+	free_mdio_bitbang(ax->mii_bus);
+ out:
+	return err;
+}
+
 static void ax_handle_link_change(struct net_device *dev)
 {
 	struct ax_device  *ax = to_ax_dev(dev);
@@ -578,103 +671,8 @@ static const struct net_device_ops ax_netdev_ops = {
 #endif
 };
 
-static void ax_bb_mdc(struct mdiobb_ctrl *ctrl, int level)
-{
-	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
-
-	if (level)
-		ax->reg_memr |= AX_MEMR_MDC;
-	else
-		ax->reg_memr &= ~AX_MEMR_MDC;
-
-	ei_outb(ax->reg_memr, ax->addr_memr);
-}
-
-static void ax_bb_dir(struct mdiobb_ctrl *ctrl, int output)
-{
-	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
-
-	if (output)
-		ax->reg_memr &= ~AX_MEMR_MDIR;
-	else
-		ax->reg_memr |= AX_MEMR_MDIR;
-
-	ei_outb(ax->reg_memr, ax->addr_memr);
-}
-
-static void ax_bb_set_data(struct mdiobb_ctrl *ctrl, int value)
-{
-	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
-
-	if (value)
-		ax->reg_memr |= AX_MEMR_MDO;
-	else
-		ax->reg_memr &= ~AX_MEMR_MDO;
-
-	ei_outb(ax->reg_memr, ax->addr_memr);
-}
-
-static int ax_bb_get_data(struct mdiobb_ctrl *ctrl)
-{
-	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
-	int reg_memr = ei_inb(ax->addr_memr);
-
-	return reg_memr & AX_MEMR_MDI ? 1 : 0;
-}
-
-static struct mdiobb_ops bb_ops = {
-	.owner = THIS_MODULE,
-	.set_mdc = ax_bb_mdc,
-	.set_mdio_dir = ax_bb_dir,
-	.set_mdio_data = ax_bb_set_data,
-	.get_mdio_data = ax_bb_get_data,
-};
-
 /* setup code */
 
-static int ax_mii_init(struct net_device *dev)
-{
-	struct platform_device *pdev = to_platform_device(dev->dev.parent);
-	struct ei_device *ei_local = netdev_priv(dev);
-	struct ax_device *ax = to_ax_dev(dev);
-	int err, i;
-
-	ax->bb_ctrl.ops = &bb_ops;
-	ax->addr_memr = ei_local->mem + AX_MEMR;
-	ax->mii_bus = alloc_mdio_bitbang(&ax->bb_ctrl);
-	if (!ax->mii_bus) {
-		err = -ENOMEM;
-		goto out;
-	}
-
-	ax->mii_bus->name = "ax88796_mii_bus";
-	ax->mii_bus->parent = dev->dev.parent;
-	snprintf(ax->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
-		pdev->name, pdev->id);
-
-	ax->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
-	if (!ax->mii_bus->irq) {
-		err = -ENOMEM;
-		goto out_free_mdio_bitbang;
-	}
-
-	for (i = 0; i < PHY_MAX_ADDR; i++)
-		ax->mii_bus->irq[i] = PHY_POLL;
-
-	err = mdiobus_register(ax->mii_bus);
-	if (err)
-		goto out_free_irq;
-
-	return 0;
-
- out_free_irq:
-	kfree(ax->mii_bus->irq);
- out_free_mdio_bitbang:
-	free_mdio_bitbang(ax->mii_bus);
- out:
-	return err;
-}
-
 static void ax_initial_setup(struct net_device *dev, struct ei_device *ei_local)
 {
 	void __iomem *ioaddr = ei_local->mem;
Signature · 1 line
1.7.0.4
#4 lore raw

PATCH 4/8 ax88796: Do not free IRQ that did not get requested

In reply to Michael Schmitz

From: Michael Karcher <[email protected]>

The irq is request on netdev open time, so do not free it in probe if something fails.
Also do not free the irq in remove, as it got already freed in close

---
 drivers/net/ethernet/8390/ax88796.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
drivers/net/ethernet/8390/ax88796.c +1 -5
index 544f3ba..6472473 100644
@@ -802,7 +802,7 @@ static int ax_init_dev(struct net_device *dev)
 
 	ret = register_netdev(dev);
 	if (ret)
-		goto out_irq;
+		goto err_out;
 
 	netdev_info(dev, "%dbit, irq %d, %lx, MAC: %pM\n",
 		    ei_local->word16 ? 16 : 8, dev->irq, dev->base_addr,
@@ -810,9 +810,6 @@ static int ax_init_dev(struct net_device *dev)
 
 	return 0;
 
- out_irq:
-	/* cleanup irq */
-	free_irq(dev->irq, dev);
  err_out:
 	return ret;
 }
@@ -825,7 +822,6 @@ static int ax_remove(struct platform_device *pdev)
 	struct resource *mem;
 
 	unregister_netdev(dev);
-	free_irq(dev->irq, dev);
 
 	iounmap(ei_local->mem);
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Signature · 1 line
1.7.0.4
#5 lore raw

PATCH 5/8 ax88796: Add block_input/output hooks to ax_plat_data

In reply to Michael Schmitz

Add platform specific hooks for block transfer reads/writes of packet buffer data, superseding the default provided ax_block_input/output. Currently used for m68k Amiga XSurf100.

---
 drivers/net/ethernet/8390/ax88796.c |   10 ++++++++--
 include/net/ax88796.h               |    7 ++++++-
 2 files changed, 14 insertions(+), 3 deletions(-)
drivers/net/ethernet/8390/ax88796.c +8 -2
index 6472473..d45c032 100644
@@ -789,8 +789,14 @@ static int ax_init_dev(struct net_device *dev)
 #endif
 
 	ei_local->reset_8390 = &ax_reset_8390;
-	ei_local->block_input = &ax_block_input;
-	ei_local->block_output = &ax_block_output;
+	if (ax->plat->block_input)
+		ei_local->block_input = ax->plat->block_input;
+	else
+		ei_local->block_input = &ax_block_input;
+	if (ax->plat->block_output)
+		ei_local->block_output = ax->plat->block_output;
+	else
+		ei_local->block_output = &ax_block_output;
 	ei_local->get_8390_hdr = &ax_get_8390_hdr;
 	ei_local->priv = 0;
 	ei_local->msg_enable = ax_msg_enable;
include/net/ax88796.h +6 -1
index b9a3bec..28d6a93 100644
@@ -8,10 +8,11 @@
  * published by the Free Software Foundation.
  *
 */
-
 #ifndef __NET_AX88796_PLAT_H
 #define __NET_AX88796_PLAT_H
 
+struct net_device;
+
 #define AXFLG_HAS_EEPROM		(1<<0)
 #define AXFLG_MAC_FROMDEV		(1<<1)	/* device already has MAC */
 #define AXFLG_HAS_93CX6			(1<<2)	/* use eeprom_93cx6 driver */
@@ -26,6 +27,10 @@ struct ax_plat_data {
 	u32		*reg_offsets;	/* register offsets */
 	u8		*mac_addr;	/* MAC addr (only used when
 					   AXFLG_MAC_FROMPLATFORM is used */
+
+        /* uses default ax88796 buffer if set to NULL */
+	void (*block_output)(struct net_device *, int, const unsigned char *, int);
+	void (*block_input)(struct net_device *, int, struct sk_buff *, int);
 };
 
 #endif /* __NET_AX88796_PLAT_H */
Signature · 1 line
1.7.0.4
#6 lore raw

PATCH 6/8 ax88796: add interrupt status callback to platform data

In reply to Michael Schmitz

To be able to tell the ax88796 driver whether it is sensible to enter the 8390 interrupt handler, an "is this interrupt caused by the 88796" callback has been added to the ax_plat_data structure (with NULL being compatible to the previous behaviour).

---
 drivers/net/ethernet/8390/ax88796.c |   23 +++++++++++++++++++++--
 include/net/ax88796.h               |    4 ++++
 2 files changed, 25 insertions(+), 2 deletions(-)
drivers/net/ethernet/8390/ax88796.c +21 -2
index d45c032..020bcf7 100644
@@ -166,6 +166,21 @@ static void ax_reset_8390(struct net_device *dev)
 	ei_outb(ENISR_RESET, addr + EN0_ISR);	/* Ack intr. */
 }
 
+/*
+ * Wrapper for __ei_interrupt for platforms that have a platform-specific
+ * way to find out whether the interrupt request might be caused by
+ * the ax88796 chip.
+ */
+static irqreturn_t ax_ei_interrupt_filtered(int irq, void *dev_id)
+{
+	struct net_device *dev = dev_id;
+	struct ax_device *ax = to_ax_dev(dev);
+	struct platform_device *pdev = to_platform_device(dev->dev.parent);
+	if (!ax->plat->check_irq(pdev))
+		return IRQ_NONE;
+
+	return ax_ei_interrupt(irq, dev_id);
+}
 
 static void ax_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
 			    int ring_page)
@@ -498,8 +513,12 @@ static int ax_open(struct net_device *dev)
 	if (ret)
 		goto failed_request_irq;
 
-	ret = request_irq(dev->irq, ax_ei_interrupt, ax->irqflags,
-			  dev->name, dev);
+	if (ax->plat->check_irq)
+		ret = request_irq(dev->irq, ax_ei_interrupt_filtered,
+		                  ax->irqflags, dev->name, dev);
+	else
+		ret = request_irq(dev->irq, ax_ei_interrupt, ax->irqflags,
+				  dev->name, dev);
 	if (ret)
 		goto failed_request_irq;
 
include/net/ax88796.h +4 -0
index 28d6a93..d5b24be 100644
@@ -12,6 +12,7 @@
 #define __NET_AX88796_PLAT_H
 
 struct net_device;
+struct platform_device;
 
 #define AXFLG_HAS_EEPROM		(1<<0)
 #define AXFLG_MAC_FROMDEV		(1<<1)	/* device already has MAC */
@@ -31,6 +32,9 @@ struct ax_plat_data {
         /* uses default ax88796 buffer if set to NULL */
 	void (*block_output)(struct net_device *, int, const unsigned char *, int);
 	void (*block_input)(struct net_device *, int, struct sk_buff *, int);
+	/* returns nonzero if a pending interrupt request might by caused by
+	   the ax88786. Handles all interrupts if set to NULL */
+	int (*check_irq)(struct platform_device *);
 };
 
 #endif /* __NET_AX88796_PLAT_H */
Signature · 1 line
1.7.0.4
#7 lore raw

PATCH 7/8 ax88796: Add X-Surf 100 zorro driver providing an ax88796 platform device

In reply to Michael Schmitz

Add platform device driver to populate the ax88796 platform data from information provided by the XSurf100 zorro device driver. This driver will have to be loaded before loading the ax88796 module, or compiled as built-in.

---
 drivers/net/ethernet/8390/Kconfig    |   10 ++++-
 drivers/net/ethernet/8390/Makefile   |    1 +
 drivers/net/ethernet/8390/xsurf100.c |   71 ++++++++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+), 1 deletions(-)
 create mode 100644 drivers/net/ethernet/8390/xsurf100.c
drivers/net/ethernet/8390/Kconfig +9 -1
index edf7225..2cb6a32 100644
@@ -30,7 +30,7 @@ config PCMCIA_AXNET
 
 config AX88796
 	tristate "ASIX AX88796 NE2000 clone support"
-	depends on (ARM || MIPS || SUPERH)
+	depends on (ARM || MIPS || SUPERH || AMIGA)
 	select CRC32
 	select PHYLIB
 	select MDIO_BITBANG
@@ -45,6 +45,14 @@ config AX88796_93CX6
 	---help---
 	  Select this if your platform comes with an external 93CX6 eeprom.
 
+config XSURF100
+	tristate "XSurf 100 support"
+	depends on ZORRO
+	depends on AX88796
+	---help---
+	  This driver is for the Individual Computers X-Surf 100 Ethernet
+          card. If you have such a card, say Y. Otherwise, say N.
+
 config HYDRA
 	tristate "Hydra support"
 	depends on ZORRO
drivers/net/ethernet/8390/Makefile +1 -0
index ff3b318..c2dab5c 100644
@@ -15,4 +15,5 @@ obj-$(CONFIG_PCMCIA_PCNET) += pcnet_cs.o 8390.o
 obj-$(CONFIG_STNIC) += stnic.o 8390.o
 obj-$(CONFIG_ULTRA) += smc-ultra.o 8390.o
 obj-$(CONFIG_WD80x3) += wd.o 8390.o
+obj-$(CONFIG_XSURF100) += xsurf100.o
 obj-$(CONFIG_ZORRO8390) += zorro8390.o 8390.o
drivers/net/ethernet/8390/xsurf100.c new file +71 -0

71 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#8 lore raw

Re: [PATCH 7/8] ax88796: Add X-Surf 100 zorro driver providing an ax88796 platform device

Hi Michael,

Quoted 23 lines · Michael Schmitz
drivers/net/ethernet/8390/xsurf100.c new file +19 -0
@@ -0,0 +1,71 @@
 
+static int xsurf100_probe(struct zorro_dev *zdev, const struct zorro_device_id *ent)
+{
+       struct platform_device *pdev;
+       struct ax_plat_data ax88796_data;
+       struct resource res[2] = {
+               DEFINE_RES_IRQ(IRQ_AMIGA_PORTS),
+               DEFINE_RES_IO(zdev->resource.start + XS1000_8390_BASE, 4 * 0x20)
+       };
+       int reg;
+       u32 reg_offsets[32];
+
+       for (reg = 0; reg < 0x20; reg++)
+               reg_offsets[reg] = 4;
+
+       ax88796_data.flags = AXFLG_HAS_EEPROM;
+       ax88796_data.wordlength = 2;
+       ax88796_data.dcr_val = 0x48;
+       ax88796_data.rcr_val = 0x40;
+       ax88796_data.reg_offsets = reg_offsets;

drivers/net/ethernet/8390/xsurf100.c line 40

Quoted 10 lines
drivers/net/ethernet/8390/xsurf100.c new file +10 -0
+
+       // TODO: xsurf100 specific accelerated data exchange
+
+       pdev = platform_device_register_resndata(
+               &zdev->dev, "ax88796", zdev->slotaddr,
+               res, 2,
+               &ax88796_data, sizeof ax88796_data);
+
+       // TODO: NULL check
+       zorro_set_drvdata(zdev, pdev);

This looks a bit strange to me: storing another platform device in the driver-specific data. But I guess it's valid ;-)

BTW, as most Zorro boards are made of one or more "discrete" devices (e.g. an IDE and Ethernet combo), but only one zorro_driver can bind to it, I started converting Zorro drivers to MFD drivers a few years ago. Unfortunately I still haven't finished that.
It would also make it simpler to embed a normal ax88796 platform device.

drivers/net/ethernet/8390/xsurf100.c line 53

Quoted 4 lines
drivers/net/ethernet/8390/xsurf100.c new file +3 -0
+       return 0;
+}
 
+static struct zorro_device_id xsurf100_zorro_tbl[] = {

const

drivers/net/ethernet/8390/xsurf100.c line 56

Quoted 3 lines
drivers/net/ethernet/8390/xsurf100.c new file +3 -0
+       { ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF100, },
+       { 0 }
+};

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#9 lore raw

Re: [PATCH 7/8] ax88796: Add X-Surf 100 zorro driver providing an ax88796 platform device

Hello Geert,

thanks for your comments!

Quoted 23 lines · Geert Uytterhoeven
Quoted 23 lines
drivers/net/ethernet/8390/xsurf100.c new file +23 -0
+static int xsurf100_probe(struct zorro_dev *zdev, const struct zorro_device_id *ent)
+{
+       struct platform_device *pdev;
+       struct ax_plat_data ax88796_data;
+       struct resource res[2] = {
+               DEFINE_RES_IRQ(IRQ_AMIGA_PORTS),
+               DEFINE_RES_IO(zdev->resource.start + XS1000_8390_BASE, 4 * 0x20)
+       };
+       int reg;
+       u32 reg_offsets[32];
+
+       for (reg = 0; reg < 0x20; reg++)
+               reg_offsets[reg] = 4;
+
+       ax88796_data.flags = AXFLG_HAS_EEPROM;
+       ax88796_data.wordlength = 2;
+       ax88796_data.dcr_val = 0x48;
+       ax88796_data.rcr_val = 0x40;
+       ax88796_data.reg_offsets = reg_offsets;
+
+       // TODO: xsurf100 specific accelerated data exchange
+
+       pdev = platform_device_register_resndata(
Quoted 8 lines

drivers/net/ethernet/8390/xsurf100.c line 40

Quoted 6 lines
drivers/net/ethernet/8390/xsurf100.c new file +6 -0
+               &zdev->dev, "ax88796", zdev->slotaddr,
+               res, 2,
+               &ax88796_data, sizeof ax88796_data);
+
+       // TODO: NULL check
+       zorro_set_drvdata(zdev, pdev);

This looks a bit strange to me: storing another platform device in the driver-specific data. But I guess it's valid ;-)

We get a zorro device from the amiga subsystem for each XSurf 100 board installed in the machine. I want to bind the platform driver ax88796 to a subrange of the address space of the XSurf 100. To get the platform driver bound, I think I need to create a platform device (for each XSurf 100 Zorro device, so I can't have a static platform device allocated in the Zorro driver). If I dynamically create a platform device, I have to save the pointer somewhere, so I can remove the platform device when the module gets unloaded. For me, the obvious place to store the pointer is the driver-specific data of the Zorro device.
If you have a different suggestion on how to connect the ax88796 platform driver to a Zorro device that looks less strange to you, I am happy to learn a different way.

Quoted 3 lines

BTW, as most Zorro boards are made of one or more "discrete" devices (e.g. an IDE and Ethernet combo), but only one zorro_driver can bind to it, I started converting Zorro drivers to MFD drivers a few years ago.

The mfd framework might in fact be the different way I should learn about. It feels a bit like the approach I used in xsurf100.c is reinventing the mfd stuff, but I still have to find good documentation on how to use the mfd framework. I didn't find anything in linux/Documentation, and the comments in linux/include/linux/mfd/core.h have a quite steep learning curve.

Quoted 2 lines

Unfortunately I still haven't finished that.
It would also make it simpler to embed a normal ax88796 platform device.

I don't see yet how your conversion of present Zorro drivers would help for this new xsurf100 driver. On the other hand, if you just meant to point out using a mfd driver instead of the "create platform devices by hand" approach, *like* you are using for other drivers, I got your point and you are likely right.

Quoted 2 lines
Quoted 1 line

+static struct zorro_device_id xsurf100_zorro_tbl[] = {

const

Of course. Thanks for pointing it out.

BTW: for me, the patch-set was trivially forward-ported by git rebasing to 4.4-rc1

Kind regards,
Michael Karcher

#10 lore raw

Re: [PATCH 7/8] ax88796: Add X-Surf 100 zorro driver providing an ax88796 platform device

Hi Michael,

Quoted 32 lines · Michael Karcher
Quoted 23 lines · Geert Uytterhoeven
Quoted 23 lines
drivers/net/ethernet/8390/xsurf100.c new file +23 -0
+static int xsurf100_probe(struct zorro_dev *zdev, const struct zorro_device_id *ent)
+{
+       struct platform_device *pdev;
+       struct ax_plat_data ax88796_data;
+       struct resource res[2] = {
+               DEFINE_RES_IRQ(IRQ_AMIGA_PORTS),
+               DEFINE_RES_IO(zdev->resource.start + XS1000_8390_BASE, 4 * 0x20)
+       };
+       int reg;
+       u32 reg_offsets[32];
+
+       for (reg = 0; reg < 0x20; reg++)
+               reg_offsets[reg] = 4;
+
+       ax88796_data.flags = AXFLG_HAS_EEPROM;
+       ax88796_data.wordlength = 2;
+       ax88796_data.dcr_val = 0x48;
+       ax88796_data.rcr_val = 0x40;
+       ax88796_data.reg_offsets = reg_offsets;
+
+       // TODO: xsurf100 specific accelerated data exchange
+
+       pdev = platform_device_register_resndata(
Quoted 8 lines

drivers/net/ethernet/8390/xsurf100.c line 40

Quoted 6 lines
drivers/net/ethernet/8390/xsurf100.c new file +6 -0
+               &zdev->dev, "ax88796", zdev->slotaddr,
+               res, 2,
+               &ax88796_data, sizeof ax88796_data);
+
+       // TODO: NULL check
+       zorro_set_drvdata(zdev, pdev);

This looks a bit strange to me: storing another platform device in the driver-specific data. But I guess it's valid ;-)

Quoted 12 lines

We get a zorro device from the amiga subsystem for each XSurf 100 board installed in the machine. I want to bind the platform driver ax88796 to a subrange of the address space of the XSurf 100. To get the platform driver bound, I think I need to create a platform device (for each XSurf 100 Zorro device, so I can't have a static platform device allocated in the Zorro driver). If I dynamically create a platform device, I have to save the pointer somewhere, so I can remove the platform device when the module gets unloaded. For me, the obvious place to store the pointer is the driver-specific data of the Zorro device.
If you have a different suggestion on how to connect the ax88796 platform driver to a Zorro device that looks less strange to you, I am happy to learn a different way.

Sure, I understand why you're doing it.

Quoted 9 lines
Quoted 3 lines

BTW, as most Zorro boards are made of one or more "discrete" devices (e.g. an IDE and Ethernet combo), but only one zorro_driver can bind to it, I started converting Zorro drivers to MFD drivers a few years ago.

The mfd framework might in fact be the different way I should learn about. It feels a bit like the approach I used in xsurf100.c is reinventing the mfd stuff, but I still have to find good documentation on how to use the mfd framework. I didn't find anything in linux/Documentation, and the comments in linux/include/linux/mfd/core.h have a quite steep learning curve.

Yeah, it looks quite complex ;-)

But in the end it's just about calling mfd_add_devices(), which will create the needed platform_device(s) for you from a list of mfd "cells".

Quoted 7 lines
Quoted 2 lines

Unfortunately I still haven't finished that.
It would also make it simpler to embed a normal ax88796 platform device.

I don't see yet how your conversion of present Zorro drivers would help for this new xsurf100 driver. On the other hand, if you just meant to point out using a mfd driver instead of the "create platform devices by hand" approach, *like* you are using for other drivers, I got your point and you are likely right.

Yes, that's what the MFD subsystem is about.

I've pushed my work-in-progress to
https://git.kernel.org/cgit/linux/kernel/git/geert/linux-m68k.git/log/?h=zorro-mfd

Please have a look at the various drivers/zorro/*-mfd.c files for inspiration. drivers/zorro/8390-cell.c is a dummy cell driver, which is basically a platform device driver. For X-Surf 100 that would be the existing ax88796 driver.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#11 lore raw

PATCH 8/8 ax88796: use interrupt status callback for XSurf100 driver

In reply to Michael Schmitz

Make use of the ax88796 platform data interupt status hook in the m68k Amiga XSurf100 driver. The XSurf100 interrupt is shared with other Amiga hardware interrupts so ei_interrupt would otherwise get called a lot without need.

---
 drivers/net/ethernet/8390/xsurf100.c |   42 +++++++++++++++++++++++++++------
 1 files changed, 34 insertions(+), 8 deletions(-)
drivers/net/ethernet/8390/xsurf100.c +34 -8
index 3c34b04..f1b1f62 100644
@@ -7,27 +7,49 @@
 
 #define ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF100 ZORRO_ID(INDIVIDUAL_COMPUTERS, 0x64, 0)
 
-#define XS1000_8390_BASE 0x800
+#define XS100_IRQSTATUS_BASE 0x40
+#define XS100_8390_BASE 0x800
+
+struct xsurf100_ax_plat_data {
+	struct ax_plat_data ax;
+	void *base_regs;
+};
+
+static int is_xsurf100_network_irq(struct platform_device *pdev)
+{
+	struct xsurf100_ax_plat_data *xs100 = dev_get_platdata(&pdev->dev);
+	return (readw(xs100->base_regs + XS100_IRQSTATUS_BASE) & 0xaaaa) != 0;
+}
 
 static int xsurf100_probe(struct zorro_dev *zdev, const struct zorro_device_id *ent)
 {
 	struct platform_device *pdev;
-	struct ax_plat_data ax88796_data;
+	struct xsurf100_ax_plat_data ax88796_data;
 	struct resource res[2] = {
 		DEFINE_RES_IRQ(IRQ_AMIGA_PORTS),
-		DEFINE_RES_IO(zdev->resource.start + XS1000_8390_BASE, 4 * 0x20)
+		DEFINE_RES_IO(zdev->resource.start + XS100_8390_BASE, 4 * 0x20)
 	};
 	int reg;
 	u32 reg_offsets[32];
 
+	if (!request_mem_region(zdev->resource.start, 0x100, zdev->name))
+	{
+		dev_err(&zdev->dev, "cannot reserve X-Surf 100 control registers\n");
+		return -ENXIO;
+	}
+
 	for (reg = 0; reg < 0x20; reg++)
 		reg_offsets[reg] = 4;
 
-	ax88796_data.flags = AXFLG_HAS_EEPROM;
-	ax88796_data.wordlength = 2;
-	ax88796_data.dcr_val = 0x48;
-	ax88796_data.rcr_val = 0x40;
-	ax88796_data.reg_offsets = reg_offsets;
+	memset(&ax88796_data, 0, sizeof ax88796_data);
+	ax88796_data.ax.flags = AXFLG_HAS_EEPROM;
+	ax88796_data.ax.wordlength = 2;
+	ax88796_data.ax.dcr_val = 0x48;
+	ax88796_data.ax.rcr_val = 0x40;
+	ax88796_data.ax.reg_offsets = reg_offsets;
+	ax88796_data.ax.check_irq = is_xsurf100_network_irq;
+	ax88796_data.base_regs = ioremap(zdev->resource.start, 0x100);
+
 
 	// TODO: xsurf100 specific accelerated data exchange
 
@@ -44,8 +66,12 @@ static int xsurf100_probe(struct zorro_dev *zdev, const struct zorro_device_id *
 static void xsurf100_remove(struct zorro_dev *zdev)
 {
 	struct platform_device *pdev;
+	struct xsurf100_ax_plat_data *xs100;
 
 	pdev = zorro_get_drvdata(zdev);
+	xs100 = dev_get_platdata(&pdev->dev);
+	iounmap(xs100->base_regs);
+	release_mem_region(zdev->resource.start, 0x100);
 
 	platform_device_unregister(pdev);
 }
Signature · 1 line
1.7.0.4
#12 lore raw
In reply to Michael Schmitz

Hi Michael,

Quoted 4 lines · Michael Schmitz

just as a heads-up, I've been working on getting this series ready for submission to -net. The first six patches will need to be taken through -net, the last two are m68k specific and might be equally well placed in arch/m68k/amiga for preference.

Please don't put drivers in arch/m68k/. drivers/net is fine for a pure-net driver.

Quoted 6 lines

Patch 6 and 8 are optional - the interrupts are handled just fine inside ei_interrupt if generated by other users of IRQ_AMIGA_PORTS.

If you know of some other hardware currently using IRQ_AMIGA_PORTS that cannot handle shared interupts, give me a shout and I'll look into handling this through a new interrupt controller for IRQ_AMIGA_PORTS.

All Amiga devices should handle shared interrupts.

Thanks a lot for your work!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#14 lore raw

Hi Michael,

Quoted 5 lines · Michael Karcher
Quoted 2 lines · Geert Uytterhoeven

Please don't put drivers in arch/m68k/. drivers/net is fine for a pure-net driver.

There is a USB daughterboard on the XSurf 100 card, so it will no longer be pure-net if that daughterboard is installed.

Then it will definitely benefit from the MFD subsystem!

MFD drivers are typically under drivers/mfd/, but if we go that way for generic Zorro drivers, I would store them under drivers/zorro/, if the MFD maintainer won't object.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#15 lore raw
In reply to Geert Uytterhoeven

Hi Geert,

Quoted 10 lines · Geert Uytterhoeven

Hi Michael,

Quoted 4 lines · Michael Schmitz

just as a heads-up, I've been working on getting this series ready for submission to -net. The first six patches will need to be taken through -net, the last two are m68k specific and might be equally well placed in arch/m68k/amiga for preference.

Please don't put drivers in arch/m68k/. drivers/net is fine for a pure-net driver.

OK, fine. arch/m68k/atai is where I had put the platform devices for the Atari network and USB drivers, but these don't require much more than a few register definitions.

Quoted 9 lines
Quoted 7 lines

Patch 6 and 8 are optional - the interrupts are handled just fine inside ei_interrupt if generated by other users of IRQ_AMIGA_PORTS.

If you know of some other hardware currently using IRQ_AMIGA_PORTS that cannot handle shared interupts, give me a shout and I'll look into handling this through a new interrupt controller for IRQ_AMIGA_PORTS.

All Amiga devices should handle shared interrupts.

Good - do you see any merit in using a platform defined interrrupt wrapper to 'protect' a driver interrupt from spurious calls?

Quoted 1 line

Thanks a lot for your work!

My pleasure, as always.

Cheers,

Michael

Quoted 11 lines

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#16 lore raw

Hi Michael,

Quoted 11 lines · Michael Schmitz
Quoted 8 lines
Quoted 6 lines

Patch 6 and 8 are optional - the interrupts are handled just fine inside ei_interrupt if generated by other users of IRQ_AMIGA_PORTS.

If you know of some other hardware currently using IRQ_AMIGA_PORTS that cannot handle shared interupts, give me a shout and I'll look into handling this through a new interrupt controller for IRQ_AMIGA_PORTS.

All Amiga devices should handle shared interrupts.

Good - do you see any merit in using a platform defined interrrupt wrapper to 'protect' a driver interrupt from spurious calls?

I can see its merit. I don't know if the ax88796 maintainer will like it.

All other 8390 drivers just use ei_interrupt(), even zorro8390.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds