Skip to content

Commit 8bfeda6

Browse files
committed
phytium: phytmac: update phytmac to v1.0.50
Update phytmac from v1.0.29 to v1.0.50. Including following details. net/phytmac: Modify cmd processing function net/phytmac: Add XDP feature support net/phytmac: Bugfix set WOL failed issue net/phytmac: Bugfix invalid wait context net/phytmac: Change the requested resource type from nRE to nRnE net/phytmac: BugFix Memory leak when releasing resource net/phytmac: Limit the number of retries to avoid deadlock net/phytmac: Set the read timeout period to the NIC register net/phytmac: Slove left-shift out of bound issue net/phytmac: Manage WOL on MAC if PHY supports WOL feature net/phytmac: Fixed the PTP test failure issue net/phytmac: Cancels the power-on/off capability net/phytmac: Exit probe when MDIO times out net/phytmac: Clear RX descriptor address after the skb construction net/phytmac: Enable the tail pointer by the driver net/phytmac: Update hardware identifiers and the driver name net/phytmac: Fix sleeping function called from invalid context net/phytmac: Fix compile error on X86 architecture net/phytmac: Fix page refcounting issue for XDP_REDIRECT net/phytmac: Bugfix the potential deadlock issue Signed-off-by: Li Wencheng <liwencheng@phytium.com.cn> Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn> Signed-off-by: Jiakun Shuai <shuaijiakun1288@phytium.com.cn>
1 parent ca6d9e6 commit 8bfeda6

9 files changed

Lines changed: 763 additions & 201 deletions

File tree

drivers/net/ethernet/phytium/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
config NET_VENDOR_PHYTIUM
77
bool "Phytium devices"
8+
depends on ARCH_PHYTIUM
89
depends on HAS_IOMEM
910
default y
1011
help

drivers/net/ethernet/phytium/phytmac.h

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
#include <linux/phylink.h>
1313
#include <linux/netdevice.h>
1414
#include <linux/etherdevice.h>
15+
#include <net/xdp.h>
1516

