Skip to content

Commit

Permalink
net: ax88796c: ASIX AX88796C SPI Ethernet Adapter Driver
Browse files Browse the repository at this point in the history
ASIX AX88796[1] is a versatile ethernet adapter chip, that can be
connected to a CPU with a 8/16-bit bus or with an SPI. This driver
supports SPI connection.

The driver has been ported from the vendor kernel for ARTIK5[2]
boards. Several changes were made to adapt it to the current kernel
which include:

+ updated DT configuration,
+ clock configuration moved to DT,
+ new timer, ethtool and gpio APIs,
+ dev_* instead of pr_* and custom printk() wrappers,
+ removed awkward vendor power managemtn.
+ introduced ethtool tunable to control SPI compression

[1] https://www.asix.com.tw/products.php?op=pItemdetail&PItemID=104;65;86&PLine=65
[2] https://git.tizen.org/cgit/profile/common/platform/kernel/linux-3.10-artik/

The other ax88796 driver is for NE2000 compatible AX88796L chip. These
chips are not compatible. Hence, two separate drivers are required.

Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Łukasz Stelmach authored and Jakub Kicinski committed Oct 21, 2021
1 parent b13c7a8 commit a97c69b
Show file tree
Hide file tree
Showing 11 changed files with 2,229 additions and 0 deletions.
6 changes: 6 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -2899,6 +2899,12 @@ S: Maintained
F: Documentation/hwmon/asc7621.rst
F: drivers/hwmon/asc7621.c

ASIX AX88796C SPI ETHERNET ADAPTER
M: Łukasz Stelmach <l.stelmach@samsung.com>
S: Maintained
F: Documentation/devicetree/bindings/net/asix,ax88796c.yaml
F: drivers/net/ethernet/asix/ax88796c_*

ASPEED PINCTRL DRIVERS
M: Andrew Jeffery <andrew@aj.id.au>
L: linux-aspeed@lists.ozlabs.org (moderated for non-subscribers)
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ source "drivers/net/ethernet/apm/Kconfig"
source "drivers/net/ethernet/apple/Kconfig"
source "drivers/net/ethernet/aquantia/Kconfig"
source "drivers/net/ethernet/arc/Kconfig"
source "drivers/net/ethernet/asix/Kconfig"
source "drivers/net/ethernet/atheros/Kconfig"
source "drivers/net/ethernet/broadcom/Kconfig"
source "drivers/net/ethernet/brocade/Kconfig"
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ obj-$(CONFIG_NET_XGENE) += apm/
obj-$(CONFIG_NET_VENDOR_APPLE) += apple/
obj-$(CONFIG_NET_VENDOR_AQUANTIA) += aquantia/
obj-$(CONFIG_NET_VENDOR_ARC) += arc/
obj-$(CONFIG_NET_VENDOR_ASIX) += asix/
obj-$(CONFIG_NET_VENDOR_ATHEROS) += atheros/
obj-$(CONFIG_NET_VENDOR_CADENCE) += cadence/
obj-$(CONFIG_NET_VENDOR_BROADCOM) += broadcom/
Expand Down
35 changes: 35 additions & 0 deletions drivers/net/ethernet/asix/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Asix network device configuration
#

config NET_VENDOR_ASIX
bool "Asix devices"
default y
help
If you have a network (Ethernet, non-USB, not NE2000 compatible)
interface based on a chip from ASIX, say Y.

if NET_VENDOR_ASIX

config SPI_AX88796C
tristate "Asix AX88796C-SPI support"
select PHYLIB
depends on SPI
depends on GPIOLIB
help
Say Y here if you intend to use ASIX AX88796C attached in SPI mode.

config SPI_AX88796C_COMPRESSION
bool "SPI transfer compression"
default n
depends on SPI_AX88796C
help
Say Y here to enable SPI transfer compression. It saves up
to 24 dummy cycles during each transfer which may noticeably
speed up short transfers. This sets the default value that is
inherited by network interfaces during probe. It can be
changed at run time via spi-compression ethtool tunable.

If unsure say N.

endif # NET_VENDOR_ASIX
6 changes: 6 additions & 0 deletions drivers/net/ethernet/asix/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# Makefile for the Asix network device drivers.
#

obj-$(CONFIG_SPI_AX88796C) += ax88796c.o
ax88796c-y := ax88796c_main.o ax88796c_ioctl.o ax88796c_spi.o
239 changes: 239 additions & 0 deletions drivers/net/ethernet/asix/ax88796c_ioctl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2010 ASIX Electronics Corporation
* Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* ASIX AX88796C SPI Fast Ethernet Linux driver
*/

