Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion arch/x86/configs/deepin_x86_desktop_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,6 @@ CONFIG_XILINX_EMACLITE=m
CONFIG_XILINX_AXI_EMAC=m
CONFIG_XILINX_LL_TEMAC=m
CONFIG_PCMCIA_XIRC2PS=m
# CONFIG_NET_VENDOR_PHYTIUM is not set
CONFIG_GRTNIC=m
CONFIG_NCE=m
CONFIG_NE6X=m
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/phytium/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

config NET_VENDOR_PHYTIUM
bool "Phytium devices"
depends on ARCH_PHYTIUM
depends on HAS_IOMEM
default y
help
Expand Down
70 changes: 58 additions & 12 deletions drivers/net/ethernet/phytium/phytmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
#include <linux/phylink.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <net/xdp.h>

#define PHYTMAC_DRV_NAME "phytium-mac"
#define PHYTMAC_PCI_DRV_NAME "phytmac_pci"
#define PHYTMAC_PLAT_DRV_NAME "phytmac_platform"
#define PHYTMAC_DRV_DESC "PHYTIUM Ethernet Driver"
#define PHYTMAC_DRIVER_VERSION "1.0.29"
#define PHYTMAC_DRIVER_VERSION "1.0.50"
#define PHYTMAC_DEFAULT_MSG_ENABLE \
(NETIF_MSG_DRV | \
NETIF_MSG_PROBE | \
Expand Down Expand Up @@ -53,6 +55,8 @@

#define DEFAULT_MSG_RING_SIZE 16

#define PHYTMAC_MDIO_TIMEOUT 1000000 /* in usecs */

#define PHYTMAC_CAPS_JUMBO 0x00000001
#define PHYTMAC_CAPS_PTP 0x00000002
#define PHYTMAC_CAPS_BD_RD_PREFETCH 0x00000004
Expand All @@ -72,7 +76,8 @@
#define PHYTMAC_TX 0x1
#define PHYTMAC_RX 0x2

#define PHYTMAC_GREGS_LEN 16
#define PHYTMAC_ETHTOOLD_REGS_LEN 64
#define PHYTMAC_STATIS_REG_NUM 45

#define PHYTMAC_MTU_MIN_SIZE ETH_MIN_MTU

Expand Down Expand Up @@ -110,9 +115,6 @@
#define PHYTMAC_MSG_READ(_pdata, _reg) \
__raw_readl((_pdata)->mac_regs + (_reg))

#define PHYTMAC_WRITE(_pdata, _reg, _val) \
__raw_writel((_val), (_pdata)->mac_regs + (_reg))

#define LSO_UFO 1
#define LSO_TSO 2

Expand All @@ -130,6 +132,14 @@
#define PHYTMAC_WAKE_UCAST 0x00000004
#define PHYTMAC_WAKE_MCAST 0x00000008

/* XDP */
#define PHYTMAC_XDP_PASS 0
#define PHYTMAC_XDP_CONSUMED BIT(0)
#define PHYTMAC_XDP_TX BIT(1)
#define PHYTMAC_XDP_REDIR BIT(2)

#define PHYTMAC_DESC_NEEDED (MAX_SKB_FRAGS + 4)

enum phytmac_interface {
PHYTMAC_PHY_INTERFACE_MODE_NA,
PHYTMAC_PHY_INTERFACE_MODE_INTERNAL,
Expand Down Expand Up @@ -334,8 +344,20 @@ struct phytmac_dma_desc {
};
#endif

/* TX resources are shared between XDP and netstack
* and we need to tag the buffer type to distinguish them
*/
enum phytmac_tx_buf_type {
PHYTMAC_TYPE_SKB = 0,
PHYTMAC_TYPE_XDP,
};

struct phytmac_tx_skb {
struct sk_buff *skb;
union {
struct sk_buff *skb;
struct xdp_frame *xdpf;
};
enum phytmac_tx_buf_type type;
dma_addr_t addr;
size_t length;
bool mapped_as_page;
Expand All @@ -358,6 +380,7 @@ struct phytmac_queue {
struct phytmac *pdata;
int irq;
int index;
struct bpf_prog *xdp_prog;

/* tx queue info */
unsigned int tx_head;
Expand All @@ -380,6 +403,7 @@ struct phytmac_queue {
struct phytmac_rx_buffer *rx_buffer_info;
struct napi_struct rx_napi;
struct phytmac_queue_stats stats;
struct xdp_rxq_info xdp_rxq;

#ifdef CONFIG_PHYTMAC_ENABLE_PTP
struct work_struct tx_ts_task;
Expand All @@ -404,11 +428,12 @@ struct phytmac_msg {
u32 tx_msg_ring_size;
u32 rx_msg_ring_size;
u32 tx_msg_head;
u32 tx_msg_tail;
u32 tx_msg_wr_tail;
u32 tx_msg_rd_tail;
u32 rx_msg_head;
u32 rx_msg_tail;
/*use msg_mutex to protect msg */
struct mutex msg_mutex;
/*use msg_lock to protect msg */
spinlock_t msg_lock;
};

struct ts_ctrl {
Expand All @@ -425,6 +450,7 @@ struct phytmac {
struct platform_device *platdev;
struct net_device *ndev;
struct device *dev;
struct bpf_prog *xdp_prog;
struct ncsi_dev *ncsidev;
struct fwnode_handle *fwnode;
struct phytmac_hw_if *hw_if;
Expand All @@ -445,8 +471,6 @@ struct phytmac {
struct work_struct restart_task;
/* Lock to protect mac config */
spinlock_t lock;
/* Lock to protect msg tx */
spinlock_t msg_lock;
u32 rx_ring_size;
u32 tx_ring_size;
u32 dma_data_width;
Expand Down Expand Up @@ -487,8 +511,26 @@ struct phytmac {
spinlock_t rx_fs_lock;
unsigned int max_rx_fs;
u32 version;
char fw_version[32];
};

/* phytmac_desc_unused - calculate if we have unused descriptors */
static inline int phytmac_txdesc_unused(struct phytmac_queue *queue)
{
struct phytmac *pdata = queue->pdata;

if (queue->tx_head > queue->tx_tail)
return queue->tx_head - queue->tx_tail - 1;

return pdata->tx_ring_size + queue->tx_head - queue->tx_tail - 1;
}

static inline struct netdev_queue *phytmac_get_txq(const struct phytmac *pdata,
struct phytmac_queue *queue)
{
return netdev_get_tx_queue(pdata->ndev, queue->index);
}

struct phytmac_hw_if {
int (*init_msg_ring)(struct phytmac *pdata);
int (*init_hw)(struct phytmac *pdata);
Expand Down Expand Up @@ -534,6 +576,7 @@ struct phytmac_hw_if {
int (*mdio_read)(struct phytmac *pdata, int mii_id, int regnum);
int (*mdio_write)(struct phytmac *pdata, int mii_id,
int regnum, u16 data);
int (*mdio_idle)(struct phytmac *pdata);
int (*mdio_read_c45)(struct phytmac *pdata, int mii_id, int devad, int regnum);
int (*mdio_write_c45)(struct phytmac *pdata, int mii_id, int devad,
int regnum, u16 data);
Expand Down Expand Up @@ -627,6 +670,7 @@ struct phytmac_hw_if {
#define PHYTMAC_RX_DMA_ATTR \
(DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
#define PHYTMAC_SKB_PAD (NET_SKB_PAD)
#define PHYTMAC_ETH_PKT_HDR_PAD (ETH_HLEN + ETH_FCS_LEN + (VLAN_HLEN * 2))

#define PHYTMAC_RXBUFFER_2048 2048
#define PHYTMAC_MAX_FRAME_BUILD_SKB \
Expand All @@ -635,6 +679,8 @@ struct phytmac_hw_if {
#define PHYTMAC_RX_PAGE_ORDER 0
#define PHYTMAC_RX_PAGE_SIZE (PAGE_SIZE << PHYTMAC_RX_PAGE_ORDER)

void __iomem *
phytmac_devm_ioremap_resource_np(struct device *dev, const struct resource *res);
struct phytmac_tx_skb *phytmac_get_tx_skb(struct phytmac_queue *queue,
unsigned int index);
inline struct phytmac_dma_desc *phytmac_get_tx_desc(struct phytmac_queue *queue,
Expand Down
36 changes: 18 additions & 18 deletions drivers/net/ethernet/phytium/phytmac_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void phytmac_get_ethtool_strings(struct net_device *ndev, u32 sset, u8 *p

static inline int phytmac_get_regs_len(struct net_device *ndev)
{
return PHYTMAC_GREGS_LEN;
return PHYTMAC_ETHTOOLD_REGS_LEN;
}

static void phytmac_get_regs(struct net_device *ndev,
Expand All @@ -81,7 +81,7 @@ static void phytmac_get_regs(struct net_device *ndev,
struct phytmac_hw_if *hw_if = pdata->hw_if;
u32 *regs_buff = p;

memset(p, 0, PHYTMAC_GREGS_LEN * sizeof(u32));
memset(p, 0, PHYTMAC_ETHTOOLD_REGS_LEN);

hw_if->get_regs(pdata, regs_buff);
}
Expand All @@ -90,24 +90,20 @@ static void phytmac_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol
{
struct phytmac *pdata = netdev_priv(ndev);

wol->wolopts = 0;
phylink_ethtool_get_wol(pdata->phylink, wol);

if (pdata->wol & PHYTMAC_WAKE_MAGIC) {
wol->supported = WAKE_MAGIC | WAKE_ARP |
WAKE_UCAST | WAKE_MCAST;

if (pdata->wol & PHYTMAC_WAKE_MAGIC)
wol->wolopts |= WAKE_MAGIC;
wol->supported |= WAKE_MAGIC;
}
if (pdata->wol & PHYTMAC_WAKE_ARP) {
if (pdata->wol & PHYTMAC_WAKE_ARP)
wol->wolopts |= WAKE_ARP;
wol->supported |= WAKE_ARP;
}
if (pdata->wol & PHYTMAC_WAKE_UCAST) {
if (pdata->wol & PHYTMAC_WAKE_UCAST)
wol->wolopts |= WAKE_UCAST;
wol->supported |= WAKE_UCAST;
}
if (pdata->wol & PHYTMAC_WAKE_MCAST) {
if (pdata->wol & PHYTMAC_WAKE_MCAST)
wol->wolopts |= WAKE_MCAST;
wol->supported |= WAKE_MCAST;
}
}

static int phytmac_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
Expand All @@ -117,7 +113,8 @@ static int phytmac_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)

ret = phylink_ethtool_set_wol(pdata->phylink, wol);

if (!ret || ret != -EOPNOTSUPP)
/* Don't manage WoL on MAC, if PHY set_wol() fails */
if (ret && ret != -EOPNOTSUPP)
return ret;

pdata->wol = 0;
Expand Down Expand Up @@ -510,13 +507,16 @@ static void phytmac_get_drvinfo(struct net_device *ndev, struct ethtool_drvinfo
{
struct phytmac *pdata = netdev_priv(ndev);

strscpy(drvinfo->driver, PHYTMAC_DRV_NAME, sizeof(drvinfo->driver));
strscpy(drvinfo->version, PHYTMAC_DRIVER_VERSION, sizeof(drvinfo->version));
strscpy(drvinfo->fw_version, pdata->fw_version, sizeof(drvinfo->fw_version));

if (pdata->platdev)
if (pdata->platdev) {
strscpy(drvinfo->driver, PHYTMAC_PLAT_DRV_NAME, sizeof(drvinfo->driver));
strscpy(drvinfo->bus_info, pdata->platdev->name, sizeof(drvinfo->bus_info));
else if (pdata->pcidev)
} else if (pdata->pcidev) {
strscpy(drvinfo->driver, PHYTMAC_PCI_DRV_NAME, sizeof(drvinfo->driver));
strscpy(drvinfo->bus_info, pci_name(pdata->pcidev), sizeof(drvinfo->bus_info));
}
}

static const struct ethtool_ops phytmac_ethtool_ops = {
Expand Down
Loading