Skip to content

Commit 2bb295f

Browse files
committed
Merge branch 'net-hisilicon-Add-support-for-HI13X1-to-hip04_eth'
Jiangfeng Xiao says: ==================== net: hisilicon: Add support for HI13X1 to hip04_eth The main purpose of this patch series is to extend the hip04_eth driver to support HI13X1_GMAC. The offset and bitmap of some registers of HI13X1_GMAC are different from hip04_eth common soc. In addition, the definition of send descriptor and parsing descriptor are different from hip04_eth common soc. So the macro of the register offset is redefined to adapt the HI13X1_GMAC. Clean up the sparse warning by the way. Change since v1: * Add a cover letter. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 03a49a1 + d413779 commit 2bb295f

3 files changed

Lines changed: 136 additions & 23 deletions

File tree

‎Documentation/devicetree/bindings/net/hisilicon-hip04-net.txt‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Required properties:
1010
phandle, specifies a reference to the syscon ppe node
1111
port, port number connected to the controller
1212
channel, recv channel start from channel * number (RX_DESC_NUM)
13+
group, field in the pkg desc, in general, it is the same as the port.
1314
- phy-mode: see ethernet.txt [1].
1415

1516
Optional properties:
@@ -66,15 +67,15 @@ Example:
6667
reg = <0x28b0000 0x10000>;
6768
interrupts = <0 413 4>;
6869
phy-mode = "mii";
69-
port-handle = <&ppe 31 0>;
70+
port-handle = <&ppe 31 0 31>;
7071
};
7172

7273
ge0: ethernet@2800000 {
7374
compatible = "hisilicon,hip04-mac";
7475
reg = <0x2800000 0x10000>;
7576
interrupts = <0 402 4>;
7677
phy-mode = "sgmii";
77-
port-handle = <&ppe 0 1>;
78+
port-handle = <&ppe 0 1 0>;
7879
phy-handle = <&phy0>;
7980
};
8081

@@ -83,6 +84,6 @@ Example:
8384
reg = <0x2880000 0x10000>;
8485
interrupts = <0 410 4>;
8586
phy-mode = "sgmii";
86-
port-handle = <&ppe 8 2>;
87+
port-handle = <&ppe 8 2 8>;
8788
phy-handle = <&phy1>;
8889
};

‎drivers/net/ethernet/hisilicon/Kconfig‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ config HIP04_ETH
4646
If you wish to compile a kernel for a hardware with hisilicon p04 SoC and
4747
want to use the internal ethernet then you should answer Y to this.
4848

49+
config HI13X1_GMAC
50+
bool "Hisilicon HI13X1 Network Device Support"
51+
depends on HIP04_ETH
52+
help
53+
If you wish to compile a kernel for a hardware with hisilicon hi13x1_gamc
54+
then you should answer Y to this. This makes this driver suitable for use
55+
on certain boards such as the HI13X1.
56+
57+
If you are unsure, say N.
58+
4959
config HNS_MDIO
5060
tristate
5161
select PHYLIB

‎drivers/net/ethernet/hisilicon/hip04_eth.c‎

Lines changed: 122 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <linux/mfd/syscon.h>
1717
#include <linux/regmap.h>
1818

19+
#define SC_PPE_RESET_DREQ 0x026C
20+
1921
#define PPE_CFG_RX_ADDR 0x100
2022
#define PPE_CFG_POOL_GRP 0x300
2123
#define PPE_CFG_RX_BUF_SIZE 0x400
@@ -33,19 +35,36 @@
3335
#define GE_MODE_CHANGE_REG 0x1b4
3436
#define GE_RECV_CONTROL_REG 0x1e0
3537
#define GE_STATION_MAC_ADDRESS 0x210
36-
#define PPE_CFG_CPU_ADD_ADDR 0x580
37-
#define PPE_CFG_MAX_FRAME_LEN_REG 0x408
38+
3839
#define PPE_CFG_BUS_CTRL_REG 0x424
3940
#define PPE_CFG_RX_CTRL_REG 0x428
41+
42+
#if defined(CONFIG_HI13X1_GMAC)
43+
#define PPE_CFG_CPU_ADD_ADDR 0x6D0
44+
#define PPE_CFG_MAX_FRAME_LEN_REG 0x500
45+
#define PPE_CFG_RX_PKT_MODE_REG 0x504
46+
#define PPE_CFG_QOS_VMID_GEN 0x520
47+
#define PPE_CFG_RX_PKT_INT 0x740
48+
#define PPE_INTEN 0x700
49+
#define PPE_INTSTS 0x708
50+
#define PPE_RINT 0x704
51+
#define PPE_CFG_STS_MODE 0x880
52+
#else
53+
#define PPE_CFG_CPU_ADD_ADDR 0x580
54+
#define PPE_CFG_MAX_FRAME_LEN_REG 0x408
4055
#define PPE_CFG_RX_PKT_MODE_REG 0x438
4156
#define PPE_CFG_QOS_VMID_GEN 0x500
4257
#define PPE_CFG_RX_PKT_INT 0x538
4358
#define PPE_INTEN 0x600
4459
#define PPE_INTSTS 0x608
4560
#define PPE_RINT 0x604
4661
#define PPE_CFG_STS_MODE 0x700
62+
#endif /* CONFIG_HI13X1_GMAC */
63+
4764
#define PPE_HIS_RX_PKT_CNT 0x804
4865

