1 // SPDX-License-Identifier: GPL-2.0
2 /* Atheros AR71xx built-in ethernet mac driver
4 * Copyright (C) 2019 Oleksij Rempel <o.rempel@pengutronix.de>
6 * List of authors contributed to this driver before mainlining:
7 * Alexander Couzens <lynxis@fe80.eu>
8 * Christian Lamparter <chunkeey@gmail.com>
9 * Chuanhong Guo <gch981213@gmail.com>
10 * Daniel F. Dickinson <cshored@thecshore.com>
11 * David Bauer <mail@david-bauer.net>
12 * Felix Fietkau <nbd@nbd.name>
13 * Gabor Juhos <juhosg@freemail.hu>
14 * Hauke Mehrtens <hauke@hauke-m.de>
15 * Johann Neuhauser <johann@it-neuhauser.de>
16 * John Crispin <john@phrozen.org>
17 * Jo-Philipp Wich <jo@mein.io>
18 * Koen Vandeputte <koen.vandeputte@ncentric.com>
19 * Lucian Cristian <lucian.cristian@gmail.com>
20 * Matt Merhar <mattmerhar@protonmail.com>
21 * Milan Krstic <milan.krstic@gmail.com>
22 * Petr Štetiar <ynezz@true.cz>
23 * Rosen Penev <rosenp@gmail.com>
24 * Stephen Walker <stephendwalker+github@gmail.com>
25 * Vittorio Gambaletta <openwrt@vittgam.net>
26 * Weijie Gao <hackpascal@gmail.com>
27 * Imre Kaloz <kaloz@openwrt.org>
30 #include <linux/if_vlan.h>
31 #include <linux/mfd/syscon.h>
33 #include <linux/of_mdio.h>
34 #include <linux/of_net.h>
35 #include <linux/platform_device.h>
36 #include <linux/phylink.h>
37 #include <linux/regmap.h>
38 #include <linux/reset.h>
39 #include <linux/clk.h>
41 #include <net/selftests.h>
43 /* For our NAPI weight bigger does *NOT* mean better - it means more
44 * D-cache misses and lots more wasted cycles than we'll ever
45 * possibly gain from saving instructions.
47 #define AG71XX_NAPI_WEIGHT 32
48 #define AG71XX_OOM_REFILL (1 + HZ / 10)
50 #define AG71XX_INT_ERR (AG71XX_INT_RX_BE | AG71XX_INT_TX_BE)
51 #define AG71XX_INT_TX (AG71XX_INT_TX_PS)
52 #define AG71XX_INT_RX (AG71XX_INT_RX_PR | AG71XX_INT_RX_OF)
54 #define AG71XX_INT_POLL (AG71XX_INT_RX | AG71XX_INT_TX)
55 #define AG71XX_INT_INIT (AG71XX_INT_ERR | AG71XX_INT_POLL)
57 #define AG71XX_TX_MTU_LEN 1540
59 #define AG71XX_TX_RING_SPLIT 512
60 #define AG71XX_TX_RING_DS_PER_PKT DIV_ROUND_UP(AG71XX_TX_MTU_LEN, \
62 #define AG71XX_TX_RING_SIZE_DEFAULT 128
63 #define AG71XX_RX_RING_SIZE_DEFAULT 256
65 #define AG71XX_MDIO_RETRY 1000
66 #define AG71XX_MDIO_DELAY 5
67 #define AG71XX_MDIO_MAX_CLK 5000000
69 /* Register offsets */
70 #define AG71XX_REG_MAC_CFG1 0x0000
71 #define MAC_CFG1_TXE BIT(0) /* Tx Enable */
72 #define MAC_CFG1_STX BIT(1) /* Synchronize Tx Enable */
73 #define MAC_CFG1_RXE BIT(2) /* Rx Enable */
74 #define MAC_CFG1_SRX BIT(3) /* Synchronize Rx Enable */
75 #define MAC_CFG1_TFC BIT(4) /* Tx Flow Control Enable */
76 #define MAC_CFG1_RFC BIT(5) /* Rx Flow Control Enable */
77 #define MAC_CFG1_SR BIT(31) /* Soft Reset */
78 #define MAC_CFG1_INIT (MAC_CFG1_RXE | MAC_CFG1_TXE | \
79 MAC_CFG1_SRX | MAC_CFG1_STX)
81 #define AG71XX_REG_MAC_CFG2 0x0004
82 #define MAC_CFG2_FDX BIT(0)
83 #define MAC_CFG2_PAD_CRC_EN BIT(2)
84 #define MAC_CFG2_LEN_CHECK BIT(4)
85 #define MAC_CFG2_IF_1000 BIT(9)
86 #define MAC_CFG2_IF_10_100 BIT(8)
88 #define AG71XX_REG_MAC_MFL 0x0010
90 #define AG71XX_REG_MII_CFG 0x0020
91 #define MII_CFG_CLK_DIV_4 0
92 #define MII_CFG_CLK_DIV_6 2
93 #define MII_CFG_CLK_DIV_8 3
94 #define MII_CFG_CLK_DIV_10 4
95 #define MII_CFG_CLK_DIV_14 5
96 #define MII_CFG_CLK_DIV_20 6
97 #define MII_CFG_CLK_DIV_28 7
98 #define MII_CFG_CLK_DIV_34 8
99 #define MII_CFG_CLK_DIV_42 9
100 #define MII_CFG_CLK_DIV_50 10
101 #define MII_CFG_CLK_DIV_58 11
102 #define MII_CFG_CLK_DIV_66 12
103 #define MII_CFG_CLK_DIV_74 13
104 #define MII_CFG_CLK_DIV_82 14
105 #define MII_CFG_CLK_DIV_98 15
106 #define MII_CFG_RESET BIT(31)
108 #define AG71XX_REG_MII_CMD 0x0024
109 #define MII_CMD_READ BIT(0)
111 #define AG71XX_REG_MII_ADDR 0x0028
112 #define MII_ADDR_SHIFT 8
114 #define AG71XX_REG_MII_CTRL 0x002c
115 #define AG71XX_REG_MII_STATUS 0x0030
116 #define AG71XX_REG_MII_IND 0x0034
117 #define MII_IND_BUSY BIT(0)
118 #define MII_IND_INVALID BIT(2)
120 #define AG71XX_REG_MAC_IFCTL 0x0038
121 #define MAC_IFCTL_SPEED BIT(16)
123 #define AG71XX_REG_MAC_ADDR1 0x0040
124 #define AG71XX_REG_MAC_ADDR2 0x0044
125 #define AG71XX_REG_FIFO_CFG0 0x0048
126 #define FIFO_CFG0_WTM BIT(0) /* Watermark Module */
127 #define FIFO_CFG0_RXS BIT(1) /* Rx System Module */
128 #define FIFO_CFG0_RXF BIT(2) /* Rx Fabric Module */
129 #define FIFO_CFG0_TXS BIT(3) /* Tx System Module */
130 #define FIFO_CFG0_TXF BIT(4) /* Tx Fabric Module */
131 #define FIFO_CFG0_ALL (FIFO_CFG0_WTM | FIFO_CFG0_RXS | FIFO_CFG0_RXF \
132 | FIFO_CFG0_TXS | FIFO_CFG0_TXF)
133 #define FIFO_CFG0_INIT (FIFO_CFG0_ALL << FIFO_CFG0_ENABLE_SHIFT)
135 #define FIFO_CFG0_ENABLE_SHIFT 8
137 #define AG71XX_REG_FIFO_CFG1 0x004c
138 #define AG71XX_REG_FIFO_CFG2 0x0050
139 #define AG71XX_REG_FIFO_CFG3 0x0054
140 #define AG71XX_REG_FIFO_CFG4 0x0058
141 #define FIFO_CFG4_DE BIT(0) /* Drop Event */
142 #define FIFO_CFG4_DV BIT(1) /* RX_DV Event */
143 #define FIFO_CFG4_FC BIT(2) /* False Carrier */
144 #define FIFO_CFG4_CE BIT(3) /* Code Error */
145 #define FIFO_CFG4_CR BIT(4) /* CRC error */
146 #define FIFO_CFG4_LM BIT(5) /* Length Mismatch */
147 #define FIFO_CFG4_LO BIT(6) /* Length out of range */
148 #define FIFO_CFG4_OK BIT(7) /* Packet is OK */
149 #define FIFO_CFG4_MC BIT(8) /* Multicast Packet */
150 #define FIFO_CFG4_BC BIT(9) /* Broadcast Packet */
151 #define FIFO_CFG4_DR BIT(10) /* Dribble */
152 #define FIFO_CFG4_CF BIT(11) /* Control Frame */
153 #define FIFO_CFG4_PF BIT(12) /* Pause Frame */
154 #define FIFO_CFG4_UO BIT(13) /* Unsupported Opcode */
155 #define FIFO_CFG4_VT BIT(14) /* VLAN tag detected */
156 #define FIFO_CFG4_LE BIT(15) /* Long Event */
157 #define FIFO_CFG4_FT BIT(16) /* Frame Truncated */
158 #define FIFO_CFG4_UC BIT(17) /* Unicast Packet */
159 #define FIFO_CFG4_INIT (FIFO_CFG4_DE | FIFO_CFG4_DV | FIFO_CFG4_FC | \
160 FIFO_CFG4_CE | FIFO_CFG4_CR | FIFO_CFG4_LM | \
161 FIFO_CFG4_LO | FIFO_CFG4_OK | FIFO_CFG4_MC | \
162 FIFO_CFG4_BC | FIFO_CFG4_DR | FIFO_CFG4_LE | \
163 FIFO_CFG4_CF | FIFO_CFG4_PF | FIFO_CFG4_UO | \
166 #define AG71XX_REG_FIFO_CFG5 0x005c
167 #define FIFO_CFG5_DE BIT(0) /* Drop Event */
168 #define FIFO_CFG5_DV BIT(1) /* RX_DV Event */
169 #define FIFO_CFG5_FC BIT(2) /* False Carrier */
170 #define FIFO_CFG5_CE BIT(3) /* Code Error */
171 #define FIFO_CFG5_CR BIT(4) /* CRC error */
172 #define FIFO_CFG5_LM BIT(5) /* Length Mismatch */
173 #define FIFO_CFG5_LO BIT(6) /* Length Out of Range */
174 #define FIFO_CFG5_OK BIT(7) /* Packet is OK */
175 #define FIFO_CFG5_MC BIT(8) /* Multicast Packet */
176 #define FIFO_CFG5_BC BIT(9) /* Broadcast Packet */
177 #define FIFO_CFG5_DR BIT(10) /* Dribble */
178 #define FIFO_CFG5_CF BIT(11) /* Control Frame */
179 #define FIFO_CFG5_PF BIT(12) /* Pause Frame */
180 #define FIFO_CFG5_UO BIT(13) /* Unsupported Opcode */
181 #define FIFO_CFG5_VT BIT(14) /* VLAN tag detected */
182 #define FIFO_CFG5_LE BIT(15) /* Long Event */
183 #define FIFO_CFG5_FT BIT(16) /* Frame Truncated */
184 #define FIFO_CFG5_UC BIT(17) /* Unicast Packet */
185 #define FIFO_CFG5_SF BIT(18) /* Short Frame */
186 #define FIFO_CFG5_BM BIT(19) /* Byte Mode */
187 #define FIFO_CFG5_INIT (FIFO_CFG5_DE | FIFO_CFG5_DV | FIFO_CFG5_FC | \
188 FIFO_CFG5_CE | FIFO_CFG5_LM | FIFO_CFG5_LO | \
189 FIFO_CFG5_OK | FIFO_CFG5_MC | FIFO_CFG5_BC | \
190 FIFO_CFG5_DR | FIFO_CFG5_CF | FIFO_CFG5_UO | \
191 FIFO_CFG5_VT | FIFO_CFG5_LE | FIFO_CFG5_FT | \
192 FIFO_CFG5_UC | FIFO_CFG5_SF)
194 #define AG71XX_REG_TX_CTRL 0x0180
195 #define TX_CTRL_TXE BIT(0) /* Tx Enable */
197 #define AG71XX_REG_TX_DESC 0x0184
198 #define AG71XX_REG_TX_STATUS 0x0188
199 #define TX_STATUS_PS BIT(0) /* Packet Sent */
200 #define TX_STATUS_UR BIT(1) /* Tx Underrun */
201 #define TX_STATUS_BE BIT(3) /* Bus Error */
203 #define AG71XX_REG_RX_CTRL 0x018c
204 #define RX_CTRL_RXE BIT(0) /* Rx Enable */
206 #define AG71XX_DMA_RETRY 10
207 #define AG71XX_DMA_DELAY 1
209 #define AG71XX_REG_RX_DESC 0x0190
210 #define AG71XX_REG_RX_STATUS 0x0194
211 #define RX_STATUS_PR BIT(0) /* Packet Received */
212 #define RX_STATUS_OF BIT(2) /* Rx Overflow */
213 #define RX_STATUS_BE BIT(3) /* Bus Error */
215 #define AG71XX_REG_INT_ENABLE 0x0198
216 #define AG71XX_REG_INT_STATUS 0x019c
217 #define AG71XX_INT_TX_PS BIT(0)
218 #define AG71XX_INT_TX_UR BIT(1)
219 #define AG71XX_INT_TX_BE BIT(3)
220 #define AG71XX_INT_RX_PR BIT(4)
221 #define AG71XX_INT_RX_OF BIT(6)
222 #define AG71XX_INT_RX_BE BIT(7)
224 #define AG71XX_REG_FIFO_DEPTH 0x01a8
225 #define AG71XX_REG_RX_SM 0x01b0
226 #define AG71XX_REG_TX_SM 0x01b4
228 #define AG71XX_DEFAULT_MSG_ENABLE \
238 struct ag71xx_statistic
{
239 unsigned short offset
;
241 const char name
[ETH_GSTRING_LEN
];
244 static const struct ag71xx_statistic ag71xx_statistics
[] = {
245 { 0x0080, GENMASK(17, 0), "Tx/Rx 64 Byte", },
246 { 0x0084, GENMASK(17, 0), "Tx/Rx 65-127 Byte", },
247 { 0x0088, GENMASK(17, 0), "Tx/Rx 128-255 Byte", },
248 { 0x008C, GENMASK(17, 0), "Tx/Rx 256-511 Byte", },
249 { 0x0090, GENMASK(17, 0), "Tx/Rx 512-1023 Byte", },
250 { 0x0094, GENMASK(17, 0), "Tx/Rx 1024-1518 Byte", },
251 { 0x0098, GENMASK(17, 0), "Tx/Rx 1519-1522 Byte VLAN", },
252 { 0x009C, GENMASK(23, 0), "Rx Byte", },
253 { 0x00A0, GENMASK(17, 0), "Rx Packet", },
254 { 0x00A4, GENMASK(11, 0), "Rx FCS Error", },
255 { 0x00A8, GENMASK(17, 0), "Rx Multicast Packet", },
256 { 0x00AC, GENMASK(21, 0), "Rx Broadcast Packet", },
257 { 0x00B0, GENMASK(17, 0), "Rx Control Frame Packet", },
258 { 0x00B4, GENMASK(11, 0), "Rx Pause Frame Packet", },
259 { 0x00B8, GENMASK(11, 0), "Rx Unknown OPCode Packet", },
260 { 0x00BC, GENMASK(11, 0), "Rx Alignment Error", },
261 { 0x00C0, GENMASK(15, 0), "Rx Frame Length Error", },
262 { 0x00C4, GENMASK(11, 0), "Rx Code Error", },
263 { 0x00C8, GENMASK(11, 0), "Rx Carrier Sense Error", },
264 { 0x00CC, GENMASK(11, 0), "Rx Undersize Packet", },
265 { 0x00D0, GENMASK(11, 0), "Rx Oversize Packet", },
266 { 0x00D4, GENMASK(11, 0), "Rx Fragments", },
267 { 0x00D8, GENMASK(11, 0), "Rx Jabber", },
268 { 0x00DC, GENMASK(11, 0), "Rx Dropped Packet", },
269 { 0x00E0, GENMASK(23, 0), "Tx Byte", },
270 { 0x00E4, GENMASK(17, 0), "Tx Packet", },
271 { 0x00E8, GENMASK(17, 0), "Tx Multicast Packet", },
272 { 0x00EC, GENMASK(17, 0), "Tx Broadcast Packet", },
273 { 0x00F0, GENMASK(11, 0), "Tx Pause Control Frame", },
274 { 0x00F4, GENMASK(11, 0), "Tx Deferral Packet", },
275 { 0x00F8, GENMASK(11, 0), "Tx Excessive Deferral Packet", },
276 { 0x00FC, GENMASK(11, 0), "Tx Single Collision Packet", },
277 { 0x0100, GENMASK(11, 0), "Tx Multiple Collision", },
278 { 0x0104, GENMASK(11, 0), "Tx Late Collision Packet", },
279 { 0x0108, GENMASK(11, 0), "Tx Excessive Collision Packet", },
280 { 0x010C, GENMASK(12, 0), "Tx Total Collision", },
281 { 0x0110, GENMASK(11, 0), "Tx Pause Frames Honored", },
282 { 0x0114, GENMASK(11, 0), "Tx Drop Frame", },
283 { 0x0118, GENMASK(11, 0), "Tx Jabber Frame", },
284 { 0x011C, GENMASK(11, 0), "Tx FCS Error", },
285 { 0x0120, GENMASK(11, 0), "Tx Control Frame", },
286 { 0x0124, GENMASK(11, 0), "Tx Oversize Frame", },
287 { 0x0128, GENMASK(11, 0), "Tx Undersize Frame", },
288 { 0x012C, GENMASK(11, 0), "Tx Fragment", },
291 #define DESC_EMPTY BIT(31)
292 #define DESC_MORE BIT(24)
293 #define DESC_PKTLEN_M 0xfff
301 #define AG71XX_DESC_SIZE roundup(sizeof(struct ag71xx_desc), \
318 /* "Hot" fields in the data path. */
322 /* "Cold" fields - not used in the data path. */
323 struct ag71xx_buf
*buf
;
326 dma_addr_t descs_dma
;
343 u16 desc_pktlen_mask
;
344 bool tx_hang_workaround
;
345 enum ag71xx_type type
;
349 /* Critical data related to the per-packet data path are clustered
350 * early in this structure to help improve the D-cache footprint.
352 struct ag71xx_ring rx_ring ____cacheline_aligned
;
353 struct ag71xx_ring tx_ring ____cacheline_aligned
;
358 struct net_device
*ndev
;
359 struct platform_device
*pdev
;
360 struct napi_struct napi
;
362 const struct ag71xx_dcfg
*dcfg
;
364 /* From this point onwards we're not looking at per-packet fields. */
365 void __iomem
*mac_base
;
367 struct ag71xx_desc
*stop_desc
;
368 dma_addr_t stop_desc_dma
;
370 phy_interface_t phy_if_mode
;
371 struct phylink
*phylink
;
372 struct phylink_config phylink_config
;
374 struct delayed_work restart_work
;
375 struct timer_list oom_timer
;
377 struct reset_control
*mac_reset
;
382 struct clk
*clk_mdio
;
385 static int ag71xx_desc_empty(struct ag71xx_desc
*desc
)
387 return (desc
->ctrl
& DESC_EMPTY
) != 0;
390 static struct ag71xx_desc
*ag71xx_ring_desc(struct ag71xx_ring
*ring
, int idx
)
392 return (struct ag71xx_desc
*)&ring
->descs_cpu
[idx
* AG71XX_DESC_SIZE
];
395 static int ag71xx_ring_size_order(int size
)
397 return fls(size
- 1);
400 static bool ag71xx_is(struct ag71xx
*ag
, enum ag71xx_type type
)
402 return ag
->dcfg
->type
== type
;
405 static void ag71xx_wr(struct ag71xx
*ag
, unsigned int reg
, u32 value
)
407 iowrite32(value
, ag
->mac_base
+ reg
);
409 (void)ioread32(ag
->mac_base
+ reg
);
412 static u32
ag71xx_rr(struct ag71xx
*ag
, unsigned int reg
)
414 return ioread32(ag
->mac_base
+ reg
);
417 static void ag71xx_sb(struct ag71xx
*ag
, unsigned int reg
, u32 mask
)
421 r
= ag
->mac_base
+ reg
;
422 iowrite32(ioread32(r
) | mask
, r
);
427 static void ag71xx_cb(struct ag71xx
*ag
, unsigned int reg
, u32 mask
)
431 r
= ag
->mac_base
+ reg
;
432 iowrite32(ioread32(r
) & ~mask
, r
);
437 static void ag71xx_int_enable(struct ag71xx
*ag
, u32 ints
)
439 ag71xx_sb(ag
, AG71XX_REG_INT_ENABLE
, ints
);
442 static void ag71xx_int_disable(struct ag71xx
*ag
, u32 ints
)
444 ag71xx_cb(ag
, AG71XX_REG_INT_ENABLE
, ints
);
447 static int ag71xx_do_ioctl(struct net_device
*ndev
, struct ifreq
*ifr
, int cmd
)
449 struct ag71xx
*ag
= netdev_priv(ndev
);
451 return phylink_mii_ioctl(ag
->phylink
, ifr
, cmd
);
454 static void ag71xx_get_drvinfo(struct net_device
*ndev
,
455 struct ethtool_drvinfo
*info
)
457 struct ag71xx
*ag
= netdev_priv(ndev
);
459 strscpy(info
->driver
, "ag71xx", sizeof(info
->driver
));
460 strscpy(info
->bus_info
, of_node_full_name(ag
->pdev
->dev
.of_node
),
461 sizeof(info
->bus_info
));
464 static int ag71xx_get_link_ksettings(struct net_device
*ndev
,
465 struct ethtool_link_ksettings
*kset
)
467 struct ag71xx
*ag
= netdev_priv(ndev
);
469 return phylink_ethtool_ksettings_get(ag
->phylink
, kset
);
472 static int ag71xx_set_link_ksettings(struct net_device
*ndev
,
473 const struct ethtool_link_ksettings
*kset
)
475 struct ag71xx
*ag
= netdev_priv(ndev
);
477 return phylink_ethtool_ksettings_set(ag
->phylink
, kset
);
480 static int ag71xx_ethtool_nway_reset(struct net_device
*ndev
)
482 struct ag71xx
*ag
= netdev_priv(ndev
);
484 return phylink_ethtool_nway_reset(ag
->phylink
);
487 static void ag71xx_ethtool_get_pauseparam(struct net_device
*ndev
,
488 struct ethtool_pauseparam
*pause
)
490 struct ag71xx
*ag
= netdev_priv(ndev
);
492 phylink_ethtool_get_pauseparam(ag
->phylink
, pause
);
495 static int ag71xx_ethtool_set_pauseparam(struct net_device
*ndev
,
496 struct ethtool_pauseparam
*pause
)
498 struct ag71xx
*ag
= netdev_priv(ndev
);
500 return phylink_ethtool_set_pauseparam(ag
->phylink
, pause
);
503 static void ag71xx_ethtool_get_strings(struct net_device
*netdev
, u32 sset
,
510 for (i
= 0; i
< ARRAY_SIZE(ag71xx_statistics
); i
++)
511 ethtool_puts(&data
, ag71xx_statistics
[i
].name
);
514 net_selftest_get_strings(data
);
519 static void ag71xx_ethtool_get_stats(struct net_device
*ndev
,
520 struct ethtool_stats
*stats
, u64
*data
)
522 struct ag71xx
*ag
= netdev_priv(ndev
);
525 for (i
= 0; i
< ARRAY_SIZE(ag71xx_statistics
); i
++)
526 *data
++ = ag71xx_rr(ag
, ag71xx_statistics
[i
].offset
)
527 & ag71xx_statistics
[i
].mask
;
530 static int ag71xx_ethtool_get_sset_count(struct net_device
*ndev
, int sset
)
534 return ARRAY_SIZE(ag71xx_statistics
);
536 return net_selftest_get_count();
542 static const struct ethtool_ops ag71xx_ethtool_ops
= {
543 .get_drvinfo
= ag71xx_get_drvinfo
,
544 .get_link
= ethtool_op_get_link
,
545 .get_ts_info
= ethtool_op_get_ts_info
,
546 .get_link_ksettings
= ag71xx_get_link_ksettings
,
547 .set_link_ksettings
= ag71xx_set_link_ksettings
,
548 .nway_reset
= ag71xx_ethtool_nway_reset
,
549 .get_pauseparam
= ag71xx_ethtool_get_pauseparam
,
550 .set_pauseparam
= ag71xx_ethtool_set_pauseparam
,
551 .get_strings
= ag71xx_ethtool_get_strings
,
552 .get_ethtool_stats
= ag71xx_ethtool_get_stats
,
553 .get_sset_count
= ag71xx_ethtool_get_sset_count
,
554 .self_test
= net_selftest
,
557 static int ag71xx_mdio_wait_busy(struct ag71xx
*ag
)
559 struct net_device
*ndev
= ag
->ndev
;
562 for (i
= 0; i
< AG71XX_MDIO_RETRY
; i
++) {
565 udelay(AG71XX_MDIO_DELAY
);
567 busy
= ag71xx_rr(ag
, AG71XX_REG_MII_IND
);
571 udelay(AG71XX_MDIO_DELAY
);
574 netif_err(ag
, link
, ndev
, "MDIO operation timed out\n");
579 static int ag71xx_mdio_mii_read(struct mii_bus
*bus
, int addr
, int reg
)
581 struct ag71xx
*ag
= bus
->priv
;
584 err
= ag71xx_mdio_wait_busy(ag
);
588 ag71xx_wr(ag
, AG71XX_REG_MII_ADDR
,
589 ((addr
& 0x1f) << MII_ADDR_SHIFT
) | (reg
& 0xff));
590 /* enable read mode */
591 ag71xx_wr(ag
, AG71XX_REG_MII_CMD
, MII_CMD_READ
);
593 err
= ag71xx_mdio_wait_busy(ag
);
597 val
= ag71xx_rr(ag
, AG71XX_REG_MII_STATUS
);
598 /* disable read mode */
599 ag71xx_wr(ag
, AG71XX_REG_MII_CMD
, 0);
601 netif_dbg(ag
, link
, ag
->ndev
, "mii_read: addr=%04x, reg=%04x, value=%04x\n",
607 static int ag71xx_mdio_mii_write(struct mii_bus
*bus
, int addr
, int reg
,
610 struct ag71xx
*ag
= bus
->priv
;
612 netif_dbg(ag
, link
, ag
->ndev
, "mii_write: addr=%04x, reg=%04x, value=%04x\n",
615 ag71xx_wr(ag
, AG71XX_REG_MII_ADDR
,
616 ((addr
& 0x1f) << MII_ADDR_SHIFT
) | (reg
& 0xff));
617 ag71xx_wr(ag
, AG71XX_REG_MII_CTRL
, val
);
619 return ag71xx_mdio_wait_busy(ag
);
622 static const u32 ar71xx_mdio_div_table
[] = {
623 4, 4, 6, 8, 10, 14, 20, 28,
626 static const u32 ar7240_mdio_div_table
[] = {
627 2, 2, 4, 6, 8, 12, 18, 26, 32, 40, 48, 56, 62, 70, 78, 96,
630 static const u32 ar933x_mdio_div_table
[] = {
631 4, 4, 6, 8, 10, 14, 20, 28, 34, 42, 50, 58, 66, 74, 82, 98,
634 static int ag71xx_mdio_get_divider(struct ag71xx
*ag
, u32
*div
)
636 unsigned long ref_clock
;
640 ref_clock
= clk_get_rate(ag
->clk_mdio
);
644 if (ag71xx_is(ag
, AR9330
) || ag71xx_is(ag
, AR9340
)) {
645 table
= ar933x_mdio_div_table
;
646 ndivs
= ARRAY_SIZE(ar933x_mdio_div_table
);
647 } else if (ag71xx_is(ag
, AR7240
)) {
648 table
= ar7240_mdio_div_table
;
649 ndivs
= ARRAY_SIZE(ar7240_mdio_div_table
);
651 table
= ar71xx_mdio_div_table
;
652 ndivs
= ARRAY_SIZE(ar71xx_mdio_div_table
);
655 for (i
= 0; i
< ndivs
; i
++) {
658 t
= ref_clock
/ table
[i
];
659 if (t
<= AG71XX_MDIO_MAX_CLK
) {
668 static int ag71xx_mdio_reset(struct mii_bus
*bus
)
670 struct ag71xx
*ag
= bus
->priv
;
674 err
= ag71xx_mdio_get_divider(ag
, &t
);
678 ag71xx_wr(ag
, AG71XX_REG_MII_CFG
, t
| MII_CFG_RESET
);
679 usleep_range(100, 200);
681 ag71xx_wr(ag
, AG71XX_REG_MII_CFG
, t
);
682 usleep_range(100, 200);
687 static int ag71xx_mdio_probe(struct ag71xx
*ag
)
689 struct device
*dev
= &ag
->pdev
->dev
;
690 struct net_device
*ndev
= ag
->ndev
;
691 struct reset_control
*mdio_reset
;
692 static struct mii_bus
*mii_bus
;
693 struct device_node
*np
, *mnp
;
698 ag
->clk_mdio
= devm_clk_get_enabled(dev
, "mdio");
699 if (IS_ERR(ag
->clk_mdio
)) {
700 netif_err(ag
, probe
, ndev
, "Failed to get mdio clk.\n");
701 return PTR_ERR(ag
->clk_mdio
);
704 mii_bus
= devm_mdiobus_alloc(dev
);
708 mdio_reset
= devm_reset_control_get_exclusive(dev
, "mdio");
709 if (IS_ERR(mdio_reset
)) {
710 netif_err(ag
, probe
, ndev
, "Failed to get reset mdio.\n");
711 return PTR_ERR(mdio_reset
);
714 mii_bus
->name
= "ag71xx_mdio";
715 mii_bus
->read
= ag71xx_mdio_mii_read
;
716 mii_bus
->write
= ag71xx_mdio_mii_write
;
717 mii_bus
->reset
= ag71xx_mdio_reset
;
719 mii_bus
->parent
= dev
;
720 snprintf(mii_bus
->id
, MII_BUS_ID_SIZE
, "%s.%d", np
->name
, ag
->mac_idx
);
722 reset_control_assert(mdio_reset
);
724 reset_control_deassert(mdio_reset
);
727 mnp
= of_get_child_by_name(np
, "mdio");
728 err
= devm_of_mdiobus_register(dev
, mii_bus
, mnp
);
736 static void ag71xx_hw_stop(struct ag71xx
*ag
)
738 /* disable all interrupts and stop the rx/tx engine */
739 ag71xx_wr(ag
, AG71XX_REG_INT_ENABLE
, 0);
740 ag71xx_wr(ag
, AG71XX_REG_RX_CTRL
, 0);
741 ag71xx_wr(ag
, AG71XX_REG_TX_CTRL
, 0);
744 static bool ag71xx_check_dma_stuck(struct ag71xx
*ag
)
746 unsigned long timestamp
;
747 u32 rx_sm
, tx_sm
, rx_fd
;
749 timestamp
= READ_ONCE(netdev_get_tx_queue(ag
->ndev
, 0)->trans_start
);
750 if (likely(time_before(jiffies
, timestamp
+ HZ
/ 10)))
753 if (!netif_carrier_ok(ag
->ndev
))
756 rx_sm
= ag71xx_rr(ag
, AG71XX_REG_RX_SM
);
757 if ((rx_sm
& 0x7) == 0x3 && ((rx_sm
>> 4) & 0x7) == 0x6)
760 tx_sm
= ag71xx_rr(ag
, AG71XX_REG_TX_SM
);
761 rx_fd
= ag71xx_rr(ag
, AG71XX_REG_FIFO_DEPTH
);
762 if (((tx_sm
>> 4) & 0x7) == 0 && ((rx_sm
& 0x7) == 0) &&
763 ((rx_sm
>> 4) & 0x7) == 0 && rx_fd
== 0)
769 static int ag71xx_tx_packets(struct ag71xx
*ag
, bool flush
, int budget
)
771 struct ag71xx_ring
*ring
= &ag
->tx_ring
;
772 int sent
= 0, bytes_compl
= 0, n
= 0;
773 struct net_device
*ndev
= ag
->ndev
;
774 int ring_mask
, ring_size
;
775 bool dma_stuck
= false;
777 ring_mask
= BIT(ring
->order
) - 1;
778 ring_size
= BIT(ring
->order
);
780 netif_dbg(ag
, tx_queued
, ndev
, "processing TX ring\n");
782 while (ring
->dirty
+ n
!= ring
->curr
) {
783 struct ag71xx_desc
*desc
;
787 i
= (ring
->dirty
+ n
) & ring_mask
;
788 desc
= ag71xx_ring_desc(ring
, i
);
789 skb
= ring
->buf
[i
].tx
.skb
;
791 if (!flush
&& !ag71xx_desc_empty(desc
)) {
792 if (ag
->dcfg
->tx_hang_workaround
&&
793 ag71xx_check_dma_stuck(ag
)) {
794 schedule_delayed_work(&ag
->restart_work
,
802 desc
->ctrl
|= DESC_EMPTY
;
808 napi_consume_skb(skb
, budget
);
809 ring
->buf
[i
].tx
.skb
= NULL
;
811 bytes_compl
+= ring
->buf
[i
].tx
.len
;
817 ag71xx_wr(ag
, AG71XX_REG_TX_STATUS
, TX_STATUS_PS
);
822 netif_dbg(ag
, tx_done
, ndev
, "%d packets sent out\n", sent
);
827 ag
->ndev
->stats
.tx_bytes
+= bytes_compl
;
828 ag
->ndev
->stats
.tx_packets
+= sent
;
830 netdev_completed_queue(ag
->ndev
, sent
, bytes_compl
);
831 if ((ring
->curr
- ring
->dirty
) < (ring_size
* 3) / 4)
832 netif_wake_queue(ag
->ndev
);
835 cancel_delayed_work(&ag
->restart_work
);
840 static void ag71xx_dma_wait_stop(struct ag71xx
*ag
)
842 struct net_device
*ndev
= ag
->ndev
;
845 for (i
= 0; i
< AG71XX_DMA_RETRY
; i
++) {
848 mdelay(AG71XX_DMA_DELAY
);
850 rx
= ag71xx_rr(ag
, AG71XX_REG_RX_CTRL
) & RX_CTRL_RXE
;
851 tx
= ag71xx_rr(ag
, AG71XX_REG_TX_CTRL
) & TX_CTRL_TXE
;
856 netif_err(ag
, hw
, ndev
, "DMA stop operation timed out\n");
859 static void ag71xx_dma_reset(struct ag71xx
*ag
)
861 struct net_device
*ndev
= ag
->ndev
;
866 ag71xx_wr(ag
, AG71XX_REG_RX_CTRL
, 0);
867 ag71xx_wr(ag
, AG71XX_REG_TX_CTRL
, 0);
869 /* give the hardware some time to really stop all rx/tx activity
870 * clearing the descriptors too early causes random memory corruption
872 ag71xx_dma_wait_stop(ag
);
874 /* clear descriptor addresses */
875 ag71xx_wr(ag
, AG71XX_REG_TX_DESC
, ag
->stop_desc_dma
);
876 ag71xx_wr(ag
, AG71XX_REG_RX_DESC
, ag
->stop_desc_dma
);
878 /* clear pending RX/TX interrupts */
879 for (i
= 0; i
< 256; i
++) {
880 ag71xx_wr(ag
, AG71XX_REG_RX_STATUS
, RX_STATUS_PR
);
881 ag71xx_wr(ag
, AG71XX_REG_TX_STATUS
, TX_STATUS_PS
);
884 /* clear pending errors */
885 ag71xx_wr(ag
, AG71XX_REG_RX_STATUS
, RX_STATUS_BE
| RX_STATUS_OF
);
886 ag71xx_wr(ag
, AG71XX_REG_TX_STATUS
, TX_STATUS_BE
| TX_STATUS_UR
);
888 val
= ag71xx_rr(ag
, AG71XX_REG_RX_STATUS
);
890 netif_err(ag
, hw
, ndev
, "unable to clear DMA Rx status: %08x\n",
893 val
= ag71xx_rr(ag
, AG71XX_REG_TX_STATUS
);
895 /* mask out reserved bits */
899 netif_err(ag
, hw
, ndev
, "unable to clear DMA Tx status: %08x\n",
903 static void ag71xx_hw_setup(struct ag71xx
*ag
)
905 u32 init
= MAC_CFG1_INIT
;
907 /* setup MAC configuration registers */
908 ag71xx_wr(ag
, AG71XX_REG_MAC_CFG1
, init
);
910 ag71xx_sb(ag
, AG71XX_REG_MAC_CFG2
,
911 MAC_CFG2_PAD_CRC_EN
| MAC_CFG2_LEN_CHECK
);
913 /* setup max frame length to zero */
914 ag71xx_wr(ag
, AG71XX_REG_MAC_MFL
, 0);
916 /* setup FIFO configuration registers */
917 ag71xx_wr(ag
, AG71XX_REG_FIFO_CFG0
, FIFO_CFG0_INIT
);
918 ag71xx_wr(ag
, AG71XX_REG_FIFO_CFG1
, ag
->fifodata
[0]);
919 ag71xx_wr(ag
, AG71XX_REG_FIFO_CFG2
, ag
->fifodata
[1]);
920 ag71xx_wr(ag
, AG71XX_REG_FIFO_CFG4
, FIFO_CFG4_INIT
);
921 ag71xx_wr(ag
, AG71XX_REG_FIFO_CFG5
, FIFO_CFG5_INIT
);
924 static unsigned int ag71xx_max_frame_len(unsigned int mtu
)
926 return ETH_HLEN
+ VLAN_HLEN
+ mtu
+ ETH_FCS_LEN
;
929 static void ag71xx_hw_set_macaddr(struct ag71xx
*ag
, const unsigned char *mac
)
933 t
= (((u32
)mac
[5]) << 24) | (((u32
)mac
[4]) << 16)
934 | (((u32
)mac
[3]) << 8) | ((u32
)mac
[2]);
936 ag71xx_wr(ag
, AG71XX_REG_MAC_ADDR1
, t
);
938 t
= (((u32
)mac
[1]) << 24) | (((u32
)mac
[0]) << 16);
939 ag71xx_wr(ag
, AG71XX_REG_MAC_ADDR2
, t
);
942 static void ag71xx_fast_reset(struct ag71xx
*ag
)
944 struct net_device
*dev
= ag
->ndev
;
950 mii_reg
= ag71xx_rr(ag
, AG71XX_REG_MII_CFG
);
951 rx_ds
= ag71xx_rr(ag
, AG71XX_REG_RX_DESC
);
953 ag71xx_tx_packets(ag
, true, 0);
955 reset_control_assert(ag
->mac_reset
);
956 usleep_range(10, 20);
957 reset_control_deassert(ag
->mac_reset
);
958 usleep_range(10, 20);
960 ag71xx_dma_reset(ag
);
962 ag
->tx_ring
.curr
= 0;
963 ag
->tx_ring
.dirty
= 0;
964 netdev_reset_queue(ag
->ndev
);
966 /* setup max frame length */
967 ag71xx_wr(ag
, AG71XX_REG_MAC_MFL
,
968 ag71xx_max_frame_len(ag
->ndev
->mtu
));
970 ag71xx_wr(ag
, AG71XX_REG_RX_DESC
, rx_ds
);
971 ag71xx_wr(ag
, AG71XX_REG_TX_DESC
, ag
->tx_ring
.descs_dma
);
972 ag71xx_wr(ag
, AG71XX_REG_MII_CFG
, mii_reg
);
974 ag71xx_hw_set_macaddr(ag
, dev
->dev_addr
);
977 static void ag71xx_hw_start(struct ag71xx
*ag
)
979 /* start RX engine */
980 ag71xx_wr(ag
, AG71XX_REG_RX_CTRL
, RX_CTRL_RXE
);
982 /* enable interrupts */
983 ag71xx_wr(ag
, AG71XX_REG_INT_ENABLE
, AG71XX_INT_INIT
);
985 netif_wake_queue(ag
->ndev
);
988 static void ag71xx_mac_config(struct phylink_config
*config
, unsigned int mode
,
989 const struct phylink_link_state
*state
)
991 struct ag71xx
*ag
= netdev_priv(to_net_dev(config
->dev
));
993 if (phylink_autoneg_inband(mode
))
996 if (!ag71xx_is(ag
, AR7100
) && !ag71xx_is(ag
, AR9130
))
997 ag71xx_fast_reset(ag
);
999 if (ag
->tx_ring
.desc_split
) {
1000 ag
->fifodata
[2] &= 0xffff;
1001 ag
->fifodata
[2] |= ((2048 - ag
->tx_ring
.desc_split
) / 4) << 16;
1004 ag71xx_wr(ag
, AG71XX_REG_FIFO_CFG3
, ag
->fifodata
[2]);
1007 static void ag71xx_mac_link_down(struct phylink_config
*config
,
1008 unsigned int mode
, phy_interface_t interface
)
1010 struct ag71xx
*ag
= netdev_priv(to_net_dev(config
->dev
));
1015 static void ag71xx_mac_link_up(struct phylink_config
*config
,
1016 struct phy_device
*phy
,
1017 unsigned int mode
, phy_interface_t interface
,
1018 int speed
, int duplex
,
1019 bool tx_pause
, bool rx_pause
)
1021 struct ag71xx
*ag
= netdev_priv(to_net_dev(config
->dev
));
1026 cfg2
= ag71xx_rr(ag
, AG71XX_REG_MAC_CFG2
);
1027 cfg2
&= ~(MAC_CFG2_IF_1000
| MAC_CFG2_IF_10_100
| MAC_CFG2_FDX
);
1028 cfg2
|= duplex
? MAC_CFG2_FDX
: 0;
1030 ifctl
= ag71xx_rr(ag
, AG71XX_REG_MAC_IFCTL
);
1031 ifctl
&= ~(MAC_IFCTL_SPEED
);
1033 fifo5
= ag71xx_rr(ag
, AG71XX_REG_FIFO_CFG5
);
1034 fifo5
&= ~FIFO_CFG5_BM
;
1038 cfg2
|= MAC_CFG2_IF_1000
;
1039 fifo5
|= FIFO_CFG5_BM
;
1042 cfg2
|= MAC_CFG2_IF_10_100
;
1043 ifctl
|= MAC_IFCTL_SPEED
;
1046 cfg2
|= MAC_CFG2_IF_10_100
;
1052 ag71xx_wr(ag
, AG71XX_REG_MAC_CFG2
, cfg2
);
1053 ag71xx_wr(ag
, AG71XX_REG_FIFO_CFG5
, fifo5
);
1054 ag71xx_wr(ag
, AG71XX_REG_MAC_IFCTL
, ifctl
);
1056 cfg1
= ag71xx_rr(ag
, AG71XX_REG_MAC_CFG1
);
1057 cfg1
&= ~(MAC_CFG1_TFC
| MAC_CFG1_RFC
);
1059 cfg1
|= MAC_CFG1_TFC
;
1062 cfg1
|= MAC_CFG1_RFC
;
1063 ag71xx_wr(ag
, AG71XX_REG_MAC_CFG1
, cfg1
);
1065 ag71xx_hw_start(ag
);
1068 static const struct phylink_mac_ops ag71xx_phylink_mac_ops
= {
1069 .mac_config
= ag71xx_mac_config
,
1070 .mac_link_down
= ag71xx_mac_link_down
,
1071 .mac_link_up
= ag71xx_mac_link_up
,
1074 static int ag71xx_phylink_setup(struct ag71xx
*ag
)
1076 struct phylink
*phylink
;
1078 ag
->phylink_config
.dev
= &ag
->ndev
->dev
;
1079 ag
->phylink_config
.type
= PHYLINK_NETDEV
;
1080 ag
->phylink_config
.mac_capabilities
= MAC_SYM_PAUSE
| MAC_ASYM_PAUSE
|
1081 MAC_10
| MAC_100
| MAC_1000FD
;
1083 if ((ag71xx_is(ag
, AR9330
) && ag
->mac_idx
== 0) ||
1084 ag71xx_is(ag
, AR9340
) ||
1085 ag71xx_is(ag
, QCA9530
) ||
1086 (ag71xx_is(ag
, QCA9550
) && ag
->mac_idx
== 1))
1087 __set_bit(PHY_INTERFACE_MODE_MII
,
1088 ag
->phylink_config
.supported_interfaces
);
1090 if ((ag71xx_is(ag
, AR9330
) && ag
->mac_idx
== 1) ||
1091 (ag71xx_is(ag
, AR9340
) && ag
->mac_idx
== 1) ||
1092 (ag71xx_is(ag
, QCA9530
) && ag
->mac_idx
== 1))
1093 __set_bit(PHY_INTERFACE_MODE_GMII
,
1094 ag
->phylink_config
.supported_interfaces
);
1096 if (ag71xx_is(ag
, QCA9550
) && ag
->mac_idx
== 0)
1097 __set_bit(PHY_INTERFACE_MODE_SGMII
,
1098 ag
->phylink_config
.supported_interfaces
);
1100 if (ag71xx_is(ag
, AR9340
) && ag
->mac_idx
== 0)
1101 __set_bit(PHY_INTERFACE_MODE_RMII
,
1102 ag
->phylink_config
.supported_interfaces
);
1104 if ((ag71xx_is(ag
, AR9340
) && ag
->mac_idx
== 0) ||
1105 (ag71xx_is(ag
, QCA9550
) && ag
->mac_idx
== 1))
1106 __set_bit(PHY_INTERFACE_MODE_RGMII
,
1107 ag
->phylink_config
.supported_interfaces
);
1109 phylink
= phylink_create(&ag
->phylink_config
, ag
->pdev
->dev
.fwnode
,
1110 ag
->phy_if_mode
, &ag71xx_phylink_mac_ops
);
1111 if (IS_ERR(phylink
))
1112 return PTR_ERR(phylink
);
1114 ag
->phylink
= phylink
;
1118 static void ag71xx_ring_tx_clean(struct ag71xx
*ag
)
1120 struct ag71xx_ring
*ring
= &ag
->tx_ring
;
1121 int ring_mask
= BIT(ring
->order
) - 1;
1122 u32 bytes_compl
= 0, pkts_compl
= 0;
1123 struct net_device
*ndev
= ag
->ndev
;
1125 while (ring
->curr
!= ring
->dirty
) {
1126 struct ag71xx_desc
*desc
;
1127 u32 i
= ring
->dirty
& ring_mask
;
1129 desc
= ag71xx_ring_desc(ring
, i
);
1130 if (!ag71xx_desc_empty(desc
)) {
1132 ndev
->stats
.tx_errors
++;
1135 if (ring
->buf
[i
].tx
.skb
) {
1136 bytes_compl
+= ring
->buf
[i
].tx
.len
;
1138 dev_kfree_skb_any(ring
->buf
[i
].tx
.skb
);
1140 ring
->buf
[i
].tx
.skb
= NULL
;
1144 /* flush descriptors */
1147 netdev_completed_queue(ndev
, pkts_compl
, bytes_compl
);
1150 static void ag71xx_ring_tx_init(struct ag71xx
*ag
)
1152 struct ag71xx_ring
*ring
= &ag
->tx_ring
;
1153 int ring_size
= BIT(ring
->order
);
1154 int ring_mask
= ring_size
- 1;
1157 for (i
= 0; i
< ring_size
; i
++) {
1158 struct ag71xx_desc
*desc
= ag71xx_ring_desc(ring
, i
);
1160 desc
->next
= (u32
)(ring
->descs_dma
+
1161 AG71XX_DESC_SIZE
* ((i
+ 1) & ring_mask
));
1163 desc
->ctrl
= DESC_EMPTY
;
1164 ring
->buf
[i
].tx
.skb
= NULL
;
1167 /* flush descriptors */
1172 netdev_reset_queue(ag
->ndev
);
1175 static void ag71xx_ring_rx_clean(struct ag71xx
*ag
)
1177 struct ag71xx_ring
*ring
= &ag
->rx_ring
;
1178 int ring_size
= BIT(ring
->order
);
1184 for (i
= 0; i
< ring_size
; i
++)
1185 if (ring
->buf
[i
].rx
.rx_buf
) {
1186 dma_unmap_single(&ag
->pdev
->dev
,
1187 ring
->buf
[i
].rx
.dma_addr
,
1188 ag
->rx_buf_size
, DMA_FROM_DEVICE
);
1189 skb_free_frag(ring
->buf
[i
].rx
.rx_buf
);
1193 static int ag71xx_buffer_size(struct ag71xx
*ag
)
1195 return ag
->rx_buf_size
+
1196 SKB_DATA_ALIGN(sizeof(struct skb_shared_info
));
1199 static bool ag71xx_fill_rx_buf(struct ag71xx
*ag
, struct ag71xx_buf
*buf
,
1201 void *(*alloc
)(unsigned int size
))
1203 struct ag71xx_ring
*ring
= &ag
->rx_ring
;
1204 struct ag71xx_desc
*desc
;
1207 desc
= ag71xx_ring_desc(ring
, buf
- &ring
->buf
[0]);
1209 data
= alloc(ag71xx_buffer_size(ag
));
1213 buf
->rx
.rx_buf
= data
;
1214 buf
->rx
.dma_addr
= dma_map_single(&ag
->pdev
->dev
, data
, ag
->rx_buf_size
,
1216 desc
->data
= (u32
)buf
->rx
.dma_addr
+ offset
;
1220 static int ag71xx_ring_rx_init(struct ag71xx
*ag
)
1222 struct ag71xx_ring
*ring
= &ag
->rx_ring
;
1223 struct net_device
*ndev
= ag
->ndev
;
1224 int ring_mask
= BIT(ring
->order
) - 1;
1225 int ring_size
= BIT(ring
->order
);
1230 for (i
= 0; i
< ring_size
; i
++) {
1231 struct ag71xx_desc
*desc
= ag71xx_ring_desc(ring
, i
);
1233 desc
->next
= (u32
)(ring
->descs_dma
+
1234 AG71XX_DESC_SIZE
* ((i
+ 1) & ring_mask
));
1236 netif_dbg(ag
, rx_status
, ndev
, "RX desc at %p, next is %08x\n",
1240 for (i
= 0; i
< ring_size
; i
++) {
1241 struct ag71xx_desc
*desc
= ag71xx_ring_desc(ring
, i
);
1243 if (!ag71xx_fill_rx_buf(ag
, &ring
->buf
[i
], ag
->rx_buf_offset
,
1244 netdev_alloc_frag
)) {
1249 desc
->ctrl
= DESC_EMPTY
;
1252 /* flush descriptors */
1261 static int ag71xx_ring_rx_refill(struct ag71xx
*ag
)
1263 struct ag71xx_ring
*ring
= &ag
->rx_ring
;
1264 int ring_mask
= BIT(ring
->order
) - 1;
1265 int offset
= ag
->rx_buf_offset
;
1269 for (; ring
->curr
- ring
->dirty
> 0; ring
->dirty
++) {
1270 struct ag71xx_desc
*desc
;
1273 i
= ring
->dirty
& ring_mask
;
1274 desc
= ag71xx_ring_desc(ring
, i
);
1276 if (!ring
->buf
[i
].rx
.rx_buf
&&
1277 !ag71xx_fill_rx_buf(ag
, &ring
->buf
[i
], offset
,
1281 desc
->ctrl
= DESC_EMPTY
;
1285 /* flush descriptors */
1288 netif_dbg(ag
, rx_status
, ag
->ndev
, "%u rx descriptors refilled\n",
1294 static int ag71xx_rings_init(struct ag71xx
*ag
)
1296 struct ag71xx_ring
*tx
= &ag
->tx_ring
;
1297 struct ag71xx_ring
*rx
= &ag
->rx_ring
;
1298 int ring_size
, tx_size
;
1300 ring_size
= BIT(tx
->order
) + BIT(rx
->order
);
1301 tx_size
= BIT(tx
->order
);
1303 tx
->buf
= kcalloc(ring_size
, sizeof(*tx
->buf
), GFP_KERNEL
);
1307 tx
->descs_cpu
= dma_alloc_coherent(&ag
->pdev
->dev
,
1308 ring_size
* AG71XX_DESC_SIZE
,
1309 &tx
->descs_dma
, GFP_KERNEL
);
1310 if (!tx
->descs_cpu
) {
1316 rx
->buf
= &tx
->buf
[tx_size
];
1317 rx
->descs_cpu
= ((void *)tx
->descs_cpu
) + tx_size
* AG71XX_DESC_SIZE
;
1318 rx
->descs_dma
= tx
->descs_dma
+ tx_size
* AG71XX_DESC_SIZE
;
1320 ag71xx_ring_tx_init(ag
);
1321 return ag71xx_ring_rx_init(ag
);
1324 static void ag71xx_rings_free(struct ag71xx
*ag
)
1326 struct ag71xx_ring
*tx
= &ag
->tx_ring
;
1327 struct ag71xx_ring
*rx
= &ag
->rx_ring
;
1330 ring_size
= BIT(tx
->order
) + BIT(rx
->order
);
1333 dma_free_coherent(&ag
->pdev
->dev
, ring_size
* AG71XX_DESC_SIZE
,
1334 tx
->descs_cpu
, tx
->descs_dma
);
1338 tx
->descs_cpu
= NULL
;
1339 rx
->descs_cpu
= NULL
;
1344 static void ag71xx_rings_cleanup(struct ag71xx
*ag
)
1346 ag71xx_ring_rx_clean(ag
);
1347 ag71xx_ring_tx_clean(ag
);
1348 ag71xx_rings_free(ag
);
1350 netdev_reset_queue(ag
->ndev
);
1353 static void ag71xx_hw_init(struct ag71xx
*ag
)
1357 ag71xx_sb(ag
, AG71XX_REG_MAC_CFG1
, MAC_CFG1_SR
);
1358 usleep_range(20, 30);
1360 reset_control_assert(ag
->mac_reset
);
1362 reset_control_deassert(ag
->mac_reset
);
1365 ag71xx_hw_setup(ag
);
1367 ag71xx_dma_reset(ag
);
1370 static int ag71xx_hw_enable(struct ag71xx
*ag
)
1374 ret
= ag71xx_rings_init(ag
);
1378 napi_enable(&ag
->napi
);
1379 ag71xx_wr(ag
, AG71XX_REG_TX_DESC
, ag
->tx_ring
.descs_dma
);
1380 ag71xx_wr(ag
, AG71XX_REG_RX_DESC
, ag
->rx_ring
.descs_dma
);
1381 netif_start_queue(ag
->ndev
);
1386 static void ag71xx_hw_disable(struct ag71xx
*ag
)
1388 netif_stop_queue(ag
->ndev
);
1391 ag71xx_dma_reset(ag
);
1393 napi_disable(&ag
->napi
);
1394 del_timer_sync(&ag
->oom_timer
);
1396 ag71xx_rings_cleanup(ag
);
1399 static int ag71xx_open(struct net_device
*ndev
)
1401 struct ag71xx
*ag
= netdev_priv(ndev
);
1402 unsigned int max_frame_len
;
1405 ret
= phylink_of_phy_connect(ag
->phylink
, ag
->pdev
->dev
.of_node
, 0);
1407 netif_err(ag
, link
, ndev
, "phylink_of_phy_connect filed with err: %i\n",
1412 max_frame_len
= ag71xx_max_frame_len(ndev
->mtu
);
1414 SKB_DATA_ALIGN(max_frame_len
+ NET_SKB_PAD
+ NET_IP_ALIGN
);
1416 /* setup max frame length */
1417 ag71xx_wr(ag
, AG71XX_REG_MAC_MFL
, max_frame_len
);
1418 ag71xx_hw_set_macaddr(ag
, ndev
->dev_addr
);
1420 ret
= ag71xx_hw_enable(ag
);
1424 phylink_start(ag
->phylink
);
1429 ag71xx_rings_cleanup(ag
);
1430 phylink_disconnect_phy(ag
->phylink
);
1434 static int ag71xx_stop(struct net_device
*ndev
)
1436 struct ag71xx
*ag
= netdev_priv(ndev
);
1438 phylink_stop(ag
->phylink
);
1439 phylink_disconnect_phy(ag
->phylink
);
1440 ag71xx_hw_disable(ag
);
1445 static int ag71xx_fill_dma_desc(struct ag71xx_ring
*ring
, u32 addr
, int len
)
1447 int i
, ring_mask
, ndesc
, split
;
1448 struct ag71xx_desc
*desc
;
1450 ring_mask
= BIT(ring
->order
) - 1;
1452 split
= ring
->desc_split
;
1458 unsigned int cur_len
= len
;
1460 i
= (ring
->curr
+ ndesc
) & ring_mask
;
1461 desc
= ag71xx_ring_desc(ring
, i
);
1463 if (!ag71xx_desc_empty(desc
))
1466 if (cur_len
> split
) {
1469 /* TX will hang if DMA transfers <= 4 bytes,
1470 * make sure next segment is more than 4 bytes long.
1472 if (len
<= split
+ 4)
1481 cur_len
|= DESC_MORE
;
1483 /* prevent early tx attempt of this descriptor */
1485 cur_len
|= DESC_EMPTY
;
1487 desc
->ctrl
= cur_len
;
1494 static netdev_tx_t
ag71xx_hard_start_xmit(struct sk_buff
*skb
,
1495 struct net_device
*ndev
)
1497 int i
, n
, ring_min
, ring_mask
, ring_size
;
1498 struct ag71xx
*ag
= netdev_priv(ndev
);
1499 struct ag71xx_ring
*ring
;
1500 struct ag71xx_desc
*desc
;
1501 dma_addr_t dma_addr
;
1503 ring
= &ag
->tx_ring
;
1504 ring_mask
= BIT(ring
->order
) - 1;
1505 ring_size
= BIT(ring
->order
);
1507 if (skb
->len
<= 4) {
1508 netif_dbg(ag
, tx_err
, ndev
, "packet len is too small\n");
1512 dma_addr
= dma_map_single(&ag
->pdev
->dev
, skb
->data
, skb
->len
,
1515 i
= ring
->curr
& ring_mask
;
1516 desc
= ag71xx_ring_desc(ring
, i
);
1518 /* setup descriptor fields */
1519 n
= ag71xx_fill_dma_desc(ring
, (u32
)dma_addr
,
1520 skb
->len
& ag
->dcfg
->desc_pktlen_mask
);
1522 goto err_drop_unmap
;
1524 i
= (ring
->curr
+ n
- 1) & ring_mask
;
1525 ring
->buf
[i
].tx
.len
= skb
->len
;
1526 ring
->buf
[i
].tx
.skb
= skb
;
1528 netdev_sent_queue(ndev
, skb
->len
);
1530 skb_tx_timestamp(skb
);
1532 desc
->ctrl
&= ~DESC_EMPTY
;
1535 /* flush descriptor */
1539 if (ring
->desc_split
)
1540 ring_min
*= AG71XX_TX_RING_DS_PER_PKT
;
1542 if (ring
->curr
- ring
->dirty
>= ring_size
- ring_min
) {
1543 netif_dbg(ag
, tx_err
, ndev
, "tx queue full\n");
1544 netif_stop_queue(ndev
);
1547 netif_dbg(ag
, tx_queued
, ndev
, "packet injected into TX queue\n");
1549 /* enable TX engine */
1550 ag71xx_wr(ag
, AG71XX_REG_TX_CTRL
, TX_CTRL_TXE
);
1552 return NETDEV_TX_OK
;
1555 dma_unmap_single(&ag
->pdev
->dev
, dma_addr
, skb
->len
, DMA_TO_DEVICE
);
1558 ndev
->stats
.tx_dropped
++;
1561 return NETDEV_TX_OK
;
1564 static void ag71xx_oom_timer_handler(struct timer_list
*t
)
1566 struct ag71xx
*ag
= from_timer(ag
, t
, oom_timer
);
1568 napi_schedule(&ag
->napi
);
1571 static void ag71xx_tx_timeout(struct net_device
*ndev
, unsigned int txqueue
)
1573 struct ag71xx
*ag
= netdev_priv(ndev
);
1575 netif_err(ag
, tx_err
, ndev
, "tx timeout\n");
1577 schedule_delayed_work(&ag
->restart_work
, 1);
1580 static void ag71xx_restart_work_func(struct work_struct
*work
)
1582 struct ag71xx
*ag
= container_of(work
, struct ag71xx
,
1586 ag71xx_hw_disable(ag
);
1587 ag71xx_hw_enable(ag
);
1589 phylink_stop(ag
->phylink
);
1590 phylink_start(ag
->phylink
);
1595 static int ag71xx_rx_packets(struct ag71xx
*ag
, int limit
)
1597 struct net_device
*ndev
= ag
->ndev
;
1598 int ring_mask
, ring_size
, done
= 0;
1599 unsigned int pktlen_mask
, offset
;
1600 struct ag71xx_ring
*ring
;
1601 struct sk_buff
*skb
;
1604 ring
= &ag
->rx_ring
;
1605 pktlen_mask
= ag
->dcfg
->desc_pktlen_mask
;
1606 offset
= ag
->rx_buf_offset
;
1607 ring_mask
= BIT(ring
->order
) - 1;
1608 ring_size
= BIT(ring
->order
);
1610 netif_dbg(ag
, rx_status
, ndev
, "rx packets, limit=%d, curr=%u, dirty=%u\n",
1611 limit
, ring
->curr
, ring
->dirty
);
1613 while (done
< limit
) {
1614 unsigned int i
= ring
->curr
& ring_mask
;
1615 struct ag71xx_desc
*desc
= ag71xx_ring_desc(ring
, i
);
1618 if (ag71xx_desc_empty(desc
))
1621 if ((ring
->dirty
+ ring_size
) == ring
->curr
) {
1622 WARN_ONCE(1, "RX out of ring");
1626 ag71xx_wr(ag
, AG71XX_REG_RX_STATUS
, RX_STATUS_PR
);
1628 pktlen
= desc
->ctrl
& pktlen_mask
;
1629 pktlen
-= ETH_FCS_LEN
;
1631 dma_unmap_single(&ag
->pdev
->dev
, ring
->buf
[i
].rx
.dma_addr
,
1632 ag
->rx_buf_size
, DMA_FROM_DEVICE
);
1634 ndev
->stats
.rx_packets
++;
1635 ndev
->stats
.rx_bytes
+= pktlen
;
1637 skb
= napi_build_skb(ring
->buf
[i
].rx
.rx_buf
, ag71xx_buffer_size(ag
));
1639 ndev
->stats
.rx_errors
++;
1640 skb_free_frag(ring
->buf
[i
].rx
.rx_buf
);
1644 skb_reserve(skb
, offset
);
1645 skb_put(skb
, pktlen
);
1648 skb
->ip_summed
= CHECKSUM_NONE
;
1649 skb
->protocol
= eth_type_trans(skb
, ndev
);
1650 list_add_tail(&skb
->list
, &rx_list
);
1653 ring
->buf
[i
].rx
.rx_buf
= NULL
;
1659 ag71xx_ring_rx_refill(ag
);
1661 netif_receive_skb_list(&rx_list
);
1663 netif_dbg(ag
, rx_status
, ndev
, "rx finish, curr=%u, dirty=%u, done=%d\n",
1664 ring
->curr
, ring
->dirty
, done
);
1669 static int ag71xx_poll(struct napi_struct
*napi
, int limit
)
1671 struct ag71xx
*ag
= container_of(napi
, struct ag71xx
, napi
);
1672 struct ag71xx_ring
*rx_ring
= &ag
->rx_ring
;
1673 int rx_ring_size
= BIT(rx_ring
->order
);
1674 struct net_device
*ndev
= ag
->ndev
;
1675 int tx_done
, rx_done
;
1678 tx_done
= ag71xx_tx_packets(ag
, false, limit
);
1680 netif_dbg(ag
, rx_status
, ndev
, "processing RX ring\n");
1681 rx_done
= ag71xx_rx_packets(ag
, limit
);
1683 if (!rx_ring
->buf
[rx_ring
->dirty
% rx_ring_size
].rx
.rx_buf
)
1686 status
= ag71xx_rr(ag
, AG71XX_REG_RX_STATUS
);
1687 if (unlikely(status
& RX_STATUS_OF
)) {
1688 ag71xx_wr(ag
, AG71XX_REG_RX_STATUS
, RX_STATUS_OF
);
1689 ndev
->stats
.rx_fifo_errors
++;
1692 ag71xx_wr(ag
, AG71XX_REG_RX_CTRL
, RX_CTRL_RXE
);
1695 if (rx_done
< limit
) {
1696 if (status
& RX_STATUS_PR
)
1699 status
= ag71xx_rr(ag
, AG71XX_REG_TX_STATUS
);
1700 if (status
& TX_STATUS_PS
)
1703 netif_dbg(ag
, rx_status
, ndev
, "disable polling mode, rx=%d, tx=%d,limit=%d\n",
1704 rx_done
, tx_done
, limit
);
1706 napi_complete(napi
);
1708 /* enable interrupts */
1709 ag71xx_int_enable(ag
, AG71XX_INT_POLL
);
1714 netif_dbg(ag
, rx_status
, ndev
, "stay in polling mode, rx=%d, tx=%d, limit=%d\n",
1715 rx_done
, tx_done
, limit
);
1719 netif_err(ag
, rx_err
, ndev
, "out of memory\n");
1721 mod_timer(&ag
->oom_timer
, jiffies
+ AG71XX_OOM_REFILL
);
1722 napi_complete(napi
);
1726 static irqreturn_t
ag71xx_interrupt(int irq
, void *dev_id
)
1728 struct net_device
*ndev
= dev_id
;
1732 ag
= netdev_priv(ndev
);
1733 status
= ag71xx_rr(ag
, AG71XX_REG_INT_STATUS
);
1735 if (unlikely(!status
))
1738 if (unlikely(status
& AG71XX_INT_ERR
)) {
1739 if (status
& AG71XX_INT_TX_BE
) {
1740 ag71xx_wr(ag
, AG71XX_REG_TX_STATUS
, TX_STATUS_BE
);
1741 netif_err(ag
, intr
, ndev
, "TX BUS error\n");
1743 if (status
& AG71XX_INT_RX_BE
) {
1744 ag71xx_wr(ag
, AG71XX_REG_RX_STATUS
, RX_STATUS_BE
);
1745 netif_err(ag
, intr
, ndev
, "RX BUS error\n");
1749 if (likely(status
& AG71XX_INT_POLL
)) {
1750 ag71xx_int_disable(ag
, AG71XX_INT_POLL
);
1751 netif_dbg(ag
, intr
, ndev
, "enable polling mode\n");
1752 napi_schedule(&ag
->napi
);
1758 static int ag71xx_change_mtu(struct net_device
*ndev
, int new_mtu
)
1760 struct ag71xx
*ag
= netdev_priv(ndev
);
1762 WRITE_ONCE(ndev
->mtu
, new_mtu
);
1763 ag71xx_wr(ag
, AG71XX_REG_MAC_MFL
,
1764 ag71xx_max_frame_len(ndev
->mtu
));
1769 static const struct net_device_ops ag71xx_netdev_ops
= {
1770 .ndo_open
= ag71xx_open
,
1771 .ndo_stop
= ag71xx_stop
,
1772 .ndo_start_xmit
= ag71xx_hard_start_xmit
,
1773 .ndo_eth_ioctl
= ag71xx_do_ioctl
,
1774 .ndo_tx_timeout
= ag71xx_tx_timeout
,
1775 .ndo_change_mtu
= ag71xx_change_mtu
,
1776 .ndo_set_mac_address
= eth_mac_addr
,
1777 .ndo_validate_addr
= eth_validate_addr
,
1780 static const u32 ar71xx_addr_ar7100
[] = {
1781 0x19000000, 0x1a000000,
1784 static int ag71xx_probe(struct platform_device
*pdev
)
1786 struct device_node
*np
= pdev
->dev
.of_node
;
1787 const struct ag71xx_dcfg
*dcfg
;
1788 struct net_device
*ndev
;
1789 struct resource
*res
;
1790 struct clk
*clk_eth
;
1791 int tx_size
, err
, i
;
1797 ndev
= devm_alloc_etherdev(&pdev
->dev
, sizeof(*ag
));
1801 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1805 dcfg
= of_device_get_match_data(&pdev
->dev
);
1809 ag
= netdev_priv(ndev
);
1811 for (i
= 0; i
< ARRAY_SIZE(ar71xx_addr_ar7100
); i
++) {
1812 if (ar71xx_addr_ar7100
[i
] == res
->start
)
1816 if (ag
->mac_idx
< 0) {
1817 netif_err(ag
, probe
, ndev
, "unknown mac idx\n");
1821 clk_eth
= devm_clk_get_enabled(&pdev
->dev
, "eth");
1822 if (IS_ERR(clk_eth
))
1823 return dev_err_probe(&pdev
->dev
, PTR_ERR(clk_eth
),
1824 "Failed to get eth clk.");
1826 SET_NETDEV_DEV(ndev
, &pdev
->dev
);
1831 ag
->msg_enable
= netif_msg_init(-1, AG71XX_DEFAULT_MSG_ENABLE
);
1832 memcpy(ag
->fifodata
, dcfg
->fifodata
, sizeof(ag
->fifodata
));
1834 ag
->mac_reset
= devm_reset_control_get(&pdev
->dev
, "mac");
1835 if (IS_ERR(ag
->mac_reset
))
1836 return dev_err_probe(&pdev
->dev
, PTR_ERR(ag
->mac_reset
),
1837 "missing mac reset");
1839 ag
->mac_base
= devm_ioremap_resource(&pdev
->dev
, res
);
1840 if (IS_ERR(ag
->mac_base
))
1841 return PTR_ERR(ag
->mac_base
);
1843 /* ensure that HW is in manual polling mode before interrupts are
1844 * activated. Otherwise ag71xx_interrupt might call napi_schedule
1845 * before it is initialized by netif_napi_add.
1847 ag71xx_int_disable(ag
, AG71XX_INT_POLL
);
1849 ndev
->irq
= platform_get_irq(pdev
, 0);
1850 err
= devm_request_irq(&pdev
->dev
, ndev
->irq
, ag71xx_interrupt
,
1851 0x0, dev_name(&pdev
->dev
), ndev
);
1853 netif_err(ag
, probe
, ndev
, "unable to request IRQ %d\n",
1858 ndev
->netdev_ops
= &ag71xx_netdev_ops
;
1859 ndev
->ethtool_ops
= &ag71xx_ethtool_ops
;
1861 INIT_DELAYED_WORK(&ag
->restart_work
, ag71xx_restart_work_func
);
1862 timer_setup(&ag
->oom_timer
, ag71xx_oom_timer_handler
, 0);
1864 tx_size
= AG71XX_TX_RING_SIZE_DEFAULT
;
1865 ag
->rx_ring
.order
= ag71xx_ring_size_order(AG71XX_RX_RING_SIZE_DEFAULT
);
1868 ndev
->max_mtu
= dcfg
->max_frame_len
- ag71xx_max_frame_len(0);
1870 ag
->rx_buf_offset
= NET_SKB_PAD
;
1871 if (!ag71xx_is(ag
, AR7100
) && !ag71xx_is(ag
, AR9130
))
1872 ag
->rx_buf_offset
+= NET_IP_ALIGN
;
1874 if (ag71xx_is(ag
, AR7100
)) {
1875 ag
->tx_ring
.desc_split
= AG71XX_TX_RING_SPLIT
;
1876 tx_size
*= AG71XX_TX_RING_DS_PER_PKT
;
1878 ag
->tx_ring
.order
= ag71xx_ring_size_order(tx_size
);
1880 ag
->stop_desc
= dmam_alloc_coherent(&pdev
->dev
,
1881 sizeof(struct ag71xx_desc
),
1882 &ag
->stop_desc_dma
, GFP_KERNEL
);
1886 ag
->stop_desc
->data
= 0;
1887 ag
->stop_desc
->ctrl
= 0;
1888 ag
->stop_desc
->next
= (u32
)ag
->stop_desc_dma
;
1890 err
= of_get_ethdev_address(np
, ndev
);
1891 if (err
== -EPROBE_DEFER
)
1894 netif_err(ag
, probe
, ndev
, "invalid MAC address, using random address\n");
1895 eth_hw_addr_random(ndev
);
1898 err
= of_get_phy_mode(np
, &ag
->phy_if_mode
);
1900 netif_err(ag
, probe
, ndev
, "missing phy-mode property in DT\n");
1904 netif_napi_add_weight(ndev
, &ag
->napi
, ag71xx_poll
,
1905 AG71XX_NAPI_WEIGHT
);
1907 ag71xx_wr(ag
, AG71XX_REG_MAC_CFG1
, 0);
1911 err
= ag71xx_mdio_probe(ag
);
1915 err
= ag71xx_phylink_setup(ag
);
1917 return dev_err_probe(&pdev
->dev
, err
,
1918 "failed to setup phylink");
1920 err
= devm_register_netdev(&pdev
->dev
, ndev
);
1922 netif_err(ag
, probe
, ndev
, "unable to register net device\n");
1926 netif_info(ag
, probe
, ndev
, "Atheros AG71xx at 0x%08lx, irq %d, mode:%s\n",
1927 (unsigned long)ag
->mac_base
, ndev
->irq
,
1928 phy_modes(ag
->phy_if_mode
));
1933 static const u32 ar71xx_fifo_ar7100
[] = {
1934 0x0fff0000, 0x00001fff, 0x00780fff,
1937 static const u32 ar71xx_fifo_ar9130
[] = {
1938 0x0fff0000, 0x00001fff, 0x008001ff,
1941 static const u32 ar71xx_fifo_ar9330
[] = {
1942 0x0010ffff, 0x015500aa, 0x01f00140,
1945 static const struct ag71xx_dcfg ag71xx_dcfg_ar7100
= {
1947 .fifodata
= ar71xx_fifo_ar7100
,
1948 .max_frame_len
= 1540,
1949 .desc_pktlen_mask
= SZ_4K
- 1,
1950 .tx_hang_workaround
= false,
1953 static const struct ag71xx_dcfg ag71xx_dcfg_ar7240
= {
1955 .fifodata
= ar71xx_fifo_ar7100
,
1956 .max_frame_len
= 1540,
1957 .desc_pktlen_mask
= SZ_4K
- 1,
1958 .tx_hang_workaround
= true,
1961 static const struct ag71xx_dcfg ag71xx_dcfg_ar9130
= {
1963 .fifodata
= ar71xx_fifo_ar9130
,
1964 .max_frame_len
= 1540,
1965 .desc_pktlen_mask
= SZ_4K
- 1,
1966 .tx_hang_workaround
= false,
1969 static const struct ag71xx_dcfg ag71xx_dcfg_ar9330
= {
1971 .fifodata
= ar71xx_fifo_ar9330
,
1972 .max_frame_len
= 1540,
1973 .desc_pktlen_mask
= SZ_4K
- 1,
1974 .tx_hang_workaround
= true,
1977 static const struct ag71xx_dcfg ag71xx_dcfg_ar9340
= {
1979 .fifodata
= ar71xx_fifo_ar9330
,
1980 .max_frame_len
= SZ_16K
- 1,
1981 .desc_pktlen_mask
= SZ_16K
- 1,
1982 .tx_hang_workaround
= true,
1985 static const struct ag71xx_dcfg ag71xx_dcfg_qca9530
= {
1987 .fifodata
= ar71xx_fifo_ar9330
,
1988 .max_frame_len
= SZ_16K
- 1,
1989 .desc_pktlen_mask
= SZ_16K
- 1,
1990 .tx_hang_workaround
= true,
1993 static const struct ag71xx_dcfg ag71xx_dcfg_qca9550
= {
1995 .fifodata
= ar71xx_fifo_ar9330
,
1996 .max_frame_len
= 1540,
1997 .desc_pktlen_mask
= SZ_16K
- 1,
1998 .tx_hang_workaround
= true,
2001 static const struct of_device_id ag71xx_match
[] = {
2002 { .compatible
= "qca,ar7100-eth", .data
= &ag71xx_dcfg_ar7100
},
2003 { .compatible
= "qca,ar7240-eth", .data
= &ag71xx_dcfg_ar7240
},
2004 { .compatible
= "qca,ar7241-eth", .data
= &ag71xx_dcfg_ar7240
},
2005 { .compatible
= "qca,ar7242-eth", .data
= &ag71xx_dcfg_ar7240
},
2006 { .compatible
= "qca,ar9130-eth", .data
= &ag71xx_dcfg_ar9130
},
2007 { .compatible
= "qca,ar9330-eth", .data
= &ag71xx_dcfg_ar9330
},
2008 { .compatible
= "qca,ar9340-eth", .data
= &ag71xx_dcfg_ar9340
},
2009 { .compatible
= "qca,qca9530-eth", .data
= &ag71xx_dcfg_qca9530
},
2010 { .compatible
= "qca,qca9550-eth", .data
= &ag71xx_dcfg_qca9550
},
2011 { .compatible
= "qca,qca9560-eth", .data
= &ag71xx_dcfg_qca9550
},
2014 MODULE_DEVICE_TABLE(of
, ag71xx_match
);
2016 static struct platform_driver ag71xx_driver
= {
2017 .probe
= ag71xx_probe
,
2020 .of_match_table
= ag71xx_match
,
2024 module_platform_driver(ag71xx_driver
);
2025 MODULE_DESCRIPTION("Atheros AR71xx built-in ethernet mac driver");
2026 MODULE_LICENSE("GPL v2");