#define pr_fmt(fmt) "ax88796c: " fmt

#include <linux/bitmap.h>
#include <linux/iopoll.h>
#include <linux/phy.h>
#include <linux/netdevice.h>

#include "ax88796c_main.h"
#include "ax88796c_ioctl.h"

static const char ax88796c_priv_flag_names[][ETH_GSTRING_LEN] = {
"SPICompression",
};

static void
ax88796c_get_drvinfo(struct net_device *ndev, struct ethtool_drvinfo *info)
{
/* Inherit standard device info */
strncpy(info->driver, DRV_NAME, sizeof(info->driver));
}

static u32 ax88796c_get_msglevel(struct net_device *ndev)
{
struct ax88796c_device *ax_local = to_ax88796c_device(ndev);

return ax_local->msg_enable;
}

static void ax88796c_set_msglevel(struct net_device *ndev, u32 level)
{
struct ax88796c_device *ax_local = to_ax88796c_device(ndev);

ax_local->msg_enable = level;
}

static void
ax88796c_get_pauseparam(struct net_device *ndev, struct ethtool_pauseparam *pause)
{
struct ax88796c_device *ax_local = to_ax88796c_device(ndev);

pause->tx_pause = !!(ax_local->flowctrl & AX_FC_TX);
pause->rx_pause = !!(ax_local->flowctrl & AX_FC_RX);
pause->autoneg = (ax_local->flowctrl & AX_FC_ANEG) ?
AUTONEG_ENABLE :
AUTONEG_DISABLE;
}

static int
ax88796c_set_pauseparam(struct net_device *ndev, struct ethtool_pauseparam *pause)
{
struct ax88796c_device *ax_local = to_ax88796c_device(ndev);
int fc;

/* The following logic comes from phylink_ethtool_set_pauseparam() */
fc = pause->tx_pause ? AX_FC_TX : 0;
fc |= pause->rx_pause ? AX_FC_RX : 0;
fc |= pause->autoneg ? AX_FC_ANEG : 0;

ax_local->flowctrl = fc;

if (pause->autoneg) {
phy_set_asym_pause(ax_local->phydev, pause->tx_pause,
pause->rx_pause);
} else {
int maccr = 0;

phy_set_asym_pause(ax_local->phydev, 0, 0);
maccr |= (ax_local->flowctrl & AX_FC_RX) ? MACCR_RXFC_ENABLE : 0;
maccr |= (ax_local->flowctrl & AX_FC_TX) ? MACCR_TXFC_ENABLE : 0;

mutex_lock(&ax_local->spi_lock);

maccr |= AX_READ(&ax_local->ax_spi, P0_MACCR) &
~(MACCR_TXFC_ENABLE | MACCR_RXFC_ENABLE);
AX_WRITE(&ax_local->ax_spi, maccr, P0_MACCR);

mutex_unlock(&ax_local->spi_lock);
}

return 0;
}

static int ax88796c_get_regs_len(struct net_device *ndev)
{
return AX88796C_REGDUMP_LEN + AX88796C_PHY_REGDUMP_LEN;
}

static void
ax88796c_get_regs(struct net_device *ndev, struct ethtool_regs *regs, void *_p)
{
struct ax88796c_device *ax_local = to_ax88796c_device(ndev);
int offset, i;
u16 *p = _p;

memset(p, 0, ax88796c_get_regs_len(ndev));

mutex_lock(&ax_local->spi_lock);

for (offset = 0; offset < AX88796C_REGDUMP_LEN; offset += 2) {
if (!test_bit(offset / 2, ax88796c_no_regs_mask))
*p = AX_READ(&ax_local->ax_spi, offset);
p++;
}

mutex_unlock(&ax_local->spi_lock);

for (i = 0; i < AX88796C_PHY_REGDUMP_LEN / 2; i++) {
*p = phy_read(ax_local->phydev, i);
p++;
}
}

static void
ax88796c_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
{
switch (stringset) {
case ETH_SS_PRIV_FLAGS:
memcpy(data, ax88796c_priv_flag_names,
sizeof(ax88796c_priv_flag_names));
break;
}
}

static int
ax88796c_get_sset_count(struct net_device *ndev, int stringset)
{
int ret = 0;

switch (stringset) {
case ETH_SS_PRIV_FLAGS:
ret = ARRAY_SIZE(ax88796c_priv_flag_names);
break;
default:
ret = -EOPNOTSUPP;
}

return ret;
}

