iPXE
intel.h
Go to the documentation of this file.
1 #ifndef _INTEL_H
2 #define _INTEL_H
3 
4 /** @file
5  *
6  * Intel 10/100/1000 network card driver
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 FILE_SECBOOT ( PERMITTED );
12 
13 #include <stdint.h>
14 #include <ipxe/if_ether.h>
15 #include <ipxe/nvs.h>
16 #include <ipxe/dma.h>
17 
18 /** Intel BAR size */
19 #define INTEL_BAR_SIZE ( 128 * 1024 )
20 
21 /** A packet descriptor */
23  /** Buffer address */
25  /** Length */
27  /** Flags */
29  /** Command */
31  /** Status */
33 } __attribute__ (( packed ));
34 
35 /** Descriptor type */
36 #define INTEL_DESC_FL_DTYP( dtyp ) ( (dtyp) << 4 )
37 #define INTEL_DESC_FL_DTYP_DATA INTEL_DESC_FL_DTYP ( 0x03 )
38 
39 /** Descriptor extension */
40 #define INTEL_DESC_CMD_DEXT 0x20
41 
42 /** Report status */
43 #define INTEL_DESC_CMD_RS 0x08
44 
45 /** Insert frame checksum (CRC) */
46 #define INTEL_DESC_CMD_IFCS 0x02
47 
48 /** End of packet */
49 #define INTEL_DESC_CMD_EOP 0x01
50 
51 /** Descriptor done */
52 #define INTEL_DESC_STATUS_DD 0x00000001UL
53 
54 /** Receive error */
55 #define INTEL_DESC_STATUS_RXE 0x00000100UL
56 
57 /** Payload length */
58 #define INTEL_DESC_STATUS_PAYLEN( len ) ( (len) << 14 )
59 
60 /** Device Control Register */
61 #define INTEL_CTRL 0x00000UL
62 #define INTEL_CTRL_LRST 0x00000008UL /**< Link reset */
63 #define INTEL_CTRL_ASDE 0x00000020UL /**< Auto-speed detection */
64 #define INTEL_CTRL_SLU 0x00000040UL /**< Set link up */
65 #define INTEL_CTRL_FRCSPD 0x00000800UL /**< Force speed */
66 #define INTEL_CTRL_FRCDPLX 0x00001000UL /**< Force duplex */
67 #define INTEL_CTRL_RST 0x04000000UL /**< Device reset */
68 #define INTEL_CTRL_PHY_RST 0x80000000UL /**< PHY reset */
69 
70 /** Time to delay for device reset, in milliseconds */
71 #define INTEL_RESET_DELAY_MS 20
72 
73 /** Device Status Register */
74 #define INTEL_STATUS 0x00008UL
75 #define INTEL_STATUS_LU 0x00000002UL /**< Link up */
76 
77 /** EEPROM Read Register */
78 #define INTEL_EERD 0x00014UL
79 #define INTEL_EERD_START 0x00000001UL /**< Start read */
80 #define INTEL_EERD_DONE_SMALL 0x00000010UL /**< Read done (small EERD) */
81 #define INTEL_EERD_DONE_LARGE 0x00000002UL /**< Read done (large EERD) */
82 #define INTEL_EERD_ADDR_SHIFT_SMALL 8 /**< Address shift (small) */
83 #define INTEL_EERD_ADDR_SHIFT_LARGE 2 /**< Address shift (large) */
84 #define INTEL_EERD_DATA(value) ( (value) >> 16 ) /**< Read data */
85 
86 /** Maximum time to wait for EEPROM read, in milliseconds */
87 #define INTEL_EEPROM_MAX_WAIT_MS 100
88 
89 /** EEPROM word length */
90 #define INTEL_EEPROM_WORD_LEN_LOG2 1
91 
92 /** Minimum EEPROM size, in words */
93 #define INTEL_EEPROM_MIN_SIZE_WORDS 64
94 
95 /** Offset of MAC address within EEPROM */
96 #define INTEL_EEPROM_MAC 0x00
97 
98 /** Interrupt Cause Read Register */
99 #define INTEL_ICR 0x000c0UL
100 #define INTEL_IRQ_TXDW 0x00000001UL /**< Transmit descriptor done */
101 #define INTEL_IRQ_TXQE 0x00000002UL /**< Transmit queue empty */
102 #define INTEL_IRQ_LSC 0x00000004UL /**< Link status change */
103 #define INTEL_IRQ_RXDMT0 0x00000010UL /**< Receive queue low */
104 #define INTEL_IRQ_RXO 0x00000040UL /**< Receive overrun */
105 #define INTEL_IRQ_RXT0 0x00000080UL /**< Receive timer */
106 
107 /** Interrupt Mask Set/Read Register */
108 #define INTEL_IMS 0x000d0UL
109 
110 /** Interrupt Mask Clear Register */
111 #define INTEL_IMC 0x000d8UL
112 
113 /** Receive Control Register */
114 #define INTEL_RCTL 0x00100UL
115 #define INTEL_RCTL_EN 0x00000002UL /**< Receive enable */
116 #define INTEL_RCTL_UPE 0x00000008UL /**< Unicast promiscuous mode */
117 #define INTEL_RCTL_MPE 0x00000010UL /**< Multicast promiscuous */
118 #define INTEL_RCTL_BAM 0x00008000UL /**< Broadcast accept mode */
119 #define INTEL_RCTL_BSIZE_BSEX(bsex,bsize) \
120  ( ( (bsize) << 16 ) | ( (bsex) << 25 ) ) /**< Buffer size */
121 #define INTEL_RCTL_BSIZE_2048 INTEL_RCTL_BSIZE_BSEX ( 0, 0 )
122 #define INTEL_RCTL_BSIZE_BSEX_MASK INTEL_RCTL_BSIZE_BSEX ( 1, 3 )
123 #define INTEL_RCTL_SECRC 0x04000000UL /**< Strip CRC */
125 /** Transmit Control Register */
126 #define INTEL_TCTL 0x00400UL
127 #define INTEL_TCTL_EN 0x00000002UL /**< Transmit enable */
128 #define INTEL_TCTL_PSP 0x00000008UL /**< Pad short packets */
129 #define INTEL_TCTL_CT(x) ( (x) << 4 ) /**< Collision threshold */
130 #define INTEL_TCTL_CT_DEFAULT INTEL_TCTL_CT ( 0x0f )
131 #define INTEL_TCTL_CT_MASK INTEL_TCTL_CT ( 0xff )
132 #define INTEL_TCTL_COLD(x) ( (x) << 12 ) /**< Collision distance */
133 #define INTEL_TCTL_COLD_DEFAULT INTEL_TCTL_COLD ( 0x040 )
134 #define INTEL_TCTL_COLD_MASK INTEL_TCTL_COLD ( 0x3ff )
136 /** Packet Buffer Allocation */
137 #define INTEL_PBA 0x01000UL
139 /** Packet Buffer Size */
140 #define INTEL_PBS 0x01008UL
142 /** Receive packet buffer size */
143 #define INTEL_RXPBS 0x02404UL
144 #define INTEL_RXPBS_I210 0x000000a2UL /**< I210 power-up default */
146 /** Receive Descriptor register block */
147 #define INTEL_RD 0x02800UL
149 /** Number of receive descriptors
150  *
151  * Minimum value is 8, since the descriptor ring length must be a
152  * multiple of 128.
153  */
154 #define INTEL_NUM_RX_DESC 16
156 /** Receive descriptor ring fill level */
157 #define INTEL_RX_FILL 8
159 /** Receive buffer length */
160 #define INTEL_RX_MAX_LEN 2048
162 /** Transmit packet buffer size */
163 #define INTEL_TXPBS 0x03404UL
164 #define INTEL_TXPBS_I210 0x04000014UL /**< I210 power-up default */
166 /** Transmit Descriptor register block */
167 #define INTEL_TD 0x03800UL
169 /** Number of transmit descriptors
170  *
171  * Descriptor ring length must be a multiple of 16. ICH8/9/10
172  * requires a minimum of 16 TX descriptors.
173  */
174 #define INTEL_NUM_TX_DESC 16
176 /** Transmit descriptor ring maximum fill level */
177 #define INTEL_TX_FILL ( INTEL_NUM_TX_DESC - 1 )
179 /** Receive/Transmit Descriptor Base Address Low (offset) */
180 #define INTEL_xDBAL 0x00
182 /** Receive/Transmit Descriptor Base Address High (offset) */
183 #define INTEL_xDBAH 0x04
185 /** Receive/Transmit Descriptor Length (offset) */
186 #define INTEL_xDLEN 0x08
188 /** Receive/Transmit Descriptor Head (offset) */
189 #define INTEL_xDH 0x10
191 /** Receive/Transmit Descriptor Tail (offset) */
192 #define INTEL_xDT 0x18
194 /** Receive/Transmit Descriptor Control (offset) */
195 #define INTEL_xDCTL 0x28
196 #define INTEL_xDCTL_ENABLE 0x02000000UL /**< Queue enable */
198 /** Maximum time to wait for queue disable, in milliseconds */
199 #define INTEL_DISABLE_MAX_WAIT_MS 100
201 /** Receive Address Low */
202 #define INTEL_RAL0 0x05400UL
204 /** Receive Address High */
205 #define INTEL_RAH0 0x05404UL
206 #define INTEL_RAH0_AV 0x80000000UL /**< Address valid */
208 /** Future Extended NVM register 11 */
209 #define INTEL_FEXTNVM11 0x05bbcUL
210 #define INTEL_FEXTNVM11_WTF 0x00002000UL /**< Don't ask */
212 /** Receive address */
213 union intel_receive_address {
214  struct {
215  uint32_t low;
217  } __attribute__ (( packed )) reg;
219 };
220 
221 /** An Intel descriptor ring */
222 struct intel_ring {
223  /** Descriptors */
224  struct intel_descriptor *desc;
225  /** Descriptor ring DMA mapping */
226  struct dma_mapping map;
227  /** Producer index */
228  unsigned int prod;
229  /** Consumer index */
230  unsigned int cons;
232  /** Register block */
233  unsigned int reg;
234  /** Length (in bytes) */
235  size_t len;
237  /** Populate descriptor
238  *
239  * @v desc Descriptor
240  * @v addr Data buffer address
241  * @v len Length of data
242  */
243  void ( * describe ) ( struct intel_descriptor *desc, physaddr_t addr,
244  size_t len );
245 };
246 
247 /**
248  * Initialise descriptor ring
249  *
250  * @v ring Descriptor ring
251  * @v count Number of descriptors
252  * @v reg Descriptor register block
253  * @v describe Method to populate descriptor
254  */
255 static inline __attribute__ (( always_inline)) void
256 intel_init_ring ( struct intel_ring *ring, unsigned int count, unsigned int reg,
257  void ( * describe ) ( struct intel_descriptor *desc,
258  physaddr_t addr, size_t len ) ) {
259 
260  ring->len = ( count * sizeof ( ring->desc[0] ) );
261  ring->reg = reg;
262  ring->describe = describe;
263 }
264 
265 /** An Intel virtual function mailbox */
266 struct intel_mailbox {
267  /** Mailbox control register */
268  unsigned int ctrl;
269  /** Mailbox memory base */
270  unsigned int mem;
271 };
272 
273 /**
274  * Initialise mailbox
275  *
276  * @v mbox Mailbox
277  * @v ctrl Mailbox control register
278  * @v mem Mailbox memory register base
279  */
280 static inline __attribute__ (( always_inline )) void
281 intel_init_mbox ( struct intel_mailbox *mbox, unsigned int ctrl,
282  unsigned int mem ) {
283 
284  mbox->ctrl = ctrl;
285  mbox->mem = mem;
286 }
287 
288 /** An Intel network card */
289 struct intel_nic {
290  /** Registers */
291  void *regs;
292  /** DMA device */
293  struct dma_device *dma;
294  /** Port number (for multi-port devices) */
295  unsigned int port;
296  /** Flags */
297  unsigned int flags;
298  /** Forced interrupts */
299  unsigned int force_icr;
301  /** EEPROM */
302  struct nvs_device eeprom;
303  /** EEPROM done flag */
305  /** EEPROM address shift */
306  unsigned int eerd_addr_shift;
308  /** Mailbox */
309  struct intel_mailbox mbox;
311  /** Transmit descriptor ring */
312  struct intel_ring tx;
313  /** Receive descriptor ring */
314  struct intel_ring rx;
315  /** Receive I/O buffers */
317 };
318 
319 /** Driver flags */
320 enum intel_flags {
321  /** PBS/PBA errata workaround required */
322  INTEL_PBS_ERRATA = 0x0001,
323  /** VMware missing interrupt workaround required */
324  INTEL_VMWARE = 0x0002,
325  /** PHY reset is broken */
326  INTEL_NO_PHY_RST = 0x0004,
327  /** ASDE is broken */
328  INTEL_NO_ASDE = 0x0008,
329  /** Reset may cause a complete device hang */
330  INTEL_RST_HANG = 0x0010,
331  /** PBSIZE registers must be explicitly reset */
332  INTEL_PBSIZE_RST = 0x0020,
333 };
334 
335 /** The i219 has a seriously broken reset mechanism */
336 #define INTEL_I219 ( INTEL_NO_PHY_RST | INTEL_RST_HANG )
338 /**
339  * Dump diagnostic information
340  *
341  * @v intel Intel device
342  */
343 static inline void intel_diag ( struct intel_nic *intel ) {
345  DBGC ( intel, "INTEL %p TX %04x(%02x)/%04x(%02x) "
346  "RX %04x(%02x)/%04x(%02x)\n", intel,
347  ( intel->tx.cons & 0xffff ),
348  readl ( intel->regs + intel->tx.reg + INTEL_xDH ),
349  ( intel->tx.prod & 0xffff ),
350  readl ( intel->regs + intel->tx.reg + INTEL_xDT ),
351  ( intel->rx.cons & 0xffff ),
352  readl ( intel->regs + intel->rx.reg + INTEL_xDH ),
353  ( intel->rx.prod & 0xffff ),
354  readl ( intel->regs + intel->rx.reg + INTEL_xDT ) );
355 }
356 
357 extern void intel_describe_tx ( struct intel_descriptor *tx,
358  physaddr_t addr, size_t len );
359 extern void intel_describe_tx_adv ( struct intel_descriptor *tx,
360  physaddr_t addr, size_t len );
361 extern void intel_describe_rx ( struct intel_descriptor *rx,
362  physaddr_t addr, size_t len );
363 extern void intel_reset_ring ( struct intel_nic *intel, unsigned int reg );
364 extern int intel_create_ring ( struct intel_nic *intel,
365  struct intel_ring *ring );
366 extern void intel_destroy_ring ( struct intel_nic *intel,
367  struct intel_ring *ring );
368 extern void intel_refill_rx ( struct intel_nic *intel );
369 extern void intel_empty_rx ( struct intel_nic *intel );
370 extern int intel_transmit ( struct net_device *netdev,
371  struct io_buffer *iobuf );
372 extern void intel_poll_tx ( struct net_device *netdev );
373 extern void intel_poll_rx ( struct net_device *netdev );
374 
375 #endif /* _INTEL_H */
unsigned int force_icr
Forced interrupts.
Definition: intel.h:300
void * regs
Registers.
Definition: intel.h:292
PHY reset is broken.
Definition: intel.h:327
#define __attribute__(x)
Definition: compiler.h:10
void intel_describe_tx_adv(struct intel_descriptor *tx, physaddr_t addr, size_t len)
Populate advanced transmit descriptor.
Definition: intel.c:415
unsigned short uint16_t
Definition: stdint.h:11
#define INTEL_NUM_RX_DESC
Number of receive descriptors.
Definition: intel.h:155
static unsigned int unsigned int reg
Definition: myson.h:162
ASDE is broken.
Definition: intel.h:329
void intel_poll_tx(struct net_device *netdev)
Poll for completed packets.
Definition: intel.c:792
VMware missing interrupt workaround required.
Definition: intel.h:325
struct dma_mapping map
Descriptor ring DMA mapping.
Definition: intel.h:227
A non-volatile storage device.
Definition: nvs.h:16
void intel_describe_rx(struct intel_descriptor *rx, physaddr_t addr, size_t len)
Populate receive descriptor.
Definition: intel.c:434
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
uint32_t status
Status.
Definition: intel.h:32
struct intel_ring rx
Receive descriptor ring.
Definition: intel.h:315
#define DBGC(...)
Definition: compiler.h:505
#define INTEL_xDT
Receive/Transmit Descriptor Tail (offset)
Definition: intel.h:193
size_t len
Length (in bytes)
Definition: intel.h:236
unsigned long long uint64_t
Definition: stdint.h:13
Non-volatile storage.
PBS/PBA errata workaround required.
Definition: intel.h:323
DMA mappings.
An Intel descriptor ring.
Definition: intel.h:223
static void intel_init_ring(struct intel_ring *ring, unsigned int count, unsigned int reg, void(*describe)(struct intel_descriptor *desc, physaddr_t addr, size_t len))
Initialise descriptor ring.
Definition: intel.h:257
uint8_t raw[ETH_ALEN]
Definition: intel.h:219
unsigned int cons
Consumer index.
Definition: intel.h:231
unsigned int reg
Register block.
Definition: intel.h:234
FILE_SECBOOT(PERMITTED)
eeprom
Definition: 3c90x.h:232
unsigned int port
Port number (for multi-port devices)
Definition: intel.h:296
#define INTEL_xDH
Receive/Transmit Descriptor Head (offset)
Definition: intel.h:190
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
static void intel_init_mbox(struct intel_mailbox *mbox, unsigned int ctrl, unsigned int mem)
Initialise mailbox.
Definition: intel.h:282
int intel_create_ring(struct intel_nic *intel, struct intel_ring *ring)
Create descriptor ring.
Definition: intel.c:512
PBSIZE registers must be explicitly reset.
Definition: intel.h:333
ring len
Length.
Definition: dwmac.h:231
uint32_t eerd_done
EEPROM done flag.
Definition: intel.h:305
static struct net_device * netdev
Definition: gdbudp.c:52
struct io_buffer * rx_iobuf[INTEL_NUM_RX_DESC]
Receive I/O buffers.
Definition: intel.h:317
static unsigned int count
Number of entries.
Definition: dwmac.h:225
Definition: golan.c:120
uint64_t address
Buffer address.
Definition: intel.h:24
static void intel_diag(struct intel_nic *intel)
Dump diagnostic information.
Definition: intel.h:344
int intel_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: intel.c:753
void intel_refill_rx(struct intel_nic *intel)
Refill receive descriptor ring.
Definition: intel.c:581
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
void intel_destroy_ring(struct intel_nic *intel, struct intel_ring *ring)
Destroy descriptor ring.
Definition: intel.c:564
An Intel virtual function mailbox.
Definition: intel.h:267
uint32_t addr
Buffer address.
Definition: dwmac.h:20
A network device.
Definition: netdevice.h:353
unsigned char uint8_t
Definition: stdint.h:10
#define ETH_ALEN
Definition: if_ether.h:9
unsigned int uint32_t
Definition: stdint.h:12
uint16_t length
Length.
Definition: intel.h:26
void intel_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: intel.c:821
void intel_reset_ring(struct intel_nic *intel, unsigned int reg)
Reset descriptor ring.
Definition: intel.c:488
void(* describe)(struct intel_descriptor *desc, physaddr_t addr, size_t len)
Populate descriptor.
Definition: intel.h:244
unsigned int mem
Mailbox memory base.
Definition: intel.h:271
unsigned long physaddr_t
Definition: stdint.h:20
struct dma_device * dma
DMA device.
Definition: intel.h:294
unsigned int ctrl
Mailbox control register.
Definition: intel.h:269
A packet descriptor.
Definition: intel.h:22
unsigned int prod
Producer index.
Definition: intel.h:229
void intel_empty_rx(struct intel_nic *intel)
Discard unused receive I/O buffers.
Definition: intel.c:631
u8 rx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets from the AP.
Definition: wpa.h:234
uint8_t ctrl
Ring control.
Definition: dwmac.h:18
An Intel network card.
Definition: intel.h:290
struct intel_receive_address::@78 reg
struct intel_descriptor * desc
Descriptors.
Definition: intel.h:225
struct intel_ring tx
Transmit descriptor ring.
Definition: intel.h:313
Receive address.
Definition: intel.h:214
Reset may cause a complete device hang.
Definition: intel.h:331
uint8_t command
Command.
Definition: intel.h:30
unsigned int eerd_addr_shift
EEPROM address shift.
Definition: intel.h:307
intel_flags
Driver flags.
Definition: intel.h:321
unsigned int flags
Flags.
Definition: intel.h:298
A DMA mapping.
Definition: dma.h:33
uint8_t flags
Flags.
Definition: intel.h:28
u8 tx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets to the AP.
Definition: wpa.h:237
A DMA-capable device.
Definition: dma.h:48
void intel_describe_tx(struct intel_descriptor *tx, physaddr_t addr, size_t len)
Populate transmit descriptor.
Definition: intel.c:396
A persistent I/O buffer.
Definition: iobuf.h:38