66+
#define RESET_DREQ_ALL 0xffffffff
67+
4968
/* REG_INTERRUPT */
5069
#define RCV_INT BIT(10)
5170
#define RCV_NOBUF BIT(8)
@@ -57,8 +76,15 @@
5776
/* TX descriptor config */
5877
#define TX_FREE_MEM BIT(0)
5978
#define TX_READ_ALLOC_L3 BIT(1)
60-
#define TX_FINISH_CACHE_INV BIT(2)
79+
#if defined(CONFIG_HI13X1_GMAC)
80+
#define TX_CLEAR_WB BIT(7)
81+
#define TX_RELEASE_TO_PPE BIT(4)
82+
#define TX_FINISH_CACHE_INV BIT(6)
83+
#define TX_POOL_SHIFT 16
84+
#else
6185
#define TX_CLEAR_WB BIT(4)
86+
#define TX_FINISH_CACHE_INV BIT(2)
87+
#endif
6288
#define TX_L3_CHECKSUM BIT(5)
6389
#define TX_LOOP_BACK BIT(11)
6490

@@ -93,18 +119,35 @@
93119
#define GE_RX_PORT_EN BIT(1)
94120
#define GE_TX_PORT_EN BIT(2)
95121

96-
#define PPE_CFG_STS_RX_PKT_CNT_RC BIT(12)
97-
98122
#define PPE_CFG_RX_PKT_ALIGN BIT(18)
99-
#define PPE_CFG_QOS_VMID_MODE BIT(14)
123+
124+
#if defined(CONFIG_HI13X1_GMAC)
125+
#define PPE_CFG_QOS_VMID_GRP_SHIFT 4
126+
#define PPE_CFG_RX_CTRL_ALIGN_SHIFT 7
127+
#define PPE_CFG_STS_RX_PKT_CNT_RC BIT(0)
128+
#define PPE_CFG_QOS_VMID_MODE BIT(15)
129+
#define PPE_CFG_BUS_LOCAL_REL (BIT(9) | BIT(15) | BIT(19) | BIT(23))
130+
131+
/* buf unit size is cache_line_size, which is 64, so the shift is 6 */
132+
#define PPE_BUF_SIZE_SHIFT 6
133+
#define PPE_TX_BUF_HOLD BIT(31)
134+
#define CACHE_LINE_MASK 0x3F
135+
#else
100136
#define PPE_CFG_QOS_VMID_GRP_SHIFT 8
137+
#define PPE_CFG_RX_CTRL_ALIGN_SHIFT 11
138+
#define PPE_CFG_STS_RX_PKT_CNT_RC BIT(12)
139+
#define PPE_CFG_QOS_VMID_MODE BIT(14)
140+
#define PPE_CFG_BUS_LOCAL_REL BIT(14)
141+
142+
/* buf unit size is 1, so the shift is 6 */
143+
#define PPE_BUF_SIZE_SHIFT 0
144+
#define PPE_TX_BUF_HOLD 0
145+
#endif /* CONFIG_HI13X1_GMAC */
101146

102147
#define PPE_CFG_RX_FIFO_FSFU BIT(11)
103148
#define PPE_CFG_RX_DEPTH_SHIFT 16
104149
#define PPE_CFG_RX_START_SHIFT 0
105-
#define PPE_CFG_RX_CTRL_ALIGN_SHIFT 11
106150

107-
#define PPE_CFG_BUS_LOCAL_REL BIT(14)
108151
#define PPE_CFG_BUS_BIG_ENDIEN BIT(0)
109152

110153
#define RX_DESC_NUM 128
@@ -128,26 +171,50 @@
128171
#define HIP04_MIN_TX_COALESCE_FRAMES 100
129172

