net: mvneta: do not schedule in mvneta_tx_timeout
[deliverable/linux.git] / drivers / net / ethernet / marvell / mvneta.c
CommitLineData
c5aff182
TP
1/*
2 * Driver for Marvell NETA network card for Armada XP and Armada 370 SoCs.
3 *
4 * Copyright (C) 2012 Marvell
5 *
6 * Rami Rosen <rosenr@marvell.com>
7 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
8 *
9 * This file is licensed under the terms of the GNU General Public
10 * License version 2. This program is licensed "as is" without any
11 * warranty of any kind, whether express or implied.
12 */
13
14#include <linux/kernel.h>
c5aff182
TP
15#include <linux/netdevice.h>
16#include <linux/etherdevice.h>
17#include <linux/platform_device.h>
18#include <linux/skbuff.h>
19#include <linux/inetdevice.h>
20#include <linux/mbus.h>
21#include <linux/module.h>
22#include <linux/interrupt.h>
23#include <net/ip.h>
24#include <net/ipv6.h>
25#include <linux/of.h>
26#include <linux/of_irq.h>
27#include <linux/of_mdio.h>
28#include <linux/of_net.h>
29#include <linux/of_address.h>
30#include <linux/phy.h>
189dd626 31#include <linux/clk.h>
c5aff182
TP
32
33/* Registers */
34#define MVNETA_RXQ_CONFIG_REG(q) (0x1400 + ((q) << 2))
35#define MVNETA_RXQ_HW_BUF_ALLOC BIT(1)
36#define MVNETA_RXQ_PKT_OFFSET_ALL_MASK (0xf << 8)
37#define MVNETA_RXQ_PKT_OFFSET_MASK(offs) ((offs) << 8)
38#define MVNETA_RXQ_THRESHOLD_REG(q) (0x14c0 + ((q) << 2))
39#define MVNETA_RXQ_NON_OCCUPIED(v) ((v) << 16)
40#define MVNETA_RXQ_BASE_ADDR_REG(q) (0x1480 + ((q) << 2))
41#define MVNETA_RXQ_SIZE_REG(q) (0x14a0 + ((q) << 2))
42#define MVNETA_RXQ_BUF_SIZE_SHIFT 19
43#define MVNETA_RXQ_BUF_SIZE_MASK (0x1fff << 19)
44#define MVNETA_RXQ_STATUS_REG(q) (0x14e0 + ((q) << 2))
45#define MVNETA_RXQ_OCCUPIED_ALL_MASK 0x3fff
46#define MVNETA_RXQ_STATUS_UPDATE_REG(q) (0x1500 + ((q) << 2))
47#define MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT 16
48#define MVNETA_RXQ_ADD_NON_OCCUPIED_MAX 255
49#define MVNETA_PORT_RX_RESET 0x1cc0
50#define MVNETA_PORT_RX_DMA_RESET BIT(0)
51#define MVNETA_PHY_ADDR 0x2000
52#define MVNETA_PHY_ADDR_MASK 0x1f
53#define MVNETA_MBUS_RETRY 0x2010
54#define MVNETA_UNIT_INTR_CAUSE 0x2080
55#define MVNETA_UNIT_CONTROL 0x20B0
56#define MVNETA_PHY_POLLING_ENABLE BIT(1)
57#define MVNETA_WIN_BASE(w) (0x2200 + ((w) << 3))
58#define MVNETA_WIN_SIZE(w) (0x2204 + ((w) << 3))
59#define MVNETA_WIN_REMAP(w) (0x2280 + ((w) << 2))
60#define MVNETA_BASE_ADDR_ENABLE 0x2290
61#define MVNETA_PORT_CONFIG 0x2400
62#define MVNETA_UNI_PROMISC_MODE BIT(0)
63#define MVNETA_DEF_RXQ(q) ((q) << 1)
64#define MVNETA_DEF_RXQ_ARP(q) ((q) << 4)
65#define MVNETA_TX_UNSET_ERR_SUM BIT(12)
66#define MVNETA_DEF_RXQ_TCP(q) ((q) << 16)
67#define MVNETA_DEF_RXQ_UDP(q) ((q) << 19)
68#define MVNETA_DEF_RXQ_BPDU(q) ((q) << 22)
69#define MVNETA_RX_CSUM_WITH_PSEUDO_HDR BIT(25)
70#define MVNETA_PORT_CONFIG_DEFL_VALUE(q) (MVNETA_DEF_RXQ(q) | \
71 MVNETA_DEF_RXQ_ARP(q) | \
72 MVNETA_DEF_RXQ_TCP(q) | \
73 MVNETA_DEF_RXQ_UDP(q) | \
74 MVNETA_DEF_RXQ_BPDU(q) | \
75 MVNETA_TX_UNSET_ERR_SUM | \
76 MVNETA_RX_CSUM_WITH_PSEUDO_HDR)
77#define MVNETA_PORT_CONFIG_EXTEND 0x2404
78#define MVNETA_MAC_ADDR_LOW 0x2414
79#define MVNETA_MAC_ADDR_HIGH 0x2418
80#define MVNETA_SDMA_CONFIG 0x241c
81#define MVNETA_SDMA_BRST_SIZE_16 4
c5aff182
TP
82#define MVNETA_RX_BRST_SZ_MASK(burst) ((burst) << 1)
83#define MVNETA_RX_NO_DATA_SWAP BIT(4)
84#define MVNETA_TX_NO_DATA_SWAP BIT(5)
9ad8fef6 85#define MVNETA_DESC_SWAP BIT(6)
c5aff182
TP
86#define MVNETA_TX_BRST_SZ_MASK(burst) ((burst) << 22)
87#define MVNETA_PORT_STATUS 0x2444
88#define MVNETA_TX_IN_PRGRS BIT(1)
89#define MVNETA_TX_FIFO_EMPTY BIT(8)
90#define MVNETA_RX_MIN_FRAME_SIZE 0x247c
5445eaf3
APR
91#define MVNETA_SGMII_SERDES_CFG 0x24A0
92#define MVNETA_SGMII_SERDES_PROTO 0x0cc7
c5aff182
TP
93#define MVNETA_TYPE_PRIO 0x24bc
94#define MVNETA_FORCE_UNI BIT(21)
95#define MVNETA_TXQ_CMD_1 0x24e4
96#define MVNETA_TXQ_CMD 0x2448
97#define MVNETA_TXQ_DISABLE_SHIFT 8
98#define MVNETA_TXQ_ENABLE_MASK 0x000000ff
99#define MVNETA_ACC_MODE 0x2500
100#define MVNETA_CPU_MAP(cpu) (0x2540 + ((cpu) << 2))
101#define MVNETA_CPU_RXQ_ACCESS_ALL_MASK 0x000000ff
102#define MVNETA_CPU_TXQ_ACCESS_ALL_MASK 0x0000ff00
103#define MVNETA_RXQ_TIME_COAL_REG(q) (0x2580 + ((q) << 2))
104#define MVNETA_INTR_NEW_CAUSE 0x25a0
105#define MVNETA_RX_INTR_MASK(nr_rxqs) (((1 << nr_rxqs) - 1) << 8)
106#define MVNETA_INTR_NEW_MASK 0x25a4
107#define MVNETA_INTR_OLD_CAUSE 0x25a8
108#define MVNETA_INTR_OLD_MASK 0x25ac
109#define MVNETA_INTR_MISC_CAUSE 0x25b0
110#define MVNETA_INTR_MISC_MASK 0x25b4
111#define MVNETA_INTR_ENABLE 0x25b8
112#define MVNETA_TXQ_INTR_ENABLE_ALL_MASK 0x0000ff00
113#define MVNETA_RXQ_INTR_ENABLE_ALL_MASK 0xff000000
114#define MVNETA_RXQ_CMD 0x2680
115#define MVNETA_RXQ_DISABLE_SHIFT 8
116#define MVNETA_RXQ_ENABLE_MASK 0x000000ff
117#define MVETH_TXQ_TOKEN_COUNT_REG(q) (0x2700 + ((q) << 4))
118#define MVETH_TXQ_TOKEN_CFG_REG(q) (0x2704 + ((q) << 4))
119#define MVNETA_GMAC_CTRL_0 0x2c00
120#define MVNETA_GMAC_MAX_RX_SIZE_SHIFT 2
121#define MVNETA_GMAC_MAX_RX_SIZE_MASK 0x7ffc
122#define MVNETA_GMAC0_PORT_ENABLE BIT(0)
123#define MVNETA_GMAC_CTRL_2 0x2c08
124#define MVNETA_GMAC2_PSC_ENABLE BIT(3)
125#define MVNETA_GMAC2_PORT_RGMII BIT(4)
126#define MVNETA_GMAC2_PORT_RESET BIT(6)
127#define MVNETA_GMAC_STATUS 0x2c10
128#define MVNETA_GMAC_LINK_UP BIT(0)
129#define MVNETA_GMAC_SPEED_1000 BIT(1)
130#define MVNETA_GMAC_SPEED_100 BIT(2)
131#define MVNETA_GMAC_FULL_DUPLEX BIT(3)
132#define MVNETA_GMAC_RX_FLOW_CTRL_ENABLE BIT(4)
133#define MVNETA_GMAC_TX_FLOW_CTRL_ENABLE BIT(5)
134#define MVNETA_GMAC_RX_FLOW_CTRL_ACTIVE BIT(6)
135#define MVNETA_GMAC_TX_FLOW_CTRL_ACTIVE BIT(7)
136#define MVNETA_GMAC_AUTONEG_CONFIG 0x2c0c
137#define MVNETA_GMAC_FORCE_LINK_DOWN BIT(0)
138#define MVNETA_GMAC_FORCE_LINK_PASS BIT(1)
139#define MVNETA_GMAC_CONFIG_MII_SPEED BIT(5)
140#define MVNETA_GMAC_CONFIG_GMII_SPEED BIT(6)
71408602 141#define MVNETA_GMAC_AN_SPEED_EN BIT(7)
c5aff182 142#define MVNETA_GMAC_CONFIG_FULL_DUPLEX BIT(12)
71408602 143#define MVNETA_GMAC_AN_DUPLEX_EN BIT(13)
c5aff182
TP
144#define MVNETA_MIB_COUNTERS_BASE 0x3080
145#define MVNETA_MIB_LATE_COLLISION 0x7c
146#define MVNETA_DA_FILT_SPEC_MCAST 0x3400
147#define MVNETA_DA_FILT_OTH_MCAST 0x3500
148#define MVNETA_DA_FILT_UCAST_BASE 0x3600
149#define MVNETA_TXQ_BASE_ADDR_REG(q) (0x3c00 + ((q) << 2))
150#define MVNETA_TXQ_SIZE_REG(q) (0x3c20 + ((q) << 2))
151#define MVNETA_TXQ_SENT_THRESH_ALL_MASK 0x3fff0000
152#define MVNETA_TXQ_SENT_THRESH_MASK(coal) ((coal) << 16)
153#define MVNETA_TXQ_UPDATE_REG(q) (0x3c60 + ((q) << 2))
154#define MVNETA_TXQ_DEC_SENT_SHIFT 16
155#define MVNETA_TXQ_STATUS_REG(q) (0x3c40 + ((q) << 2))
156#define MVNETA_TXQ_SENT_DESC_SHIFT 16
157#define MVNETA_TXQ_SENT_DESC_MASK 0x3fff0000
158#define MVNETA_PORT_TX_RESET 0x3cf0
159#define MVNETA_PORT_TX_DMA_RESET BIT(0)
160#define MVNETA_TX_MTU 0x3e0c
161#define MVNETA_TX_TOKEN_SIZE 0x3e14
162#define MVNETA_TX_TOKEN_SIZE_MAX 0xffffffff
163#define MVNETA_TXQ_TOKEN_SIZE_REG(q) (0x3e40 + ((q) << 2))
164#define MVNETA_TXQ_TOKEN_SIZE_MAX 0x7fffffff
165
166#define MVNETA_CAUSE_TXQ_SENT_DESC_ALL_MASK 0xff
167
168/* Descriptor ring Macros */
169#define MVNETA_QUEUE_NEXT_DESC(q, index) \
170 (((index) < (q)->last_desc) ? ((index) + 1) : 0)
171
172/* Various constants */
173
174/* Coalescing */
175#define MVNETA_TXDONE_COAL_PKTS 16
176#define MVNETA_RX_COAL_PKTS 32
177#define MVNETA_RX_COAL_USEC 100
178
179/* Timer */
180#define MVNETA_TX_DONE_TIMER_PERIOD 10
181
182/* Napi polling weight */
183#define MVNETA_RX_POLL_WEIGHT 64
184
6a20c175 185/* The two bytes Marvell header. Either contains a special value used
c5aff182
TP
186 * by Marvell switches when a specific hardware mode is enabled (not
187 * supported by this driver) or is filled automatically by zeroes on
188 * the RX side. Those two bytes being at the front of the Ethernet
189 * header, they allow to have the IP header aligned on a 4 bytes
190 * boundary automatically: the hardware skips those two bytes on its
191 * own.
192 */
193#define MVNETA_MH_SIZE 2
194
195#define MVNETA_VLAN_TAG_LEN 4
196
197#define MVNETA_CPU_D_CACHE_LINE_SIZE 32
198#define MVNETA_TX_CSUM_MAX_SIZE 9800
199#define MVNETA_ACC_MODE_EXT 1
200
201/* Timeout constants */
202#define MVNETA_TX_DISABLE_TIMEOUT_MSEC 1000
203#define MVNETA_RX_DISABLE_TIMEOUT_MSEC 1000
204#define MVNETA_TX_FIFO_EMPTY_TIMEOUT 10000
205
206#define MVNETA_TX_MTU_MAX 0x3ffff
207
208/* Max number of Rx descriptors */
209#define MVNETA_MAX_RXD 128
210
211/* Max number of Tx descriptors */
212#define MVNETA_MAX_TXD 532
213
214/* descriptor aligned size */
215#define MVNETA_DESC_ALIGNED_SIZE 32
216
217#define MVNETA_RX_PKT_SIZE(mtu) \
218 ALIGN((mtu) + MVNETA_MH_SIZE + MVNETA_VLAN_TAG_LEN + \
219 ETH_HLEN + ETH_FCS_LEN, \
220 MVNETA_CPU_D_CACHE_LINE_SIZE)
221
222#define MVNETA_RX_BUF_SIZE(pkt_size) ((pkt_size) + NET_SKB_PAD)
223
74c41b04 224struct mvneta_pcpu_stats {
c5aff182 225 struct u64_stats_sync syncp;
74c41b04 226 u64 rx_packets;
227 u64 rx_bytes;
228 u64 tx_packets;
229 u64 tx_bytes;
c5aff182
TP
230};
231
232struct mvneta_port {
233 int pkt_size;
234 void __iomem *base;
235 struct mvneta_rx_queue *rxqs;
236 struct mvneta_tx_queue *txqs;
237 struct timer_list tx_done_timer;
238 struct net_device *dev;
239
240 u32 cause_rx_tx;
241 struct napi_struct napi;
242
243 /* Flags */
244 unsigned long flags;
245#define MVNETA_F_TX_DONE_TIMER_BIT 0
246
247 /* Napi weight */
248 int weight;
249
250 /* Core clock */
189dd626 251 struct clk *clk;
c5aff182
TP
252 u8 mcast_count[256];
253 u16 tx_ring_size;
254 u16 rx_ring_size;
74c41b04 255 struct mvneta_pcpu_stats *stats;
c5aff182
TP
256
257 struct mii_bus *mii_bus;
258 struct phy_device *phy_dev;
259 phy_interface_t phy_interface;
260 struct device_node *phy_node;
261 unsigned int link;
262 unsigned int duplex;
263 unsigned int speed;
264};
265
6a20c175 266/* The mvneta_tx_desc and mvneta_rx_desc structures describe the
c5aff182
TP
267 * layout of the transmit and reception DMA descriptors, and their
268 * layout is therefore defined by the hardware design
269 */
6083ed44 270
c5aff182
TP
271#define MVNETA_TX_L3_OFF_SHIFT 0
272#define MVNETA_TX_IP_HLEN_SHIFT 8
273#define MVNETA_TX_L4_UDP BIT(16)
274#define MVNETA_TX_L3_IP6 BIT(17)
275#define MVNETA_TXD_IP_CSUM BIT(18)
276#define MVNETA_TXD_Z_PAD BIT(19)
277#define MVNETA_TXD_L_DESC BIT(20)
278#define MVNETA_TXD_F_DESC BIT(21)
279#define MVNETA_TXD_FLZ_DESC (MVNETA_TXD_Z_PAD | \
280 MVNETA_TXD_L_DESC | \
281 MVNETA_TXD_F_DESC)
282#define MVNETA_TX_L4_CSUM_FULL BIT(30)
283#define MVNETA_TX_L4_CSUM_NOT BIT(31)
284
c5aff182
TP
285#define MVNETA_RXD_ERR_CRC 0x0
286#define MVNETA_RXD_ERR_SUMMARY BIT(16)
287#define MVNETA_RXD_ERR_OVERRUN BIT(17)
288#define MVNETA_RXD_ERR_LEN BIT(18)
289#define MVNETA_RXD_ERR_RESOURCE (BIT(17) | BIT(18))
290#define MVNETA_RXD_ERR_CODE_MASK (BIT(17) | BIT(18))
291#define MVNETA_RXD_L3_IP4 BIT(25)
292#define MVNETA_RXD_FIRST_LAST_DESC (BIT(26) | BIT(27))
293#define MVNETA_RXD_L4_CSUM_OK BIT(30)
294
9ad8fef6 295#if defined(__LITTLE_ENDIAN)
6083ed44
TP
296struct mvneta_tx_desc {
297 u32 command; /* Options used by HW for packet transmitting.*/
298 u16 reserverd1; /* csum_l4 (for future use) */
299 u16 data_size; /* Data size of transmitted packet in bytes */
300 u32 buf_phys_addr; /* Physical addr of transmitted buffer */
301 u32 reserved2; /* hw_cmd - (for future use, PMT) */
302 u32 reserved3[4]; /* Reserved - (for future use) */
303};
304
305struct mvneta_rx_desc {
306 u32 status; /* Info about received packet */
c5aff182
TP
307 u16 reserved1; /* pnc_info - (for future use, PnC) */
308 u16 data_size; /* Size of received packet in bytes */
6083ed44 309
c5aff182
TP
310 u32 buf_phys_addr; /* Physical address of the buffer */
311 u32 reserved2; /* pnc_flow_id (for future use, PnC) */
6083ed44 312
c5aff182
TP
313 u32 buf_cookie; /* cookie for access to RX buffer in rx path */
314 u16 reserved3; /* prefetch_cmd, for future use */
315 u16 reserved4; /* csum_l4 - (for future use, PnC) */
6083ed44 316
c5aff182
TP
317 u32 reserved5; /* pnc_extra PnC (for future use, PnC) */
318 u32 reserved6; /* hw_cmd (for future use, PnC and HWF) */
319};
9ad8fef6
TP
320#else
321struct mvneta_tx_desc {
322 u16 data_size; /* Data size of transmitted packet in bytes */
323 u16 reserverd1; /* csum_l4 (for future use) */
324 u32 command; /* Options used by HW for packet transmitting.*/
325 u32 reserved2; /* hw_cmd - (for future use, PMT) */
326 u32 buf_phys_addr; /* Physical addr of transmitted buffer */
327 u32 reserved3[4]; /* Reserved - (for future use) */
328};
329
330struct mvneta_rx_desc {
331 u16 data_size; /* Size of received packet in bytes */
332 u16 reserved1; /* pnc_info - (for future use, PnC) */
333 u32 status; /* Info about received packet */
334
335 u32 reserved2; /* pnc_flow_id (for future use, PnC) */
336 u32 buf_phys_addr; /* Physical address of the buffer */
337
338 u16 reserved4; /* csum_l4 - (for future use, PnC) */
339 u16 reserved3; /* prefetch_cmd, for future use */
340 u32 buf_cookie; /* cookie for access to RX buffer in rx path */
341
342 u32 reserved5; /* pnc_extra PnC (for future use, PnC) */
343 u32 reserved6; /* hw_cmd (for future use, PnC and HWF) */
344};
345#endif
c5aff182
TP
346
347struct mvneta_tx_queue {
348 /* Number of this TX queue, in the range 0-7 */
349 u8 id;
350
351 /* Number of TX DMA descriptors in the descriptor ring */
352 int size;
353
354 /* Number of currently used TX DMA descriptor in the
6a20c175
TP
355 * descriptor ring
356 */
c5aff182
TP
357 int count;
358
359 /* Array of transmitted skb */
360 struct sk_buff **tx_skb;
361
362 /* Index of last TX DMA descriptor that was inserted */
363 int txq_put_index;
364
365 /* Index of the TX DMA descriptor to be cleaned up */
366 int txq_get_index;
367
368 u32 done_pkts_coal;
369
370 /* Virtual address of the TX DMA descriptors array */
371 struct mvneta_tx_desc *descs;
372
373 /* DMA address of the TX DMA descriptors array */
374 dma_addr_t descs_phys;
375
376 /* Index of the last TX DMA descriptor */
377 int last_desc;
378
379 /* Index of the next TX DMA descriptor to process */
380 int next_desc_to_proc;
381};
382
383struct mvneta_rx_queue {
384 /* rx queue number, in the range 0-7 */
385 u8 id;
386
387 /* num of rx descriptors in the rx descriptor ring */
388 int size;
389
390 /* counter of times when mvneta_refill() failed */
391 int missed;
392
393 u32 pkts_coal;
394 u32 time_coal;
395
396 /* Virtual address of the RX DMA descriptors array */
397 struct mvneta_rx_desc *descs;
398
399 /* DMA address of the RX DMA descriptors array */
400 dma_addr_t descs_phys;
401
402 /* Index of the last RX DMA descriptor */
403 int last_desc;
404
405 /* Index of the next RX DMA descriptor to process */
406 int next_desc_to_proc;
407};
408
409static int rxq_number = 8;
410static int txq_number = 8;
411
412static int rxq_def;
c5aff182
TP
413
414#define MVNETA_DRIVER_NAME "mvneta"
415#define MVNETA_DRIVER_VERSION "1.0"
416
417/* Utility/helper methods */
418
419/* Write helper method */
420static void mvreg_write(struct mvneta_port *pp, u32 offset, u32 data)
421{
422 writel(data, pp->base + offset);
423}
424
425/* Read helper method */
426static u32 mvreg_read(struct mvneta_port *pp, u32 offset)
427{
428 return readl(pp->base + offset);
429}
430
431/* Increment txq get counter */
432static void mvneta_txq_inc_get(struct mvneta_tx_queue *txq)
433{
434 txq->txq_get_index++;
435 if (txq->txq_get_index == txq->size)
436 txq->txq_get_index = 0;
437}
438
439/* Increment txq put counter */
440static void mvneta_txq_inc_put(struct mvneta_tx_queue *txq)
441{
442 txq->txq_put_index++;
443 if (txq->txq_put_index == txq->size)
444 txq->txq_put_index = 0;
445}
446
447
448/* Clear all MIB counters */
449static void mvneta_mib_counters_clear(struct mvneta_port *pp)
450{
451 int i;
452 u32 dummy;
453
454 /* Perform dummy reads from MIB counters */
455 for (i = 0; i < MVNETA_MIB_LATE_COLLISION; i += 4)
456 dummy = mvreg_read(pp, (MVNETA_MIB_COUNTERS_BASE + i));
457}
458
459/* Get System Network Statistics */
460struct rtnl_link_stats64 *mvneta_get_stats64(struct net_device *dev,
461 struct rtnl_link_stats64 *stats)
462{
463 struct mvneta_port *pp = netdev_priv(dev);
464 unsigned int start;
74c41b04 465 int cpu;
c5aff182 466
74c41b04 467 for_each_possible_cpu(cpu) {
468 struct mvneta_pcpu_stats *cpu_stats;
469 u64 rx_packets;
470 u64 rx_bytes;
471 u64 tx_packets;
472 u64 tx_bytes;
c5aff182 473
74c41b04 474 cpu_stats = per_cpu_ptr(pp->stats, cpu);
475 do {
476 start = u64_stats_fetch_begin_bh(&cpu_stats->syncp);
477 rx_packets = cpu_stats->rx_packets;
478 rx_bytes = cpu_stats->rx_bytes;
479 tx_packets = cpu_stats->tx_packets;
480 tx_bytes = cpu_stats->tx_bytes;
481 } while (u64_stats_fetch_retry_bh(&cpu_stats->syncp, start));
c5aff182 482
74c41b04 483 stats->rx_packets += rx_packets;
484 stats->rx_bytes += rx_bytes;
485 stats->tx_packets += tx_packets;
486 stats->tx_bytes += tx_bytes;
487 }
c5aff182
TP
488
489 stats->rx_errors = dev->stats.rx_errors;
490 stats->rx_dropped = dev->stats.rx_dropped;
491
492 stats->tx_dropped = dev->stats.tx_dropped;
493
494 return stats;
495}
496
497/* Rx descriptors helper methods */
498
6a20c175 499/* Checks whether the given RX descriptor is both the first and the
c5aff182
TP
500 * last descriptor for the RX packet. Each RX packet is currently
501 * received through a single RX descriptor, so not having each RX
502 * descriptor with its first and last bits set is an error
503 */
504static int mvneta_rxq_desc_is_first_last(struct mvneta_rx_desc *desc)
505{
506 return (desc->status & MVNETA_RXD_FIRST_LAST_DESC) ==
507 MVNETA_RXD_FIRST_LAST_DESC;
508}
509
510/* Add number of descriptors ready to receive new packets */
511static void mvneta_rxq_non_occup_desc_add(struct mvneta_port *pp,
512 struct mvneta_rx_queue *rxq,
513 int ndescs)
514{
515 /* Only MVNETA_RXQ_ADD_NON_OCCUPIED_MAX (255) descriptors can
6a20c175
TP
516 * be added at once
517 */
c5aff182
TP
518 while (ndescs > MVNETA_RXQ_ADD_NON_OCCUPIED_MAX) {
519 mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id),
520 (MVNETA_RXQ_ADD_NON_OCCUPIED_MAX <<
521 MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT));
522 ndescs -= MVNETA_RXQ_ADD_NON_OCCUPIED_MAX;
523 }
524
525 mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id),
526 (ndescs << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT));
527}
528
529/* Get number of RX descriptors occupied by received packets */
530static int mvneta_rxq_busy_desc_num_get(struct mvneta_port *pp,
531 struct mvneta_rx_queue *rxq)
532{
533 u32 val;
534
535 val = mvreg_read(pp, MVNETA_RXQ_STATUS_REG(rxq->id));
536 return val & MVNETA_RXQ_OCCUPIED_ALL_MASK;
537}
538
6a20c175 539/* Update num of rx desc called upon return from rx path or
c5aff182
TP
540 * from mvneta_rxq_drop_pkts().
541 */
542static void mvneta_rxq_desc_num_update(struct mvneta_port *pp,
543 struct mvneta_rx_queue *rxq,
544 int rx_done, int rx_filled)
545{
546 u32 val;
547
548 if ((rx_done <= 0xff) && (rx_filled <= 0xff)) {
549 val = rx_done |
550 (rx_filled << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT);
551 mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id), val);
552 return;
553 }
554
555 /* Only 255 descriptors can be added at once */
556 while ((rx_done > 0) || (rx_filled > 0)) {
557 if (rx_done <= 0xff) {
558 val = rx_done;
559 rx_done = 0;
560 } else {
561 val = 0xff;
562 rx_done -= 0xff;
563 }
564 if (rx_filled <= 0xff) {
565 val |= rx_filled << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT;
566 rx_filled = 0;
567 } else {
568 val |= 0xff << MVNETA_RXQ_ADD_NON_OCCUPIED_SHIFT;
569 rx_filled -= 0xff;
570 }
571 mvreg_write(pp, MVNETA_RXQ_STATUS_UPDATE_REG(rxq->id), val);
572 }
573}
574
575/* Get pointer to next RX descriptor to be processed by SW */
576static struct mvneta_rx_desc *
577mvneta_rxq_next_desc_get(struct mvneta_rx_queue *rxq)
578{
579 int rx_desc = rxq->next_desc_to_proc;
580
581 rxq->next_desc_to_proc = MVNETA_QUEUE_NEXT_DESC(rxq, rx_desc);
582 return rxq->descs + rx_desc;
583}
584
585/* Change maximum receive size of the port. */
586static void mvneta_max_rx_size_set(struct mvneta_port *pp, int max_rx_size)
587{
588 u32 val;
589
590 val = mvreg_read(pp, MVNETA_GMAC_CTRL_0);
591 val &= ~MVNETA_GMAC_MAX_RX_SIZE_MASK;
592 val |= ((max_rx_size - MVNETA_MH_SIZE) / 2) <<
593 MVNETA_GMAC_MAX_RX_SIZE_SHIFT;
594 mvreg_write(pp, MVNETA_GMAC_CTRL_0, val);
595}
596
597
598/* Set rx queue offset */
599static void mvneta_rxq_offset_set(struct mvneta_port *pp,
600 struct mvneta_rx_queue *rxq,
601 int offset)
602{
603 u32 val;
604
605 val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id));
606 val &= ~MVNETA_RXQ_PKT_OFFSET_ALL_MASK;
607
608 /* Offset is in */
609 val |= MVNETA_RXQ_PKT_OFFSET_MASK(offset >> 3);
610 mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val);
611}
612
613
614/* Tx descriptors helper methods */
615
616/* Update HW with number of TX descriptors to be sent */
617static void mvneta_txq_pend_desc_add(struct mvneta_port *pp,
618 struct mvneta_tx_queue *txq,
619 int pend_desc)
620{
621 u32 val;
622
623 /* Only 255 descriptors can be added at once ; Assume caller
6a20c175
TP
624 * process TX desriptors in quanta less than 256
625 */
c5aff182
TP
626 val = pend_desc;
627 mvreg_write(pp, MVNETA_TXQ_UPDATE_REG(txq->id), val);
628}
629
630/* Get pointer to next TX descriptor to be processed (send) by HW */
631static struct mvneta_tx_desc *
632mvneta_txq_next_desc_get(struct mvneta_tx_queue *txq)
633{
634 int tx_desc = txq->next_desc_to_proc;
635
636 txq->next_desc_to_proc = MVNETA_QUEUE_NEXT_DESC(txq, tx_desc);
637 return txq->descs + tx_desc;
638}
639
640/* Release the last allocated TX descriptor. Useful to handle DMA
6a20c175
TP
641 * mapping failures in the TX path.
642 */
c5aff182
TP
643static void mvneta_txq_desc_put(struct mvneta_tx_queue *txq)
644{
645 if (txq->next_desc_to_proc == 0)
646 txq->next_desc_to_proc = txq->last_desc - 1;
647 else
648 txq->next_desc_to_proc--;
649}
650
651/* Set rxq buf size */
652static void mvneta_rxq_buf_size_set(struct mvneta_port *pp,
653 struct mvneta_rx_queue *rxq,
654 int buf_size)
655{
656 u32 val;
657
658 val = mvreg_read(pp, MVNETA_RXQ_SIZE_REG(rxq->id));
659
660 val &= ~MVNETA_RXQ_BUF_SIZE_MASK;
661 val |= ((buf_size >> 3) << MVNETA_RXQ_BUF_SIZE_SHIFT);
662
663 mvreg_write(pp, MVNETA_RXQ_SIZE_REG(rxq->id), val);
664}
665
666/* Disable buffer management (BM) */
667static void mvneta_rxq_bm_disable(struct mvneta_port *pp,
668 struct mvneta_rx_queue *rxq)
669{
670 u32 val;
671
672 val = mvreg_read(pp, MVNETA_RXQ_CONFIG_REG(rxq->id));
673 val &= ~MVNETA_RXQ_HW_BUF_ALLOC;
674 mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val);
675}
676
677
678
679/* Sets the RGMII Enable bit (RGMIIEn) in port MAC control register */
03ce758e 680static void mvneta_gmac_rgmii_set(struct mvneta_port *pp, int enable)
c5aff182
TP
681{
682 u32 val;
683
684 val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
685
686 if (enable)
687 val |= MVNETA_GMAC2_PORT_RGMII;
688 else
689 val &= ~MVNETA_GMAC2_PORT_RGMII;
690
691 mvreg_write(pp, MVNETA_GMAC_CTRL_2, val);
692}
693
694/* Config SGMII port */
03ce758e 695static void mvneta_port_sgmii_config(struct mvneta_port *pp)
c5aff182
TP
696{
697 u32 val;
698
699 val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
700 val |= MVNETA_GMAC2_PSC_ENABLE;
701 mvreg_write(pp, MVNETA_GMAC_CTRL_2, val);
5445eaf3
APR
702
703 mvreg_write(pp, MVNETA_SGMII_SERDES_CFG, MVNETA_SGMII_SERDES_PROTO);
c5aff182
TP
704}
705
706/* Start the Ethernet port RX and TX activity */
707static void mvneta_port_up(struct mvneta_port *pp)
708{
709 int queue;
710 u32 q_map;
711
712 /* Enable all initialized TXs. */
713 mvneta_mib_counters_clear(pp);
714 q_map = 0;
715 for (queue = 0; queue < txq_number; queue++) {
716 struct mvneta_tx_queue *txq = &pp->txqs[queue];
717 if (txq->descs != NULL)
718 q_map |= (1 << queue);
719 }
720 mvreg_write(pp, MVNETA_TXQ_CMD, q_map);
721
722 /* Enable all initialized RXQs. */
723 q_map = 0;
724 for (queue = 0; queue < rxq_number; queue++) {
725 struct mvneta_rx_queue *rxq = &pp->rxqs[queue];
726 if (rxq->descs != NULL)
727 q_map |= (1 << queue);
728 }
729
730 mvreg_write(pp, MVNETA_RXQ_CMD, q_map);
731}
732
733/* Stop the Ethernet port activity */
734static void mvneta_port_down(struct mvneta_port *pp)
735{
736 u32 val;
737 int count;
738
739 /* Stop Rx port activity. Check port Rx activity. */
740 val = mvreg_read(pp, MVNETA_RXQ_CMD) & MVNETA_RXQ_ENABLE_MASK;
741
742 /* Issue stop command for active channels only */
743 if (val != 0)
744 mvreg_write(pp, MVNETA_RXQ_CMD,
745 val << MVNETA_RXQ_DISABLE_SHIFT);
746
747 /* Wait for all Rx activity to terminate. */
748 count = 0;
749 do {
750 if (count++ >= MVNETA_RX_DISABLE_TIMEOUT_MSEC) {
751 netdev_warn(pp->dev,
752 "TIMEOUT for RX stopped ! rx_queue_cmd: 0x08%x\n",
753 val);
754 break;
755 }
756 mdelay(1);
757
758 val = mvreg_read(pp, MVNETA_RXQ_CMD);
759 } while (val & 0xff);
760
761 /* Stop Tx port activity. Check port Tx activity. Issue stop
6a20c175
TP
762 * command for active channels only
763 */
c5aff182
TP
764 val = (mvreg_read(pp, MVNETA_TXQ_CMD)) & MVNETA_TXQ_ENABLE_MASK;
765
766 if (val != 0)
767 mvreg_write(pp, MVNETA_TXQ_CMD,
768 (val << MVNETA_TXQ_DISABLE_SHIFT));
769
770 /* Wait for all Tx activity to terminate. */
771 count = 0;
772 do {
773 if (count++ >= MVNETA_TX_DISABLE_TIMEOUT_MSEC) {
774 netdev_warn(pp->dev,
775 "TIMEOUT for TX stopped status=0x%08x\n",
776 val);
777 break;
778 }
779 mdelay(1);
780
781 /* Check TX Command reg that all Txqs are stopped */
782 val = mvreg_read(pp, MVNETA_TXQ_CMD);
783
784 } while (val & 0xff);
785
786 /* Double check to verify that TX FIFO is empty */
787 count = 0;
788 do {
789 if (count++ >= MVNETA_TX_FIFO_EMPTY_TIMEOUT) {
790 netdev_warn(pp->dev,
791 "TX FIFO empty timeout status=0x08%x\n",
792 val);
793 break;
794 }
795 mdelay(1);
796
797 val = mvreg_read(pp, MVNETA_PORT_STATUS);
798 } while (!(val & MVNETA_TX_FIFO_EMPTY) &&
799 (val & MVNETA_TX_IN_PRGRS));
800
801 udelay(200);
802}
803
804/* Enable the port by setting the port enable bit of the MAC control register */
805static void mvneta_port_enable(struct mvneta_port *pp)
806{
807 u32 val;
808
809 /* Enable port */
810 val = mvreg_read(pp, MVNETA_GMAC_CTRL_0);
811 val |= MVNETA_GMAC0_PORT_ENABLE;
812 mvreg_write(pp, MVNETA_GMAC_CTRL_0, val);
813}
814
815/* Disable the port and wait for about 200 usec before retuning */
816static void mvneta_port_disable(struct mvneta_port *pp)
817{
818 u32 val;
819
820 /* Reset the Enable bit in the Serial Control Register */
821 val = mvreg_read(pp, MVNETA_GMAC_CTRL_0);
822 val &= ~MVNETA_GMAC0_PORT_ENABLE;
823 mvreg_write(pp, MVNETA_GMAC_CTRL_0, val);
824
825 udelay(200);
826}
827
828/* Multicast tables methods */
829
830/* Set all entries in Unicast MAC Table; queue==-1 means reject all */
831static void mvneta_set_ucast_table(struct mvneta_port *pp, int queue)
832{
833 int offset;
834 u32 val;
835
836 if (queue == -1) {
837 val = 0;
838 } else {
839 val = 0x1 | (queue << 1);
840 val |= (val << 24) | (val << 16) | (val << 8);
841 }
842
843 for (offset = 0; offset <= 0xc; offset += 4)
844 mvreg_write(pp, MVNETA_DA_FILT_UCAST_BASE + offset, val);
845}
846
847/* Set all entries in Special Multicast MAC Table; queue==-1 means reject all */
848static void mvneta_set_special_mcast_table(struct mvneta_port *pp, int queue)
849{
850 int offset;
851 u32 val;
852
853 if (queue == -1) {
854 val = 0;
855 } else {
856 val = 0x1 | (queue << 1);
857 val |= (val << 24) | (val << 16) | (val << 8);
858 }
859
860 for (offset = 0; offset <= 0xfc; offset += 4)
861 mvreg_write(pp, MVNETA_DA_FILT_SPEC_MCAST + offset, val);
862
863}
864
865/* Set all entries in Other Multicast MAC Table. queue==-1 means reject all */
866static void mvneta_set_other_mcast_table(struct mvneta_port *pp, int queue)
867{
868 int offset;
869 u32 val;
870
871 if (queue == -1) {
872 memset(pp->mcast_count, 0, sizeof(pp->mcast_count));
873 val = 0;
874 } else {
875 memset(pp->mcast_count, 1, sizeof(pp->mcast_count));
876 val = 0x1 | (queue << 1);
877 val |= (val << 24) | (val << 16) | (val << 8);
878 }
879
880 for (offset = 0; offset <= 0xfc; offset += 4)
881 mvreg_write(pp, MVNETA_DA_FILT_OTH_MCAST + offset, val);
882}
883
884/* This method sets defaults to the NETA port:
885 * Clears interrupt Cause and Mask registers.
886 * Clears all MAC tables.
887 * Sets defaults to all registers.
888 * Resets RX and TX descriptor rings.
889 * Resets PHY.
890 * This method can be called after mvneta_port_down() to return the port
891 * settings to defaults.
892 */
893static void mvneta_defaults_set(struct mvneta_port *pp)
894{
895 int cpu;
896 int queue;
897 u32 val;
898
899 /* Clear all Cause registers */
900 mvreg_write(pp, MVNETA_INTR_NEW_CAUSE, 0);
901 mvreg_write(pp, MVNETA_INTR_OLD_CAUSE, 0);
902 mvreg_write(pp, MVNETA_INTR_MISC_CAUSE, 0);
903
904 /* Mask all interrupts */
905 mvreg_write(pp, MVNETA_INTR_NEW_MASK, 0);
906 mvreg_write(pp, MVNETA_INTR_OLD_MASK, 0);
907 mvreg_write(pp, MVNETA_INTR_MISC_MASK, 0);
908 mvreg_write(pp, MVNETA_INTR_ENABLE, 0);
909
910 /* Enable MBUS Retry bit16 */
911 mvreg_write(pp, MVNETA_MBUS_RETRY, 0x20);
912
913 /* Set CPU queue access map - all CPUs have access to all RX
6a20c175
TP
914 * queues and to all TX queues
915 */
c5aff182
TP
916 for (cpu = 0; cpu < CONFIG_NR_CPUS; cpu++)
917 mvreg_write(pp, MVNETA_CPU_MAP(cpu),
918 (MVNETA_CPU_RXQ_ACCESS_ALL_MASK |
919 MVNETA_CPU_TXQ_ACCESS_ALL_MASK));
920
921 /* Reset RX and TX DMAs */
922 mvreg_write(pp, MVNETA_PORT_RX_RESET, MVNETA_PORT_RX_DMA_RESET);
923 mvreg_write(pp, MVNETA_PORT_TX_RESET, MVNETA_PORT_TX_DMA_RESET);
924
925 /* Disable Legacy WRR, Disable EJP, Release from reset */
926 mvreg_write(pp, MVNETA_TXQ_CMD_1, 0);
927 for (queue = 0; queue < txq_number; queue++) {
928 mvreg_write(pp, MVETH_TXQ_TOKEN_COUNT_REG(queue), 0);
929 mvreg_write(pp, MVETH_TXQ_TOKEN_CFG_REG(queue), 0);
930 }
931
932 mvreg_write(pp, MVNETA_PORT_TX_RESET, 0);
933 mvreg_write(pp, MVNETA_PORT_RX_RESET, 0);
934
935 /* Set Port Acceleration Mode */
936 val = MVNETA_ACC_MODE_EXT;
937 mvreg_write(pp, MVNETA_ACC_MODE, val);
938
939 /* Update val of portCfg register accordingly with all RxQueue types */
940 val = MVNETA_PORT_CONFIG_DEFL_VALUE(rxq_def);
941 mvreg_write(pp, MVNETA_PORT_CONFIG, val);
942
943 val = 0;
944 mvreg_write(pp, MVNETA_PORT_CONFIG_EXTEND, val);
945 mvreg_write(pp, MVNETA_RX_MIN_FRAME_SIZE, 64);
946
947 /* Build PORT_SDMA_CONFIG_REG */
948 val = 0;
949
950 /* Default burst size */
951 val |= MVNETA_TX_BRST_SZ_MASK(MVNETA_SDMA_BRST_SIZE_16);
952 val |= MVNETA_RX_BRST_SZ_MASK(MVNETA_SDMA_BRST_SIZE_16);
9ad8fef6 953 val |= MVNETA_RX_NO_DATA_SWAP | MVNETA_TX_NO_DATA_SWAP;
c5aff182 954
9ad8fef6
TP
955#if defined(__BIG_ENDIAN)
956 val |= MVNETA_DESC_SWAP;
957#endif
c5aff182
TP
958
959 /* Assign port SDMA configuration */
960 mvreg_write(pp, MVNETA_SDMA_CONFIG, val);
961
71408602
TP
962 /* Disable PHY polling in hardware, since we're using the
963 * kernel phylib to do this.
964 */
965 val = mvreg_read(pp, MVNETA_UNIT_CONTROL);
966 val &= ~MVNETA_PHY_POLLING_ENABLE;
967 mvreg_write(pp, MVNETA_UNIT_CONTROL, val);
968
c5aff182
TP
969 mvneta_set_ucast_table(pp, -1);
970 mvneta_set_special_mcast_table(pp, -1);
971 mvneta_set_other_mcast_table(pp, -1);
972
973 /* Set port interrupt enable register - default enable all */
974 mvreg_write(pp, MVNETA_INTR_ENABLE,
975 (MVNETA_RXQ_INTR_ENABLE_ALL_MASK
976 | MVNETA_TXQ_INTR_ENABLE_ALL_MASK));
977}
978
979/* Set max sizes for tx queues */
980static void mvneta_txq_max_tx_size_set(struct mvneta_port *pp, int max_tx_size)
981
982{
983 u32 val, size, mtu;
984 int queue;
985
986 mtu = max_tx_size * 8;
987 if (mtu > MVNETA_TX_MTU_MAX)
988 mtu = MVNETA_TX_MTU_MAX;
989
990 /* Set MTU */
991 val = mvreg_read(pp, MVNETA_TX_MTU);
992 val &= ~MVNETA_TX_MTU_MAX;
993 val |= mtu;
994 mvreg_write(pp, MVNETA_TX_MTU, val);
995
996 /* TX token size and all TXQs token size must be larger that MTU */
997 val = mvreg_read(pp, MVNETA_TX_TOKEN_SIZE);
998
999 size = val & MVNETA_TX_TOKEN_SIZE_MAX;
1000 if (size < mtu) {
1001 size = mtu;
1002 val &= ~MVNETA_TX_TOKEN_SIZE_MAX;
1003 val |= size;
1004 mvreg_write(pp, MVNETA_TX_TOKEN_SIZE, val);
1005 }
1006 for (queue = 0; queue < txq_number; queue++) {
1007 val = mvreg_read(pp, MVNETA_TXQ_TOKEN_SIZE_REG(queue));
1008
1009 size = val & MVNETA_TXQ_TOKEN_SIZE_MAX;
1010 if (size < mtu) {
1011 size = mtu;
1012 val &= ~MVNETA_TXQ_TOKEN_SIZE_MAX;
1013 val |= size;
1014 mvreg_write(pp, MVNETA_TXQ_TOKEN_SIZE_REG(queue), val);
1015 }
1016 }
1017}
1018
1019/* Set unicast address */
1020static void mvneta_set_ucast_addr(struct mvneta_port *pp, u8 last_nibble,
1021 int queue)
1022{
1023 unsigned int unicast_reg;
1024 unsigned int tbl_offset;
1025 unsigned int reg_offset;
1026
1027 /* Locate the Unicast table entry */
1028 last_nibble = (0xf & last_nibble);
1029
1030 /* offset from unicast tbl base */
1031 tbl_offset = (last_nibble / 4) * 4;
1032
1033 /* offset within the above reg */
1034 reg_offset = last_nibble % 4;
1035
1036 unicast_reg = mvreg_read(pp, (MVNETA_DA_FILT_UCAST_BASE + tbl_offset));
1037
1038 if (queue == -1) {
1039 /* Clear accepts frame bit at specified unicast DA tbl entry */
1040 unicast_reg &= ~(0xff << (8 * reg_offset));
1041 } else {
1042 unicast_reg &= ~(0xff << (8 * reg_offset));
1043 unicast_reg |= ((0x01 | (queue << 1)) << (8 * reg_offset));
1044 }
1045
1046 mvreg_write(pp, (MVNETA_DA_FILT_UCAST_BASE + tbl_offset), unicast_reg);
1047}
1048
1049/* Set mac address */
1050static void mvneta_mac_addr_set(struct mvneta_port *pp, unsigned char *addr,
1051 int queue)
1052{
1053 unsigned int mac_h;
1054 unsigned int mac_l;
1055
1056 if (queue != -1) {
1057 mac_l = (addr[4] << 8) | (addr[5]);
1058 mac_h = (addr[0] << 24) | (addr[1] << 16) |
1059 (addr[2] << 8) | (addr[3] << 0);
1060
1061 mvreg_write(pp, MVNETA_MAC_ADDR_LOW, mac_l);
1062 mvreg_write(pp, MVNETA_MAC_ADDR_HIGH, mac_h);
1063 }
1064
1065 /* Accept frames of this address */
1066 mvneta_set_ucast_addr(pp, addr[5], queue);
1067}
1068
6a20c175
TP
1069/* Set the number of packets that will be received before RX interrupt
1070 * will be generated by HW.
c5aff182
TP
1071 */
1072static void mvneta_rx_pkts_coal_set(struct mvneta_port *pp,
1073 struct mvneta_rx_queue *rxq, u32 value)
1074{
1075 mvreg_write(pp, MVNETA_RXQ_THRESHOLD_REG(rxq->id),
1076 value | MVNETA_RXQ_NON_OCCUPIED(0));
1077 rxq->pkts_coal = value;
1078}
1079
6a20c175
TP
1080/* Set the time delay in usec before RX interrupt will be generated by
1081 * HW.
c5aff182
TP
1082 */
1083static void mvneta_rx_time_coal_set(struct mvneta_port *pp,
1084 struct mvneta_rx_queue *rxq, u32 value)
1085{
189dd626
TP
1086 u32 val;
1087 unsigned long clk_rate;
1088
1089 clk_rate = clk_get_rate(pp->clk);
1090 val = (clk_rate / 1000000) * value;
c5aff182
TP
1091
1092 mvreg_write(pp, MVNETA_RXQ_TIME_COAL_REG(rxq->id), val);
1093 rxq->time_coal = value;
1094}
1095
1096/* Set threshold for TX_DONE pkts coalescing */
1097static void mvneta_tx_done_pkts_coal_set(struct mvneta_port *pp,
1098 struct mvneta_tx_queue *txq, u32 value)
1099{
1100 u32 val;
1101
1102 val = mvreg_read(pp, MVNETA_TXQ_SIZE_REG(txq->id));
1103
1104 val &= ~MVNETA_TXQ_SENT_THRESH_ALL_MASK;
1105 val |= MVNETA_TXQ_SENT_THRESH_MASK(value);
1106
1107 mvreg_write(pp, MVNETA_TXQ_SIZE_REG(txq->id), val);
1108
1109 txq->done_pkts_coal = value;
1110}
1111
1112/* Trigger tx done timer in MVNETA_TX_DONE_TIMER_PERIOD msecs */
1113static void mvneta_add_tx_done_timer(struct mvneta_port *pp)
1114{
1115 if (test_and_set_bit(MVNETA_F_TX_DONE_TIMER_BIT, &pp->flags) == 0) {
1116 pp->tx_done_timer.expires = jiffies +
1117 msecs_to_jiffies(MVNETA_TX_DONE_TIMER_PERIOD);
1118 add_timer(&pp->tx_done_timer);
1119 }
1120}
1121
1122
1123/* Handle rx descriptor fill by setting buf_cookie and buf_phys_addr */
1124static void mvneta_rx_desc_fill(struct mvneta_rx_desc *rx_desc,
1125 u32 phys_addr, u32 cookie)
1126{
1127 rx_desc->buf_cookie = cookie;
1128 rx_desc->buf_phys_addr = phys_addr;
1129}
1130
1131/* Decrement sent descriptors counter */
1132static void mvneta_txq_sent_desc_dec(struct mvneta_port *pp,
1133 struct mvneta_tx_queue *txq,
1134 int sent_desc)
1135{
1136 u32 val;
1137
1138 /* Only 255 TX descriptors can be updated at once */
1139 while (sent_desc > 0xff) {
1140 val = 0xff << MVNETA_TXQ_DEC_SENT_SHIFT;
1141 mvreg_write(pp, MVNETA_TXQ_UPDATE_REG(txq->id), val);
1142 sent_desc = sent_desc - 0xff;
1143 }
1144
1145 val = sent_desc << MVNETA_TXQ_DEC_SENT_SHIFT;
1146 mvreg_write(pp, MVNETA_TXQ_UPDATE_REG(txq->id), val);
1147}
1148
1149/* Get number of TX descriptors already sent by HW */
1150static int mvneta_txq_sent_desc_num_get(struct mvneta_port *pp,
1151 struct mvneta_tx_queue *txq)
1152{
1153 u32 val;
1154 int sent_desc;
1155
1156 val = mvreg_read(pp, MVNETA_TXQ_STATUS_REG(txq->id));
1157 sent_desc = (val & MVNETA_TXQ_SENT_DESC_MASK) >>
1158 MVNETA_TXQ_SENT_DESC_SHIFT;
1159
1160 return sent_desc;
1161}
1162
6a20c175 1163/* Get number of sent descriptors and decrement counter.
c5aff182
TP
1164 * The number of sent descriptors is returned.
1165 */
1166static int mvneta_txq_sent_desc_proc(struct mvneta_port *pp,
1167 struct mvneta_tx_queue *txq)
1168{
1169 int sent_desc;
1170
1171 /* Get number of sent descriptors */
1172 sent_desc = mvneta_txq_sent_desc_num_get(pp, txq);
1173
1174 /* Decrement sent descriptors counter */
1175 if (sent_desc)
1176 mvneta_txq_sent_desc_dec(pp, txq, sent_desc);
1177
1178 return sent_desc;
1179}
1180
1181/* Set TXQ descriptors fields relevant for CSUM calculation */
1182static u32 mvneta_txq_desc_csum(int l3_offs, int l3_proto,
1183 int ip_hdr_len, int l4_proto)
1184{
1185 u32 command;
1186
1187 /* Fields: L3_offset, IP_hdrlen, L3_type, G_IPv4_chk,
6a20c175
TP
1188 * G_L4_chk, L4_type; required only for checksum
1189 * calculation
1190 */
c5aff182
TP
1191 command = l3_offs << MVNETA_TX_L3_OFF_SHIFT;
1192 command |= ip_hdr_len << MVNETA_TX_IP_HLEN_SHIFT;
1193
1194 if (l3_proto == swab16(ETH_P_IP))
1195 command |= MVNETA_TXD_IP_CSUM;
1196 else
1197 command |= MVNETA_TX_L3_IP6;
1198
1199 if (l4_proto == IPPROTO_TCP)
1200 command |= MVNETA_TX_L4_CSUM_FULL;
1201 else if (l4_proto == IPPROTO_UDP)
1202 command |= MVNETA_TX_L4_UDP | MVNETA_TX_L4_CSUM_FULL;
1203 else
1204 command |= MVNETA_TX_L4_CSUM_NOT;
1205
1206 return command;
1207}
1208
1209
1210/* Display more error info */
1211static void mvneta_rx_error(struct mvneta_port *pp,
1212 struct mvneta_rx_desc *rx_desc)
1213{
1214 u32 status = rx_desc->status;
1215
1216 if (!mvneta_rxq_desc_is_first_last(rx_desc)) {
1217 netdev_err(pp->dev,
1218 "bad rx status %08x (buffer oversize), size=%d\n",
1219 rx_desc->status, rx_desc->data_size);
1220 return;
1221 }
1222
1223 switch (status & MVNETA_RXD_ERR_CODE_MASK) {
1224 case MVNETA_RXD_ERR_CRC:
1225 netdev_err(pp->dev, "bad rx status %08x (crc error), size=%d\n",
1226 status, rx_desc->data_size);
1227 break;
1228 case MVNETA_RXD_ERR_OVERRUN:
1229 netdev_err(pp->dev, "bad rx status %08x (overrun error), size=%d\n",
1230 status, rx_desc->data_size);
1231 break;
1232 case MVNETA_RXD_ERR_LEN:
1233 netdev_err(pp->dev, "bad rx status %08x (max frame length error), size=%d\n",
1234 status, rx_desc->data_size);
1235 break;
1236 case MVNETA_RXD_ERR_RESOURCE:
1237 netdev_err(pp->dev, "bad rx status %08x (resource error), size=%d\n",
1238 status, rx_desc->data_size);
1239 break;
1240 }
1241}
1242
1243/* Handle RX checksum offload */
1244static void mvneta_rx_csum(struct mvneta_port *pp,
1245 struct mvneta_rx_desc *rx_desc,
1246 struct sk_buff *skb)
1247{
1248 if ((rx_desc->status & MVNETA_RXD_L3_IP4) &&
1249 (rx_desc->status & MVNETA_RXD_L4_CSUM_OK)) {
1250 skb->csum = 0;
1251 skb->ip_summed = CHECKSUM_UNNECESSARY;
1252 return;
1253 }
1254
1255 skb->ip_summed = CHECKSUM_NONE;
1256}
1257
1258/* Return tx queue pointer (find last set bit) according to causeTxDone reg */
1259static struct mvneta_tx_queue *mvneta_tx_done_policy(struct mvneta_port *pp,
1260 u32 cause)
1261{
1262 int queue = fls(cause) - 1;
1263
1264 return (queue < 0 || queue >= txq_number) ? NULL : &pp->txqs[queue];
1265}
1266
1267/* Free tx queue skbuffs */
1268static void mvneta_txq_bufs_free(struct mvneta_port *pp,
1269 struct mvneta_tx_queue *txq, int num)
1270{
1271 int i;
1272
1273 for (i = 0; i < num; i++) {
1274 struct mvneta_tx_desc *tx_desc = txq->descs +
1275 txq->txq_get_index;
1276 struct sk_buff *skb = txq->tx_skb[txq->txq_get_index];
1277
1278 mvneta_txq_inc_get(txq);
1279
1280 if (!skb)
1281 continue;
1282
1283 dma_unmap_single(pp->dev->dev.parent, tx_desc->buf_phys_addr,
1284 tx_desc->data_size, DMA_TO_DEVICE);
1285 dev_kfree_skb_any(skb);
1286 }
1287}
1288
1289/* Handle end of transmission */
1290static int mvneta_txq_done(struct mvneta_port *pp,
1291 struct mvneta_tx_queue *txq)
1292{
1293 struct netdev_queue *nq = netdev_get_tx_queue(pp->dev, txq->id);
1294 int tx_done;
1295
1296 tx_done = mvneta_txq_sent_desc_proc(pp, txq);
1297 if (tx_done == 0)
1298 return tx_done;
1299 mvneta_txq_bufs_free(pp, txq, tx_done);
1300
1301 txq->count -= tx_done;
1302
1303 if (netif_tx_queue_stopped(nq)) {
1304 if (txq->size - txq->count >= MAX_SKB_FRAGS + 1)
1305 netif_tx_wake_queue(nq);
1306 }
1307
1308 return tx_done;
1309}
1310
1311/* Refill processing */
1312static int mvneta_rx_refill(struct mvneta_port *pp,
1313 struct mvneta_rx_desc *rx_desc)
1314
1315{
1316 dma_addr_t phys_addr;
1317 struct sk_buff *skb;
1318
1319 skb = netdev_alloc_skb(pp->dev, pp->pkt_size);
1320 if (!skb)
1321 return -ENOMEM;
1322
1323 phys_addr = dma_map_single(pp->dev->dev.parent, skb->head,
1324 MVNETA_RX_BUF_SIZE(pp->pkt_size),
1325 DMA_FROM_DEVICE);
1326 if (unlikely(dma_mapping_error(pp->dev->dev.parent, phys_addr))) {
1327 dev_kfree_skb(skb);
1328 return -ENOMEM;
1329 }
1330
1331 mvneta_rx_desc_fill(rx_desc, phys_addr, (u32)skb);
1332
1333 return 0;
1334}
1335
1336/* Handle tx checksum */
1337static u32 mvneta_skb_tx_csum(struct mvneta_port *pp, struct sk_buff *skb)
1338{
1339 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1340 int ip_hdr_len = 0;
1341 u8 l4_proto;
1342
1343 if (skb->protocol == htons(ETH_P_IP)) {
1344 struct iphdr *ip4h = ip_hdr(skb);
1345
1346 /* Calculate IPv4 checksum and L4 checksum */
1347 ip_hdr_len = ip4h->ihl;
1348 l4_proto = ip4h->protocol;
1349 } else if (skb->protocol == htons(ETH_P_IPV6)) {
1350 struct ipv6hdr *ip6h = ipv6_hdr(skb);
1351
1352 /* Read l4_protocol from one of IPv6 extra headers */
1353 if (skb_network_header_len(skb) > 0)
1354 ip_hdr_len = (skb_network_header_len(skb) >> 2);
1355 l4_proto = ip6h->nexthdr;
1356 } else
1357 return MVNETA_TX_L4_CSUM_NOT;
1358
1359 return mvneta_txq_desc_csum(skb_network_offset(skb),
1360 skb->protocol, ip_hdr_len, l4_proto);
1361 }
1362
1363 return MVNETA_TX_L4_CSUM_NOT;
1364}
1365
6a20c175 1366/* Returns rx queue pointer (find last set bit) according to causeRxTx
c5aff182
TP
1367 * value
1368 */
1369static struct mvneta_rx_queue *mvneta_rx_policy(struct mvneta_port *pp,
1370 u32 cause)
1371{
1372 int queue = fls(cause >> 8) - 1;
1373
1374 return (queue < 0 || queue >= rxq_number) ? NULL : &pp->rxqs[queue];
1375}
1376
1377/* Drop packets received by the RXQ and free buffers */
1378static void mvneta_rxq_drop_pkts(struct mvneta_port *pp,
1379 struct mvneta_rx_queue *rxq)
1380{
1381 int rx_done, i;
1382
1383 rx_done = mvneta_rxq_busy_desc_num_get(pp, rxq);
1384 for (i = 0; i < rxq->size; i++) {
1385 struct mvneta_rx_desc *rx_desc = rxq->descs + i;
1386 struct sk_buff *skb = (struct sk_buff *)rx_desc->buf_cookie;
1387
1388 dev_kfree_skb_any(skb);
1389 dma_unmap_single(pp->dev->dev.parent, rx_desc->buf_phys_addr,
a328f3a0 1390 MVNETA_RX_BUF_SIZE(pp->pkt_size), DMA_FROM_DEVICE);
c5aff182
TP
1391 }
1392
1393 if (rx_done)
1394 mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_done);
1395}
1396
1397/* Main rx processing */
1398static int mvneta_rx(struct mvneta_port *pp, int rx_todo,
1399 struct mvneta_rx_queue *rxq)
1400{
1401 struct net_device *dev = pp->dev;
1402 int rx_done, rx_filled;
dc4277dd 1403 u32 rcvd_pkts = 0;
1404 u32 rcvd_bytes = 0;
c5aff182
TP
1405
1406 /* Get number of received packets */
1407 rx_done = mvneta_rxq_busy_desc_num_get(pp, rxq);
1408
1409 if (rx_todo > rx_done)
1410 rx_todo = rx_done;
1411
1412 rx_done = 0;
1413 rx_filled = 0;
1414
1415 /* Fairness NAPI loop */
1416 while (rx_done < rx_todo) {
1417 struct mvneta_rx_desc *rx_desc = mvneta_rxq_next_desc_get(rxq);
1418 struct sk_buff *skb;
1419 u32 rx_status;
1420 int rx_bytes, err;
1421
1422 prefetch(rx_desc);
1423 rx_done++;
1424 rx_filled++;
1425 rx_status = rx_desc->status;
1426 skb = (struct sk_buff *)rx_desc->buf_cookie;
1427
1428 if (!mvneta_rxq_desc_is_first_last(rx_desc) ||
1429 (rx_status & MVNETA_RXD_ERR_SUMMARY)) {
1430 dev->stats.rx_errors++;
1431 mvneta_rx_error(pp, rx_desc);
1432 mvneta_rx_desc_fill(rx_desc, rx_desc->buf_phys_addr,
1433 (u32)skb);
1434 continue;
1435 }
1436
1437 dma_unmap_single(pp->dev->dev.parent, rx_desc->buf_phys_addr,
a328f3a0 1438 MVNETA_RX_BUF_SIZE(pp->pkt_size), DMA_FROM_DEVICE);
c5aff182
TP
1439
1440 rx_bytes = rx_desc->data_size -
1441 (ETH_FCS_LEN + MVNETA_MH_SIZE);
dc4277dd 1442 rcvd_pkts++;
1443 rcvd_bytes += rx_bytes;
c5aff182
TP
1444
1445 /* Linux processing */
1446 skb_reserve(skb, MVNETA_MH_SIZE);
1447 skb_put(skb, rx_bytes);
1448
1449 skb->protocol = eth_type_trans(skb, dev);
1450
1451 mvneta_rx_csum(pp, rx_desc, skb);
1452
1453 napi_gro_receive(&pp->napi, skb);
1454
1455 /* Refill processing */
1456 err = mvneta_rx_refill(pp, rx_desc);
1457 if (err) {
1458 netdev_err(pp->dev, "Linux processing - Can't refill\n");
1459 rxq->missed++;
1460 rx_filled--;
1461 }
1462 }
1463
dc4277dd 1464 if (rcvd_pkts) {
74c41b04 1465 struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
1466
1467 u64_stats_update_begin(&stats->syncp);
1468 stats->rx_packets += rcvd_pkts;
1469 stats->rx_bytes += rcvd_bytes;
1470 u64_stats_update_end(&stats->syncp);
dc4277dd 1471 }
1472
c5aff182
TP
1473 /* Update rxq management counters */
1474 mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_filled);
1475
1476 return rx_done;
1477}
1478
1479/* Handle tx fragmentation processing */
1480static int mvneta_tx_frag_process(struct mvneta_port *pp, struct sk_buff *skb,
1481 struct mvneta_tx_queue *txq)
1482{
1483 struct mvneta_tx_desc *tx_desc;
1484 int i;
1485
1486 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1487 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1488 void *addr = page_address(frag->page.p) + frag->page_offset;
1489
1490 tx_desc = mvneta_txq_next_desc_get(txq);
1491 tx_desc->data_size = frag->size;
1492
1493 tx_desc->buf_phys_addr =
1494 dma_map_single(pp->dev->dev.parent, addr,
1495 tx_desc->data_size, DMA_TO_DEVICE);
1496
1497 if (dma_mapping_error(pp->dev->dev.parent,
1498 tx_desc->buf_phys_addr)) {
1499 mvneta_txq_desc_put(txq);
1500 goto error;
1501 }
1502
1503 if (i == (skb_shinfo(skb)->nr_frags - 1)) {
1504 /* Last descriptor */
1505 tx_desc->command = MVNETA_TXD_L_DESC | MVNETA_TXD_Z_PAD;
1506
1507 txq->tx_skb[txq->txq_put_index] = skb;
1508
1509 mvneta_txq_inc_put(txq);
1510 } else {
1511 /* Descriptor in the middle: Not First, Not Last */
1512 tx_desc->command = 0;
1513
1514 txq->tx_skb[txq->txq_put_index] = NULL;
1515 mvneta_txq_inc_put(txq);
1516 }
1517 }
1518
1519 return 0;
1520
1521error:
1522 /* Release all descriptors that were used to map fragments of
6a20c175
TP
1523 * this packet, as well as the corresponding DMA mappings
1524 */
c5aff182
TP
1525 for (i = i - 1; i >= 0; i--) {
1526 tx_desc = txq->descs + i;
1527 dma_unmap_single(pp->dev->dev.parent,
1528 tx_desc->buf_phys_addr,
1529 tx_desc->data_size,
1530 DMA_TO_DEVICE);
1531 mvneta_txq_desc_put(txq);
1532 }
1533
1534 return -ENOMEM;
1535}
1536
1537/* Main tx processing */
1538static int mvneta_tx(struct sk_buff *skb, struct net_device *dev)
1539{
1540 struct mvneta_port *pp = netdev_priv(dev);
ee40a116
WT
1541 u16 txq_id = skb_get_queue_mapping(skb);
1542 struct mvneta_tx_queue *txq = &pp->txqs[txq_id];
c5aff182
TP
1543 struct mvneta_tx_desc *tx_desc;
1544 struct netdev_queue *nq;
1545 int frags = 0;
1546 u32 tx_cmd;
1547
1548 if (!netif_running(dev))
1549 goto out;
1550
1551 frags = skb_shinfo(skb)->nr_frags + 1;
ee40a116 1552 nq = netdev_get_tx_queue(dev, txq_id);
c5aff182
TP
1553
1554 /* Get a descriptor for the first part of the packet */
1555 tx_desc = mvneta_txq_next_desc_get(txq);
1556
1557 tx_cmd = mvneta_skb_tx_csum(pp, skb);
1558
1559 tx_desc->data_size = skb_headlen(skb);
1560
1561 tx_desc->buf_phys_addr = dma_map_single(dev->dev.parent, skb->data,
1562 tx_desc->data_size,
1563 DMA_TO_DEVICE);
1564 if (unlikely(dma_mapping_error(dev->dev.parent,
1565 tx_desc->buf_phys_addr))) {
1566 mvneta_txq_desc_put(txq);
1567 frags = 0;
1568 goto out;
1569 }
1570
1571 if (frags == 1) {
1572 /* First and Last descriptor */
1573 tx_cmd |= MVNETA_TXD_FLZ_DESC;
1574 tx_desc->command = tx_cmd;
1575 txq->tx_skb[txq->txq_put_index] = skb;
1576 mvneta_txq_inc_put(txq);
1577 } else {
1578 /* First but not Last */
1579 tx_cmd |= MVNETA_TXD_F_DESC;
1580 txq->tx_skb[txq->txq_put_index] = NULL;
1581 mvneta_txq_inc_put(txq);
1582 tx_desc->command = tx_cmd;
1583 /* Continue with other skb fragments */
1584 if (mvneta_tx_frag_process(pp, skb, txq)) {
1585 dma_unmap_single(dev->dev.parent,
1586 tx_desc->buf_phys_addr,
1587 tx_desc->data_size,
1588 DMA_TO_DEVICE);
1589 mvneta_txq_desc_put(txq);
1590 frags = 0;
1591 goto out;
1592 }
1593 }
1594
1595 txq->count += frags;
1596 mvneta_txq_pend_desc_add(pp, txq, frags);
1597
1598 if (txq->size - txq->count < MAX_SKB_FRAGS + 1)
1599 netif_tx_stop_queue(nq);
1600
1601out:
1602 if (frags > 0) {
74c41b04 1603 struct mvneta_pcpu_stats *stats = this_cpu_ptr(pp->stats);
c5aff182 1604
74c41b04 1605 u64_stats_update_begin(&stats->syncp);
1606 stats->tx_packets++;
1607 stats->tx_bytes += skb->len;
1608 u64_stats_update_end(&stats->syncp);
c5aff182
TP
1609 } else {
1610 dev->stats.tx_dropped++;
1611 dev_kfree_skb_any(skb);
1612 }
1613
1614 if (txq->count >= MVNETA_TXDONE_COAL_PKTS)
1615 mvneta_txq_done(pp, txq);
1616
1617 /* If after calling mvneta_txq_done, count equals
6a20c175
TP
1618 * frags, we need to set the timer
1619 */
c5aff182
TP
1620 if (txq->count == frags && frags > 0)
1621 mvneta_add_tx_done_timer(pp);
1622
1623 return NETDEV_TX_OK;
1624}
1625
1626
1627/* Free tx resources, when resetting a port */
1628static void mvneta_txq_done_force(struct mvneta_port *pp,
1629 struct mvneta_tx_queue *txq)
1630
1631{
1632 int tx_done = txq->count;
1633
1634 mvneta_txq_bufs_free(pp, txq, tx_done);
1635
1636 /* reset txq */
1637 txq->count = 0;
1638 txq->txq_put_index = 0;
1639 txq->txq_get_index = 0;
1640}
1641
1642/* handle tx done - called from tx done timer callback */
1643static u32 mvneta_tx_done_gbe(struct mvneta_port *pp, u32 cause_tx_done,
1644 int *tx_todo)
1645{
1646 struct mvneta_tx_queue *txq;
1647 u32 tx_done = 0;
1648 struct netdev_queue *nq;
1649
1650 *tx_todo = 0;
1651 while (cause_tx_done != 0) {
1652 txq = mvneta_tx_done_policy(pp, cause_tx_done);
1653 if (!txq)
1654 break;
1655
1656 nq = netdev_get_tx_queue(pp->dev, txq->id);
1657 __netif_tx_lock(nq, smp_processor_id());
1658
1659 if (txq->count) {
1660 tx_done += mvneta_txq_done(pp, txq);
1661 *tx_todo += txq->count;
1662 }
1663
1664 __netif_tx_unlock(nq);
1665 cause_tx_done &= ~((1 << txq->id));
1666 }
1667
1668 return tx_done;
1669}
1670
6a20c175 1671/* Compute crc8 of the specified address, using a unique algorithm ,
c5aff182
TP
1672 * according to hw spec, different than generic crc8 algorithm
1673 */
1674static int mvneta_addr_crc(unsigned char *addr)
1675{
1676 int crc = 0;
1677 int i;
1678
1679 for (i = 0; i < ETH_ALEN; i++) {
1680 int j;
1681
1682 crc = (crc ^ addr[i]) << 8;
1683 for (j = 7; j >= 0; j--) {
1684 if (crc & (0x100 << j))
1685 crc ^= 0x107 << j;
1686 }
1687 }
1688
1689 return crc;
1690}
1691
1692/* This method controls the net device special MAC multicast support.
1693 * The Special Multicast Table for MAC addresses supports MAC of the form
1694 * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0xFF).
1695 * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
1696 * Table entries in the DA-Filter table. This method set the Special
1697 * Multicast Table appropriate entry.
1698 */
1699static void mvneta_set_special_mcast_addr(struct mvneta_port *pp,
1700 unsigned char last_byte,
1701 int queue)
1702{
1703 unsigned int smc_table_reg;
1704 unsigned int tbl_offset;
1705 unsigned int reg_offset;
1706
1707 /* Register offset from SMC table base */
1708 tbl_offset = (last_byte / 4);
1709 /* Entry offset within the above reg */
1710 reg_offset = last_byte % 4;
1711
1712 smc_table_reg = mvreg_read(pp, (MVNETA_DA_FILT_SPEC_MCAST
1713 + tbl_offset * 4));
1714
1715 if (queue == -1)
1716 smc_table_reg &= ~(0xff << (8 * reg_offset));
1717 else {
1718 smc_table_reg &= ~(0xff << (8 * reg_offset));
1719 smc_table_reg |= ((0x01 | (queue << 1)) << (8 * reg_offset));
1720 }
1721
1722 mvreg_write(pp, MVNETA_DA_FILT_SPEC_MCAST + tbl_offset * 4,
1723 smc_table_reg);
1724}
1725
1726/* This method controls the network device Other MAC multicast support.
1727 * The Other Multicast Table is used for multicast of another type.
1728 * A CRC-8 is used as an index to the Other Multicast Table entries
1729 * in the DA-Filter table.
1730 * The method gets the CRC-8 value from the calling routine and
1731 * sets the Other Multicast Table appropriate entry according to the
1732 * specified CRC-8 .
1733 */
1734static void mvneta_set_other_mcast_addr(struct mvneta_port *pp,
1735 unsigned char crc8,
1736 int queue)
1737{
1738 unsigned int omc_table_reg;
1739 unsigned int tbl_offset;
1740 unsigned int reg_offset;
1741
1742 tbl_offset = (crc8 / 4) * 4; /* Register offset from OMC table base */
1743 reg_offset = crc8 % 4; /* Entry offset within the above reg */
1744
1745 omc_table_reg = mvreg_read(pp, MVNETA_DA_FILT_OTH_MCAST + tbl_offset);
1746
1747 if (queue == -1) {
1748 /* Clear accepts frame bit at specified Other DA table entry */
1749 omc_table_reg &= ~(0xff << (8 * reg_offset));
1750 } else {
1751 omc_table_reg &= ~(0xff << (8 * reg_offset));
1752 omc_table_reg |= ((0x01 | (queue << 1)) << (8 * reg_offset));
1753 }
1754
1755 mvreg_write(pp, MVNETA_DA_FILT_OTH_MCAST + tbl_offset, omc_table_reg);
1756}
1757
1758/* The network device supports multicast using two tables:
1759 * 1) Special Multicast Table for MAC addresses of the form
1760 * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0xFF).
1761 * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
1762 * Table entries in the DA-Filter table.
1763 * 2) Other Multicast Table for multicast of another type. A CRC-8 value
1764 * is used as an index to the Other Multicast Table entries in the
1765 * DA-Filter table.
1766 */
1767static int mvneta_mcast_addr_set(struct mvneta_port *pp, unsigned char *p_addr,
1768 int queue)
1769{
1770 unsigned char crc_result = 0;
1771
1772 if (memcmp(p_addr, "\x01\x00\x5e\x00\x00", 5) == 0) {
1773 mvneta_set_special_mcast_addr(pp, p_addr[5], queue);
1774 return 0;
1775 }
1776
1777 crc_result = mvneta_addr_crc(p_addr);
1778 if (queue == -1) {
1779 if (pp->mcast_count[crc_result] == 0) {
1780 netdev_info(pp->dev, "No valid Mcast for crc8=0x%02x\n",
1781 crc_result);
1782 return -EINVAL;
1783 }
1784
1785 pp->mcast_count[crc_result]--;
1786 if (pp->mcast_count[crc_result] != 0) {
1787 netdev_info(pp->dev,
1788 "After delete there are %d valid Mcast for crc8=0x%02x\n",
1789 pp->mcast_count[crc_result], crc_result);
1790 return -EINVAL;
1791 }
1792 } else
1793 pp->mcast_count[crc_result]++;
1794
1795 mvneta_set_other_mcast_addr(pp, crc_result, queue);
1796
1797 return 0;
1798}
1799
1800/* Configure Fitering mode of Ethernet port */
1801static void mvneta_rx_unicast_promisc_set(struct mvneta_port *pp,
1802 int is_promisc)
1803{
1804 u32 port_cfg_reg, val;
1805
1806 port_cfg_reg = mvreg_read(pp, MVNETA_PORT_CONFIG);
1807
1808 val = mvreg_read(pp, MVNETA_TYPE_PRIO);
1809
1810 /* Set / Clear UPM bit in port configuration register */
1811 if (is_promisc) {
1812 /* Accept all Unicast addresses */
1813 port_cfg_reg |= MVNETA_UNI_PROMISC_MODE;
1814 val |= MVNETA_FORCE_UNI;
1815 mvreg_write(pp, MVNETA_MAC_ADDR_LOW, 0xffff);
1816 mvreg_write(pp, MVNETA_MAC_ADDR_HIGH, 0xffffffff);
1817 } else {
1818 /* Reject all Unicast addresses */
1819 port_cfg_reg &= ~MVNETA_UNI_PROMISC_MODE;
1820 val &= ~MVNETA_FORCE_UNI;
1821 }
1822
1823 mvreg_write(pp, MVNETA_PORT_CONFIG, port_cfg_reg);
1824 mvreg_write(pp, MVNETA_TYPE_PRIO, val);
1825}
1826
1827/* register unicast and multicast addresses */
1828static void mvneta_set_rx_mode(struct net_device *dev)
1829{
1830 struct mvneta_port *pp = netdev_priv(dev);
1831 struct netdev_hw_addr *ha;
1832
1833 if (dev->flags & IFF_PROMISC) {
1834 /* Accept all: Multicast + Unicast */
1835 mvneta_rx_unicast_promisc_set(pp, 1);
1836 mvneta_set_ucast_table(pp, rxq_def);
1837 mvneta_set_special_mcast_table(pp, rxq_def);
1838 mvneta_set_other_mcast_table(pp, rxq_def);
1839 } else {
1840 /* Accept single Unicast */
1841 mvneta_rx_unicast_promisc_set(pp, 0);
1842 mvneta_set_ucast_table(pp, -1);
1843 mvneta_mac_addr_set(pp, dev->dev_addr, rxq_def);
1844
1845 if (dev->flags & IFF_ALLMULTI) {
1846 /* Accept all multicast */
1847 mvneta_set_special_mcast_table(pp, rxq_def);
1848 mvneta_set_other_mcast_table(pp, rxq_def);
1849 } else {
1850 /* Accept only initialized multicast */
1851 mvneta_set_special_mcast_table(pp, -1);
1852 mvneta_set_other_mcast_table(pp, -1);
1853
1854 if (!netdev_mc_empty(dev)) {
1855 netdev_for_each_mc_addr(ha, dev) {
1856 mvneta_mcast_addr_set(pp, ha->addr,
1857 rxq_def);
1858 }
1859 }
1860 }
1861 }
1862}
1863
1864/* Interrupt handling - the callback for request_irq() */
1865static irqreturn_t mvneta_isr(int irq, void *dev_id)
1866{
1867 struct mvneta_port *pp = (struct mvneta_port *)dev_id;
1868
1869 /* Mask all interrupts */
1870 mvreg_write(pp, MVNETA_INTR_NEW_MASK, 0);
1871
1872 napi_schedule(&pp->napi);
1873
1874 return IRQ_HANDLED;
1875}
1876
1877/* NAPI handler
1878 * Bits 0 - 7 of the causeRxTx register indicate that are transmitted
1879 * packets on the corresponding TXQ (Bit 0 is for TX queue 1).
1880 * Bits 8 -15 of the cause Rx Tx register indicate that are received
1881 * packets on the corresponding RXQ (Bit 8 is for RX queue 0).
1882 * Each CPU has its own causeRxTx register
1883 */
1884static int mvneta_poll(struct napi_struct *napi, int budget)
1885{
1886 int rx_done = 0;
1887 u32 cause_rx_tx;
1888 unsigned long flags;
1889 struct mvneta_port *pp = netdev_priv(napi->dev);
1890
1891 if (!netif_running(pp->dev)) {
1892 napi_complete(napi);
1893 return rx_done;
1894 }
1895
1896 /* Read cause register */
1897 cause_rx_tx = mvreg_read(pp, MVNETA_INTR_NEW_CAUSE) &
1898 MVNETA_RX_INTR_MASK(rxq_number);
1899
6a20c175 1900 /* For the case where the last mvneta_poll did not process all
c5aff182
TP
1901 * RX packets
1902 */
1903 cause_rx_tx |= pp->cause_rx_tx;
1904 if (rxq_number > 1) {
1905 while ((cause_rx_tx != 0) && (budget > 0)) {
1906 int count;
1907 struct mvneta_rx_queue *rxq;
1908 /* get rx queue number from cause_rx_tx */
1909 rxq = mvneta_rx_policy(pp, cause_rx_tx);
1910 if (!rxq)
1911 break;
1912
1913 /* process the packet in that rx queue */
1914 count = mvneta_rx(pp, budget, rxq);
1915 rx_done += count;
1916 budget -= count;
1917 if (budget > 0) {
6a20c175
TP
1918 /* set off the rx bit of the
1919 * corresponding bit in the cause rx
1920 * tx register, so that next iteration
1921 * will find the next rx queue where
1922 * packets are received on
1923 */
c5aff182
TP
1924 cause_rx_tx &= ~((1 << rxq->id) << 8);
1925 }
1926 }
1927 } else {
1928 rx_done = mvneta_rx(pp, budget, &pp->rxqs[rxq_def]);
1929 budget -= rx_done;
1930 }
1931
1932 if (budget > 0) {
1933 cause_rx_tx = 0;
1934 napi_complete(napi);
1935 local_irq_save(flags);
1936 mvreg_write(pp, MVNETA_INTR_NEW_MASK,
1937 MVNETA_RX_INTR_MASK(rxq_number));
1938 local_irq_restore(flags);
1939 }
1940
1941 pp->cause_rx_tx = cause_rx_tx;
1942 return rx_done;
1943}
1944
1945/* tx done timer callback */
1946static void mvneta_tx_done_timer_callback(unsigned long data)
1947{
1948 struct net_device *dev = (struct net_device *)data;
1949 struct mvneta_port *pp = netdev_priv(dev);
1950 int tx_done = 0, tx_todo = 0;
1951
1952 if (!netif_running(dev))
1953 return ;
1954
1955 clear_bit(MVNETA_F_TX_DONE_TIMER_BIT, &pp->flags);
1956
1957 tx_done = mvneta_tx_done_gbe(pp,
1958 (((1 << txq_number) - 1) &
1959 MVNETA_CAUSE_TXQ_SENT_DESC_ALL_MASK),
1960 &tx_todo);
1961 if (tx_todo > 0)
1962 mvneta_add_tx_done_timer(pp);
1963}
1964
1965/* Handle rxq fill: allocates rxq skbs; called when initializing a port */
1966static int mvneta_rxq_fill(struct mvneta_port *pp, struct mvneta_rx_queue *rxq,
1967 int num)
1968{
1969 struct net_device *dev = pp->dev;
1970 int i;
1971
1972 for (i = 0; i < num; i++) {
1973 struct sk_buff *skb;
1974 struct mvneta_rx_desc *rx_desc;
1975 unsigned long phys_addr;
1976
1977 skb = dev_alloc_skb(pp->pkt_size);
1978 if (!skb) {
1979 netdev_err(dev, "%s:rxq %d, %d of %d buffs filled\n",
1980 __func__, rxq->id, i, num);
1981 break;
1982 }
1983
1984 rx_desc = rxq->descs + i;
1985 memset(rx_desc, 0, sizeof(struct mvneta_rx_desc));
1986 phys_addr = dma_map_single(dev->dev.parent, skb->head,
1987 MVNETA_RX_BUF_SIZE(pp->pkt_size),
1988 DMA_FROM_DEVICE);
1989 if (unlikely(dma_mapping_error(dev->dev.parent, phys_addr))) {
1990 dev_kfree_skb(skb);
1991 break;
1992 }
1993
1994 mvneta_rx_desc_fill(rx_desc, phys_addr, (u32)skb);
1995 }
1996
1997 /* Add this number of RX descriptors as non occupied (ready to
6a20c175
TP
1998 * get packets)
1999 */
c5aff182
TP
2000 mvneta_rxq_non_occup_desc_add(pp, rxq, i);
2001
2002 return i;
2003}
2004
2005/* Free all packets pending transmit from all TXQs and reset TX port */
2006static void mvneta_tx_reset(struct mvneta_port *pp)
2007{
2008 int queue;
2009
2010 /* free the skb's in the hal tx ring */
2011 for (queue = 0; queue < txq_number; queue++)
2012 mvneta_txq_done_force(pp, &pp->txqs[queue]);
2013
2014 mvreg_write(pp, MVNETA_PORT_TX_RESET, MVNETA_PORT_TX_DMA_RESET);
2015 mvreg_write(pp, MVNETA_PORT_TX_RESET, 0);
2016}
2017
2018static void mvneta_rx_reset(struct mvneta_port *pp)
2019{
2020 mvreg_write(pp, MVNETA_PORT_RX_RESET, MVNETA_PORT_RX_DMA_RESET);
2021 mvreg_write(pp, MVNETA_PORT_RX_RESET, 0);
2022}
2023
2024/* Rx/Tx queue initialization/cleanup methods */
2025
2026/* Create a specified RX queue */
2027static int mvneta_rxq_init(struct mvneta_port *pp,
2028 struct mvneta_rx_queue *rxq)
2029
2030{
2031 rxq->size = pp->rx_ring_size;
2032
2033 /* Allocate memory for RX descriptors */
2034 rxq->descs = dma_alloc_coherent(pp->dev->dev.parent,
2035 rxq->size * MVNETA_DESC_ALIGNED_SIZE,
2036 &rxq->descs_phys, GFP_KERNEL);
d0320f75 2037 if (rxq->descs == NULL)
c5aff182 2038 return -ENOMEM;
c5aff182
TP
2039
2040 BUG_ON(rxq->descs !=
2041 PTR_ALIGN(rxq->descs, MVNETA_CPU_D_CACHE_LINE_SIZE));
2042
2043 rxq->last_desc = rxq->size - 1;
2044
2045 /* Set Rx descriptors queue starting address */
2046 mvreg_write(pp, MVNETA_RXQ_BASE_ADDR_REG(rxq->id), rxq->descs_phys);
2047 mvreg_write(pp, MVNETA_RXQ_SIZE_REG(rxq->id), rxq->size);
2048
2049 /* Set Offset */
2050 mvneta_rxq_offset_set(pp, rxq, NET_SKB_PAD);
2051
2052 /* Set coalescing pkts and time */
2053 mvneta_rx_pkts_coal_set(pp, rxq, rxq->pkts_coal);
2054 mvneta_rx_time_coal_set(pp, rxq, rxq->time_coal);
2055
2056 /* Fill RXQ with buffers from RX pool */
2057 mvneta_rxq_buf_size_set(pp, rxq, MVNETA_RX_BUF_SIZE(pp->pkt_size));
2058 mvneta_rxq_bm_disable(pp, rxq);
2059 mvneta_rxq_fill(pp, rxq, rxq->size);
2060
2061 return 0;
2062}
2063
2064/* Cleanup Rx queue */
2065static void mvneta_rxq_deinit(struct mvneta_port *pp,
2066 struct mvneta_rx_queue *rxq)
2067{
2068 mvneta_rxq_drop_pkts(pp, rxq);
2069
2070 if (rxq->descs)
2071 dma_free_coherent(pp->dev->dev.parent,
2072 rxq->size * MVNETA_DESC_ALIGNED_SIZE,
2073 rxq->descs,
2074 rxq->descs_phys);
2075
2076 rxq->descs = NULL;
2077 rxq->last_desc = 0;
2078 rxq->next_desc_to_proc = 0;
2079 rxq->descs_phys = 0;
2080}
2081
2082/* Create and initialize a tx queue */
2083static int mvneta_txq_init(struct mvneta_port *pp,
2084 struct mvneta_tx_queue *txq)
2085{
2086 txq->size = pp->tx_ring_size;
2087
2088 /* Allocate memory for TX descriptors */
2089 txq->descs = dma_alloc_coherent(pp->dev->dev.parent,
2090 txq->size * MVNETA_DESC_ALIGNED_SIZE,
2091 &txq->descs_phys, GFP_KERNEL);
d0320f75 2092 if (txq->descs == NULL)
c5aff182 2093 return -ENOMEM;
c5aff182
TP
2094
2095 /* Make sure descriptor address is cache line size aligned */
2096 BUG_ON(txq->descs !=
2097 PTR_ALIGN(txq->descs, MVNETA_CPU_D_CACHE_LINE_SIZE));
2098
2099 txq->last_desc = txq->size - 1;
2100
2101 /* Set maximum bandwidth for enabled TXQs */
2102 mvreg_write(pp, MVETH_TXQ_TOKEN_CFG_REG(txq->id), 0x03ffffff);
2103 mvreg_write(pp, MVETH_TXQ_TOKEN_COUNT_REG(txq->id), 0x3fffffff);
2104
2105 /* Set Tx descriptors queue starting address */
2106 mvreg_write(pp, MVNETA_TXQ_BASE_ADDR_REG(txq->id), txq->descs_phys);
2107 mvreg_write(pp, MVNETA_TXQ_SIZE_REG(txq->id), txq->size);
2108
2109 txq->tx_skb = kmalloc(txq->size * sizeof(*txq->tx_skb), GFP_KERNEL);
2110 if (txq->tx_skb == NULL) {
2111 dma_free_coherent(pp->dev->dev.parent,
2112 txq->size * MVNETA_DESC_ALIGNED_SIZE,
2113 txq->descs, txq->descs_phys);
2114 return -ENOMEM;
2115 }
2116 mvneta_tx_done_pkts_coal_set(pp, txq, txq->done_pkts_coal);
2117
2118 return 0;
2119}
2120
2121/* Free allocated resources when mvneta_txq_init() fails to allocate memory*/
2122static void mvneta_txq_deinit(struct mvneta_port *pp,
2123 struct mvneta_tx_queue *txq)
2124{
2125 kfree(txq->tx_skb);
2126
2127 if (txq->descs)
2128 dma_free_coherent(pp->dev->dev.parent,
2129 txq->size * MVNETA_DESC_ALIGNED_SIZE,
2130 txq->descs, txq->descs_phys);
2131
2132 txq->descs = NULL;
2133 txq->last_desc = 0;
2134 txq->next_desc_to_proc = 0;
2135 txq->descs_phys = 0;
2136
2137 /* Set minimum bandwidth for disabled TXQs */
2138 mvreg_write(pp, MVETH_TXQ_TOKEN_CFG_REG(txq->id), 0);
2139 mvreg_write(pp, MVETH_TXQ_TOKEN_COUNT_REG(txq->id), 0);
2140
2141 /* Set Tx descriptors queue starting address and size */
2142 mvreg_write(pp, MVNETA_TXQ_BASE_ADDR_REG(txq->id), 0);
2143 mvreg_write(pp, MVNETA_TXQ_SIZE_REG(txq->id), 0);
2144}
2145
2146/* Cleanup all Tx queues */
2147static void mvneta_cleanup_txqs(struct mvneta_port *pp)
2148{
2149 int queue;
2150
2151 for (queue = 0; queue < txq_number; queue++)
2152 mvneta_txq_deinit(pp, &pp->txqs[queue]);
2153}
2154
2155/* Cleanup all Rx queues */
2156static void mvneta_cleanup_rxqs(struct mvneta_port *pp)
2157{
2158 int queue;
2159
2160 for (queue = 0; queue < rxq_number; queue++)
2161 mvneta_rxq_deinit(pp, &pp->rxqs[queue]);
2162}
2163
2164
2165/* Init all Rx queues */
2166static int mvneta_setup_rxqs(struct mvneta_port *pp)
2167{
2168 int queue;
2169
2170 for (queue = 0; queue < rxq_number; queue++) {
2171 int err = mvneta_rxq_init(pp, &pp->rxqs[queue]);
2172 if (err) {
2173 netdev_err(pp->dev, "%s: can't create rxq=%d\n",
2174 __func__, queue);
2175 mvneta_cleanup_rxqs(pp);
2176 return err;
2177 }
2178 }
2179
2180 return 0;
2181}
2182
2183/* Init all tx queues */
2184static int mvneta_setup_txqs(struct mvneta_port *pp)
2185{
2186 int queue;
2187
2188 for (queue = 0; queue < txq_number; queue++) {
2189 int err = mvneta_txq_init(pp, &pp->txqs[queue]);
2190 if (err) {
2191 netdev_err(pp->dev, "%s: can't create txq=%d\n",
2192 __func__, queue);
2193 mvneta_cleanup_txqs(pp);
2194 return err;
2195 }
2196 }
2197
2198 return 0;
2199}
2200
2201static void mvneta_start_dev(struct mvneta_port *pp)
2202{
2203 mvneta_max_rx_size_set(pp, pp->pkt_size);
2204 mvneta_txq_max_tx_size_set(pp, pp->pkt_size);
2205
2206 /* start the Rx/Tx activity */
2207 mvneta_port_enable(pp);
2208
2209 /* Enable polling on the port */
2210 napi_enable(&pp->napi);
2211
2212 /* Unmask interrupts */
2213 mvreg_write(pp, MVNETA_INTR_NEW_MASK,
2214 MVNETA_RX_INTR_MASK(rxq_number));
2215
2216 phy_start(pp->phy_dev);
2217 netif_tx_start_all_queues(pp->dev);
2218}
2219
2220static void mvneta_stop_dev(struct mvneta_port *pp)
2221{
2222 phy_stop(pp->phy_dev);
2223
2224 napi_disable(&pp->napi);
2225
2226 netif_carrier_off(pp->dev);
2227
2228 mvneta_port_down(pp);
2229 netif_tx_stop_all_queues(pp->dev);
2230
2231 /* Stop the port activity */
2232 mvneta_port_disable(pp);
2233
2234 /* Clear all ethernet port interrupts */
2235 mvreg_write(pp, MVNETA_INTR_MISC_CAUSE, 0);
2236 mvreg_write(pp, MVNETA_INTR_OLD_CAUSE, 0);
2237
2238 /* Mask all ethernet port interrupts */
2239 mvreg_write(pp, MVNETA_INTR_NEW_MASK, 0);
2240 mvreg_write(pp, MVNETA_INTR_OLD_MASK, 0);
2241 mvreg_write(pp, MVNETA_INTR_MISC_MASK, 0);
2242
2243 mvneta_tx_reset(pp);
2244 mvneta_rx_reset(pp);
2245}
2246
c5aff182
TP
2247/* Return positive if MTU is valid */
2248static int mvneta_check_mtu_valid(struct net_device *dev, int mtu)
2249{
2250 if (mtu < 68) {
2251 netdev_err(dev, "cannot change mtu to less than 68\n");
2252 return -EINVAL;
2253 }
2254
6a20c175 2255 /* 9676 == 9700 - 20 and rounding to 8 */
c5aff182
TP
2256 if (mtu > 9676) {
2257 netdev_info(dev, "Illegal MTU value %d, round to 9676\n", mtu);
2258 mtu = 9676;
2259 }
2260
2261 if (!IS_ALIGNED(MVNETA_RX_PKT_SIZE(mtu), 8)) {
2262 netdev_info(dev, "Illegal MTU value %d, rounding to %d\n",
2263 mtu, ALIGN(MVNETA_RX_PKT_SIZE(mtu), 8));
2264 mtu = ALIGN(MVNETA_RX_PKT_SIZE(mtu), 8);
2265 }
2266
2267 return mtu;
2268}
2269
2270/* Change the device mtu */
2271static int mvneta_change_mtu(struct net_device *dev, int mtu)
2272{
2273 struct mvneta_port *pp = netdev_priv(dev);
2274 int ret;
2275
2276 mtu = mvneta_check_mtu_valid(dev, mtu);
2277 if (mtu < 0)
2278 return -EINVAL;
2279
2280 dev->mtu = mtu;
2281
2282 if (!netif_running(dev))
2283 return 0;
2284
6a20c175 2285 /* The interface is running, so we have to force a
c5aff182
TP
2286 * reallocation of the RXQs
2287 */
2288 mvneta_stop_dev(pp);
2289
2290 mvneta_cleanup_txqs(pp);
2291 mvneta_cleanup_rxqs(pp);
2292
2293 pp->pkt_size = MVNETA_RX_PKT_SIZE(pp->dev->mtu);
2294
2295 ret = mvneta_setup_rxqs(pp);
2296 if (ret) {
2297 netdev_err(pp->dev, "unable to setup rxqs after MTU change\n");
2298 return ret;
2299 }
2300
2301 mvneta_setup_txqs(pp);
2302
2303 mvneta_start_dev(pp);
2304 mvneta_port_up(pp);
2305
2306 return 0;
2307}
2308
8cc3e439
TP
2309/* Get mac address */
2310static void mvneta_get_mac_addr(struct mvneta_port *pp, unsigned char *addr)
2311{
2312 u32 mac_addr_l, mac_addr_h;
2313
2314 mac_addr_l = mvreg_read(pp, MVNETA_MAC_ADDR_LOW);
2315 mac_addr_h = mvreg_read(pp, MVNETA_MAC_ADDR_HIGH);
2316 addr[0] = (mac_addr_h >> 24) & 0xFF;
2317 addr[1] = (mac_addr_h >> 16) & 0xFF;
2318 addr[2] = (mac_addr_h >> 8) & 0xFF;
2319 addr[3] = mac_addr_h & 0xFF;
2320 addr[4] = (mac_addr_l >> 8) & 0xFF;
2321 addr[5] = mac_addr_l & 0xFF;
2322}
2323
c5aff182
TP
2324/* Handle setting mac address */
2325static int mvneta_set_mac_addr(struct net_device *dev, void *addr)
2326{
2327 struct mvneta_port *pp = netdev_priv(dev);
2328 u8 *mac = addr + 2;
2329 int i;
2330
2331 if (netif_running(dev))
2332 return -EBUSY;
2333
2334 /* Remove previous address table entry */
2335 mvneta_mac_addr_set(pp, dev->dev_addr, -1);
2336
2337 /* Set new addr in hw */
2338 mvneta_mac_addr_set(pp, mac, rxq_def);
2339
2340 /* Set addr in the device */
2341 for (i = 0; i < ETH_ALEN; i++)
2342 dev->dev_addr[i] = mac[i];
2343
2344 return 0;
2345}
2346
2347static void mvneta_adjust_link(struct net_device *ndev)
2348{
2349 struct mvneta_port *pp = netdev_priv(ndev);
2350 struct phy_device *phydev = pp->phy_dev;
2351 int status_change = 0;
2352
2353 if (phydev->link) {
2354 if ((pp->speed != phydev->speed) ||
2355 (pp->duplex != phydev->duplex)) {
2356 u32 val;
2357
2358 val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
2359 val &= ~(MVNETA_GMAC_CONFIG_MII_SPEED |
2360 MVNETA_GMAC_CONFIG_GMII_SPEED |
71408602
TP
2361 MVNETA_GMAC_CONFIG_FULL_DUPLEX |
2362 MVNETA_GMAC_AN_SPEED_EN |
2363 MVNETA_GMAC_AN_DUPLEX_EN);
c5aff182
TP
2364
2365 if (phydev->duplex)
2366 val |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
2367
2368 if (phydev->speed == SPEED_1000)
2369 val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
2370 else
2371 val |= MVNETA_GMAC_CONFIG_MII_SPEED;
2372
2373 mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
2374
2375 pp->duplex = phydev->duplex;
2376 pp->speed = phydev->speed;
2377 }
2378 }
2379
2380 if (phydev->link != pp->link) {
2381 if (!phydev->link) {
2382 pp->duplex = -1;
2383 pp->speed = 0;
2384 }
2385
2386 pp->link = phydev->link;
2387 status_change = 1;
2388 }
2389
2390 if (status_change) {
2391 if (phydev->link) {
2392 u32 val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
2393 val |= (MVNETA_GMAC_FORCE_LINK_PASS |
2394 MVNETA_GMAC_FORCE_LINK_DOWN);
2395 mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
2396 mvneta_port_up(pp);
2397 netdev_info(pp->dev, "link up\n");
2398 } else {
2399 mvneta_port_down(pp);
2400 netdev_info(pp->dev, "link down\n");
2401 }
2402 }
2403}
2404
2405static int mvneta_mdio_probe(struct mvneta_port *pp)
2406{
2407 struct phy_device *phy_dev;
2408
2409 phy_dev = of_phy_connect(pp->dev, pp->phy_node, mvneta_adjust_link, 0,
2410 pp->phy_interface);
2411 if (!phy_dev) {
2412 netdev_err(pp->dev, "could not find the PHY\n");
2413 return -ENODEV;
2414 }
2415
2416 phy_dev->supported &= PHY_GBIT_FEATURES;
2417 phy_dev->advertising = phy_dev->supported;
2418
2419 pp->phy_dev = phy_dev;
2420 pp->link = 0;
2421 pp->duplex = 0;
2422 pp->speed = 0;
2423
2424 return 0;
2425}
2426
2427static void mvneta_mdio_remove(struct mvneta_port *pp)
2428{
2429 phy_disconnect(pp->phy_dev);
2430 pp->phy_dev = NULL;
2431}
2432
2433static int mvneta_open(struct net_device *dev)
2434{
2435 struct mvneta_port *pp = netdev_priv(dev);
2436 int ret;
2437
2438 mvneta_mac_addr_set(pp, dev->dev_addr, rxq_def);
2439
2440 pp->pkt_size = MVNETA_RX_PKT_SIZE(pp->dev->mtu);
2441
2442 ret = mvneta_setup_rxqs(pp);
2443 if (ret)
2444 return ret;
2445
2446 ret = mvneta_setup_txqs(pp);
2447 if (ret)
2448 goto err_cleanup_rxqs;
2449
2450 /* Connect to port interrupt line */
2451 ret = request_irq(pp->dev->irq, mvneta_isr, 0,
2452 MVNETA_DRIVER_NAME, pp);
2453 if (ret) {
2454 netdev_err(pp->dev, "cannot request irq %d\n", pp->dev->irq);
2455 goto err_cleanup_txqs;
2456 }
2457
2458 /* In default link is down */
2459 netif_carrier_off(pp->dev);
2460
2461 ret = mvneta_mdio_probe(pp);
2462 if (ret < 0) {
2463 netdev_err(dev, "cannot probe MDIO bus\n");
2464 goto err_free_irq;
2465 }
2466
2467 mvneta_start_dev(pp);
2468
2469 return 0;
2470
2471err_free_irq:
2472 free_irq(pp->dev->irq, pp);
2473err_cleanup_txqs:
2474 mvneta_cleanup_txqs(pp);
2475err_cleanup_rxqs:
2476 mvneta_cleanup_rxqs(pp);
2477 return ret;
2478}
2479
2480/* Stop the port, free port interrupt line */
2481static int mvneta_stop(struct net_device *dev)
2482{
2483 struct mvneta_port *pp = netdev_priv(dev);
2484
2485 mvneta_stop_dev(pp);
2486 mvneta_mdio_remove(pp);
2487 free_irq(dev->irq, pp);
2488 mvneta_cleanup_rxqs(pp);
2489 mvneta_cleanup_txqs(pp);
2490 del_timer(&pp->tx_done_timer);
2491 clear_bit(MVNETA_F_TX_DONE_TIMER_BIT, &pp->flags);
2492
2493 return 0;
2494}
2495
15f59456
TP
2496static int mvneta_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2497{
2498 struct mvneta_port *pp = netdev_priv(dev);
2499 int ret;
2500
2501 if (!pp->phy_dev)
2502 return -ENOTSUPP;
2503
2504 ret = phy_mii_ioctl(pp->phy_dev, ifr, cmd);
2505 if (!ret)
2506 mvneta_adjust_link(dev);
2507
2508 return ret;
2509}
2510
c5aff182
TP
2511/* Ethtool methods */
2512
2513/* Get settings (phy address, speed) for ethtools */
2514int mvneta_ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2515{
2516 struct mvneta_port *pp = netdev_priv(dev);
2517
2518 if (!pp->phy_dev)
2519 return -ENODEV;
2520
2521 return phy_ethtool_gset(pp->phy_dev, cmd);
2522}
2523
2524/* Set settings (phy address, speed) for ethtools */
2525int mvneta_ethtool_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2526{
2527 struct mvneta_port *pp = netdev_priv(dev);
2528
2529 if (!pp->phy_dev)
2530 return -ENODEV;
2531
2532 return phy_ethtool_sset(pp->phy_dev, cmd);
2533}
2534
2535/* Set interrupt coalescing for ethtools */
2536static int mvneta_ethtool_set_coalesce(struct net_device *dev,
2537 struct ethtool_coalesce *c)
2538{
2539 struct mvneta_port *pp = netdev_priv(dev);
2540 int queue;
2541
2542 for (queue = 0; queue < rxq_number; queue++) {
2543 struct mvneta_rx_queue *rxq = &pp->rxqs[queue];
2544 rxq->time_coal = c->rx_coalesce_usecs;
2545 rxq->pkts_coal = c->rx_max_coalesced_frames;
2546 mvneta_rx_pkts_coal_set(pp, rxq, rxq->pkts_coal);
2547 mvneta_rx_time_coal_set(pp, rxq, rxq->time_coal);
2548 }
2549
2550 for (queue = 0; queue < txq_number; queue++) {
2551 struct mvneta_tx_queue *txq = &pp->txqs[queue];
2552 txq->done_pkts_coal = c->tx_max_coalesced_frames;
2553 mvneta_tx_done_pkts_coal_set(pp, txq, txq->done_pkts_coal);
2554 }
2555
2556 return 0;
2557}
2558
2559/* get coalescing for ethtools */
2560static int mvneta_ethtool_get_coalesce(struct net_device *dev,
2561 struct ethtool_coalesce *c)
2562{
2563 struct mvneta_port *pp = netdev_priv(dev);
2564
2565 c->rx_coalesce_usecs = pp->rxqs[0].time_coal;
2566 c->rx_max_coalesced_frames = pp->rxqs[0].pkts_coal;
2567
2568 c->tx_max_coalesced_frames = pp->txqs[0].done_pkts_coal;
2569 return 0;
2570}
2571
2572
2573static void mvneta_ethtool_get_drvinfo(struct net_device *dev,
2574 struct ethtool_drvinfo *drvinfo)
2575{
2576 strlcpy(drvinfo->driver, MVNETA_DRIVER_NAME,
2577 sizeof(drvinfo->driver));
2578 strlcpy(drvinfo->version, MVNETA_DRIVER_VERSION,
2579 sizeof(drvinfo->version));
2580 strlcpy(drvinfo->bus_info, dev_name(&dev->dev),
2581 sizeof(drvinfo->bus_info));
2582}
2583
2584
2585static void mvneta_ethtool_get_ringparam(struct net_device *netdev,
2586 struct ethtool_ringparam *ring)
2587{
2588 struct mvneta_port *pp = netdev_priv(netdev);
2589
2590 ring->rx_max_pending = MVNETA_MAX_RXD;
2591 ring->tx_max_pending = MVNETA_MAX_TXD;
2592 ring->rx_pending = pp->rx_ring_size;
2593 ring->tx_pending = pp->tx_ring_size;
2594}
2595
2596static int mvneta_ethtool_set_ringparam(struct net_device *dev,
2597 struct ethtool_ringparam *ring)
2598{
2599 struct mvneta_port *pp = netdev_priv(dev);
2600
2601 if ((ring->rx_pending == 0) || (ring->tx_pending == 0))
2602 return -EINVAL;
2603 pp->rx_ring_size = ring->rx_pending < MVNETA_MAX_RXD ?
2604 ring->rx_pending : MVNETA_MAX_RXD;
2605 pp->tx_ring_size = ring->tx_pending < MVNETA_MAX_TXD ?
2606 ring->tx_pending : MVNETA_MAX_TXD;
2607
2608 if (netif_running(dev)) {
2609 mvneta_stop(dev);
2610 if (mvneta_open(dev)) {
2611 netdev_err(dev,
2612 "error on opening device after ring param change\n");
2613 return -ENOMEM;
2614 }
2615 }
2616
2617 return 0;
2618}
2619
2620static const struct net_device_ops mvneta_netdev_ops = {
2621 .ndo_open = mvneta_open,
2622 .ndo_stop = mvneta_stop,
2623 .ndo_start_xmit = mvneta_tx,
2624 .ndo_set_rx_mode = mvneta_set_rx_mode,
2625 .ndo_set_mac_address = mvneta_set_mac_addr,
2626 .ndo_change_mtu = mvneta_change_mtu,
c5aff182 2627 .ndo_get_stats64 = mvneta_get_stats64,
15f59456 2628 .ndo_do_ioctl = mvneta_ioctl,
c5aff182
TP
2629};
2630
2631const struct ethtool_ops mvneta_eth_tool_ops = {
2632 .get_link = ethtool_op_get_link,
2633 .get_settings = mvneta_ethtool_get_settings,
2634 .set_settings = mvneta_ethtool_set_settings,
2635 .set_coalesce = mvneta_ethtool_set_coalesce,
2636 .get_coalesce = mvneta_ethtool_get_coalesce,
2637 .get_drvinfo = mvneta_ethtool_get_drvinfo,
2638 .get_ringparam = mvneta_ethtool_get_ringparam,
2639 .set_ringparam = mvneta_ethtool_set_ringparam,
2640};
2641
2642/* Initialize hw */
03ce758e 2643static int mvneta_init(struct mvneta_port *pp, int phy_addr)
c5aff182
TP
2644{
2645 int queue;
2646
2647 /* Disable port */
2648 mvneta_port_disable(pp);
2649
2650 /* Set port default values */
2651 mvneta_defaults_set(pp);
2652
2653 pp->txqs = kzalloc(txq_number * sizeof(struct mvneta_tx_queue),
2654 GFP_KERNEL);
2655 if (!pp->txqs)
2656 return -ENOMEM;
2657
2658 /* Initialize TX descriptor rings */
2659 for (queue = 0; queue < txq_number; queue++) {
2660 struct mvneta_tx_queue *txq = &pp->txqs[queue];
2661 txq->id = queue;
2662 txq->size = pp->tx_ring_size;
2663 txq->done_pkts_coal = MVNETA_TXDONE_COAL_PKTS;
2664 }
2665
2666 pp->rxqs = kzalloc(rxq_number * sizeof(struct mvneta_rx_queue),
2667 GFP_KERNEL);
2668 if (!pp->rxqs) {
2669 kfree(pp->txqs);
2670 return -ENOMEM;
2671 }
2672
2673 /* Create Rx descriptor rings */
2674 for (queue = 0; queue < rxq_number; queue++) {
2675 struct mvneta_rx_queue *rxq = &pp->rxqs[queue];
2676 rxq->id = queue;
2677 rxq->size = pp->rx_ring_size;
2678 rxq->pkts_coal = MVNETA_RX_COAL_PKTS;
2679 rxq->time_coal = MVNETA_RX_COAL_USEC;
2680 }
2681
2682 return 0;
2683}
2684
70eeaf98 2685static void mvneta_deinit(struct mvneta_port *pp)
c5aff182
TP
2686{
2687 kfree(pp->txqs);
2688 kfree(pp->rxqs);
2689}
2690
2691/* platform glue : initialize decoding windows */
03ce758e
GK
2692static void mvneta_conf_mbus_windows(struct mvneta_port *pp,
2693 const struct mbus_dram_target_info *dram)
c5aff182
TP
2694{
2695 u32 win_enable;
2696 u32 win_protect;
2697 int i;
2698
2699 for (i = 0; i < 6; i++) {
2700 mvreg_write(pp, MVNETA_WIN_BASE(i), 0);
2701 mvreg_write(pp, MVNETA_WIN_SIZE(i), 0);
2702
2703 if (i < 4)
2704 mvreg_write(pp, MVNETA_WIN_REMAP(i), 0);
2705 }
2706
2707 win_enable = 0x3f;
2708 win_protect = 0;
2709
2710 for (i = 0; i < dram->num_cs; i++) {
2711 const struct mbus_dram_window *cs = dram->cs + i;
2712 mvreg_write(pp, MVNETA_WIN_BASE(i), (cs->base & 0xffff0000) |
2713 (cs->mbus_attr << 8) | dram->mbus_dram_target_id);
2714
2715 mvreg_write(pp, MVNETA_WIN_SIZE(i),
2716 (cs->size - 1) & 0xffff0000);
2717
2718 win_enable &= ~(1 << i);
2719 win_protect |= 3 << (2 * i);
2720 }
2721
2722 mvreg_write(pp, MVNETA_BASE_ADDR_ENABLE, win_enable);
2723}
2724
2725/* Power up the port */
03ce758e 2726static void mvneta_port_power_up(struct mvneta_port *pp, int phy_mode)
c5aff182
TP
2727{
2728 u32 val;
2729
2730 /* MAC Cause register should be cleared */
2731 mvreg_write(pp, MVNETA_UNIT_INTR_CAUSE, 0);
2732
2733 if (phy_mode == PHY_INTERFACE_MODE_SGMII)
2734 mvneta_port_sgmii_config(pp);
2735
2736 mvneta_gmac_rgmii_set(pp, 1);
2737
2738 /* Cancel Port Reset */
2739 val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
2740 val &= ~MVNETA_GMAC2_PORT_RESET;
2741 mvreg_write(pp, MVNETA_GMAC_CTRL_2, val);
2742
2743 while ((mvreg_read(pp, MVNETA_GMAC_CTRL_2) &
2744 MVNETA_GMAC2_PORT_RESET) != 0)
2745 continue;
2746}
2747
2748/* Device initialization routine */
03ce758e 2749static int mvneta_probe(struct platform_device *pdev)
c5aff182
TP
2750{
2751 const struct mbus_dram_target_info *dram_target_info;
2752 struct device_node *dn = pdev->dev.of_node;
2753 struct device_node *phy_node;
189dd626 2754 u32 phy_addr;
c5aff182
TP
2755 struct mvneta_port *pp;
2756 struct net_device *dev;
8cc3e439
TP
2757 const char *dt_mac_addr;
2758 char hw_mac_addr[ETH_ALEN];
2759 const char *mac_from;
c5aff182
TP
2760 int phy_mode;
2761 int err;
74c41b04 2762 int cpu;
c5aff182 2763
6a20c175 2764 /* Our multiqueue support is not complete, so for now, only
c5aff182
TP
2765 * allow the usage of the first RX queue
2766 */
2767 if (rxq_def != 0) {
2768 dev_err(&pdev->dev, "Invalid rxq_def argument: %d\n", rxq_def);
2769 return -EINVAL;
2770 }
2771
ee40a116 2772 dev = alloc_etherdev_mqs(sizeof(struct mvneta_port), txq_number, rxq_number);
c5aff182
TP
2773 if (!dev)
2774 return -ENOMEM;
2775
2776 dev->irq = irq_of_parse_and_map(dn, 0);
2777 if (dev->irq == 0) {
2778 err = -EINVAL;
2779 goto err_free_netdev;
2780 }
2781
2782 phy_node = of_parse_phandle(dn, "phy", 0);
2783 if (!phy_node) {
2784 dev_err(&pdev->dev, "no associated PHY\n");
2785 err = -ENODEV;
2786 goto err_free_irq;
2787 }
2788
2789 phy_mode = of_get_phy_mode(dn);
2790 if (phy_mode < 0) {
2791 dev_err(&pdev->dev, "incorrect phy-mode\n");
2792 err = -EINVAL;
2793 goto err_free_irq;
2794 }
2795
c5aff182
TP
2796 dev->tx_queue_len = MVNETA_MAX_TXD;
2797 dev->watchdog_timeo = 5 * HZ;
2798 dev->netdev_ops = &mvneta_netdev_ops;
2799
2800 SET_ETHTOOL_OPS(dev, &mvneta_eth_tool_ops);
2801
2802 pp = netdev_priv(dev);
2803
c5aff182 2804 pp->weight = MVNETA_RX_POLL_WEIGHT;
c5aff182
TP
2805 pp->phy_node = phy_node;
2806 pp->phy_interface = phy_mode;
2807
189dd626
TP
2808 pp->clk = devm_clk_get(&pdev->dev, NULL);
2809 if (IS_ERR(pp->clk)) {
2810 err = PTR_ERR(pp->clk);
5445eaf3 2811 goto err_free_irq;
189dd626
TP
2812 }
2813
2814 clk_prepare_enable(pp->clk);
2815
5445eaf3
APR
2816 pp->base = of_iomap(dn, 0);
2817 if (pp->base == NULL) {
2818 err = -ENOMEM;
2819 goto err_clk;
2820 }
2821
74c41b04 2822 /* Alloc per-cpu stats */
2823 pp->stats = alloc_percpu(struct mvneta_pcpu_stats);
2824 if (!pp->stats) {
2825 err = -ENOMEM;
2826 goto err_unmap;
2827 }
2828
2829 for_each_possible_cpu(cpu) {
2830 struct mvneta_pcpu_stats *stats;
2831 stats = per_cpu_ptr(pp->stats, cpu);
2832 u64_stats_init(&stats->syncp);
2833 }
2834
8cc3e439 2835 dt_mac_addr = of_get_mac_address(dn);
6c7a9a3c 2836 if (dt_mac_addr) {
8cc3e439
TP
2837 mac_from = "device tree";
2838 memcpy(dev->dev_addr, dt_mac_addr, ETH_ALEN);
2839 } else {
2840 mvneta_get_mac_addr(pp, hw_mac_addr);
2841 if (is_valid_ether_addr(hw_mac_addr)) {
2842 mac_from = "hardware";
2843 memcpy(dev->dev_addr, hw_mac_addr, ETH_ALEN);
2844 } else {
2845 mac_from = "random";
2846 eth_hw_addr_random(dev);
2847 }
2848 }
2849
c5aff182 2850 pp->tx_done_timer.data = (unsigned long)dev;
aded0955
APR
2851 pp->tx_done_timer.function = mvneta_tx_done_timer_callback;
2852 init_timer(&pp->tx_done_timer);
2853 clear_bit(MVNETA_F_TX_DONE_TIMER_BIT, &pp->flags);
c5aff182
TP
2854
2855 pp->tx_ring_size = MVNETA_MAX_TXD;
2856 pp->rx_ring_size = MVNETA_MAX_RXD;
2857
2858 pp->dev = dev;
2859 SET_NETDEV_DEV(dev, &pdev->dev);
2860
2861 err = mvneta_init(pp, phy_addr);
2862 if (err < 0) {
2863 dev_err(&pdev->dev, "can't init eth hal\n");
74c41b04 2864 goto err_free_stats;
c5aff182
TP
2865 }
2866 mvneta_port_power_up(pp, phy_mode);
2867
2868 dram_target_info = mv_mbus_dram_info();
2869 if (dram_target_info)
2870 mvneta_conf_mbus_windows(pp, dram_target_info);
2871
2872 netif_napi_add(dev, &pp->napi, mvneta_poll, pp->weight);
2873
b50b72de 2874 dev->features = NETIF_F_SG | NETIF_F_IP_CSUM;
2875 dev->hw_features |= NETIF_F_SG | NETIF_F_IP_CSUM;
2876 dev->vlan_features |= NETIF_F_SG | NETIF_F_IP_CSUM;
2877 dev->priv_flags |= IFF_UNICAST_FLT;
2878
c5aff182
TP
2879 err = register_netdev(dev);
2880 if (err < 0) {
2881 dev_err(&pdev->dev, "failed to register\n");
2882 goto err_deinit;
2883 }
2884
8cc3e439
TP
2885 netdev_info(dev, "Using %s mac address %pM\n", mac_from,
2886 dev->dev_addr);
c5aff182
TP
2887
2888 platform_set_drvdata(pdev, pp->dev);
2889
2890 return 0;
2891
2892err_deinit:
2893 mvneta_deinit(pp);
74c41b04 2894err_free_stats:
2895 free_percpu(pp->stats);
c5aff182
TP
2896err_unmap:
2897 iounmap(pp->base);
5445eaf3
APR
2898err_clk:
2899 clk_disable_unprepare(pp->clk);
c5aff182
TP
2900err_free_irq:
2901 irq_dispose_mapping(dev->irq);
2902err_free_netdev:
2903 free_netdev(dev);
2904 return err;
2905}
2906
2907/* Device removal routine */
03ce758e 2908static int mvneta_remove(struct platform_device *pdev)
c5aff182
TP
2909{
2910 struct net_device *dev = platform_get_drvdata(pdev);
2911 struct mvneta_port *pp = netdev_priv(dev);
2912
2913 unregister_netdev(dev);
2914 mvneta_deinit(pp);
189dd626 2915 clk_disable_unprepare(pp->clk);
74c41b04 2916 free_percpu(pp->stats);
c5aff182
TP
2917 iounmap(pp->base);
2918 irq_dispose_mapping(dev->irq);
2919 free_netdev(dev);
2920
c5aff182
TP
2921 return 0;
2922}
2923
2924static const struct of_device_id mvneta_match[] = {
2925 { .compatible = "marvell,armada-370-neta" },
2926 { }
2927};
2928MODULE_DEVICE_TABLE(of, mvneta_match);
2929
2930static struct platform_driver mvneta_driver = {
2931 .probe = mvneta_probe,
03ce758e 2932 .remove = mvneta_remove,
c5aff182
TP
2933 .driver = {
2934 .name = MVNETA_DRIVER_NAME,
2935 .of_match_table = mvneta_match,
2936 },
2937};
2938
2939module_platform_driver(mvneta_driver);
2940
2941MODULE_DESCRIPTION("Marvell NETA Ethernet Driver - www.marvell.com");
2942MODULE_AUTHOR("Rami Rosen <rosenr@marvell.com>, Thomas Petazzoni <thomas.petazzoni@free-electrons.com>");
2943MODULE_LICENSE("GPL");
2944
2945module_param(rxq_number, int, S_IRUGO);
2946module_param(txq_number, int, S_IRUGO);
2947
2948module_param(rxq_def, int, S_IRUGO);
This page took 0.238992 seconds and 5 git commands to generate.