Commit bda73d4e authored by David S. Miller's avatar David S. Miller

Merge branch 'Amiga-xsurf100'

Michael Schmitz says:

====================
New network driver for Amiga X-Surf 100 (m68k)

[This is a resend of my v3 series which was based on the wrong version and
tree. Only substantial change is to Asix AX99796B PHY driver.]

This patch series adds support for the Individual Computers X-Surf 100
network card for m68k Amiga, a network adapter based on the AX88796 chip set.

The driver was originally written for kernel version 3.19 by Michael Karcher
(see CC:), and adapted to 4.16+ for submission to netdev by me. Questions
regarding motivation for some of the changes are probably best directed at
Michael Karcher.

The driver has been tested by Adrian <glaubitz@physik.fu-berlin.de> who will
send his Tested-by tag separately.

A few changes to the ax88796 driver were required:
- to read the MAC address, some setup of the ax99796 chip must be done,
- attach to the MII bus only on device open to allow module unloading,
- allow to supersede ax_block_input/ax_block_output by card-specific
  optimized code,
- use an optional interrupt status callback to allow easier sharing of the
  card interrupt,
- set IRQF_SHARED if platform IRQ resource is marked shareable

The Asix Electronix PHY used on the X-Surf 100 is buggy, and causes the
software reset to hang if the previous command sent to the PHY was also
a soft reset. This bug requires addition of a PHY driver for Asix PHYs
to provide a fixed .soft_reset function, included in this series.

Some additional cleanup:
- do not attempt to free IRQ in ax_remove (complements 82533ad9),
- clear platform drvdata on probe fail and module remove.

Changes since v1:

Raised in review by Andrew Lunn:
- move MII code around to avoid need for forward declaration,
- combine patches 2 and 7 to add cleanup in error path

Changes since v2:

- corrected authorship attribution to Michael Karcher

Suggested by Geert Uytterhoeven:
- use ei_local->reset_8390() instead of duplicating ax_reset_8390(),
- use %pR to format struct resource pointers,
- assign pdev and xs100 pointers in declaration,
- don't split error messages,
- change Kconfig logic to only require XSURF100 set on Amiga

Suggested by Andrew Lunn:
- add COMPILE_TEST to ax88796 Kconfig options,
- use new Asix PHY driver for X-Surf 100

Suggested by Andrew Lunn/Finn Thain:
- declare struct sk_buff in ax88796.h,
- correct whitespace error in ax88796.h

Changes since v3:

- various checkpatch cleanup