130173
struct tx_desc {
174+
#if defined(CONFIG_HI13X1_GMAC)
175+
u32 reserved1[2];
176+
u32 send_addr;
177+
u16 send_size;
178+
u16 data_offset;
179+
u32 reserved2[7];
180+
u32 cfg;
181+
u32 wb_addr;
182+
u32 reserved3[3];
183+
#else
131184
u32 send_addr;
132185
u32 send_size;
133186
u32 next_addr;
134187
u32 cfg;
135188
u32 wb_addr;
189+
#endif
136190
} __aligned(64);
137191

138192
struct rx_desc {
193+
#if defined(CONFIG_HI13X1_GMAC)
194+
u32 reserved1[3];
195+
u16 pkt_len;
196+
u16 reserved_16;
197+
u32 reserved2[6];
198+
u32 pkt_err;
199+
u32 reserved3[5];
200+
#else
139201
u16 reserved_16;
140202
u16 pkt_len;
141203
u32 reserve1[3];
142204
u32 pkt_err;
143205
u32 reserve2[4];
206+
#endif
144207
};
145208

146209
struct hip04_priv {
147210
void __iomem *base;
211+
#if defined(CONFIG_HI13X1_GMAC)
212+
void __iomem *sysctrl_base;
213+
#endif
148214
int phy_mode;
149215
int chan;
150216
unsigned int port;
217+
unsigned int group;
151218
unsigned int speed;
152219
unsigned int duplex;
153220
unsigned int reg_inten;
@@ -221,6 +288,13 @@ static void hip04_config_port(struct net_device *ndev, u32 speed, u32 duplex)
221288
writel_relaxed(val, priv->base + GE_MODE_CHANGE_REG);
222289
}
223290

291+
static void hip04_reset_dreq(struct hip04_priv *priv)
292+
{
293+
#if defined(CONFIG_HI13X1_GMAC)
294+
writel_relaxed(RESET_DREQ_ALL, priv->sysctrl_base + SC_PPE_RESET_DREQ);
295+
#endif
296+
}
297+
224298
static void hip04_reset_ppe(struct hip04_priv *priv)
225299
{
226300
u32 val, tmp, timeout = 0;
@@ -241,14 +315,14 @@ static void hip04_config_fifo(struct hip04_priv *priv)
241315
val |= PPE_CFG_STS_RX_PKT_CNT_RC;
242316
writel_relaxed(val, priv->base + PPE_CFG_STS_MODE);
243317

244-
val = BIT(priv->port);
318+
val = BIT(priv->group);
245319
regmap_write(priv->map, priv->port * 4 + PPE_CFG_POOL_GRP, val);
246320

247-
val = priv->port << PPE_CFG_QOS_VMID_GRP_SHIFT;
321+
val = priv->group << PPE_CFG_QOS_VMID_GRP_SHIFT;
248322
val |= PPE_CFG_QOS_VMID_MODE;
249323
writel_relaxed(val, priv->base + PPE_CFG_QOS_VMID_GEN);
250324

251-
val = RX_BUF_SIZE;
325+
val = RX_BUF_SIZE >> PPE_BUF_SIZE_SHIFT;
252326
regmap_write(priv->map, priv->port * 4 + PPE_CFG_RX_BUF_SIZE, val);
253327

254328
val = RX_DESC_NUM << PPE_CFG_RX_DEPTH_SHIFT;
@@ -285,8 +359,10 @@ static void hip04_config_fifo(struct hip04_priv *priv)
285359
val |= GE_RX_STRIP_PAD | GE_RX_PAD_EN;
286360
writel_relaxed(val, priv->base + GE_RECV_CONTROL_REG);
287361

362+
#ifndef CONFIG_HI13X1_GMAC
288363
val = GE_AUTO_NEG_CTL;
289364
writel_relaxed(val, priv->base + GE_TX_LOCAL_PAGE_REG);
365+
#endif
290366
}
291367

292368
static void hip04_mac_enable(struct net_device *ndev)
@@ -329,12 +405,18 @@ static void hip04_mac_disable(struct net_device *ndev)
329405

330406
static void hip04_set_xmit_desc(struct hip04_priv *priv, dma_addr_t phys)
331407
{
332-
writel(phys, priv->base + PPE_CFG_CPU_ADD_ADDR);
408+
u32 val;
409+
410+
val = phys >> PPE_BUF_SIZE_SHIFT | PPE_TX_BUF_HOLD;
411+
writel(val, priv->base + PPE_CFG_CPU_ADD_ADDR);
333412
}
334413

335414
static void hip04_set_recv_desc(struct hip04_priv *priv, dma_addr_t phys)
336415
{
337-
regmap_write(priv->map, priv->port * 4 + PPE_CFG_RX_ADDR, phys);
416+
u32 val;
417+
418+
val = phys >> PPE_BUF_SIZE_SHIFT;
419+
regmap_write(priv->map, priv->port * 4 + PPE_CFG_RX_ADDR, val);
338420
}
339421

340422
static u32 hip04_recv_cnt(struct hip04_priv *priv)
@@ -442,11 +524,20 @@ hip04_mac_start_xmit(struct sk_buff *skb, struct net_device *ndev)
442524

443525
priv->tx_skb[tx_head] = skb;
444526
priv->tx_phys[tx_head] = phys;
445-
desc->send_addr = cpu_to_be32(phys);
446-
desc->send_size = cpu_to_be32(skb->len);
447-
desc->cfg = cpu_to_be32(TX_CLEAR_WB | TX_FINISH_CACHE_INV);
527+
528+
desc->send_size = (__force u32)cpu_to_be32(skb->len);
529+
#if defined(CONFIG_HI13X1_GMAC)
530+
desc->cfg = (__force u32)cpu_to_be32(TX_CLEAR_WB | TX_FINISH_CACHE_INV
531+
| TX_RELEASE_TO_PPE | priv->port << TX_POOL_SHIFT);
532+
desc->data_offset = (__force u32)cpu_to_be32(phys & CACHE_LINE_MASK);
533+
desc->send_addr = (__force u32)cpu_to_be32(phys & ~CACHE_LINE_MASK);
534+
#else
535+
desc->cfg = (__force u32)cpu_to_be32(TX_CLEAR_WB | TX_FINISH_CACHE_INV);
536+
desc->send_addr = (__force u32)cpu_to_be32(phys);
537+
#endif
448538
phys = priv->tx_desc_dma + tx_head * sizeof(struct tx_desc);
449-
desc->wb_addr = cpu_to_be32(phys);
539+
desc->wb_addr = (__force u32)cpu_to_be32(phys +
540+
offsetof(struct tx_desc, send_addr));
450541
skb_tx_timestamp(skb);
451542

452543
hip04_set_xmit_desc(priv, phys);
@@ -507,8 +598,8 @@ static int hip04_rx_poll(struct napi_struct *napi, int budget)
507598
priv->rx_phys[priv->rx_head] = 0;
508599

509600
desc = (struct rx_desc *)skb->data;
510-
len = be16_to_cpu(desc->pkt_len);
511-
err = be32_to_cpu(desc->pkt_err);
601+
len = be16_to_cpu((__force __be16)desc->pkt_len);
602+
err = be32_to_cpu((__force __be32)desc->pkt_err);
512603

513604
if (0 == len) {
514605
dev_kfree_skb_any(skb);
@@ -828,14 +919,24 @@ static int hip04_mac_probe(struct platform_device *pdev)
828919
goto init_fail;
829920
}
830921

831-
ret = of_parse_phandle_with_fixed_args(node, "port-handle", 2, 0, &arg);
922+
#if defined(CONFIG_HI13X1_GMAC)
923+
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
924+
priv->sysctrl_base = devm_ioremap_resource(d, res);
925+
if (IS_ERR(priv->sysctrl_base)) {
926+
ret = PTR_ERR(priv->sysctrl_base);
927+
goto init_fail;
928+
}
929+
#endif
930+
931+
ret = of_parse_phandle_with_fixed_args(node, "port-handle", 3, 0, &arg);
832932
if (ret < 0) {
833933
dev_warn(d, "no port-handle\n");
834934
goto init_fail;
835935
}
836936

837937
priv->port = arg.args[0];
838938
priv->chan = arg.args[1] * RX_DESC_NUM;
939+
priv->group = arg.args[2];
839940

840941
hrtimer_init(&priv->tx_coalesce_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
841942

@@ -896,6 +997,7 @@ static int hip04_mac_probe(struct platform_device *pdev)
896997
ndev->irq = irq;
897998
netif_napi_add(ndev, &priv->napi, hip04_rx_poll, NAPI_POLL_WEIGHT);
898999

1000+
hip04_reset_dreq(priv);
8991001
hip04_reset_ppe(priv);
9001002
if (priv->phy_mode == PHY_INTERFACE_MODE_MII)
9011003
hip04_config_port(ndev, SPEED_100, DUPLEX_FULL);

0 commit comments

Comments
 (0)