iPXE
cgem.h
Go to the documentation of this file.
1#ifndef _CGEM_H
2#define _CGEM_H
3
4/** @file
5 *
6 * Cadence Gigabit Ethernet MAC (GEM) network driver
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
12#include <ipxe/if_ether.h>
13#include <ipxe/mii.h>
14#include <ipxe/dma.h>
15#include <ipxe/retry.h>
16
17/** I/O region index */
18#define CGEM_REG_IDX 0
19
20/** I/O region length */
21#define CGEM_REG_LEN 0x800
22
23/** Network control register */
24#define CGEM_NWCTRL 0x000
25#define CGEM_NWCTRL_STARTTX 0x00000200 /**< Start transmission */
26#define CGEM_NWCTRL_STATCLR 0x00000020 /**< Clear statistics */
27#define CGEM_NWCTRL_MDEN 0x00000010 /**< MII interface enable */
28#define CGEM_NWCTRL_TXEN 0x00000008 /**< Transmit enable */
29#define CGEM_NWCTRL_RXEN 0x00000004 /**< Receive enable */
30
31/** Normal value for network control register while up and running */
32#define CGEM_NWCTRL_NORMAL \
33 ( CGEM_NWCTRL_MDEN | CGEM_NWCTRL_TXEN | CGEM_NWCTRL_RXEN )
34
35/** Network configuration register */
36#define CGEM_NWCFG 0x004
37
38/** Network status register */
39#define CGEM_NWSR 0x008
40#define CGEM_NWSR_MII_IDLE 0x00000004 /**< MII interface is idle */
41
42/** DMA configuration register */
43#define CGEM_DMACR 0x010
44#define CGEM_DMACR_RXBUF( x ) ( ( (x) / 64 ) << 16 ) /**< RX buffer size */
45#define CGEM_DMACR_TXSIZE( x ) ( (x) << 10 ) /**< TX memory size */
46#define CGEM_DMACR_TXSIZE_MAX \
47 CGEM_DMACR_TXSIZE ( 0x1 ) /**< Max TX memory size */
48#define CGEM_DMACR_RXSIZE( x ) ( (x) << 8 ) /**< RX memory size */
49#define CGEM_DMACR_RXSIZE_MAX \
50 CGEM_DMACR_RXSIZE ( 0x3 ) /**< Max RX memory size */
51#define CGEM_DMACR_BLENGTH( x ) ( (x) << 0 ) /**< DMA burst length */
52#define CGEM_DMACR_BLENGTH_MAX \
53 CGEM_DMACR_BLENGTH ( 0x10 ) /**< Max DMA burst length */
54
55/** RX queue base address register */
56#define CGEM_RXQBASE 0x018
57
58/** TX queue base address register */
59#define CGEM_TXQBASE 0x01c
60
61/** Interrupt disable register */
62#define CGEM_IDR 0x02c
63#define CGEM_IDR_ALL 0xffffffff /**< Disable all interrupts */
64
65/** PHY maintenance register */
66#define CGEM_PHYMNTNC 0x034
67#define CGEM_PHYMNTNC_CLAUSE22 0x40000000 /**< Clause 22 operation */
68#define CGEM_PHYMNTNC_OP_WRITE 0x10000000 /**< Write to PHY register */
69#define CGEM_PHYMNTNC_OP_READ 0x20000000 /**< Read from PHY register */
70#define CGEM_PHYMNTNC_ADDR( x ) ( (x) << 23 ) /**< PHY address */
71#define CGEM_PHYMNTNC_REG( x ) ( (x) << 18 ) /**< Register address */
72#define CGEM_PHYMNTNC_FIXED 0x00020000 /**< Fixed value to write */
73#define CGEM_PHYMNTNC_DATA_MASK 0x0000ffff /**< Data mask */
74
75/** Maximum time to wait for PHY access, in microseconds */
76#define CGEM_MII_MAX_WAIT_US 500
77
78/** Link state check interval */
79#define CGEM_LINK_INTERVAL ( 2 * TICKS_PER_SEC )
80
81/** Local MAC address (low half) register */
82#define CGEM_LADDRL 0x088
83
84/** Local MAC address (high half) register */
85#define CGEM_LADDRH 0x08c
86
87/** A Cadence GEM descriptor */
89 /** Buffer address */
91 /** Flags */
93} __attribute__ (( packed ));
94
95/** Transmit flags */
96#define CGEM_TX_FL_OWNED 0x80000000 /**< Owned by software */
97#define CGEM_TX_FL_WRAP 0x40000000 /**< End of descriptor ring */
98#define CGEM_TX_FL_LAST 0x00008000 /**< Last buffer in frame */
99
100/** Transmit ring length */
101#define CGEM_NUM_TX_DESC 8
102
103/** Receive flags (in buffer address) */
104#define CGEM_RX_ADDR_OWNED 0x00000001 /**< Owned by software */
105#define CGEM_RX_ADDR_WRAP 0x00000002 /**< End of descriptor ring */
106
107/** Receive flags */
108#define CGEM_RX_FL_LEN( x ) ( (x) & 0x1fff ) /**< RX packet length */
109
110/** Receive ring length */
111#define CGEM_NUM_RX_DESC 8
112
113/** Length of receive buffers
114 *
115 * Must be a multiple of 64.
116 */
117#define CGEM_RX_LEN 1536
118
119/** A Cadence GEM MAC address */
120union cgem_mac {
121 struct {
124 } __attribute__ (( packed )) reg;
126};
127
128/** A Cadence GEM descriptor ring */
129struct cgem_ring {
130 /** Descriptors */
132 /** Descriptor ring DMA mapping */
134 /** Producer index */
135 unsigned int prod;
136 /** Consumer index */
137 unsigned int cons;
138
139 /** Queue base address register */
141 /** Number of descriptors */
143 /** Length of descriptors */
145};
146
147/**
148 * Initialise descriptor ring
149 *
150 * @v ring Descriptor ring
151 * @v count Number of descriptors
152 * @v qbase Queue base address register
153 */
154static inline __attribute__ (( always_inline )) void
155cgem_init_ring ( struct cgem_ring *ring, unsigned int count,
156 unsigned int qbase ) {
157
158 ring->qbase = qbase;
159 ring->count = count;
160 ring->len = ( count * sizeof ( ring->desc[0] ) );
161}
162
163/** A Cadence GEM network card */
164struct cgem_nic {
165 /** Registers */
166 void *regs;
167 /** DMA device */
169 /** Network device */
171 /** Device name (for debugging) */
172 const char *name;
173
174 /** PHY interface */
176 /** PHY device */
178 /** Link state timer */
180
181 /** Transmit ring */
182 struct cgem_ring tx;
183 /** Receive ring */
184 struct cgem_ring rx;
185 /** Receive I/O buffers */
187};
188
189#endif /* _CGEM_H */
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
#define CGEM_NUM_RX_DESC
Receive ring length.
Definition cgem.h:111
static void cgem_init_ring(struct cgem_ring *ring, unsigned int count, unsigned int qbase)
Initialise descriptor ring.
Definition cgem.h:155
static unsigned int unsigned int qbase
Definition dwmac.h:221
static unsigned int count
Number of entries.
Definition dwmac.h:220
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define ETH_ALEN
Definition if_ether.h:9
#define __attribute__(x)
Definition compiler.h:10
DMA mappings.
Media Independent Interface.
static unsigned int unsigned int reg
Definition myson.h:162
Retry timers.
A Cadence GEM descriptor.
Definition cgem.h:88
uint32_t addr
Buffer address.
Definition cgem.h:90
uint32_t flags
Flags.
Definition cgem.h:92
A Cadence GEM network card.
Definition cgem.h:164
struct cgem_ring rx
Receive ring.
Definition cgem.h:184
struct mii_device mii
PHY device.
Definition cgem.h:177
struct mii_interface mdio
PHY interface.
Definition cgem.h:175
struct net_device * netdev
Network device.
Definition cgem.h:170
struct cgem_ring tx
Transmit ring.
Definition cgem.h:182
struct io_buffer * rx_iobuf[CGEM_NUM_RX_DESC]
Receive I/O buffers.
Definition cgem.h:186
struct retry_timer timer
Link state timer.
Definition cgem.h:179
void * regs
Registers.
Definition cgem.h:166
const char * name
Device name (for debugging)
Definition cgem.h:172
struct dma_device * dma
DMA device.
Definition cgem.h:168
A Cadence GEM descriptor ring.
Definition cgem.h:129
struct cgem_descriptor * desc
Descriptors.
Definition cgem.h:131
unsigned int cons
Consumer index.
Definition cgem.h:137
uint16_t len
Length of descriptors.
Definition cgem.h:144
struct dma_mapping map
Descriptor ring DMA mapping.
Definition cgem.h:133
uint8_t qbase
Queue base address register.
Definition cgem.h:140
uint8_t count
Number of descriptors.
Definition cgem.h:142
unsigned int prod
Producer index.
Definition cgem.h:135
A DMA-capable device.
Definition dma.h:48
A DMA mapping.
Definition dma.h:33
A persistent I/O buffer.
Definition iobuf.h:38
An MII device.
Definition mii.h:50
An MII interface.
Definition mii.h:44
A network device.
Definition netdevice.h:353
A retry timer.
Definition retry.h:22
A Cadence GEM MAC address.
Definition cgem.h:120
uint32_t high
Definition cgem.h:123
uint8_t raw[ETH_ALEN]
Definition cgem.h:125
uint32_t low
Definition cgem.h:122