Andrew Lunn:
- don't duplicate genphy_soft_reset in Asix PHY driver, just call
  genphy_soft_reset after writing zero to control register
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 32e43779 861928f4
...@@ -29,8 +29,8 @@ config PCMCIA_AXNET ...@@ -29,8 +29,8 @@ config PCMCIA_AXNET
called axnet_cs. If unsure, say N. called axnet_cs. If unsure, say N.
config AX88796 config AX88796
tristate "ASIX AX88796 NE2000 clone support" tristate "ASIX AX88796 NE2000 clone support" if !ZORRO
depends on (ARM || MIPS || SUPERH) depends on (ARM || MIPS || SUPERH || ZORRO || COMPILE_TEST)
select CRC32 select CRC32
select PHYLIB select PHYLIB
select MDIO_BITBANG select MDIO_BITBANG
...@@ -45,6 +45,19 @@ config AX88796_93CX6 ...@@ -45,6 +45,19 @@ config AX88796_93CX6
---help--- ---help---
Select this if your platform comes with an external 93CX6 eeprom. Select this if your platform comes with an external 93CX6 eeprom.
config XSURF100
tristate "Amiga XSurf 100 AX88796/NE2000 clone support"
depends on ZORRO
select AX88796
select ASIX_PHY
help
This driver is for the Individual Computers X-Surf 100 Ethernet
card (based on the Asix AX88796 chip). If you have such a card,
say Y. Otherwise, say N.
To compile this driver as a module, choose M here: the module
will be called xsurf100.
config HYDRA config HYDRA
tristate "Hydra support" tristate "Hydra support"
depends on ZORRO depends on ZORRO
......
...@@ -16,4 +16,5 @@ obj-$(CONFIG_PCMCIA_PCNET) += pcnet_cs.o 8390.o ...@@ -16,4 +16,5 @@ obj-$(CONFIG_PCMCIA_PCNET) += pcnet_cs.o 8390.o
obj-$(CONFIG_STNIC) += stnic.o 8390.o obj-$(CONFIG_STNIC) += stnic.o 8390.o
obj-$(CONFIG_ULTRA) += smc-ultra.o 8390.o obj-$(CONFIG_ULTRA) += smc-ultra.o 8390.o
obj-$(CONFIG_WD80x3) += wd.o 8390.o obj-$(CONFIG_WD80x3) += wd.o 8390.o
obj-$(CONFIG_XSURF100) += xsurf100.o
obj-$(CONFIG_ZORRO8390) += zorro8390.o obj-$(CONFIG_ZORRO8390) += zorro8390.o
...@@ -163,6 +163,21 @@ static void ax_reset_8390(struct net_device *dev) ...@@ -163,6 +163,21 @@ static void ax_reset_8390(struct net_device *dev)
ei_outb(ENISR_RESET, addr + EN0_ISR); /* Ack intr. */ 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, static void ax_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
int ring_page) int ring_page)
...@@ -387,6 +402,90 @@ static void ax_phy_switch(struct net_device *dev, int on) ...@@ -387,6 +402,90 @@ static void ax_phy_switch(struct net_device *dev, int on)
ei_outb(reg_gpoc, ei_local->mem + EI_SHIFT(0x17)); ei_outb(reg_gpoc, ei_local->mem + EI_SHIFT(0x17));
} }
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 const 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;
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);
err = mdiobus_register(ax->mii_bus);
if (err)
goto out_free_mdio_bitbang;
return 0;
out_free_mdio_bitbang:
free_mdio_bitbang(ax->mii_bus);
out:
return err;
}
static int ax_open(struct net_device *dev) static int ax_open(struct net_device *dev)
{ {
struct ax_device *ax = to_ax_dev(dev); struct ax_device *ax = to_ax_dev(dev);
...@@ -394,8 +493,16 @@ static int ax_open(struct net_device *dev) ...@@ -394,8 +493,16 @@ static int ax_open(struct net_device *dev)
netdev_dbg(dev, "open\n"); netdev_dbg(dev, "open\n");
ret = request_irq(dev->irq, ax_ei_interrupt, ax->irqflags, ret = ax_mii_init(dev);
dev->name, dev); if (ret)
goto failed_mii;
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) if (ret)
goto failed_request_irq; goto failed_request_irq;
...@@ -421,6 +528,10 @@ static int ax_open(struct net_device *dev) ...@@ -421,6 +528,10 @@ static int ax_open(struct net_device *dev)
ax_phy_switch(dev, 0); ax_phy_switch(dev, 0);
free_irq(dev->irq, dev); free_irq(dev->irq, dev);
failed_request_irq: failed_request_irq:
/* unregister mdiobus */
mdiobus_unregister(ax->mii_bus);
free_mdio_bitbang(ax->mii_bus);
failed_mii:
return ret; return ret;
} }
...@@ -440,6 +551,9 @@ static int ax_close(struct net_device *dev) ...@@ -440,6 +551,9 @@ static int ax_close(struct net_device *dev)
phy_disconnect(dev->phydev); phy_disconnect(dev->phydev);
free_irq(dev->irq, dev); free_irq(dev->irq, dev);
mdiobus_unregister(ax->mii_bus);
free_mdio_bitbang(ax->mii_bus);
return 0; return 0;
} }
...@@ -539,92 +653,8 @@ static const struct net_device_ops ax_netdev_ops = { ...@@ -539,92 +653,8 @@ static const struct net_device_ops ax_netdev_ops = {
#endif #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 const 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 */ /* 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;
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);
err = mdiobus_register(ax->mii_bus);
if (err)
goto out_free_mdio_bitbang;
return 0;
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) static void ax_initial_setup(struct net_device *dev, struct ei_device *ei_local)
{ {
void __iomem *ioaddr = ei_local->mem; void __iomem *ioaddr = ei_local->mem;
...@@ -669,10 +699,16 @@ static int ax_init_dev(struct net_device *dev) ...@@ -669,10 +699,16 @@ static int ax_init_dev(struct net_device *dev)
if (ax->plat->flags & AXFLG_HAS_EEPROM) { if (ax->plat->flags & AXFLG_HAS_EEPROM) {
unsigned char SA_prom[32]; 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) { for (i = 0; i < sizeof(SA_prom); i += 2) {
SA_prom[i] = ei_inb(ioaddr + NE_DATAPORT); SA_prom[i] = ei_inb(ioaddr + NE_DATAPORT);
SA_prom[i + 1] = 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) if (ax->plat->wordlength == 2)
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
...@@ -741,18 +777,20 @@ static int ax_init_dev(struct net_device *dev) ...@@ -741,18 +777,20 @@ static int ax_init_dev(struct net_device *dev)
#endif #endif
ei_local->reset_8390 = &ax_reset_8390; ei_local->reset_8390 = &ax_reset_8390;
ei_local->block_input = &ax_block_input; if (ax->plat->block_input)
ei_local->block_output = &ax_block_output; 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->get_8390_hdr = &ax_get_8390_hdr;
ei_local->priv = 0; ei_local->priv = 0;
dev->netdev_ops = &ax_netdev_ops; dev->netdev_ops = &ax_netdev_ops;
dev->ethtool_ops = &ax_ethtool_ops; dev->ethtool_ops = &ax_ethtool_ops;
ret = ax_mii_init(dev);
if (ret)
goto err_out;
ax_NS8390_init(dev, 0); ax_NS8390_init(dev, 0);
ret = register_netdev(dev); ret = register_netdev(dev);
...@@ -777,7 +815,6 @@ static int ax_remove(struct platform_device *pdev) ...@@ -777,7 +815,6 @@ static int ax_remove(struct platform_device *pdev)
struct resource *mem; struct resource *mem;
unregister_netdev(dev); unregister_netdev(dev);
free_irq(dev->irq, dev);
iounmap(ei_local->mem); iounmap(ei_local->mem);
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
...@@ -789,6 +826,7 @@ static int ax_remove(struct platform_device *pdev) ...@@ -789,6 +826,7 @@ static int ax_remove(struct platform_device *pdev)
release_mem_region(mem->start, resource_size(mem)); release_mem_region(mem->start, resource_size(mem));
} }
platform_set_drvdata(pdev, NULL);
free_netdev(dev); free_netdev(dev);
return 0; return 0;
...@@ -835,6 +873,9 @@ static int ax_probe(struct platform_device *pdev) ...@@ -835,6 +873,9 @@ static int ax_probe(struct platform_device *pdev)
dev->irq = irq->start; dev->irq = irq->start;
ax->irqflags = irq->flags & IRQF_TRIGGER_MASK; ax->irqflags = irq->flags & IRQF_TRIGGER_MASK;
if (irq->flags & IORESOURCE_IRQ_SHAREABLE)
ax->irqflags |= IRQF_SHARED;
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!mem) { if (!mem) {
dev_err(&pdev->dev, "no MEM specified\n"); dev_err(&pdev->dev, "no MEM specified\n");
...@@ -919,6 +960,7 @@ static int ax_probe(struct platform_device *pdev) ...@@ -919,6 +960,7 @@ static int ax_probe(struct platform_device *pdev)
release_mem_region(mem->start, mem_size); release_mem_region(mem->start, mem_size);
exit_mem: exit_mem:
platform_set_drvdata(pdev, NULL);
free_netdev(dev); free_netdev(dev);
return ret; return ret;
......
This diff is collapsed.
...@@ -218,6 +218,12 @@ config AQUANTIA_PHY ...@@ -218,6 +218,12 @@ config AQUANTIA_PHY
---help--- ---help---
Currently supports the Aquantia AQ1202, AQ2104, AQR105, AQR405 Currently supports the Aquantia AQ1202, AQ2104, AQR105, AQR405
config ASIX_PHY
tristate "Asix PHYs"
help
Currently supports the Asix Electronics PHY found in the X-Surf 100
AX88796B package.
config AT803X_PHY config AT803X_PHY
tristate "AT803X PHYs" tristate "AT803X PHYs"
---help--- ---help---
......
...@@ -45,6 +45,7 @@ obj-y += $(sfp-obj-y) $(sfp-obj-m) ...@@ -45,6 +45,7 @@ obj-y += $(sfp-obj-y) $(sfp-obj-m)
obj-$(CONFIG_AMD_PHY) += amd.o obj-$(CONFIG_AMD_PHY) += amd.o
obj-$(CONFIG_AQUANTIA_PHY) += aquantia.o obj-$(CONFIG_AQUANTIA_PHY) += aquantia.o
obj-$(CONFIG_ASIX_PHY) += asix.o
obj-$(CONFIG_AT803X_PHY) += at803x.o obj-$(CONFIG_AT803X_PHY) += at803x.o
obj-$(CONFIG_BCM63XX_PHY) += bcm63xx.o obj-$(CONFIG_BCM63XX_PHY) += bcm63xx.o
obj-$(CONFIG_BCM7XXX_PHY) += bcm7xxx.o obj-$(CONFIG_BCM7XXX_PHY) += bcm7xxx.o
......
// SPDX-License-Identifier: GPL-2.0
/* Driver for Asix PHYs
*
* Author: Michael Schmitz <schmitzmic@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
*/
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/mii.h>
#include <linux/phy.h>
#define PHY_ID_ASIX_AX88796B 0x003b1841
MODULE_DESCRIPTION("Asix PHY driver");
MODULE_AUTHOR("Michael Schmitz <schmitzmic@gmail.com>");
MODULE_LICENSE("GPL");
/**
* asix_soft_reset - software reset the PHY via BMCR_RESET bit
* @phydev: target phy_device struct
*
* Description: Perform a software PHY reset using the standard
* BMCR_RESET bit and poll for the reset bit to be cleared.
* Toggle BMCR_RESET bit off to accommodate broken AX8796B PHY implementation
* such as used on the Individual Computers' X-Surf 100 Zorro card.
*
* Returns: 0 on success, < 0 on failure
*/
static int asix_soft_reset(struct phy_device *phydev)
{
int ret;
/* Asix PHY won't reset unless reset bit toggles */
ret = phy_write(phydev, MII_BMCR, 0);
if (ret < 0)
return ret;
return genphy_soft_reset(phydev);
}
static struct phy_driver asix_driver[] = { {
.phy_id = PHY_ID_ASIX_AX88796B,
.name = "Asix Electronics AX88796B",
.phy_id_mask = 0xfffffff0,
.features = PHY_BASIC_FEATURES,
.soft_reset = asix_soft_reset,
} };
module_phy_driver(asix_driver);
static struct mdio_device_id __maybe_unused asix_tbl[] = {
{ PHY_ID_ASIX_AX88796B, 0xfffffff0 },
{ }
};
MODULE_DEVICE_TABLE(mdio, asix_tbl);
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
#ifndef __NET_AX88796_PLAT_H #ifndef __NET_AX88796_PLAT_H
#define __NET_AX88796_PLAT_H #define __NET_AX88796_PLAT_H
struct sk_buff;
struct net_device;
struct platform_device;
#define AXFLG_HAS_EEPROM (1<<0) #define AXFLG_HAS_EEPROM (1<<0)
#define AXFLG_MAC_FROMDEV (1<<1) /* device already has MAC */ #define AXFLG_MAC_FROMDEV (1<<1) /* device already has MAC */
#define AXFLG_HAS_93CX6 (1<<2) /* use eeprom_93cx6 driver */ #define AXFLG_HAS_93CX6 (1<<2) /* use eeprom_93cx6 driver */
...@@ -26,6 +30,16 @@ struct ax_plat_data { ...@@ -26,6 +30,16 @@ struct ax_plat_data {
u32 *reg_offsets; /* register offsets */ u32 *reg_offsets; /* register offsets */
u8 *mac_addr; /* MAC addr (only used when u8 *mac_addr; /* MAC addr (only used when
AXFLG_MAC_FROMPLATFORM is used */ AXFLG_MAC_FROMPLATFORM is used */
/* uses default ax88796 buffer if set to NULL */
void (*block_output)(struct net_device *dev, int count,
const unsigned char *buf, int star_page);
void (*block_input)(struct net_device *dev, int count,
struct sk_buff *skb, int ring_offset);
/* 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 *pdev);
}; };
#endif /* __NET_AX88796_PLAT_H */ #endif /* __NET_AX88796_PLAT_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment