-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ax88796c-spi-ethernet-adapter'
Łukasz Stelmach says: ==================== AX88796C SPI Ethernet Adapter This is a driver for AX88796C Ethernet Adapter connected in SPI mode as found on ARTIK5 evaluation board. The driver has been ported from a v3.10.9 vendor kernel for ARTIK5 board. ==================== Link: https://lore.kernel.org/r/20211020182422.362647-1-l.stelmach@samsung.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
- Loading branch information
Showing
13 changed files
with
2,304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause | ||
%YAML 1.2 | ||
--- | ||
$id: http://devicetree.org/schemas/net/asix,ax88796c.yaml# | ||
$schema: http://devicetree.org/meta-schemas/core.yaml# | ||
|
||
title: ASIX AX88796C SPI Ethernet Adapter | ||
|
||
maintainers: | ||
- Łukasz Stelmach <l.stelmach@samsung.com> | ||
|
||
description: | | ||
ASIX AX88796C is an Ethernet controller with a built in PHY. This | ||
describes SPI mode of the chip. | ||
The node for this driver must be a child node of an SPI controller, | ||
hence all mandatory properties described in | ||
../spi/spi-controller.yaml must be specified. | ||
allOf: | ||
- $ref: ethernet-controller.yaml# | ||
|
||
properties: | ||
compatible: | ||
const: asix,ax88796c | ||
|
||
reg: | ||
maxItems: 1 | ||
|
||
spi-max-frequency: | ||
maximum: 40000000 | ||
|
||
interrupts: | ||
maxItems: 1 | ||
|
||
reset-gpios: | ||
description: | ||
A GPIO line handling reset of the chip. As the line is active low, | ||
it should be marked GPIO_ACTIVE_LOW. | ||
maxItems: 1 | ||
|
||
local-mac-address: true | ||
|
||
mac-address: true | ||
|
||
required: | ||
- compatible | ||
- reg | ||
- spi-max-frequency | ||
- interrupts | ||
- reset-gpios | ||
|
||
additionalProperties: false | ||
|
||
examples: | ||
# Artik5 eval board | ||
- | | ||
#include <dt-bindings/interrupt-controller/irq.h> | ||
#include <dt-bindings/gpio/gpio.h> | ||
spi0 { | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
ethernet@0 { | ||
compatible = "asix,ax88796c"; | ||
reg = <0x0>; | ||
local-mac-address = [00 00 00 00 00 00]; /* Filled in by a bootloader */ | ||
interrupt-parent = <&gpx2>; | ||
interrupts = <0 IRQ_TYPE_LEVEL_LOW>; | ||
spi-max-frequency = <40000000>; | ||
reset-gpios = <&gpe0 2 GPIO_ACTIVE_LOW>; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.