16-
#define PHYTMAC_DRV_NAME "phytium-mac"
17+
#define PHYTMAC_PCI_DRV_NAME "phytmac_pci"
18+
#define PHYTMAC_PLAT_DRV_NAME "phytmac_platform"
1719
#define PHYTMAC_DRV_DESC "PHYTIUM Ethernet Driver"
18-
#define PHYTMAC_DRIVER_VERSION "1.0.29"
20+
#define PHYTMAC_DRIVER_VERSION "1.0.50"
1921
#define PHYTMAC_DEFAULT_MSG_ENABLE \
2022
(NETIF_MSG_DRV | \
2123
NETIF_MSG_PROBE | \
@@ -53,6 +55,8 @@
5355

5456
#define DEFAULT_MSG_RING_SIZE 16
5557

58+
#define PHYTMAC_MDIO_TIMEOUT 1000000 /* in usecs */
59+
5660
#define PHYTMAC_CAPS_JUMBO 0x00000001
5761
#define PHYTMAC_CAPS_PTP 0x00000002
5862
#define PHYTMAC_CAPS_BD_RD_PREFETCH 0x00000004
@@ -72,7 +76,8 @@
7276
#define PHYTMAC_TX 0x1
7377
#define PHYTMAC_RX 0x2
7478

75-
#define PHYTMAC_GREGS_LEN 16
79+
#define PHYTMAC_ETHTOOLD_REGS_LEN 64
80+
#define PHYTMAC_STATIS_REG_NUM 45
7681

7782
#define PHYTMAC_MTU_MIN_SIZE ETH_MIN_MTU
7883

@@ -110,9 +115,6 @@
110115
#define PHYTMAC_MSG_READ(_pdata, _reg) \
111116
__raw_readl((_pdata)->mac_regs + (_reg))
112117

113-
#define PHYTMAC_WRITE(_pdata, _reg, _val) \
114-
__raw_writel((_val), (_pdata)->mac_regs + (_reg))
115-
116118
#define LSO_UFO 1
117119
#define LSO_TSO 2
118120

@@ -130,6 +132,14 @@
130132
#define PHYTMAC_WAKE_UCAST 0x00000004
131133
#define PHYTMAC_WAKE_MCAST 0x00000008
132134

135+
/* XDP */
136+
#define PHYTMAC_XDP_PASS 0
137+
#define PHYTMAC_XDP_CONSUMED BIT(0)
138+
#define PHYTMAC_XDP_TX BIT(1)
139+
#define PHYTMAC_XDP_REDIR BIT(2)
140+
141+
#define PHYTMAC_DESC_NEEDED (MAX_SKB_FRAGS + 4)
142+
133143
enum phytmac_interface {
134144
PHYTMAC_PHY_INTERFACE_MODE_NA,
135145
PHYTMAC_PHY_INTERFACE_MODE_INTERNAL,
@@ -334,8 +344,20 @@ struct phytmac_dma_desc {
334344
};
335345
#endif
336346

347+
/* TX resources are shared between XDP and netstack
348+
* and we need to tag the buffer type to distinguish them
349+
*/
350+
enum phytmac_tx_buf_type {
351+
PHYTMAC_TYPE_SKB = 0,
352+
PHYTMAC_TYPE_XDP,
353+
};
354+
337355
struct phytmac_tx_skb {
338-
struct sk_buff *skb;
356+
union {
357+
struct sk_buff *skb;
358+
struct xdp_frame *xdpf;
359+
};
360+
enum phytmac_tx_buf_type type;
339361
dma_addr_t addr;
340362
size_t length;
341363
bool mapped_as_page;
@@ -358,6 +380,7 @@ struct phytmac_queue {
358380
struct phytmac *pdata;
359381
int irq;
360382
int index;
383+
struct bpf_prog *xdp_prog;
361384

362385
/* tx queue info */
363386
unsigned int tx_head;
@@ -380,6 +403,7 @@ struct phytmac_queue {
380403
struct phytmac_rx_buffer *rx_buffer_info;
381404
struct napi_struct rx_napi;
382405
struct phytmac_queue_stats stats;
406+
struct xdp_rxq_info xdp_rxq;
383407

384408
#ifdef CONFIG_PHYTMAC_ENABLE_PTP
385409
struct work_struct tx_ts_task;
@@ -404,11 +428,12 @@ struct phytmac_msg {
404428
u32 tx_msg_ring_size;
405429
u32 rx_msg_ring_size;
406430
u32 tx_msg_head;
407-
u32 tx_msg_tail;
431+
u32 tx_msg_wr_tail;
432+
u32 tx_msg_rd_tail;
408433
u32 rx_msg_head;
409434
u32 rx_msg_tail;
410-
/*use msg_mutex to protect msg */
411-
struct mutex msg_mutex;
435+
/*use msg_lock to protect msg */
436+
spinlock_t msg_lock;
412437
};
413438

414439
struct ts_ctrl {
@@ -425,6 +450,7 @@ struct phytmac {
425450
struct platform_device *platdev;
426451
struct net_device *ndev;
427452
struct device *dev;
453+
struct bpf_prog *xdp_prog;
428454
struct ncsi_dev *ncsidev;
429455
struct fwnode_handle *fwnode;
430456
struct phytmac_hw_if *hw_if;
@@ -445,8 +471,6 @@ struct phytmac {
445471
struct work_struct restart_task;
446472
/* Lock to protect mac config */
447473
spinlock_t lock;
448-
/* Lock to protect msg tx */
449-
spinlock_t msg_lock;
450474
u32 rx_ring_size;
451475
u32 tx_ring_size;
452476
u32 dma_data_width;
@@ -487,8 +511,26 @@ struct phytmac {
487511
spinlock_t rx_fs_lock;
488512
unsigned int max_rx_fs;
489513
u32 version;
514+
char fw_version[32];
490515
};
491516

517+
/* phytmac_desc_unused - calculate if we have unused descriptors */
518+
static inline int phytmac_txdesc_unused(struct phytmac_queue *queue)
519+
{
520+
struct phytmac *pdata = queue->pdata;
521+
522+
if (queue->tx_head > queue->tx_tail)
523+
return queue->tx_head - queue->tx_tail - 1;
524+
525+
return pdata->tx_ring_size + queue->tx_head - queue->tx_tail - 1;
526+
}
527+
528+
static inline struct netdev_queue *phytmac_get_txq(const struct phytmac *pdata,
529+
struct phytmac_queue *queue)
530+
{
531+
return netdev_get_tx_queue(pdata->ndev, queue->index);
532+
}
533+
492534
struct phytmac_hw_if {
493535
int (*init_msg_ring)(struct phytmac *pdata);
494536
int (*init_hw)(struct phytmac *pdata);
@@ -534,6 +576,7 @@ struct phytmac_hw_if {
534576
int (*mdio_read)(struct phytmac *pdata, int mii_id, int regnum);
535577
int (*mdio_write)(struct phytmac *pdata, int mii_id,
536578
int regnum, u16 data);
579+
int (*mdio_idle)(struct phytmac *pdata);
537580
int (*mdio_read_c45)(struct phytmac *pdata, int mii_id, int devad, int regnum);
538581
int (*mdio_write_c45)(struct phytmac *pdata, int mii_id, int devad,
539582
int regnum, u16 data);
@@ -627,6 +670,7 @@ struct phytmac_hw_if {
627670
#define PHYTMAC_RX_DMA_ATTR \
628671
(DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
629672
#define PHYTMAC_SKB_PAD (NET_SKB_PAD)
673+
#define PHYTMAC_ETH_PKT_HDR_PAD (ETH_HLEN + ETH_FCS_LEN + (VLAN_HLEN * 2))
630674

631675
#define PHYTMAC_RXBUFFER_2048 2048
632676
#define PHYTMAC_MAX_FRAME_BUILD_SKB \
@@ -635,6 +679,8 @@ struct phytmac_hw_if {
635679
#define PHYTMAC_RX_PAGE_ORDER 0
636680
#define PHYTMAC_RX_PAGE_SIZE (PAGE_SIZE << PHYTMAC_RX_PAGE_ORDER)
637681

682+
void __iomem *
683+
phytmac_devm_ioremap_resource_np(struct device *dev, const struct resource *res);
638684
struct phytmac_tx_skb *phytmac_get_tx_skb(struct phytmac_queue *queue,
639685
unsigned int index);
640686
inline struct phytmac_dma_desc *phytmac_get_tx_desc(struct phytmac_queue *queue,

drivers/net/ethernet/phytium/phytmac_ethtool.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static void phytmac_get_ethtool_strings(struct net_device *ndev, u32 sset, u8 *p
7070

7171
static inline int phytmac_get_regs_len(struct net_device *ndev)
7272
{
73-
return PHYTMAC_GREGS_LEN;
73+
return PHYTMAC_ETHTOOLD_REGS_LEN;
7474
}
7575

7676
static void phytmac_get_regs(struct net_device *ndev,
@@ -81,7 +81,7 @@ static void phytmac_get_regs(struct net_device *ndev,
8181
struct phytmac_hw_if *hw_if = pdata->hw_if;
8282
u32 *regs_buff = p;
8383

84-
memset(p, 0, PHYTMAC_GREGS_LEN * sizeof(u32));
84+
memset(p, 0, PHYTMAC_ETHTOOLD_REGS_LEN);
8585

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

93+
wol->wolopts = 0;
9394
phylink_ethtool_get_wol(pdata->phylink, wol);
9495

95-
if (pdata->wol & PHYTMAC_WAKE_MAGIC) {
96+
wol->supported = WAKE_MAGIC | WAKE_ARP |
97+
WAKE_UCAST | WAKE_MCAST;
98+
99+
if (pdata->wol & PHYTMAC_WAKE_MAGIC)
96100
wol->wolopts |= WAKE_MAGIC;
97-
wol->supported |= WAKE_MAGIC;
98-
}
99-
if (pdata->wol & PHYTMAC_WAKE_ARP) {
101+
if (pdata->wol & PHYTMAC_WAKE_ARP)
100102
wol->wolopts |= WAKE_ARP;
101-
wol->supported |= WAKE_ARP;
102-
}
103-
if (pdata->wol & PHYTMAC_WAKE_UCAST) {
103+
if (pdata->wol & PHYTMAC_WAKE_UCAST)
104104
wol->wolopts |= WAKE_UCAST;
105-
wol->supported |= WAKE_UCAST;
106-
}
107-
if (pdata->wol & PHYTMAC_WAKE_MCAST) {
105+
if (pdata->wol & PHYTMAC_WAKE_MCAST)
108106
wol->wolopts |= WAKE_MCAST;
109-
wol->supported |= WAKE_MCAST;
110-
}
111107
}
112108

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

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

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

123120
pdata->wol = 0;
@@ -510,13 +507,16 @@ static void phytmac_get_drvinfo(struct net_device *ndev, struct ethtool_drvinfo
510507
{
511508
struct phytmac *pdata = netdev_priv(ndev);
512509

513-
strscpy(drvinfo->driver, PHYTMAC_DRV_NAME, sizeof(drvinfo->driver));
514510
strscpy(drvinfo->version, PHYTMAC_DRIVER_VERSION, sizeof(drvinfo->version));
511+
strscpy(drvinfo->fw_version, pdata->fw_version, sizeof(drvinfo->fw_version));
515512

516-
if (pdata->platdev)
513+
if (pdata->platdev) {
514+
strscpy(drvinfo->driver, PHYTMAC_PLAT_DRV_NAME, sizeof(drvinfo->driver));
517515
strscpy(drvinfo->bus_info, pdata->platdev->name, sizeof(drvinfo->bus_info));
518-
else if (pdata->pcidev)
516+
} else if (pdata->pcidev) {
517+
strscpy(drvinfo->driver, PHYTMAC_PCI_DRV_NAME, sizeof(drvinfo->driver));
519518
strscpy(drvinfo->bus_info, pci_name(pdata->pcidev), sizeof(drvinfo->bus_info));
519+
}
520520
}
521521

522522
static const struct ethtool_ops phytmac_ethtool_ops = {

0 commit comments

Comments
 (0)