iPXE
dwmac.h
Go to the documentation of this file.
1 #ifndef _DWMAC_H
2 #define _DWMAC_H
3 
4 /** @file
5  *
6  * Synopsys DesignWare MAC network driver
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <stdint.h>
13 #include <ipxe/if_ether.h>
14 
15 /** I/O region index */
16 #define DWMAC_REG_IDX 0
17 
18 /** I/O region length */
19 #define DWMAC_REG_LEN 0x2000
20 
21 /** MAC register block */
22 #define DWMAC_MAC 0x0000
23 #define DWMAC_MAC_REG( n ) ( DWMAC_MAC + ( (n) * 4 ) )
24 
25 /** MAC configuration register */
26 #define DWMAC_CFG DWMAC_MAC_REG ( 0 )
27 #define DWMAC_CFG_DO 0x00002000 /**< Disable RX own frames */
28 #define DWMAC_CFG_FD 0x00000800 /**< Full duplex */
29 #define DWMAC_CFG_TXEN 0x00000008 /**< TX enabled */
30 #define DWMAC_CFG_RXEN 0x00000004 /**< RX enabled */
31 
32 /** MAC filter register */
33 #define DWMAC_FILTER DWMAC_MAC_REG ( 1 )
34 #define DWMAC_FILTER_PR 0x00000001 /**< Promiscuous mode */
35 
36 /** Flow control register */
37 #define DWMAC_FLOW DWMAC_MAC_REG ( 6 )
38 
39 /** Version register */
40 #define DWMAC_VER DWMAC_MAC_REG ( 8 )
41 #define DWMAC_VER_USER_MAJOR( x ) \
42  ( ( (x) >> 12 ) & 0xf ) /**< User major version */
43 #define DWMAC_VER_USER_MINOR( x ) \
44  ( ( (x) >> 8 ) & 0xf ) /**< User minor version */
45 #define DWMAC_VER_CORE_MAJOR( x ) \
46  ( ( (x) >> 4 ) & 0xf ) /**< Core major version */
47 #define DWMAC_VER_CORE_MINOR( x ) \
48  ( ( (x) >> 0 ) & 0xf ) /**< Core minor version */
49 
50 /** Debug register */
51 #define DWMAC_DEBUG DWMAC_MAC_REG ( 9 )
52 
53 /** Interrupt status register */
54 #define DWMAC_ISR DWMAC_MAC_REG ( 14 )
55 
56 /** MAC address high register */
57 #define DWMAC_ADDRH DWMAC_MAC_REG ( 16 )
58 
59 /** MAC address low register */
60 #define DWMAC_ADDRL DWMAC_MAC_REG ( 17 )
61 
62 /** A DesignWare MAC address */
63 union dwmac_mac {
64  struct {
67  } __attribute__ (( packed )) reg;
69 };
70 
71 /** SGMII/RGMII status register */
72 #define DWMAC_GMII DWMAC_MAC_REG ( 54 )
73 #define DWMAC_GMII_LINK 0x00000008 /**< Link up */
74 
75 /** DMA register block */
76 #define DWMAC_DMA 0x1000
77 #define DWMAC_DMA_REG( n ) ( DWMAC_DMA + ( (n) * 4 ) )
78 
79 /** Bus mode register */
80 #define DWMAC_BUS DWMAC_DMA_REG ( 0 )
81 #define DWMAC_BUS_PBL4 0x01000000 /**< 4x PBL mode */
82 #define DWMAC_BUS_USP 0x00800000 /**< Use separate PBL */
83 #define DWMAC_BUS_RPBL(x) ( (x) << 17 ) /**< RX DMA PBL */
84 #define DWMAC_BUS_FB 0x00010000 /**< Fixed burst */
85 #define DWMAC_BUS_PBL(x) ( (x) << 8 ) /**< (TX) DMA PBL */
86 #define DWMAC_BUS_SWR 0x00000001 /**< Software reset */
87 
88 /** Time to wait for software reset to complete */
89 #define DWMAC_RESET_MAX_WAIT_MS 500
90 
91 /** Transmit poll demand register */
92 #define DWMAC_TXPOLL DWMAC_DMA_REG ( 1 )
93 
94 /** Receive poll demand register */
95 #define DWMAC_RXPOLL DWMAC_DMA_REG ( 2 )
96 
97 /** Receive descriptor list address register */
98 #define DWMAC_RXBASE DWMAC_DMA_REG ( 3 )
99 
100 /** Transmit descriptor list address register */
101 #define DWMAC_TXBASE DWMAC_DMA_REG ( 4 )
103 /** Status register */
104 #define DWMAC_STATUS DWMAC_DMA_REG ( 5 )
105 #define DWMAC_STATUS_LINK 0x04000000 /**< Link status change */
106 
107 /** Operation mode register */
108 #define DWMAC_OP DWMAC_DMA_REG ( 6 )
109 #define DWMAC_OP_RXSF 0x02000000 /**< RX store and forward */
110 #define DWMAC_OP_TXSF 0x00200000 /**< TX store and forward */
111 #define DWMAC_OP_TXEN 0x00002000 /**< TX enabled */
112 #define DWMAC_OP_RXEN 0x00000002 /**< RX enabled */
114 /** Packet drop counter register */
115 #define DWMAC_DROP DWMAC_DMA_REG ( 8 )
117 /** AXI bus mode register */
118 #define DWMAC_AXI DWMAC_DMA_REG ( 10 )
120 /** AHB or AXI status register */
121 #define DWMAC_AHB DWMAC_DMA_REG ( 11 )
123 /** Current transmit descriptor register */
124 #define DWMAC_TXDESC DWMAC_DMA_REG ( 18 )
126 /** Current receive descriptor register */
127 #define DWMAC_RXDESC DWMAC_DMA_REG ( 19 )
129 /** Current transmit buffer address register */
130 #define DWMAC_TXBUF DWMAC_DMA_REG ( 20 )
132 /** Current receive buffer address register */
133 #define DWMAC_RXBUF DWMAC_DMA_REG ( 21 )
135 /** Hardware feature register */
136 #define DWMAC_FEATURE DWMAC_DMA_REG ( 22 )
138 /** A frame descriptor
139  *
140  * We populate the descriptor with values that are valid for both
141  * normal and enhanced descriptor formats, to avoid needing to care
142  * about which version of the hardware we have.
143  */
144 struct dwmac_descriptor {
145  /** Completion status */
146  uint32_t stat;
147  /** Buffer size */
149  /** Reserved */
151  /** Ring control */
153  /** Buffer address */
155  /** Next descriptor address */
157 } __attribute__ (( packed ));
159 /* Completion status */
160 #define DWMAC_STAT_OWN 0x80000000 /**< Owned by hardware */
161 #define DWMAC_STAT_TX_LAST 0x20000000 /**< Last segment (TX) */
162 #define DWMAC_STAT_TX_FIRST 0x10000000 /**< First segment (TX) */
163 #define DWMAC_STAT_TX_CHAIN 0x00100000 /**< Chained descriptor (TX) */
164 #define DWMAC_STAT_ERR 0x00008000 /**< Error summary */
165 #define DWMAC_STAT_RX_FIRST 0x00000200 /**< First segment (RX) */
166 #define DWMAC_STAT_RX_LAST 0x00000100 /**< Last segment (RX) */
167 #define DWMAC_STAT_RX_LEN(x) \
168  ( ( (x) >> 16 ) & 0x3fff ) /**< Frame length (RX) */
170 /** Buffer size */
171 #define DWMAC_SIZE_RX_CHAIN 0x4000 /**< Chained descriptor (RX) */
172 
173 /* Ring control */
174 #define DWMAC_CTRL_TX_LAST 0x40 /**< Last segment (TX) */
175 #define DWMAC_CTRL_TX_FIRST 0x20 /**< First segment (TX) */
176 #define DWMAC_CTRL_CHAIN 0x01 /**< Chained descriptor */
177 
178 /** A DesignWare descriptor ring */
179 struct dwmac_ring {
180  /** Descriptors */
182  /** Descriptor ring DMA mapping */
183  struct dma_mapping map;
184  /** Producer index */
185  unsigned int prod;
186  /** Consumer index */
187  unsigned int cons;
189  /** Queue base address register (within DMA block) */
191  /** Number of descriptors */
193  /** Default control flags */
194  uint8_t ctrl;
195  /** Length of descriptors */
196  size_t len;
197 };
198 
199 /** Number of transmit descriptors */
200 #define DWMAC_NUM_TX_DESC 16
202 /** Number of receive descriptors */
203 #define DWMAC_NUM_RX_DESC 16
204 
205 /** Length of receive buffers
206  *
207  * Must be a multiple of 16.
208  */
209 #define DWMAC_RX_LEN 1536
210 
211 /**
212  * Initialise descriptor ring
213  *
214  * @v ring Descriptor ring
215  * @v count Number of descriptors
216  * @v qbase Queue base address register
217  * @v ctrl Default descriptor control flags
218  */
219 static inline __attribute__ (( always_inline )) void
220 dwmac_init_ring ( struct dwmac_ring *ring, unsigned int count,
221  unsigned int qbase, unsigned int ctrl ) {
222 
223  ring->qbase = ( qbase - DWMAC_DMA );
224  ring->count = count;
225  ring->ctrl = ctrl;
226  ring->len = ( count * sizeof ( ring->desc[0] ) );
227 }
228 
229 /** A DesignWare MAC network card */
230 struct dwmac {
231  /** Registers */
232  void *regs;
233  /** DMA device */
234  struct dma_device *dma;
235  /** Device name (for debugging) */
236  const char *name;
238  /** Transmit ring */
239  struct dwmac_ring tx;
240  /** Receive ring */
241  struct dwmac_ring rx;
242  /** Receive I/O buffers */
244 };
245 
246 #endif /* _DWMAC_H */
struct dwmac_mac::@39 __attribute__((packed)) reg
unsigned short uint16_t
Definition: stdint.h:11
static unsigned int unsigned int reg
Definition: myson.h:162
unsigned int cons
Consumer index.
Definition: dwmac.h:192
uint8_t ctrl
Ring control.
Definition: dwmac.h:156
uint8_t raw[ETH_ALEN]
Definition: dwmac.h:72
size_t len
Length of descriptors.
Definition: dwmac.h:201
struct dwmac_descriptor * desc
Descriptors.
Definition: dwmac.h:186
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
A frame descriptor.
Definition: dwmac.h:148
uint8_t count
Number of descriptors.
Definition: dwmac.h:197
A DesignWare MAC address.
Definition: dwmac.h:67
static unsigned int unsigned int qbase
Definition: dwmac.h:225
A DesignWare MAC network card.
Definition: dwmac.h:235
struct io_buffer * rx_iobuf[DWMAC_NUM_RX_DESC]
Receive I/O buffers.
Definition: dwmac.h:248
const char * name
Device name (for debugging)
Definition: dwmac.h:241
static unsigned int count
Number of entries.
Definition: dwmac.h:225
#define DWMAC_DMA
DMA register block.
Definition: dwmac.h:80
unsigned char uint8_t
Definition: stdint.h:10
A DesignWare descriptor ring.
Definition: dwmac.h:184
struct dwmac_ring __attribute__
uint16_t size
Buffer size.
Definition: dwmac.h:152
#define ETH_ALEN
Definition: if_ether.h:8
unsigned int uint32_t
Definition: stdint.h:12
#define DWMAC_NUM_RX_DESC
Number of receive descriptors.
Definition: dwmac.h:208
uint32_t next
Next descriptor address.
Definition: dwmac.h:160
struct dwmac_ring tx
Transmit ring.
Definition: dwmac.h:244
void * regs
Registers.
Definition: dwmac.h:237
uint32_t addrl
Definition: dwmac.h:69
uint8_t qbase
Queue base address register (within DMA block)
Definition: dwmac.h:195
uint32_t addrh
Definition: dwmac.h:70
uint32_t stat
Completion status.
Definition: dwmac.h:150
uint8_t ctrl
Ring control.
Definition: dwmac.h:18
uint8_t ctrl
Default control flags.
Definition: dwmac.h:199
unsigned int prod
Producer index.
Definition: dwmac.h:190
A DMA mapping.
Definition: dma.h:32
struct dwmac_ring rx
Receive ring.
Definition: dwmac.h:246
uint8_t reserved_a
Reserved.
Definition: dwmac.h:154
struct dma_mapping map
Descriptor ring DMA mapping.
Definition: dwmac.h:188
A DMA-capable device.
Definition: dma.h:47
struct dma_device * dma
DMA device.
Definition: dwmac.h:239
A persistent I/O buffer.
Definition: iobuf.h:37
uint32_t addr
Buffer address.
Definition: dwmac.h:158