Lines Matching +full:build +full:- +full:tci
25 * 2006-Jan-28 Mark Malakanov : TSAD and CSCR implementation (for Windows driver)
27 * 2006-Apr-28 Juergen Lock : EEPROM emulation changes for FreeBSD driver
30 * 2006-Jul-01 Igor Kovalenko : Implemented loopback mode for FreeBSD driver
37 * 2006-Jul-04 Igor Kovalenko : Implemented TCP segmentation offloading
40 * 2006-Jul-09 Igor Kovalenko : Fixed TCP header length calculation while processing
45 * 2010-Feb-04 Frediano Ziglio: Rewrote timer support using QEMU timer only
48 * 2011-Mar-22 Benjamin Poirier: Implemented VLAN offloading
55 #include "hw/qdev-properties.h"
76 ( ( input ) & ( size - 1 ) )
112 Timer = 0x48, /* A general-purpose counter. */
120 Config4 = 0x5A, /* absent on RTL-8139A */
135 Config5 = 0xD8, /* absent on RTL-8139A */
141 RxRingAddrLO = 0xE4, /* 64-bit start addr of Rx ring */
142 RxRingAddrHI = 0xE8, /* 64-bit start addr of Rx ring */
225 TxDMAShift = 8, /* DMA burst value (0-7) is shifted this many bits */
226 TxRetryShift = 4, /* TXRR value (0-15) is shifted this many bits */
228 TxVersionMask = 0x7C800000, /* mask out version bits 30-26, 23 */
325 CSCR_Testfun = 1<<15, /* 1 = Auto-neg speeds up internal timer, WO, def 0 */
373 #define EEPROM_9346_ADDR_MASK (EEPROM_9346_SIZE - 1)
501 /* Non-persistent data */
529 eeprom->address = command & EEPROM_9346_ADDR_MASK; in prom9346_decode_command()
530 eeprom->output = eeprom->contents[eeprom->address]; in prom9346_decode_command()
531 eeprom->eedo = 0; in prom9346_decode_command()
532 eeprom->tick = 0; in prom9346_decode_command()
533 eeprom->mode = Chip9346_data_read; in prom9346_decode_command()
535 eeprom->address, eeprom->output); in prom9346_decode_command()
541 eeprom->address = command & EEPROM_9346_ADDR_MASK; in prom9346_decode_command()
542 eeprom->input = 0; in prom9346_decode_command()
543 eeprom->tick = 0; in prom9346_decode_command()
544 eeprom->mode = Chip9346_none; /* Chip9346_data_write */ in prom9346_decode_command()
546 eeprom->address); in prom9346_decode_command()
550 eeprom->mode = Chip9346_none; in prom9346_decode_command()
569 int bit = eeprom->eedi?1:0; in prom9346_shift_clock()
571 ++ eeprom->tick; in prom9346_shift_clock()
573 DPRINTF("eeprom: tick %d eedi=%d eedo=%d\n", eeprom->tick, eeprom->eedi, in prom9346_shift_clock()
574 eeprom->eedo); in prom9346_shift_clock()
576 switch (eeprom->mode) in prom9346_shift_clock()
581 eeprom->mode = Chip9346_read_command; in prom9346_shift_clock()
582 eeprom->tick = 0; in prom9346_shift_clock()
583 eeprom->input = 0; in prom9346_shift_clock()
589 eeprom->input = (eeprom->input << 1) | (bit & 1); in prom9346_shift_clock()
590 if (eeprom->tick == 8) in prom9346_shift_clock()
592 prom9346_decode_command(eeprom, eeprom->input & 0xff); in prom9346_shift_clock()
597 eeprom->eedo = (eeprom->output & 0x8000)?1:0; in prom9346_shift_clock()
598 eeprom->output <<= 1; in prom9346_shift_clock()
599 if (eeprom->tick == 16) in prom9346_shift_clock()
604 // so we need to enter wait-for-command state here in prom9346_shift_clock()
605 eeprom->mode = Chip9346_enter_command_mode; in prom9346_shift_clock()
606 eeprom->input = 0; in prom9346_shift_clock()
607 eeprom->tick = 0; in prom9346_shift_clock()
612 ++eeprom->address; in prom9346_shift_clock()
613 eeprom->address &= EEPROM_9346_ADDR_MASK; in prom9346_shift_clock()
614 eeprom->output = eeprom->contents[eeprom->address]; in prom9346_shift_clock()
615 eeprom->tick = 0; in prom9346_shift_clock()
618 eeprom->address, eeprom->output); in prom9346_shift_clock()
624 eeprom->input = (eeprom->input << 1) | (bit & 1); in prom9346_shift_clock()
625 if (eeprom->tick == 16) in prom9346_shift_clock()
628 eeprom->address, eeprom->input); in prom9346_shift_clock()
630 eeprom->contents[eeprom->address] = eeprom->input; in prom9346_shift_clock()
631 eeprom->mode = Chip9346_none; /* waiting for next command after CS cycle */ in prom9346_shift_clock()
632 eeprom->tick = 0; in prom9346_shift_clock()
633 eeprom->input = 0; in prom9346_shift_clock()
638 eeprom->input = (eeprom->input << 1) | (bit & 1); in prom9346_shift_clock()
639 if (eeprom->tick == 16) in prom9346_shift_clock()
644 eeprom->contents[i] = eeprom->input; in prom9346_shift_clock()
646 DPRINTF("eeprom filled with data=0x%04x\n", eeprom->input); in prom9346_shift_clock()
648 eeprom->mode = Chip9346_enter_command_mode; in prom9346_shift_clock()
649 eeprom->tick = 0; in prom9346_shift_clock()
650 eeprom->input = 0; in prom9346_shift_clock()
661 EEprom9346 *eeprom = &s->eeprom; in prom9346_get_wire()
662 if (!eeprom->eecs) in prom9346_get_wire()
665 return eeprom->eedo; in prom9346_get_wire()
671 EEprom9346 *eeprom = &s->eeprom; in prom9346_set_wire()
672 uint8_t old_eecs = eeprom->eecs; in prom9346_set_wire()
673 uint8_t old_eesk = eeprom->eesk; in prom9346_set_wire()
675 eeprom->eecs = eecs; in prom9346_set_wire()
676 eeprom->eesk = eesk; in prom9346_set_wire()
677 eeprom->eedi = eedi; in prom9346_set_wire()
679 DPRINTF("eeprom: +++ wires CS=%d SK=%d DI=%d DO=%d\n", eeprom->eecs, in prom9346_set_wire()
680 eeprom->eesk, eeprom->eedi, eeprom->eedo); in prom9346_set_wire()
685 eeprom->tick = 0; in prom9346_set_wire()
686 eeprom->input = 0; in prom9346_set_wire()
687 eeprom->output = 0; in prom9346_set_wire()
688 eeprom->mode = Chip9346_enter_command_mode; in prom9346_set_wire()
710 isr = (s->IntrStatus & s->IntrMask) & 0xffff; in rtl8139_update_irq()
712 DPRINTF("Set IRQ to %d (%04x %04x)\n", isr ? 1 : 0, s->IntrStatus, in rtl8139_update_irq()
713 s->IntrMask); in rtl8139_update_irq()
721 return (s->RxConfig & (1 << 7)); in rtl8139_RxWrap()
726 return s->bChipCmdState & CmdRxEnb; in rtl8139_receiver_enabled()
731 return s->bChipCmdState & CmdTxEnb; in rtl8139_transmitter_enabled()
736 return s->CpCmd & CPlusRxEnb; in rtl8139_cp_receiver_enabled()
741 return s->CpCmd & CPlusTxEnb; in rtl8139_cp_transmitter_enabled()
748 if (s->RxBufAddr + size > s->RxBufferSize) in rtl8139_write_buffer()
750 int wrapped = MOD2(s->RxBufAddr + size, s->RxBufferSize); in rtl8139_write_buffer()
753 if (wrapped && !(s->RxBufferSize < 65536 && rtl8139_RxWrap(s))) in rtl8139_write_buffer()
755 DPRINTF(">>> rx packet wrapped in buffer at %d\n", size - wrapped); in rtl8139_write_buffer()
759 pci_dma_write(d, s->RxBuf + s->RxBufAddr, in rtl8139_write_buffer()
760 buf, size-wrapped); in rtl8139_write_buffer()
764 s->RxBufAddr = 0; in rtl8139_write_buffer()
766 pci_dma_write(d, s->RxBuf + s->RxBufAddr, in rtl8139_write_buffer()
767 buf + (size-wrapped), wrapped); in rtl8139_write_buffer()
769 s->RxBufAddr = wrapped; in rtl8139_write_buffer()
775 /* non-wrapping path or overwrapping enabled */ in rtl8139_write_buffer()
776 pci_dma_write(d, s->RxBuf + s->RxBufAddr, buf, size); in rtl8139_write_buffer()
778 s->RxBufAddr += size; in rtl8139_write_buffer()
791 return !(s->RxRingAddrLO == 0 && s->RxRingAddrHI == 0); in rtl8139_cp_rx_valid()
800 if (!s->clock_enabled) { in rtl8139_can_receive()
813 avail = MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, in rtl8139_can_receive()
814 s->RxBufferSize); in rtl8139_can_receive()
815 return avail == 0 || avail >= 1514 || (s->IntrMask & RxOverflow); in rtl8139_can_receive()
834 if (!s->clock_enabled) in rtl8139_do_receive()
837 return -1; in rtl8139_do_receive()
845 return -1; in rtl8139_do_receive()
849 if (s->RxConfig & AcceptAllPhys) { in rtl8139_do_receive()
856 if (!(s->RxConfig & AcceptBroadcast)) in rtl8139_do_receive()
861 ++s->tally_counters.RxERR; in rtl8139_do_receive()
871 ++s->tally_counters.RxOkBrd; in rtl8139_do_receive()
875 if (!(s->RxConfig & AcceptMulticast)) in rtl8139_do_receive()
880 ++s->tally_counters.RxERR; in rtl8139_do_receive()
887 if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) in rtl8139_do_receive()
892 ++s->tally_counters.RxERR; in rtl8139_do_receive()
902 ++s->tally_counters.RxOkMul; in rtl8139_do_receive()
904 } else if (s->phys[0] == buf[0] && in rtl8139_do_receive()
905 s->phys[1] == buf[1] && in rtl8139_do_receive()
906 s->phys[2] == buf[2] && in rtl8139_do_receive()
907 s->phys[3] == buf[3] && in rtl8139_do_receive()
908 s->phys[4] == buf[4] && in rtl8139_do_receive()
909 s->phys[5] == buf[5]) { in rtl8139_do_receive()
911 if (!(s->RxConfig & AcceptMyPhys)) in rtl8139_do_receive()
916 ++s->tally_counters.RxERR; in rtl8139_do_receive()
926 ++s->tally_counters.RxOkPhy; in rtl8139_do_receive()
933 ++s->tally_counters.RxERR; in rtl8139_do_receive()
954 #define CP_RX_BUFFER_SIZE_MASK ((1<<13) - 1) in rtl8139_do_receive()
958 #define CP_RX_VLAN_TAG_MASK ((1<<16) - 1) in rtl8139_do_receive()
962 int descriptor = s->currCPlusRxDesc; in rtl8139_do_receive()
965 cplus_rx_ring_desc = rtl8139_addr64(s->RxRingAddrLO, s->RxRingAddrHI); in rtl8139_do_receive()
969 "%08x %08x = "DMA_ADDR_FMT"\n", descriptor, s->RxRingAddrHI, in rtl8139_do_receive()
970 s->RxRingAddrLO, cplus_rx_ring_desc); in rtl8139_do_receive()
991 s->IntrStatus |= RxOverflow; in rtl8139_do_receive()
992 ++s->RxMissed; in rtl8139_do_receive()
995 ++s->tally_counters.RxERR; in rtl8139_do_receive()
996 ++s->tally_counters.MissPkt; in rtl8139_do_receive()
1005 if (s->CpCmd & CPlusRxVLAN && in rtl8139_do_receive()
1008 size -= VLAN_HLEN; in rtl8139_do_receive()
1018 DPRINTF("C+ Rx mode : extracted vlan tag with tci: ""%u\n", in rtl8139_do_receive()
1032 s->IntrStatus |= RxOverflow; in rtl8139_do_receive()
1033 ++s->RxMissed; in rtl8139_do_receive()
1036 ++s->tally_counters.RxERR; in rtl8139_do_receive()
1037 ++s->tally_counters.MissPkt; in rtl8139_do_receive()
1050 size - 2 * ETH_ALEN); in rtl8139_do_receive()
1055 if (s->CpCmd & CPlusRxChkSum) in rtl8139_do_receive()
1070 /* physical-matching packet flag */ in rtl8139_do_receive()
1113 ++s->tally_counters.RxOk; in rtl8139_do_receive()
1118 s->currCPlusRxDesc = 0; in rtl8139_do_receive()
1122 ++s->currCPlusRxDesc; in rtl8139_do_receive()
1125 DPRINTF("done C+ Rx mode ----------------\n"); in rtl8139_do_receive()
1133 int avail = MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, s->RxBufferSize); in rtl8139_do_receive()
1143 s->RxBufferSize, s->RxBufAddr, s->RxBufPtr, avail, size + 8); in rtl8139_do_receive()
1145 s->IntrStatus |= RxOverflow; in rtl8139_do_receive()
1146 ++s->RxMissed; in rtl8139_do_receive()
1167 s->RxBufAddr = MOD2(RX_ALIGN(s->RxBufAddr), s->RxBufferSize); in rtl8139_do_receive()
1172 s->RxBufferSize, s->RxBufAddr, s->RxBufPtr); in rtl8139_do_receive()
1175 s->IntrStatus |= RxOK; in rtl8139_do_receive()
1192 s->RxBufferSize = bufferSize; in rtl8139_reset_rxring()
1193 s->RxBufPtr = 0; in rtl8139_reset_rxring()
1194 s->RxBufAddr = 0; in rtl8139_reset_rxring()
1199 s->BasicModeStatus = 0x7809; in rtl8139_reset_phy()
1200 s->BasicModeStatus |= 0x0020; /* autonegotiation completed */ in rtl8139_reset_phy()
1202 s->BasicModeStatus |= qemu_get_queue(s->nic)->link_down ? 0 : 0x04; in rtl8139_reset_phy()
1204 s->NWayAdvert = 0x05e1; /* all modes, full duplex */ in rtl8139_reset_phy()
1205 s->NWayLPAR = 0x05e1; /* all modes, full duplex */ in rtl8139_reset_phy()
1206 s->NWayExpansion = 0x0001; /* autonegotiation supported */ in rtl8139_reset_phy()
1208 s->CSCR = CSCR_F_LINK_100 | CSCR_HEART_BIT | CSCR_LD; in rtl8139_reset_phy()
1217 memcpy(s->phys, s->conf.macaddr.a, 6); in rtl8139_reset()
1218 qemu_format_nic_info_str(qemu_get_queue(s->nic), s->phys); in rtl8139_reset()
1221 s->IntrStatus = 0; in rtl8139_reset()
1222 s->IntrMask = 0; in rtl8139_reset()
1229 s->TxStatus[i] = TxHostOwns; in rtl8139_reset()
1232 s->currTxDesc = 0; in rtl8139_reset()
1233 s->currCPlusRxDesc = 0; in rtl8139_reset()
1234 s->currCPlusTxDesc = 0; in rtl8139_reset()
1236 s->RxRingAddrLO = 0; in rtl8139_reset()
1237 s->RxRingAddrHI = 0; in rtl8139_reset()
1239 s->RxBuf = 0; in rtl8139_reset()
1244 s->TxConfig = 0; in rtl8139_reset()
1247 // s->TxConfig |= HW_REVID(1, 0, 0, 0, 0, 0, 0); // RTL-8139 HasHltClk in rtl8139_reset()
1248 s->clock_enabled = 0; in rtl8139_reset()
1250 s->TxConfig |= HW_REVID(1, 1, 1, 0, 1, 1, 0); // RTL-8139C+ HasLWake in rtl8139_reset()
1251 s->clock_enabled = 1; in rtl8139_reset()
1254 s->bChipCmdState = CmdReset; /* RxBufEmpty bit is calculated on read from ChipCmd */; in rtl8139_reset()
1257 s->Config0 = 0x0; /* No boot ROM */ in rtl8139_reset()
1258 s->Config1 = 0xC; /* IO mapped and MEM mapped registers available */ in rtl8139_reset()
1259 s->Config3 = 0x1; /* fast back-to-back compatible */ in rtl8139_reset()
1260 s->Config5 = 0x0; in rtl8139_reset()
1262 s->CpCmd = 0x0; /* reset C+ mode */ in rtl8139_reset()
1263 s->cplus_enabled = 0; in rtl8139_reset()
1265 // s->BasicModeCtrl = 0x3100; // 100Mbps, full duplex, autonegotiation in rtl8139_reset()
1266 // s->BasicModeCtrl = 0x2100; // 100Mbps, full duplex in rtl8139_reset()
1267 s->BasicModeCtrl = 0x1000; // autonegotiation in rtl8139_reset()
1272 s->TCTR = 0; in rtl8139_reset()
1273 s->TimerInt = 0; in rtl8139_reset()
1274 s->TCTR_base = 0; in rtl8139_reset()
1278 RTL8139TallyCounters_clear(&s->tally_counters); in rtl8139_reset()
1283 counters->TxOk = 0; in RTL8139TallyCounters_clear()
1284 counters->RxOk = 0; in RTL8139TallyCounters_clear()
1285 counters->TxERR = 0; in RTL8139TallyCounters_clear()
1286 counters->RxERR = 0; in RTL8139TallyCounters_clear()
1287 counters->MissPkt = 0; in RTL8139TallyCounters_clear()
1288 counters->FAE = 0; in RTL8139TallyCounters_clear()
1289 counters->Tx1Col = 0; in RTL8139TallyCounters_clear()
1290 counters->TxMCol = 0; in RTL8139TallyCounters_clear()
1291 counters->RxOkPhy = 0; in RTL8139TallyCounters_clear()
1292 counters->RxOkBrd = 0; in RTL8139TallyCounters_clear()
1293 counters->RxOkMul = 0; in RTL8139TallyCounters_clear()
1294 counters->TxAbt = 0; in RTL8139TallyCounters_clear()
1295 counters->TxUndrn = 0; in RTL8139TallyCounters_clear()
1301 RTL8139TallyCounters *tally_counters = &s->tally_counters; in RTL8139TallyCounters_dma_write()
1306 val64 = cpu_to_le64(tally_counters->TxOk); in RTL8139TallyCounters_dma_write()
1309 val64 = cpu_to_le64(tally_counters->RxOk); in RTL8139TallyCounters_dma_write()
1312 val64 = cpu_to_le64(tally_counters->TxERR); in RTL8139TallyCounters_dma_write()
1315 val32 = cpu_to_le32(tally_counters->RxERR); in RTL8139TallyCounters_dma_write()
1318 val16 = cpu_to_le16(tally_counters->MissPkt); in RTL8139TallyCounters_dma_write()
1321 val16 = cpu_to_le16(tally_counters->FAE); in RTL8139TallyCounters_dma_write()
1324 val32 = cpu_to_le32(tally_counters->Tx1Col); in RTL8139TallyCounters_dma_write()
1327 val32 = cpu_to_le32(tally_counters->TxMCol); in RTL8139TallyCounters_dma_write()
1330 val64 = cpu_to_le64(tally_counters->RxOkPhy); in RTL8139TallyCounters_dma_write()
1333 val64 = cpu_to_le64(tally_counters->RxOkBrd); in RTL8139TallyCounters_dma_write()
1336 val32 = cpu_to_le32(tally_counters->RxOkMul); in RTL8139TallyCounters_dma_write()
1339 val16 = cpu_to_le16(tally_counters->TxAbt); in RTL8139TallyCounters_dma_write()
1342 val16 = cpu_to_le16(tally_counters->TxUndrn); in RTL8139TallyCounters_dma_write()
1363 s->currCPlusRxDesc = 0; in rtl8139_ChipCmd_write()
1369 s->currCPlusTxDesc = 0; in rtl8139_ChipCmd_write()
1373 val = SET_MASKED(val, 0xe3, s->bChipCmdState); in rtl8139_ChipCmd_write()
1378 s->bChipCmdState = val; in rtl8139_ChipCmd_write()
1383 int unread = MOD2(s->RxBufferSize + s->RxBufAddr - s->RxBufPtr, s->RxBufferSize); in rtl8139_RxBufferEmpty()
1398 uint32_t ret = s->bChipCmdState; in rtl8139_ChipCmd_read()
1414 s->cplus_enabled = 1; in rtl8139_CpCmd_write()
1417 val = SET_MASKED(val, 0xff84, s->CpCmd); in rtl8139_CpCmd_write()
1419 s->CpCmd = val; in rtl8139_CpCmd_write()
1424 uint32_t ret = s->CpCmd; in rtl8139_CpCmd_read()
1447 if ((s->Cfg9346 & Chip9346_op_mask) == Cfg9346_ConfigWrite) in rtl8139_config_writable()
1452 DPRINTF("Configuration registers are write-protected\n"); in rtl8139_config_writable()
1468 /* Speed setting and autonegotiation enable bits are read-only */ in rtl8139_BasicModeCtrl_write()
1470 /* Duplex mode setting is read-only */ in rtl8139_BasicModeCtrl_write()
1479 val = SET_MASKED(val, mask, s->BasicModeCtrl); in rtl8139_BasicModeCtrl_write()
1481 s->BasicModeCtrl = val; in rtl8139_BasicModeCtrl_write()
1486 uint32_t ret = s->BasicModeCtrl; in rtl8139_BasicModeCtrl_read()
1500 val = SET_MASKED(val, 0xff3f, s->BasicModeStatus); in rtl8139_BasicModeStatus_write()
1502 s->BasicModeStatus = val; in rtl8139_BasicModeStatus_write()
1507 uint32_t ret = s->BasicModeStatus; in rtl8139_BasicModeStatus_read()
1523 val = SET_MASKED(val, 0x31, s->Cfg9346); in rtl8139_Cfg9346_write()
1540 s->Cfg9346 = val; in rtl8139_Cfg9346_write()
1545 uint32_t ret = s->Cfg9346; in rtl8139_Cfg9346_read()
1579 val = SET_MASKED(val, 0xf8, s->Config0); in rtl8139_Config0_write()
1581 s->Config0 = val; in rtl8139_Config0_write()
1586 uint32_t ret = s->Config0; in rtl8139_Config0_read()
1604 val = SET_MASKED(val, 0xC, s->Config1); in rtl8139_Config1_write()
1606 s->Config1 = val; in rtl8139_Config1_write()
1611 uint32_t ret = s->Config1; in rtl8139_Config1_read()
1629 val = SET_MASKED(val, 0x8F, s->Config3); in rtl8139_Config3_write()
1631 s->Config3 = val; in rtl8139_Config3_write()
1636 uint32_t ret = s->Config3; in rtl8139_Config3_read()
1654 val = SET_MASKED(val, 0x0a, s->Config4); in rtl8139_Config4_write()
1656 s->Config4 = val; in rtl8139_Config4_write()
1661 uint32_t ret = s->Config4; in rtl8139_Config4_read()
1675 val = SET_MASKED(val, 0x80, s->Config5); in rtl8139_Config5_write()
1677 s->Config5 = val; in rtl8139_Config5_write()
1682 uint32_t ret = s->Config5; in rtl8139_Config5_read()
1699 val = SET_MASKED(val, TxVersionMask | 0x8070f80f, s->TxConfig); in rtl8139_TxConfig_write()
1701 s->TxConfig = val; in rtl8139_TxConfig_write()
1708 uint32_t tc = s->TxConfig; in rtl8139_TxConfig_writeb()
1716 uint32_t ret = s->TxConfig; in rtl8139_TxConfig_read()
1728 val = SET_MASKED(val, 0xf0fc0040, s->RxConfig); in rtl8139_RxConfig_write()
1730 s->RxConfig = val; in rtl8139_RxConfig_write()
1733 rtl8139_reset_rxring(s, 8192 << ((s->RxConfig >> 11) & 0x3)); in rtl8139_RxConfig_write()
1735 DPRINTF("RxConfig write reset buffer size to %d\n", s->RxBufferSize); in rtl8139_RxConfig_write()
1740 uint32_t ret = s->RxConfig; in rtl8139_RxConfig_read()
1764 .iov_len = size - ETH_ALEN * 2 }, in rtl8139_transfer_frame()
1771 if (TxLoopBack == (s->TxConfig & TxLoopBack)) in rtl8139_transfer_frame()
1784 qemu_receive_packet(qemu_get_queue(s->nic), buf, size); in rtl8139_transfer_frame()
1793 qemu_sendv_packet(qemu_get_queue(s->nic), iov, 3); in rtl8139_transfer_frame()
1795 qemu_send_packet(qemu_get_queue(s->nic), buf, size); in rtl8139_transfer_frame()
1809 if (s->TxStatus[descriptor] & TxHostOwns) in rtl8139_transmit_one()
1812 "(%08x)\n", descriptor, s->TxStatus[descriptor]); in rtl8139_transmit_one()
1819 int txsize = s->TxStatus[descriptor] & 0x1fff; in rtl8139_transmit_one()
1823 txsize, s->TxAddr[descriptor]); in rtl8139_transmit_one()
1825 pci_dma_read(d, s->TxAddr[descriptor], txbuffer, txsize); in rtl8139_transmit_one()
1828 s->TxStatus[descriptor] |= TxHostOwns; in rtl8139_transmit_one()
1829 s->TxStatus[descriptor] |= TxStatOK; in rtl8139_transmit_one()
1837 s->IntrStatus |= TxOK; in rtl8139_transmit_one()
1843 #define TCP_HEADER_CLEAR_FLAGS(tcp, off) ((tcp)->th_offset_flags &= cpu_to_be16(~TCP_FLAGS_ONLY(off…
1850 for (; len > 1; data+=2, len-=2) in ones_complement_sum()
1888 int descriptor = s->currCPlusTxDesc; in rtl8139_cplus_transmit_one()
1890 dma_addr_t cplus_tx_ring_desc = rtl8139_addr64(s->TxAddr[0], s->TxAddr[1]); in rtl8139_cplus_transmit_one()
1896 "%08x %08x = 0x"DMA_ADDR_FMT"\n", descriptor, s->TxAddr[1], in rtl8139_cplus_transmit_one()
1897 s->TxAddr[0], cplus_tx_ring_desc); in rtl8139_cplus_transmit_one()
1925 #define CP_TC_LGSEN_MSS_MASK ((1 << 11) - 1) in rtl8139_cplus_transmit_one()
1936 #define CP_TX_BUFFER_SIZE_MASK (CP_TX_BUFFER_SIZE - 1) in rtl8139_cplus_transmit_one()
1940 #define CP_TX_VLAN_TAG_MASK ((1<<16) - 1) in rtl8139_cplus_transmit_one()
1949 /* out-of-window collision flag */ in rtl8139_cplus_transmit_one()
1970 s->cplus_txbuffer_offset = 0; in rtl8139_cplus_transmit_one()
1977 if (!s->cplus_txbuffer) in rtl8139_cplus_transmit_one()
1979 s->cplus_txbuffer_len = CP_TX_BUFFER_SIZE; in rtl8139_cplus_transmit_one()
1980 s->cplus_txbuffer = g_malloc(s->cplus_txbuffer_len); in rtl8139_cplus_transmit_one()
1981 s->cplus_txbuffer_offset = 0; in rtl8139_cplus_transmit_one()
1984 s->cplus_txbuffer_len); in rtl8139_cplus_transmit_one()
1987 if (s->cplus_txbuffer_offset + txsize >= s->cplus_txbuffer_len) in rtl8139_cplus_transmit_one()
1990 txsize = s->cplus_txbuffer_len - s->cplus_txbuffer_offset; in rtl8139_cplus_transmit_one()
1999 s->cplus_txbuffer_offset); in rtl8139_cplus_transmit_one()
2002 s->cplus_txbuffer + s->cplus_txbuffer_offset, txsize); in rtl8139_cplus_transmit_one()
2003 s->cplus_txbuffer_offset += txsize; in rtl8139_cplus_transmit_one()
2008 s->currCPlusTxDesc = 0; in rtl8139_cplus_transmit_one()
2012 ++s->currCPlusTxDesc; in rtl8139_cplus_transmit_one()
2013 if (s->currCPlusTxDesc >= 64) in rtl8139_cplus_transmit_one()
2014 s->currCPlusTxDesc = 0; in rtl8139_cplus_transmit_one()
2017 /* Build the Tx Status Descriptor */ in rtl8139_cplus_transmit_one()
2045 uint8_t *saved_buffer = s->cplus_txbuffer; in rtl8139_cplus_transmit_one()
2046 int saved_size = s->cplus_txbuffer_offset; in rtl8139_cplus_transmit_one()
2047 int saved_buffer_len = s->cplus_txbuffer_len; in rtl8139_cplus_transmit_one()
2053 DPRINTF("+++ C+ Tx mode : inserting vlan tag with ""tci: %u\n", in rtl8139_cplus_transmit_one()
2065 s->cplus_txbuffer = NULL; in rtl8139_cplus_transmit_one()
2066 s->cplus_txbuffer_offset = 0; in rtl8139_cplus_transmit_one()
2067 s->cplus_txbuffer_len = 0; in rtl8139_cplus_transmit_one()
2095 /* Note on memory alignment: eth_payload_data is 16-bit aligned in rtl8139_cplus_transmit_one()
2097 * even. 32-bit accesses must use ldl/stl wrappers to avoid in rtl8139_cplus_transmit_one()
2101 eth_payload_len = saved_size - ETH_HLEN; in rtl8139_cplus_transmit_one()
2117 ip_protocol = ip->ip_p; in rtl8139_cplus_transmit_one()
2119 ip_data_len = be16_to_cpu(ip->ip_len); in rtl8139_cplus_transmit_one()
2123 ip_data_len -= hlen; in rtl8139_cplus_transmit_one()
2129 ip->ip_sum = 0; in rtl8139_cplus_transmit_one()
2130 ip->ip_sum = ip_checksum(ip, hlen); in rtl8139_cplus_transmit_one()
2132 hlen, ip->ip_sum); in rtl8139_cplus_transmit_one()
2150 ip_data_len, saved_size - ETH_HLEN, large_send_mss); in rtl8139_cplus_transmit_one()
2161 uint8_t *data_to_checksum = eth_payload_data + hlen - 12; in rtl8139_cplus_transmit_one()
2162 // size_t data_to_checksum_len = eth_payload_len - hlen + 12; in rtl8139_cplus_transmit_one()
2174 int tcp_data_len = ip_data_len - tcp_hlen; in rtl8139_cplus_transmit_one()
2192 chunk_size = tcp_data_len - tcp_send_offset; in rtl8139_cplus_transmit_one()
2196 ldl_be_p(&p_tcp_hdr->th_seq)); in rtl8139_cplus_transmit_one()
2219 p_tcpip_hdr->zeros = 0; in rtl8139_cplus_transmit_one()
2220 p_tcpip_hdr->ip_proto = IP_PROTO_TCP; in rtl8139_cplus_transmit_one()
2221 p_tcpip_hdr->ip_payload = cpu_to_be16(tcp_hlen + chunk_size); in rtl8139_cplus_transmit_one()
2223 p_tcp_hdr->th_sum = 0; in rtl8139_cplus_transmit_one()
2229 p_tcp_hdr->th_sum = tcp_checksum; in rtl8139_cplus_transmit_one()
2235 ip->ip_len = cpu_to_be16(hlen + tcp_hlen + chunk_size); in rtl8139_cplus_transmit_one()
2238 … ip->ip_id = cpu_to_be16(tcp_send_offset/large_send_mss + be16_to_cpu(ip->ip_id)); in rtl8139_cplus_transmit_one()
2240 ip->ip_sum = 0; in rtl8139_cplus_transmit_one()
2241 ip->ip_sum = ip_checksum(eth_payload_data, hlen); in rtl8139_cplus_transmit_one()
2243 "checksum=%04x\n", hlen, ip->ip_sum); in rtl8139_cplus_transmit_one()
2252 stl_be_p(&p_tcp_hdr->th_seq, in rtl8139_cplus_transmit_one()
2253 chunk_size + ldl_be_p(&p_tcp_hdr->th_seq)); in rtl8139_cplus_transmit_one()
2267 uint8_t *data_to_checksum = eth_payload_data + hlen - 12; in rtl8139_cplus_transmit_one()
2268 // size_t data_to_checksum_len = eth_payload_len - hlen + 12; in rtl8139_cplus_transmit_one()
2280 p_tcpip_hdr->zeros = 0; in rtl8139_cplus_transmit_one()
2281 p_tcpip_hdr->ip_proto = IP_PROTO_TCP; in rtl8139_cplus_transmit_one()
2282 p_tcpip_hdr->ip_payload = cpu_to_be16(ip_data_len); in rtl8139_cplus_transmit_one()
2286 p_tcp_hdr->th_sum = 0; in rtl8139_cplus_transmit_one()
2292 p_tcp_hdr->th_sum = tcp_checksum; in rtl8139_cplus_transmit_one()
2300 p_udpip_hdr->zeros = 0; in rtl8139_cplus_transmit_one()
2301 p_udpip_hdr->ip_proto = IP_PROTO_UDP; in rtl8139_cplus_transmit_one()
2302 p_udpip_hdr->ip_payload = cpu_to_be16(ip_data_len); in rtl8139_cplus_transmit_one()
2306 p_udp_hdr->uh_sum = 0; in rtl8139_cplus_transmit_one()
2312 p_udp_hdr->uh_sum = udp_checksum; in rtl8139_cplus_transmit_one()
2322 ++s->tally_counters.TxOk; in rtl8139_cplus_transmit_one()
2330 if (!s->cplus_txbuffer) in rtl8139_cplus_transmit_one()
2332 s->cplus_txbuffer = saved_buffer; in rtl8139_cplus_transmit_one()
2333 s->cplus_txbuffer_len = saved_buffer_len; in rtl8139_cplus_transmit_one()
2334 s->cplus_txbuffer_offset = 0; in rtl8139_cplus_transmit_one()
2362 s->currCPlusTxDesc); in rtl8139_cplus_transmit()
2367 s->IntrStatus |= TxOK; in rtl8139_cplus_transmit()
2374 int descriptor = s->currTxDesc, txcount = 0; in rtl8139_transmit()
2379 ++s->currTxDesc; in rtl8139_transmit()
2380 s->currTxDesc %= 4; in rtl8139_transmit()
2388 s->currTxDesc); in rtl8139_transmit()
2399 if (s->cplus_enabled) in rtl8139_TxStatus_write()
2405 s->TxStatus[descriptor] = val; in rtl8139_TxStatus_write()
2409 hwaddr tc_addr = rtl8139_addr64(s->TxStatus[0] & ~0x3f, s->TxStatus[1]); in rtl8139_TxStatus_write()
2415 s->TxStatus[0] &= ~0x8; in rtl8139_TxStatus_write()
2426 val = SET_MASKED(val, 0x00c00000, s->TxStatus[descriptor]); in rtl8139_TxStatus_write()
2428 s->TxStatus[descriptor] = val; in rtl8139_TxStatus_write()
2438 uint32_t reg = (addr - base) / 4; in rtl8139_TxStatus_TxAddr_read()
2442 if (addr & (size - 1)) { in rtl8139_TxStatus_TxAddr_read()
2452 ret = (regs[reg] >> offset * 8) & (((uint64_t)1 << (size * 8)) - 1); in rtl8139_TxStatus_TxAddr_read()
2470 ret = ((s->TxStatus[3] & TxStatOK )?TSAD_TOK3:0) in rtl8139_TSAD_read()
2471 |((s->TxStatus[2] & TxStatOK )?TSAD_TOK2:0) in rtl8139_TSAD_read()
2472 |((s->TxStatus[1] & TxStatOK )?TSAD_TOK1:0) in rtl8139_TSAD_read()
2473 |((s->TxStatus[0] & TxStatOK )?TSAD_TOK0:0) in rtl8139_TSAD_read()
2475 |((s->TxStatus[3] & TxUnderrun)?TSAD_TUN3:0) in rtl8139_TSAD_read()
2476 |((s->TxStatus[2] & TxUnderrun)?TSAD_TUN2:0) in rtl8139_TSAD_read()
2477 |((s->TxStatus[1] & TxUnderrun)?TSAD_TUN1:0) in rtl8139_TSAD_read()
2478 |((s->TxStatus[0] & TxUnderrun)?TSAD_TUN0:0) in rtl8139_TSAD_read()
2480 |((s->TxStatus[3] & TxAborted )?TSAD_TABT3:0) in rtl8139_TSAD_read()
2481 |((s->TxStatus[2] & TxAborted )?TSAD_TABT2:0) in rtl8139_TSAD_read()
2482 |((s->TxStatus[1] & TxAborted )?TSAD_TABT1:0) in rtl8139_TSAD_read()
2483 |((s->TxStatus[0] & TxAborted )?TSAD_TABT0:0) in rtl8139_TSAD_read()
2485 |((s->TxStatus[3] & TxHostOwns )?TSAD_OWN3:0) in rtl8139_TSAD_read()
2486 |((s->TxStatus[2] & TxHostOwns )?TSAD_OWN2:0) in rtl8139_TSAD_read()
2487 |((s->TxStatus[1] & TxHostOwns )?TSAD_OWN1:0) in rtl8139_TSAD_read()
2488 |((s->TxStatus[0] & TxHostOwns )?TSAD_OWN0:0) ; in rtl8139_TSAD_read()
2498 uint16_t ret = s->CSCR; in rtl8139_CSCR_read()
2509 s->TxAddr[txAddrOffset/4] = val; in rtl8139_TxAddr_write()
2514 uint32_t ret = s->TxAddr[txAddrOffset/4]; in rtl8139_TxAddr_read()
2526 s->RxBufPtr = MOD2(val + 0x10, s->RxBufferSize); in rtl8139_RxBufPtr_write()
2529 qemu_flush_queued_packets(qemu_get_queue(s->nic)); in rtl8139_RxBufPtr_write()
2532 s->RxBufferSize, s->RxBufAddr, s->RxBufPtr); in rtl8139_RxBufPtr_write()
2538 uint32_t ret = s->RxBufPtr - 0x10; in rtl8139_RxBufPtr_read()
2548 uint32_t ret = s->RxBufAddr; in rtl8139_RxBufAddr_read()
2559 s->RxBuf = val; in rtl8139_RxBuf_write()
2566 uint32_t ret = s->RxBuf; in rtl8139_RxBuf_read()
2578 val = SET_MASKED(val, 0x1e00, s->IntrMask); in rtl8139_IntrMask_write()
2580 s->IntrMask = val; in rtl8139_IntrMask_write()
2588 uint32_t ret = s->IntrMask; in rtl8139_IntrMask_read()
2606 uint16_t newStatus = s->IntrStatus & ~val; in rtl8139_IntrStatus_write()
2609 newStatus = SET_MASKED(newStatus, 0x1e00, s->IntrStatus); in rtl8139_IntrStatus_write()
2612 s->IntrStatus = 0; in rtl8139_IntrStatus_write()
2615 s->IntrStatus = newStatus; in rtl8139_IntrStatus_write()
2624 uint32_t ret = s->IntrStatus; in rtl8139_IntrStatus_read()
2631 s->IntrStatus = 0; in rtl8139_IntrStatus_read()
2645 val = SET_MASKED(val, 0xf000, s->MultiIntr); in rtl8139_MultiIntr_write()
2647 s->MultiIntr = val; in rtl8139_MultiIntr_write()
2652 uint32_t ret = s->MultiIntr; in rtl8139_MultiIntr_read()
2666 s->phys[addr - MAC0] = val; in rtl8139_io_writeb()
2669 s->phys[addr - MAC0] = val; in rtl8139_io_writeb()
2670 qemu_format_nic_info_str(qemu_get_queue(s->nic), s->phys); in rtl8139_io_writeb()
2676 s->mult[addr - MAR0] = val; in rtl8139_io_writeb()
2684 case TxConfig: /* windows driver sometimes writes using byte-lenth call */ in rtl8139_io_writeb()
2712 s->clock_enabled = 1; in rtl8139_io_writeb()
2716 s->clock_enabled = 0; in rtl8139_io_writeb()
2722 s->TxThresh = val; in rtl8139_io_writeb()
2782 s->NWayAdvert = val; in rtl8139_io_writew()
2789 s->NWayExpansion = val; in rtl8139_io_writew()
2823 while (s->TCTR_base + ns_per_period <= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)) { in rtl8139_set_next_tctr_time()
2824 s->TCTR_base += ns_per_period; in rtl8139_set_next_tctr_time()
2827 if (!s->TimerInt) { in rtl8139_set_next_tctr_time()
2828 timer_del(s->timer); in rtl8139_set_next_tctr_time()
2830 uint64_t delta = (uint64_t)s->TimerInt * PCI_PERIOD; in rtl8139_set_next_tctr_time()
2831 if (s->TCTR_base + delta <= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)) { in rtl8139_set_next_tctr_time()
2834 timer_mod(s->timer, s->TCTR_base + delta); in rtl8139_set_next_tctr_time()
2846 s->RxMissed = 0; in rtl8139_io_writel()
2857 case TxStatus0 ... TxStatus0+4*4-1: in rtl8139_io_writel()
2858 rtl8139_TxStatus_write(s, addr-TxStatus0, val); in rtl8139_io_writel()
2861 case TxAddr0 ... TxAddr0+4*4-1: in rtl8139_io_writel()
2862 rtl8139_TxAddr_write(s, addr-TxAddr0, val); in rtl8139_io_writel()
2871 s->RxRingAddrLO = val; in rtl8139_io_writel()
2876 s->RxRingAddrHI = val; in rtl8139_io_writel()
2881 s->TCTR_base = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); in rtl8139_io_writel()
2887 if (s->TimerInt != val) { in rtl8139_io_writel()
2888 s->TimerInt = val; in rtl8139_io_writel()
2912 ret = s->phys[addr - MAC0]; in rtl8139_io_readb()
2918 ret = s->mult[addr - MAR0]; in rtl8139_io_readb()
2920 case TxStatus0 ... TxStatus0+4*4-1: in rtl8139_io_readb()
2921 ret = rtl8139_TxStatus_TxAddr_read(s, s->TxStatus, TxStatus0, in rtl8139_io_readb()
2948 ret = 0xd0 | (~s->BasicModeStatus & 0x04); in rtl8139_io_readb()
2953 ret = s->clock_enabled; in rtl8139_io_readb()
2963 ret = s->TxThresh; in rtl8139_io_readb()
2968 ret = s->TxConfig >> 24; in rtl8139_io_readb()
2988 case TxAddr0 ... TxAddr0+4*4-1: in rtl8139_io_readw()
2989 ret = rtl8139_TxStatus_TxAddr_read(s, s->TxAddr, TxAddr0, addr, 2); in rtl8139_io_readw()
3018 ret = s->NWayAdvert; in rtl8139_io_readw()
3022 ret = s->NWayLPAR; in rtl8139_io_readw()
3026 ret = s->NWayExpansion; in rtl8139_io_readw()
3067 ret = s->RxMissed; in rtl8139_io_readl()
3080 case TxStatus0 ... TxStatus0+4*4-1: in rtl8139_io_readl()
3081 ret = rtl8139_TxStatus_TxAddr_read(s, s->TxStatus, TxStatus0, in rtl8139_io_readl()
3085 case TxAddr0 ... TxAddr0+4*4-1: in rtl8139_io_readl()
3086 ret = rtl8139_TxAddr_read(s, addr-TxAddr0); in rtl8139_io_readl()
3094 ret = s->RxRingAddrLO; in rtl8139_io_readl()
3099 ret = s->RxRingAddrHI; in rtl8139_io_readl()
3104 ret = (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - s->TCTR_base) / in rtl8139_io_readl()
3110 ret = s->TimerInt; in rtl8139_io_readl()
3136 s->cplus_enabled = s->CpCmd != 0; in rtl8139_post_load()
3141 qemu_get_queue(s->nic)->link_down = (s->BasicModeStatus & 0x04) == 0; in rtl8139_post_load()
3167 s->TCTR = (current_time - s->TCTR_base) / PCI_PERIOD; in rtl8139_pre_save()
3168 s->rtl8139_mmio_io_addr_dummy = 0; in rtl8139_pre_save()
3300 return -1; in rtl8139_ioport_read()
3317 if (!s->clock_enabled) in rtl8139_timer()
3323 s->IntrStatus |= PCSTimeout; in rtl8139_timer()
3332 g_free(s->cplus_txbuffer); in pci_rtl8139_uninit()
3333 s->cplus_txbuffer = NULL; in pci_rtl8139_uninit()
3334 timer_free(s->timer); in pci_rtl8139_uninit()
3335 qemu_del_nic(s->nic); in pci_rtl8139_uninit()
3342 if (nc->link_down) { in rtl8139_set_link_status()
3343 s->BasicModeStatus &= ~0x04; in rtl8139_set_link_status()
3345 s->BasicModeStatus |= 0x04; in rtl8139_set_link_status()
3348 s->IntrStatus |= RxUnderrun; in rtl8139_set_link_status()
3366 pci_conf = dev->config; in pci_rtl8139_realize()
3372 memory_region_init_io(&s->bar_io, OBJECT(s), &rtl8139_io_ops, s, in pci_rtl8139_realize()
3374 memory_region_init_alias(&s->bar_mem, OBJECT(s), "rtl8139-mem", &s->bar_io, in pci_rtl8139_realize()
3377 pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->bar_io); in pci_rtl8139_realize()
3378 pci_register_bar(dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->bar_mem); in pci_rtl8139_realize()
3380 qemu_macaddr_default_if_unset(&s->conf.macaddr); in pci_rtl8139_realize()
3383 s->eeprom.contents[0] = 0x8129; in pci_rtl8139_realize()
3386 s->eeprom.contents[1] = PCI_VENDOR_ID_REALTEK; in pci_rtl8139_realize()
3387 s->eeprom.contents[2] = PCI_DEVICE_ID_REALTEK_8139; in pci_rtl8139_realize()
3389 s->eeprom.contents[7] = s->conf.macaddr.a[0] | s->conf.macaddr.a[1] << 8; in pci_rtl8139_realize()
3390 s->eeprom.contents[8] = s->conf.macaddr.a[2] | s->conf.macaddr.a[3] << 8; in pci_rtl8139_realize()
3391 s->eeprom.contents[9] = s->conf.macaddr.a[4] | s->conf.macaddr.a[5] << 8; in pci_rtl8139_realize()
3393 s->nic = qemu_new_nic(&net_rtl8139_info, &s->conf, in pci_rtl8139_realize()
3394 object_get_typename(OBJECT(dev)), d->id, in pci_rtl8139_realize()
3395 &d->mem_reentrancy_guard, s); in pci_rtl8139_realize()
3396 qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); in pci_rtl8139_realize()
3398 s->cplus_txbuffer = NULL; in pci_rtl8139_realize()
3399 s->cplus_txbuffer_len = 0; in pci_rtl8139_realize()
3400 s->cplus_txbuffer_offset = 0; in pci_rtl8139_realize()
3402 s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, rtl8139_timer, s); in pci_rtl8139_realize()
3409 device_add_bootindex_property(obj, &s->conf.bootindex, in rtl8139_instance_init()
3410 "bootindex", "/ethernet-phy@0", in rtl8139_instance_init()
3423 k->realize = pci_rtl8139_realize; in rtl8139_class_init()
3424 k->exit = pci_rtl8139_uninit; in rtl8139_class_init()
3425 k->romfile = "efi-rtl8139.rom"; in rtl8139_class_init()
3426 k->vendor_id = PCI_VENDOR_ID_REALTEK; in rtl8139_class_init()
3427 k->device_id = PCI_DEVICE_ID_REALTEK_8139; in rtl8139_class_init()
3428 k->revision = RTL8139_PCI_REVID; /* >=0x20 is for 8139C+ */ in rtl8139_class_init()
3429 k->class_id = PCI_CLASS_NETWORK_ETHERNET; in rtl8139_class_init()
3431 dc->vmsd = &vmstate_rtl8139; in rtl8139_class_init()
3433 set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); in rtl8139_class_init()