1
2
3
4
5
6
7
8#ifndef XILINX_AXIENET_H
9#define XILINX_AXIENET_H
10
11#include <linux/netdevice.h>
12#include <linux/spinlock.h>
13#include <linux/interrupt.h>
14#include <linux/if_vlan.h>
15#include <linux/net_tstamp.h>
16
17
18#define XAE_HDR_SIZE 14
19#define XAE_TRL_SIZE 4
20#define XAE_MTU 1500
21#define XAE_JUMBO_MTU 9000
22
23#define XAE_MAX_FRAME_SIZE (XAE_MTU + XAE_HDR_SIZE + XAE_TRL_SIZE)
24#define XAE_MAX_VLAN_FRAME_SIZE (XAE_MTU + VLAN_ETH_HLEN + XAE_TRL_SIZE)
25#define XAE_MAX_JUMBO_FRAME_SIZE (XAE_JUMBO_MTU + XAE_HDR_SIZE + XAE_TRL_SIZE)
26
27
28
29
30#define XAE_OPTION_PROMISC (1 << 0)
31
32
33#define XAE_OPTION_JUMBO (1 << 1)
34
35
36#define XAE_OPTION_VLAN (1 << 2)
37
38
39#define XAE_OPTION_FLOW_CONTROL (1 << 4)
40
41
42
43
44#define XAE_OPTION_FCS_STRIP (1 << 5)
45
46
47
48
49#define XAE_OPTION_FCS_INSERT (1 << 6)
50
51
52
53
54
55
56
57#define XAE_OPTION_LENTYPE_ERR (1 << 7)
58
59
60#define XAE_OPTION_TXEN (1 << 11)
61
62
63#define XAE_OPTION_RXEN (1 << 12)
64
65
66#define XAE_OPTION_DEFAULTS \
67 (XAE_OPTION_TXEN | \
68 XAE_OPTION_FLOW_CONTROL | \
69 XAE_OPTION_RXEN)
70
71
72
73#define XAXIDMA_TX_CR_OFFSET 0x00000000
74#define XAXIDMA_TX_SR_OFFSET 0x00000004
75#define XAXIDMA_TX_CDESC_OFFSET 0x00000008
76#define XAXIDMA_TX_TDESC_OFFSET 0x00000010
77
78#define XAXIDMA_RX_CR_OFFSET 0x00000030
79#define XAXIDMA_RX_SR_OFFSET 0x00000034
80#define XAXIDMA_RX_CDESC_OFFSET 0x00000038
81#define XAXIDMA_RX_TDESC_OFFSET 0x00000040
82
83#define XAXIDMA_CR_RUNSTOP_MASK 0x00000001
84#define XAXIDMA_CR_RESET_MASK 0x00000004
85
86#define XAXIDMA_BD_NDESC_OFFSET 0x00
87#define XAXIDMA_BD_BUFA_OFFSET 0x08
88#define XAXIDMA_BD_CTRL_LEN_OFFSET 0x18
89#define XAXIDMA_BD_STS_OFFSET 0x1C
90#define XAXIDMA_BD_USR0_OFFSET 0x20
91#define XAXIDMA_BD_USR1_OFFSET 0x24
92#define XAXIDMA_BD_USR2_OFFSET 0x28
93#define XAXIDMA_BD_USR3_OFFSET 0x2C
94#define XAXIDMA_BD_USR4_OFFSET 0x30
95#define XAXIDMA_BD_ID_OFFSET 0x34
96#define XAXIDMA_BD_HAS_STSCNTRL_OFFSET 0x38
97#define XAXIDMA_BD_HAS_DRE_OFFSET 0x3C
98
99#define XAXIDMA_BD_HAS_DRE_SHIFT 8
100#define XAXIDMA_BD_HAS_DRE_MASK 0xF00
101#define XAXIDMA_BD_WORDLEN_MASK 0xFF
102
103#define XAXIDMA_BD_CTRL_LENGTH_MASK 0x007FFFFF
104#define XAXIDMA_BD_CTRL_TXSOF_MASK 0x08000000
105#define XAXIDMA_BD_CTRL_TXEOF_MASK 0x04000000
106#define XAXIDMA_BD_CTRL_ALL_MASK 0x0C000000
107
108#define XAXIDMA_DELAY_MASK 0xFF000000
109#define XAXIDMA_COALESCE_MASK 0x00FF0000
110
111#define XAXIDMA_DELAY_SHIFT 24
112#define XAXIDMA_COALESCE_SHIFT 16
113
114#define XAXIDMA_IRQ_IOC_MASK 0x00001000
115#define XAXIDMA_IRQ_DELAY_MASK 0x00002000
116#define XAXIDMA_IRQ_ERROR_MASK 0x00004000
117#define XAXIDMA_IRQ_ALL_MASK 0x00007000
118
119
120#define XAXIDMA_DFT_TX_THRESHOLD 24
121#define XAXIDMA_DFT_TX_WAITBOUND 254
122#define XAXIDMA_DFT_RX_THRESHOLD 1
123#define XAXIDMA_DFT_RX_WAITBOUND 254
124
125#define XAXIDMA_BD_CTRL_TXSOF_MASK 0x08000000
126#define XAXIDMA_BD_CTRL_TXEOF_MASK 0x04000000
127#define XAXIDMA_BD_CTRL_ALL_MASK 0x0C000000
128
129#define XAXIDMA_BD_STS_ACTUAL_LEN_MASK 0x007FFFFF
130#define XAXIDMA_BD_STS_COMPLETE_MASK 0x80000000
131#define XAXIDMA_BD_STS_DEC_ERR_MASK 0x40000000
132#define XAXIDMA_BD_STS_SLV_ERR_MASK 0x20000000
133#define XAXIDMA_BD_STS_INT_ERR_MASK 0x10000000
134#define XAXIDMA_BD_STS_ALL_ERR_MASK 0x70000000
135#define XAXIDMA_BD_STS_RXSOF_MASK 0x08000000
136#define XAXIDMA_BD_STS_RXEOF_MASK 0x04000000
137#define XAXIDMA_BD_STS_ALL_MASK 0xFC000000
138
139#define XAXIDMA_BD_MINIMUM_ALIGNMENT 0x40
140
141
142#define XAXIFIFO_TXTS_ISR 0x00000000
143#define XAXIFIFO_TXTS_RXFD 0x00000020
144#define XAXIFIFO_TXTS_RLR 0x00000024
145
146#define XAXIFIFO_TXTS_INT_RC_MASK 0x04000000
147#define XAXIFIFO_TXTS_RXFD_MASK 0x7FFFFFFF
148#define XAXIFIFO_TXTS_TAG_MASK 0xFFFF0000
149#define XAXIFIFO_TXTS_TAG_SHIFT 16
150
151
152#define XAE_RAF_OFFSET 0x00000000
153#define XAE_TPF_OFFSET 0x00000004
154#define XAE_IFGP_OFFSET 0x00000008
155#define XAE_IS_OFFSET 0x0000000C
156#define XAE_IP_OFFSET 0x00000010
157#define XAE_IE_OFFSET 0x00000014
158#define XAE_TTAG_OFFSET 0x00000018
159#define XAE_RTAG_OFFSET 0x0000001C
160#define XAE_UAWL_OFFSET 0x00000020
161#define XAE_UAWU_OFFSET 0x00000024
162#define XAE_TPID0_OFFSET 0x00000028
163#define XAE_TPID1_OFFSET 0x0000002C
164#define XAE_PPST_OFFSET 0x00000030
165#define XAE_RCW0_OFFSET 0x00000400
166#define XAE_RCW1_OFFSET 0x00000404
167#define XAE_TC_OFFSET 0x00000408
168#define XAE_FCC_OFFSET 0x0000040C
169#define XAE_EMMC_OFFSET 0x00000410
170#define XAE_PHYC_OFFSET 0x00000414
171#define XAE_MDIO_MC_OFFSET 0x00000500
172#define XAE_MDIO_MCR_OFFSET 0x00000504
173#define XAE_MDIO_MWD_OFFSET 0x00000508
174#define XAE_MDIO_MRD_OFFSET 0x0000050C
175#define XAE_MDIO_MIS_OFFSET 0x00000600
176
177#define XAE_MDIO_MIP_OFFSET 0x00000620
178
179#define XAE_MDIO_MIE_OFFSET 0x00000640
180
181#define XAE_MDIO_MIC_OFFSET 0x00000660
182#define XAE_UAW0_OFFSET 0x00000700
183#define XAE_UAW1_OFFSET 0x00000704
184#define XAE_FMI_OFFSET 0x00000708
185#define XAE_AF0_OFFSET 0x00000710
186#define XAE_AF1_OFFSET 0x00000714
187
188#define XAE_TX_VLAN_DATA_OFFSET 0x00004000
189#define XAE_RX_VLAN_DATA_OFFSET 0x00008000
190#define XAE_MCAST_TABLE_OFFSET 0x00020000
191
192
193
194#define XAE_RAF_MCSTREJ_MASK 0x00000002
195
196#define XAE_RAF_BCSTREJ_MASK 0x00000004
197#define XAE_RAF_TXVTAGMODE_MASK 0x00000018
198#define XAE_RAF_RXVTAGMODE_MASK 0x00000060
199#define XAE_RAF_TXVSTRPMODE_MASK 0x00000180
200#define XAE_RAF_RXVSTRPMODE_MASK 0x00000600
201#define XAE_RAF_NEWFNCENBL_MASK 0x00000800
202
203#define XAE_RAF_EMULTIFLTRENBL_MASK 0x00001000
204#define XAE_RAF_STATSRST_MASK 0x00002000
205#define XAE_RAF_RXBADFRMEN_MASK 0x00004000
206#define XAE_RAF_TXVTAGMODE_SHIFT 3
207#define XAE_RAF_RXVTAGMODE_SHIFT 5
208#define XAE_RAF_TXVSTRPMODE_SHIFT 7
209#define XAE_RAF_RXVSTRPMODE_SHIFT 9
210
211
212#define XAE_TPF_TPFV_MASK 0x0000FFFF
213
214#define XAE_IFGP0_IFGP_MASK 0x0000007F
215
216
217
218
219
220#define XAE_INT_HARDACSCMPLT_MASK 0x00000001
221
222#define XAE_INT_AUTONEG_MASK 0x00000002
223#define XAE_INT_RXCMPIT_MASK 0x00000004
224#define XAE_INT_RXRJECT_MASK 0x00000008
225#define XAE_INT_RXFIFOOVR_MASK 0x00000010
226#define XAE_INT_TXCMPIT_MASK 0x00000020
227#define XAE_INT_RXDCMLOCK_MASK 0x00000040
228#define XAE_INT_MGTRDY_MASK 0x00000080
229#define XAE_INT_PHYRSTCMPLT_MASK 0x00000100
230#define XAE_INT_ALL_MASK 0x0000003F
231
232
233#define XAE_INT_RECV_ERROR_MASK \
234 (XAE_INT_RXRJECT_MASK | XAE_INT_RXFIFOOVR_MASK)
235
236
237#define XAE_TPID_0_MASK 0x0000FFFF
238#define XAE_TPID_1_MASK 0xFFFF0000
239
240
241#define XAE_TPID_2_MASK 0x0000FFFF
242#define XAE_TPID_3_MASK 0xFFFF0000
243
244
245#define XAE_RCW1_INBAND1588_MASK 0x00400000
246#define XAE_RCW1_RST_MASK 0x80000000
247#define XAE_RCW1_JUM_MASK 0x40000000
248
249#define XAE_RCW1_FCS_MASK 0x20000000
250#define XAE_RCW1_RX_MASK 0x10000000
251#define XAE_RCW1_VLAN_MASK 0x08000000
252
253#define XAE_RCW1_LT_DIS_MASK 0x02000000
254
255#define XAE_RCW1_CL_DIS_MASK 0x01000000
256
257
258
259#define XAE_RCW1_PAUSEADDR_MASK 0x0000FFFF
260
261
262#define XAE_TC_INBAND1588_MASK 0x00400000
263#define XAE_TC_RST_MASK 0x80000000
264#define XAE_TC_JUM_MASK 0x40000000
265
266#define XAE_TC_FCS_MASK 0x20000000
267#define XAE_TC_TX_MASK 0x10000000
268#define XAE_TC_VLAN_MASK 0x08000000
269
270#define XAE_TC_IFG_MASK 0x02000000
271
272
273#define XAE_FCC_FCRX_MASK 0x20000000
274#define XAE_FCC_FCTX_MASK 0x40000000
275
276
277#define XAE_EMMC_LINKSPEED_MASK 0xC0000000
278#define XAE_EMMC_RGMII_MASK 0x20000000
279#define XAE_EMMC_SGMII_MASK 0x10000000
280#define XAE_EMMC_GPCS_MASK 0x08000000
281#define XAE_EMMC_HOST_MASK 0x04000000
282#define XAE_EMMC_TX16BIT 0x02000000
283#define XAE_EMMC_RX16BIT 0x01000000
284#define XAE_EMMC_LINKSPD_10 0x00000000
285#define XAE_EMMC_LINKSPD_100 0x40000000
286#define XAE_EMMC_LINKSPD_1000 0x80000000
287
288
289#define XAE_PHYC_SGMIILINKSPEED_MASK 0xC0000000
290#define XAE_PHYC_RGMIILINKSPEED_MASK 0x0000000C
291#define XAE_PHYC_RGMIIHD_MASK 0x00000002
292#define XAE_PHYC_RGMIILINK_MASK 0x00000001
293#define XAE_PHYC_RGLINKSPD_10 0x00000000
294#define XAE_PHYC_RGLINKSPD_100 0x00000004
295#define XAE_PHYC_RGLINKSPD_1000 0x00000008
296#define XAE_PHYC_SGLINKSPD_10 0x00000000
297#define XAE_PHYC_SGLINKSPD_100 0x40000000
298#define XAE_PHYC_SGLINKSPD_1000 0x80000000
299
300
301#define XAE_MDIO_MC_MDIOEN_MASK 0x00000040
302#define XAE_MDIO_MC_CLOCK_DIVIDE_MAX 0x3F
303
304
305#define XAE_MDIO_MCR_PHYAD_MASK 0x1F000000
306#define XAE_MDIO_MCR_PHYAD_SHIFT 24
307#define XAE_MDIO_MCR_REGAD_MASK 0x001F0000
308#define XAE_MDIO_MCR_REGAD_SHIFT 16
309#define XAE_MDIO_MCR_OP_MASK 0x0000C000
310#define XAE_MDIO_MCR_OP_SHIFT 13
311#define XAE_MDIO_MCR_OP_READ_MASK 0x00008000
312#define XAE_MDIO_MCR_OP_WRITE_MASK 0x00004000
313#define XAE_MDIO_MCR_INITIATE_MASK 0x00000800
314#define XAE_MDIO_MCR_READY_MASK 0x00000080
315
316
317#define XAE_MDIO_INT_MIIM_RDY_MASK 0x00000001
318
319
320
321
322
323#define XAE_UAW1_UNICASTADDR_MASK 0x0000FFFF
324
325
326#define XAE_FMI_PM_MASK 0x80000000
327#define XAE_FMI_IND_MASK 0x00000003
328
329#define XAE_MDIO_DIV_DFT 29
330
331
332#define XAE_MULTICAST_CAM_TABLE_NUM 4
333
334
335#define XAE_FEATURE_PARTIAL_RX_CSUM (1 << 0)
336#define XAE_FEATURE_PARTIAL_TX_CSUM (1 << 1)
337#define XAE_FEATURE_FULL_RX_CSUM (1 << 2)
338#define XAE_FEATURE_FULL_TX_CSUM (1 << 3)
339
340#define XAE_NO_CSUM_OFFLOAD 0
341
342#define XAE_FULL_CSUM_STATUS_MASK 0x00000038
343#define XAE_IP_UDP_CSUM_VALIDATED 0x00000003
344#define XAE_IP_TCP_CSUM_VALIDATED 0x00000002
345
346#define DELAY_OF_ONE_MILLISEC 1000
347
348#define XAXIENET_NAPI_WEIGHT 64
349
350
351#define TX_TS_OP_NOOP 0x0
352#define TX_TS_OP_ONESTEP 0x1
353#define TX_TS_OP_TWOSTEP 0x2
354#define TX_TS_CSUM_UPDATE 0x1
355#define TX_PTP_CSUM_OFFSET 0x28
356#define TX_PTP_TS_OFFSET 0x4C
357
358
359#ifndef out_be32
360#if defined(CONFIG_ARCH_ZYNQ) || defined(CONFIG_ARCH_ZYNQMP)
361#define in_be32(offset) __raw_readl(offset)
362#define out_be32(offset, val) __raw_writel(val, offset)
363#endif
364#endif
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388struct axidma_bd {
389 u32 next;
390 u32 reserved1;
391 u32 phys;
392 u32 reserved2;
393 u32 reserved3;
394 u32 reserved4;
395 u32 cntrl;
396 u32 status;
397 u32 app0;
398 u32 app1;
399 u32 app2;
400 u32 app3;
401 u32 app4;
402 phys_addr_t sw_id_offset;
403 phys_addr_t ptp_tx_skb;
404 u32 ptp_tx_ts_tag;
405 phys_addr_t tx_skb;
406 u32 tx_desc_mapping;
407} __aligned(128);
408
409#define DESC_DMA_MAP_SINGLE 0
410#define DESC_DMA_MAP_PAGE 1
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457struct axienet_local {
458 struct net_device *ndev;
459 struct device *dev;
460
461
462 struct phy_device *phy_dev;
463 struct device_node *phy_node;
464
465
466 struct mii_bus *mii_bus;
467
468
469 void __iomem *regs;
470 void __iomem *dma_regs;
471
472 struct tasklet_struct dma_err_tasklet;
473 spinlock_t tx_lock;
474 spinlock_t rx_lock;
475 struct napi_struct napi;
476
477 int tx_irq;
478 int rx_irq;
479 int eth_irq;
480 u32 phy_type;
481
482 u32 options;
483 u32 last_link;
484 u32 features;
485
486
487 struct axidma_bd *tx_bd_v;
488 dma_addr_t tx_bd_p;
489 struct axidma_bd *rx_bd_v;
490 dma_addr_t rx_bd_p;
491 u32 tx_bd_ci;
492 u32 tx_bd_tail;
493 u32 rx_bd_ci;
494
495 u32 max_frm_size;
496 u32 rxmem;
497
498 int csum_offload_on_tx_path;
499 int csum_offload_on_rx_path;
500
501 u32 coalesce_count_rx;
502 u32 coalesce_count_tx;
503 u32 is_10Gmac;
504 u32 phy_interface;
505 u32 phy_flags;
506 bool eth_hasnobuf;
507
508#ifdef CONFIG_XILINX_AXI_EMAC_HWTSTAMP
509 void __iomem *tx_ts_regs;
510 struct hwtstamp_config tstamp_config;
511#endif
512};
513
514
515
516
517
518
519
520struct axienet_option {
521 u32 opt;
522 u32 reg;
523 u32 m_or;
524};
525
526
527
528
529
530
531
532
533
534
535static inline u32 axienet_ior(struct axienet_local *lp, off_t offset)
536{
537 return in_be32(lp->regs + offset);
538}
539
540
541
542
543
544
545
546
547
548
549static inline void axienet_iow(struct axienet_local *lp, off_t offset,
550 u32 value)
551{
552 out_be32((lp->regs + offset), value);
553}
554
555#ifdef CONFIG_XILINX_AXI_EMAC_HWTSTAMP
556
557
558
559
560
561
562
563
564
565static inline u32 axienet_txts_ior(struct axienet_local *lp, off_t reg)
566{
567 return in_be32(lp->tx_ts_regs + reg);
568}
569
570
571
572
573
574
575
576
577static inline void axienet_txts_iow(struct axienet_local *lp, off_t reg,
578 u32 value)
579{
580 out_be32((lp->tx_ts_regs + reg), value);
581}
582#endif
583
584
585int axienet_mdio_setup(struct axienet_local *lp, struct device_node *np);
586int axienet_mdio_wait_until_ready(struct axienet_local *lp);
587void axienet_mdio_teardown(struct axienet_local *lp);
588
589#endif
590