static int ax88796c_set_priv_flags(struct net_device *ndev, u32 flags)
{
struct ax88796c_device *ax_local = to_ax88796c_device(ndev);

if (flags & ~AX_PRIV_FLAGS_MASK)
return -EOPNOTSUPP;

if ((ax_local->priv_flags ^ flags) & AX_CAP_COMP)
if (netif_running(ndev))
return -EBUSY;

ax_local->priv_flags = flags;

return 0;
}

static u32 ax88796c_get_priv_flags(struct net_device *ndev)
{
struct ax88796c_device *ax_local = to_ax88796c_device(ndev);

return ax_local->priv_flags;
}

int ax88796c_mdio_read(struct mii_bus *mdiobus, int phy_id, int loc)
{
struct ax88796c_device *ax_local = mdiobus->priv;
int ret;

mutex_lock(&ax_local->spi_lock);
AX_WRITE(&ax_local->ax_spi, MDIOCR_RADDR(loc)
| MDIOCR_FADDR(phy_id) | MDIOCR_READ, P2_MDIOCR);

ret = read_poll_timeout(AX_READ, ret,
(ret != 0),
0, jiffies_to_usecs(HZ / 100), false,
&ax_local->ax_spi, P2_MDIOCR);
if (!ret)
ret = AX_READ(&ax_local->ax_spi, P2_MDIODR);

mutex_unlock(&ax_local->spi_lock);

return ret;
}

int
ax88796c_mdio_write(struct mii_bus *mdiobus, int phy_id, int loc, u16 val)
{
struct ax88796c_device *ax_local = mdiobus->priv;
int ret;

mutex_lock(&ax_local->spi_lock);
AX_WRITE(&ax_local->ax_spi, val, P2_MDIODR);

AX_WRITE(&ax_local->ax_spi,
MDIOCR_RADDR(loc) | MDIOCR_FADDR(phy_id)
| MDIOCR_WRITE, P2_MDIOCR);

ret = read_poll_timeout(AX_READ, ret,
((ret & MDIOCR_VALID) != 0), 0,
jiffies_to_usecs(HZ / 100), false,
&ax_local->ax_spi, P2_MDIOCR);
mutex_unlock(&ax_local->spi_lock);

return ret;
}

const struct ethtool_ops ax88796c_ethtool_ops = {
.get_drvinfo = ax88796c_get_drvinfo,
.get_link = ethtool_op_get_link,
.get_msglevel = ax88796c_get_msglevel,
.set_msglevel = ax88796c_set_msglevel,
.get_link_ksettings = phy_ethtool_get_link_ksettings,
.set_link_ksettings = phy_ethtool_set_link_ksettings,
.nway_reset = phy_ethtool_nway_reset,
.get_pauseparam = ax88796c_get_pauseparam,
.set_pauseparam = ax88796c_set_pauseparam,
.get_regs_len = ax88796c_get_regs_len,
.get_regs = ax88796c_get_regs,
.get_strings = ax88796c_get_strings,
.get_sset_count = ax88796c_get_sset_count,
.get_priv_flags = ax88796c_get_priv_flags,
.set_priv_flags = ax88796c_set_priv_flags,
};

int ax88796c_ioctl(struct net_device *ndev, struct ifreq *ifr, int cmd)
{
int ret;

ret = phy_mii_ioctl(ndev->phydev, ifr, cmd);

return ret;
}
26 changes: 26 additions & 0 deletions drivers/net/ethernet/asix/ax88796c_ioctl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2010 ASIX Electronics Corporation
* Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* ASIX AX88796C SPI Fast Ethernet Linux driver
*/

#ifndef _AX88796C_IOCTL_H
#define _AX88796C_IOCTL_H

#include <linux/ethtool.h>
#include <linux/netdevice.h>

#include "ax88796c_main.h"

extern const struct ethtool_ops ax88796c_ethtool_ops;

bool ax88796c_check_power(const struct ax88796c_device *ax_local);
bool ax88796c_check_power_and_wake(struct ax88796c_device *ax_local);
void ax88796c_set_power_saving(struct ax88796c_device *ax_local, u8 ps_level);
int ax88796c_mdio_read(struct mii_bus *mdiobus, int phy_id, int loc);
int ax88796c_mdio_write(struct mii_bus *mdiobus, int phy_id, int loc, u16 val);
int ax88796c_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);

#endif
Loading

0 comments on commit a97c69b

Please sign in to comment.