6 * Intel 10/100/1000 network card driver
10 FILE_LICENCE ( GPL2_OR_LATER );
13 #include <ipxe/if_ether.h>
17 #define INTEL_BAR_SIZE ( 128 * 1024 )
19 /** A packet descriptor */
20 struct intel_descriptor {
35 } __attribute__ (( packed ));
37 /** Packet descriptor command bits */
38 enum intel_descriptor_command {
40 INTEL_DESC_CMD_RS = 0x08,
41 /** Insert frame checksum (CRC) */
42 INTEL_DESC_CMD_IFCS = 0x02,
44 INTEL_DESC_CMD_EOP = 0x01,
47 /** Packet descriptor status bits */
48 enum intel_descriptor_status {
49 /** Descriptor done */
50 INTEL_DESC_STATUS_DD = 0x01,
53 /** Device Control Register */
54 #define INTEL_CTRL 0x00000UL
55 #define INTEL_CTRL_LRST 0x00000008UL /**< Link reset */
56 #define INTEL_CTRL_ASDE 0x00000020UL /**< Auto-speed detection */
57 #define INTEL_CTRL_SLU 0x00000040UL /**< Set link up */
58 #define INTEL_CTRL_FRCSPD 0x00000800UL /**< Force speed */
59 #define INTEL_CTRL_FRCDPLX 0x00001000UL /**< Force duplex */
60 #define INTEL_CTRL_RST 0x04000000UL /**< Device reset */
61 #define INTEL_CTRL_PHY_RST 0x80000000UL /**< PHY reset */
63 /** Time to delay for device reset, in milliseconds */
64 #define INTEL_RESET_DELAY_MS 20
66 /** Device Status Register */
67 #define INTEL_STATUS 0x00008UL
68 #define INTEL_STATUS_LU 0x00000002UL /**< Link up */
70 /** EEPROM Read Register */
71 #define INTEL_EERD 0x00014UL
72 #define INTEL_EERD_START 0x00000001UL /**< Start read */
73 #define INTEL_EERD_DONE_SMALL 0x00000010UL /**< Read done (small EERD) */
74 #define INTEL_EERD_DONE_LARGE 0x00000002UL /**< Read done (large EERD) */
75 #define INTEL_EERD_ADDR_SHIFT_SMALL 8 /**< Address shift (small) */
76 #define INTEL_EERD_ADDR_SHIFT_LARGE 2 /**< Address shift (large) */
77 #define INTEL_EERD_DATA(value) ( (value) >> 16 ) /**< Read data */
79 /** Maximum time to wait for EEPROM read, in milliseconds */
80 #define INTEL_EEPROM_MAX_WAIT_MS 100
82 /** EEPROM word length */
83 #define INTEL_EEPROM_WORD_LEN_LOG2 1
85 /** Minimum EEPROM size, in words */
86 #define INTEL_EEPROM_MIN_SIZE_WORDS 64
88 /** Offset of MAC address within EEPROM */
89 #define INTEL_EEPROM_MAC 0x00
91 /** Interrupt Cause Read Register */
92 #define INTEL_ICR 0x000c0UL
93 #define INTEL_IRQ_TXDW 0x00000001UL /**< Transmit descriptor done */
94 #define INTEL_IRQ_LSC 0x00000004UL /**< Link status change */
95 #define INTEL_IRQ_RXT0 0x00000080UL /**< Receive timer */
96 #define INTEL_IRQ_RXO 0x00000400UL /**< Receive overrun */
98 /** Interrupt Mask Set/Read Register */
99 #define INTEL_IMS 0x000d0UL
101 /** Interrupt Mask Clear Register */
102 #define INTEL_IMC 0x000d8UL
104 /** Receive Control Register */
105 #define INTEL_RCTL 0x00100UL
106 #define INTEL_RCTL_EN 0x00000002UL /**< Receive enable */
107 #define INTEL_RCTL_UPE 0x00000008UL /**< Unicast promiscuous mode */
108 #define INTEL_RCTL_MPE 0x00000010UL /**< Multicast promiscuous */
109 #define INTEL_RCTL_BAM 0x00008000UL /**< Broadcast accept mode */
110 #define INTEL_RCTL_BSIZE_BSEX(bsex,bsize) \
111 ( ( (bsize) << 16 ) | ( (bsex) << 25 ) ) /**< Buffer size */
112 #define INTEL_RCTL_BSIZE_2048 INTEL_RCTL_BSIZE_BSEX ( 0, 0 )
113 #define INTEL_RCTL_BSIZE_BSEX_MASK INTEL_RCTL_BSIZE_BSEX ( 1, 3 )
114 #define INTEL_RCTL_SECRC 0x04000000UL /**< Strip CRC */
116 /** Transmit Control Register */
117 #define INTEL_TCTL 0x00400UL
118 #define INTEL_TCTL_EN 0x00000002UL /**< Transmit enable */
119 #define INTEL_TCTL_PSP 0x00000008UL /**< Pad short packets */
120 #define INTEL_TCTL_CT(x) ( (x) << 4 ) /**< Collision threshold */
121 #define INTEL_TCTL_CT_DEFAULT INTEL_TCTL_CT ( 0x0f )
122 #define INTEL_TCTL_CT_MASK INTEL_TCTL_CT ( 0xff )
123 #define INTEL_TCTL_COLD(x) ( (x) << 12 ) /**< Collision distance */
124 #define INTEL_TCTL_COLD_DEFAULT INTEL_TCTL_COLD ( 0x040 )
125 #define INTEL_TCTL_COLD_MASK INTEL_TCTL_COLD ( 0x3ff )
127 /** Packet Buffer Allocation */
128 #define INTEL_PBA 0x01000UL
130 /** Packet Buffer Size */
131 #define INTEL_PBS 0x01008UL
133 /** Receive Descriptor register block */
134 #define INTEL_RD 0x02800UL
136 /** Number of receive descriptors
138 * Minimum value is 8, since the descriptor ring length must be a
141 #define INTEL_NUM_RX_DESC 16
143 /** Receive descriptor ring fill level */
144 #define INTEL_RX_FILL 8
146 /** Receive buffer length */
147 #define INTEL_RX_MAX_LEN 2048
149 /** Transmit Descriptor register block */
150 #define INTEL_TD 0x03800UL
152 /** Number of transmit descriptors
154 * Descriptor ring length must be a multiple of 16. ICH8/9/10
155 * requires a minimum of 16 TX descriptors.
157 #define INTEL_NUM_TX_DESC 16
159 /** Transmit descriptor ring maximum fill level */
160 #define INTEL_TX_FILL ( INTEL_NUM_TX_DESC - 1 )
162 /** Receive/Transmit Descriptor Base Address Low (offset) */
163 #define INTEL_xDBAL 0x00
165 /** Receive/Transmit Descriptor Base Address High (offset) */
166 #define INTEL_xDBAH 0x04
168 /** Receive/Transmit Descriptor Length (offset) */
169 #define INTEL_xDLEN 0x08
171 /** Receive/Transmit Descriptor Head (offset) */
172 #define INTEL_xDH 0x10
174 /** Receive/Transmit Descriptor Tail (offset) */
175 #define INTEL_xDT 0x18
177 /** Receive/Transmit Descriptor Control (offset) */
178 #define INTEL_xDCTL 0x28
179 #define INTEL_xDCTL_ENABLE 0x02000000UL /**< Queue enable */
181 /** Receive Address Low */
182 #define INTEL_RAL0 0x05400UL
184 /** Receive Address High */
185 #define INTEL_RAH0 0x05404UL
186 #define INTEL_RAH0_AV 0x80000000UL /**< Address valid */
188 /** Receive address */
189 union intel_receive_address {
193 } __attribute__ (( packed )) reg;
194 uint8_t raw[ETH_ALEN];
197 /** An Intel descriptor ring */
200 struct intel_descriptor *desc;
201 /** Producer index */
203 /** Consumer index */
206 /** Register block */
208 /** Length (in bytes) */
213 * Initialise descriptor ring
215 * @v ring Descriptor ring
216 * @v count Number of descriptors
217 * @v reg Descriptor register block
219 static inline __attribute__ (( always_inline)) void
220 intel_init_ring ( struct intel_ring *ring, unsigned int count,
222 ring->len = ( count * sizeof ( ring->desc[0] ) );
226 /** An Intel network card */
230 /** Port number (for multi-port devices) */
236 struct nvs_device eeprom;
237 /** EEPROM done flag */
239 /** EEPROM address shift */
240 unsigned int eerd_addr_shift;
242 /** Transmit descriptor ring */
243 struct intel_ring tx;
244 /** Receive descriptor ring */
245 struct intel_ring rx;
246 /** Receive I/O buffers */
247 struct io_buffer *rx_iobuf[INTEL_NUM_RX_DESC];
252 /** PBS/PBA errata workaround required */
253 INTEL_PBS_ERRATA = 0x0001,
256 extern int intel_create_ring ( struct intel_nic *intel,
257 struct intel_ring *ring );
258 extern void intel_destroy_ring ( struct intel_nic *intel,
259 struct intel_ring *ring );
260 extern void intel_refill_rx ( struct intel_nic *intel );
261 extern void intel_empty_rx ( struct intel_nic *intel );
262 extern int intel_transmit ( struct net_device *netdev,
263 struct io_buffer *iobuf );
264 extern void intel_poll_tx ( struct net_device *netdev );
265 extern void intel_poll_rx ( struct net_device *netdev );
267 #endif /* _INTEL_H */