121 static const uint32_t NIS_mask = 0x4045;
122 static const uint32_t AIS_mask = 0x27ba;
123 static const uint32_t NIS_bit = 1 << 16;
124 static const uint32_t AIS_bit = 1 << 15;
125 static const uint32_t IS_mask = NIS_mask | AIS_mask;
126 static const uint32_t IS_bits = NIS_bit | AIS_bit;
127 static const uint32_t BE_mask = 7;
130 EarlyReceive = 1 << 14,
132 EarlyTransmit = 1 << 10,
133 RxWatchdogTimeout = 1 << 9,
135 RxBufUnavailable = 1 << 7,
139 TxJabberTimeout = 1 << 3,
140 TxBufUnavailable = 1 << 2,
145 void setTxState(DwmacState::Tx state)
147 m_dma_reg_status.ts = state;
148 m_regstate_staled =
true;
151 void setRxState(DwmacState::Rx state)
153 m_dma_reg_status.rs = state;
154 m_regstate_staled =
true;
157 DwmacState::Tx getTxState()
const {
return m_dma_reg_status.ts; }
158 DwmacState::Rx getRxState()
const {
return m_dma_reg_status.rs; }
162 m_regstate_staled =
false;
169 m_dma_reg_status.value = 0;
172 void clear(uint32_t clear)
174 clear &= IS_mask | IS_bits;
176 if ((clear & NIS_mask) && !(clear & NIS_bit)) {
177 SCP_INFO(
"dwmac.h") <<
"Clearing normal interrupts without clearing NIS";
180 if ((clear & AIS_mask) && !(clear & AIS_bit)) {
181 SCP_INFO(
"dwmac.h") <<
"Clearing abnormal interrupts without clearing AIS";
184 m_interrupts &= ((~clear) & IS_mask);
186 if ((m_interrupts & NIS_mask) && (m_regmask & NIS_bit)) m_interrupts |= NIS_bit;
187 if ((m_interrupts & AIS_mask) && (m_regmask & AIS_bit)) m_interrupts |= AIS_bit;
189 m_regstate_staled =
true;
192 void fire(uint32_t interrupts)
194 interrupts &= m_regmask;
195 interrupts &= IS_mask;
197 if ((interrupts & NIS_mask) && (m_regmask & NIS_bit)) interrupts |= NIS_bit;
198 if ((interrupts & AIS_mask) && (m_regmask & AIS_bit)) interrupts |= AIS_bit;
199 m_interrupts |= interrupts;
200 m_regstate_staled =
true;
203 bool has_interrupts()
const {
return ((m_interrupts & m_regmask) != 0); }
205 void set_interrupts(uint32_t mask) { m_regmask = (mask & (IS_mask | IS_bits)); }
207 void set_status(uint32_t value) { clear(value & (IS_mask | IS_bits)); }
209 uint32_t interrupts()
const {
return m_regmask; }
211 uint32_t status()
const
213 if (m_regstate_staled) {
214 m_regstate = m_interrupts | m_dma_reg_status.value;
216 m_regstate_staled =
false;
222 mutable bool m_regstate_staled;
223 mutable uint32_t m_regstate;
226 uint32_t m_interrupts;
237 uint32_t payload_csum_error:1;
238 uint32_t crc_error:1;
239 uint32_t dribbling:1;
240 uint32_t mii_error:1;
241 uint32_t receive_watchdog:1;
242 uint32_t frame_type:1;
243 uint32_t collision:1;
244 uint32_t ipc_csum_error:1;
245 uint32_t last_descriptor:1;
246 uint32_t first_descriptor:1;
248 uint32_t overflow_error:1;
249 uint32_t length_error:1;
250 uint32_t sa_filter_fail:1;
251 uint32_t descriptor_error:1;
252 uint32_t error_summary:1;
253 uint32_t frame_length:14;
254 uint32_t da_filter_fail:1;
257 uint32_t buffer1_size:11;
258 uint32_t buffer2_size:11;
259 uint32_t reserved1:2;
260 uint32_t second_address_chained:1;
262 uint32_t reserved2:5;
263 uint32_t disable_ic:1;
268 uint32_t rx_mac_addr : 1;
269 uint32_t crc_error : 1;
270 uint32_t dribbling : 1;
271 uint32_t error_gmii : 1;
272 uint32_t receive_watchdog : 1;
273 uint32_t frame_type : 1;
274 uint32_t late_collision : 1;
275 uint32_t ipc_csum_error : 1;
276 uint32_t last_descriptor : 1;
277 uint32_t first_descriptor : 1;
278 uint32_t vlan_tag : 1;
279 uint32_t overflow_error : 1;
280 uint32_t length_error : 1;
281 uint32_t sa_filter_fail : 1;
282 uint32_t descriptor_error : 1;
283 uint32_t error_summary : 1;
284 uint32_t frame_length : 14;
285 uint32_t da_filter_fail : 1;
288 uint32_t buffer1_size : 13;
289 uint32_t reserved1 : 1;
290 uint32_t second_address_chained : 1;
291 uint32_t end_ring : 1;
292 uint32_t buffer2_size : 13;
293 uint32_t reserved2 : 2;
294 uint32_t disable_ic : 1;
302 uint32_t underflow_error:1;
303 uint32_t excessive_deferral:1;
304 uint32_t collision_count:4;
305 uint32_t vlan_frame:1;
306 uint32_t excessive_collisions:1;
307 uint32_t late_collision:1;
308 uint32_t no_carrier:1;
309 uint32_t loss_carrier:1;
310 uint32_t payload_error:1;
311 uint32_t frame_flushed:1;
312 uint32_t jabber_timeout:1;
313 uint32_t error_summary:1;
314 uint32_t ip_header_error:1;
315 uint32_t time_stamp_status:1;
316 uint32_t reserved1:13;
319 uint32_t buffer1_size:11;
320 uint32_t buffer2_size:11;
321 uint32_t time_stamp_enable:1;
322 uint32_t disable_padding:1;
323 uint32_t second_address_chained:1;
325 uint32_t crc_disable:1;
326 uint32_t checksum_insertion:2;
327 uint32_t first_segment:1;
328 uint32_t last_segment:1;
329 uint32_t interrupt:1;
334 uint32_t deferred : 1;
335 uint32_t underflow_error : 1;
336 uint32_t excessive_deferral : 1;
337 uint32_t collision_count : 4;
338 uint32_t vlan_frame : 1;
339 uint32_t excessive_collisions : 1;
340 uint32_t late_collision : 1;
341 uint32_t no_carrier : 1;
342 uint32_t loss_carrier : 1;
343 uint32_t payload_error : 1;
344 uint32_t frame_flushed : 1;
345 uint32_t jabber_timeout : 1;
346 uint32_t error_summary : 1;
347 uint32_t ip_header_error : 1;
348 uint32_t time_stamp_status : 1;
349 uint32_t reserved1 : 2;
350 uint32_t second_address_chained : 1;
351 uint32_t end_ring : 1;
352 uint32_t checksum_insertion : 2;
353 uint32_t reserved2 : 1;
354 uint32_t time_stamp_enable : 1;
355 uint32_t disable_padding : 1;
356 uint32_t crc_disable : 1;
357 uint32_t first_segment : 1;
358 uint32_t last_segment : 1;
359 uint32_t interrupt : 1;
362 uint32_t buffer1_size : 13;
363 uint32_t reserved3 : 3;
364 uint32_t buffer2_size : 13;
365 uint32_t reserved4 : 3;
378class dwmac :
public sc_core::sc_module
381 bool warn_anregs =
true;
383 sc_core::sc_event m_tx_event;
384 sc_core::sc_event intr_wake;
388 void interrupts_fire(uint32_t interrupts);
389 void interrupts_clear(uint32_t interrupts);
397 void move_to_next_tx_desc(
dma_desc& desc);
403 static const uint32_t DMA_BUS_MODE = 0x1000;
404 static const uint32_t DMA_TX_POLL = 0x1004;
405 static const uint32_t DMA_RX_POLL = 0x1008;
406 static const uint32_t DMA_RX_DESC_LIST_ADDR = 0x100C;
407 static const uint32_t DMA_TX_DESC_LIST_ADDR = 0x1010;
408 static const uint32_t DMA_STATUS = 0x1014;
409 static const uint32_t DMA_OPERATION_MODE = 0x1018;
410 static const uint32_t DMA_INTERRUPTS = 0x101C;
411 static const uint32_t DMA_COUNTERS = 0x1020;
412 static const uint32_t DMA_RX_INT_WDT = 0x1024;
413 static const uint32_t DMA_AXI_BUS_MODE = 0x1028;
414 static const uint32_t DMA_CURRENT_TX_DESC = 0x1048;
415 static const uint32_t DMA_CURRENT_RX_DESC = 0x104C;
416 static const uint32_t DMA_CURRENT_TX_BUF = 0x1050;
417 static const uint32_t DMA_CURRENT_RX_BUF = 0x1054;
418 static const uint32_t HW_FEATURE = 0x1058;
424 uint32_t rx_desc_addr;
425 uint32_t tx_desc_addr;
429 uint32_t current_tx_desc;
430 uint32_t current_rx_desc;
431 uint32_t current_tx_buf;
432 uint32_t current_rx_buf;
434 uint32_t desc_size() {
return (bus_mode.atds == 0) ? 16 : 32; }
440 static const uint32_t DWMAC_VERSION_VALUE = 0x0010;
442 static const uint32_t DWMAC_CONFIGURATION = 0x0000;
443 static const uint32_t DWMAC_FRAME_FILTER = 0x0004;
444 static const uint32_t DWMAC_HASH_TABLE_HI = 0x0008;
445 static const uint32_t DWMAC_HASH_TABLE_LO = 0x000C;
446 static const uint32_t DWMAC_GMII_ADDRESS = 0x0010;
447 static const uint32_t DWMAC_GMII_DATA = 0x0014;
448 static const uint32_t DWMAC_FLOW_CONTROL = 0x0018;
449 static const uint32_t DWMAC_VLAN_TAG = 0x001C;
450 static const uint32_t DWMAC_VERSION = 0x0020;
451 static const uint32_t DWMAC_WAKE_UP_FILTER = 0x0028;
452 static const uint32_t DWMAC_PMT = 0x002C;
453 static const uint32_t DWMAC_INTERRUPT = 0x0038;
454 static const uint32_t DWMAC_INTERRUPT_MASK = 0x003C;
455 static const uint32_t DWMAC_AN_CONTROL = 0x00C0;
456 static const uint32_t DWMAC_AN_STATUS = 0x00C4;
457 static const uint32_t DWMAC_AN_ADVERTISEMENT = 0x00C8;
458 static const uint32_t DWMAC_AN_LINK_PARTNER_ABILITY = 0x00CC;
459 static const uint32_t DWMAC_AN_EXPANSION = 0x00D0;
460 static const uint32_t DWMAC_MAC0_HI = 0x0040;
461 static const uint32_t DWMAC_MAC0_LO = 0x0044;
462 static const uint32_t DWMAC_MACn = 0x0048;
463 static const uint32_t DWMAC_MMC_CONTROL = 0x0100;
464 static const uint32_t DWMAC_MMC_RX_INT = 0x0104;
465 static const uint32_t DWMAC_MMC_TX_INT = 0x0108;
466 static const uint32_t DWMAC_MMC_RX_INT_MASK = 0x010C;
467 static const uint32_t DWMAC_MMC_TX_INT_MASK = 0x0110;
468 static const uint32_t DWMAC_MMC_IPC_RX_INT_MASK = 0x0200;
469 static const uint32_t DWMAC_MMC_IPC_RX_INT = 0x0208;
471 static const uint32_t MACn_COUNT = 15;
473 uint32_t m_configuration;
474 uint32_t m_frame_filter;
475 uint32_t m_hash_table_hi;
476 uint32_t m_hash_table_lo;
478 uint32_t m_gmii_data;
479 uint32_t m_flow_control;
486 uint32_t m_axi_bus_mode;
489 sc_core::sc_out<bool> intr0, intr1;
490 tlm_utils::simple_target_socket<dwmac, DEFAULT_TLM_BUSWIDTH> socket;
498 m_backend->register_receive(
this, eth_rx_sc, eth_can_rx_sc);
501 static void eth_rx_sc(
void* opaque,
Payload& frame) { ((
dwmac*)opaque)->payload_recv(frame); }
503 static int eth_can_rx_sc(
void* opaque) {
return 1; }
508 dwmac(sc_core::sc_module_name name);
511 uint32_t read_word(uint32_t address);
512 void write_word(uint32_t address, uint32_t data);
514 void b_transport(tlm::tlm_generic_payload& trans, sc_core::sc_time& delay)
516 unsigned char* ptr = trans.get_data_ptr();
517 uint64_t addr = trans.get_address();
519 trans.set_dmi_allowed(
false);
520 trans.set_response_status(tlm::TLM_OK_RESPONSE);
522 switch (trans.get_command()) {
523 case tlm::TLM_WRITE_COMMAND:
524 write_word(addr, *(uint32_t*)ptr);
526 case tlm::TLM_READ_COMMAND:
527 *(uint32_t*)ptr = read_word(addr);
534 virtual void payload_recv(Payload& frame);