Lines Matching +full:- +full:s
9 * Contributions after 2012-01-13 are licensed under the terms of the
21 #include "hw/qdev-properties.h"
37 /* The tx and rx fifo ports are a range of aliased 32-bit registers */
344 static void lan9118_update(lan9118_state *s) in lan9118_update() argument
349 level = (s->int_sts & s->int_en) != 0; in lan9118_update()
351 s->irq_cfg |= IRQ_INT; in lan9118_update()
353 s->irq_cfg &= ~IRQ_INT; in lan9118_update()
355 if ((s->irq_cfg & IRQ_EN) == 0) { in lan9118_update()
358 if ((s->irq_cfg & (IRQ_TYPE | IRQ_POL)) != (IRQ_TYPE | IRQ_POL)) { in lan9118_update()
360 * active-high polarity, push-pull type. in lan9118_update()
364 qemu_set_irq(s->irq, level); in lan9118_update()
367 static void lan9118_mac_changed(lan9118_state *s) in lan9118_mac_changed() argument
369 qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); in lan9118_mac_changed()
372 static void lan9118_reload_eeprom(lan9118_state *s) in lan9118_reload_eeprom() argument
375 if (s->eeprom[0] != 0xa5) { in lan9118_reload_eeprom()
376 s->e2p_cmd &= ~E2P_CMD_MAC_ADDR_LOADED; in lan9118_reload_eeprom()
381 s->conf.macaddr.a[i] = s->eeprom[i + 1]; in lan9118_reload_eeprom()
383 s->e2p_cmd |= E2P_CMD_MAC_ADDR_LOADED; in lan9118_reload_eeprom()
385 lan9118_mac_changed(s); in lan9118_reload_eeprom()
388 static void phy_update_irq(lan9118_state *s) in phy_update_irq() argument
390 if (s->phy_int & s->phy_int_mask) { in phy_update_irq()
391 s->int_sts |= PHY_INT; in phy_update_irq()
393 s->int_sts &= ~PHY_INT; in phy_update_irq()
395 lan9118_update(s); in phy_update_irq()
398 static void phy_update_link(lan9118_state *s) in phy_update_link() argument
401 if (qemu_get_queue(s->nic)->link_down) { in phy_update_link()
402 s->phy_status &= ~0x0024; in phy_update_link()
403 s->phy_int |= PHY_INT_DOWN; in phy_update_link()
405 s->phy_status |= 0x0024; in phy_update_link()
406 s->phy_int |= PHY_INT_ENERGYON; in phy_update_link()
407 s->phy_int |= PHY_INT_AUTONEG_COMPLETE; in phy_update_link()
409 phy_update_irq(s); in phy_update_link()
417 static void phy_reset(lan9118_state *s) in phy_reset() argument
419 s->phy_status = 0x7809; in phy_reset()
420 s->phy_control = 0x3000; in phy_reset()
421 s->phy_advertise = 0x01e1; in phy_reset()
422 s->phy_int_mask = 0; in phy_reset()
423 s->phy_int = 0; in phy_reset()
424 phy_update_link(s); in phy_reset()
429 lan9118_state *s = LAN9118(d); in lan9118_reset() local
431 s->irq_cfg &= (IRQ_TYPE | IRQ_POL); in lan9118_reset()
432 s->int_sts = 0; in lan9118_reset()
433 s->int_en = 0; in lan9118_reset()
434 s->fifo_int = 0x48000000; in lan9118_reset()
435 s->rx_cfg = 0; in lan9118_reset()
436 s->tx_cfg = 0; in lan9118_reset()
437 s->hw_cfg = s->mode_16bit ? 0x00050000 : 0x00050004; in lan9118_reset()
438 s->pmt_ctrl &= 0x45; in lan9118_reset()
439 s->gpio_cfg = 0; in lan9118_reset()
440 s->txp->fifo_used = 0; in lan9118_reset()
441 s->txp->state = TX_IDLE; in lan9118_reset()
442 s->txp->cmd_a = 0xffffffffu; in lan9118_reset()
443 s->txp->cmd_b = 0xffffffffu; in lan9118_reset()
444 s->txp->len = 0; in lan9118_reset()
445 s->txp->fifo_used = 0; in lan9118_reset()
446 s->tx_fifo_size = 4608; in lan9118_reset()
447 s->tx_status_fifo_used = 0; in lan9118_reset()
448 s->rx_status_fifo_size = 704; in lan9118_reset()
449 s->rx_fifo_size = 2640; in lan9118_reset()
450 s->rx_fifo_used = 0; in lan9118_reset()
451 s->rx_status_fifo_size = 176; in lan9118_reset()
452 s->rx_status_fifo_used = 0; in lan9118_reset()
453 s->rxp_offset = 0; in lan9118_reset()
454 s->rxp_size = 0; in lan9118_reset()
455 s->rxp_pad = 0; in lan9118_reset()
456 s->rx_packet_size_tail = s->rx_packet_size_head; in lan9118_reset()
457 s->rx_packet_size[s->rx_packet_size_head] = 0; in lan9118_reset()
458 s->mac_cmd = 0; in lan9118_reset()
459 s->mac_data = 0; in lan9118_reset()
460 s->afc_cfg = 0; in lan9118_reset()
461 s->e2p_cmd = 0; in lan9118_reset()
462 s->e2p_data = 0; in lan9118_reset()
463 s->free_timer_start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / 40; in lan9118_reset()
465 ptimer_transaction_begin(s->timer); in lan9118_reset()
466 ptimer_stop(s->timer); in lan9118_reset()
467 ptimer_set_count(s->timer, 0xffff); in lan9118_reset()
468 ptimer_transaction_commit(s->timer); in lan9118_reset()
469 s->gpt_cfg = 0xffff; in lan9118_reset()
471 s->mac_cr = MAC_CR_PRMS; in lan9118_reset()
472 s->mac_hashh = 0; in lan9118_reset()
473 s->mac_hashl = 0; in lan9118_reset()
474 s->mac_mii_acc = 0; in lan9118_reset()
475 s->mac_mii_data = 0; in lan9118_reset()
476 s->mac_flow = 0; in lan9118_reset()
478 s->read_word_n = 0; in lan9118_reset()
479 s->write_word_n = 0; in lan9118_reset()
481 phy_reset(s); in lan9118_reset()
483 s->eeprom_writable = 0; in lan9118_reset()
484 lan9118_reload_eeprom(s); in lan9118_reset()
487 static void rx_fifo_push(lan9118_state *s, uint32_t val) in rx_fifo_push() argument
490 fifo_pos = s->rx_fifo_head + s->rx_fifo_used; in rx_fifo_push()
491 if (fifo_pos >= s->rx_fifo_size) in rx_fifo_push()
492 fifo_pos -= s->rx_fifo_size; in rx_fifo_push()
493 s->rx_fifo[fifo_pos] = val; in rx_fifo_push()
494 s->rx_fifo_used++; in rx_fifo_push()
498 static int lan9118_filter(lan9118_state *s, const uint8_t *addr) in lan9118_filter() argument
503 if (s->mac_cr & MAC_CR_PRMS) { in lan9118_filter()
508 return (s->mac_cr & MAC_CR_BCAST) == 0; in lan9118_filter()
512 if (multicast &&s->mac_cr & MAC_CR_MCPAS) { in lan9118_filter()
515 if (multicast ? (s->mac_cr & MAC_CR_HPFILT) == 0 in lan9118_filter()
516 : (s->mac_cr & MAC_CR_HO) == 0) { in lan9118_filter()
518 hash = memcmp(addr, s->conf.macaddr.a, 6); in lan9118_filter()
519 if (s->mac_cr & MAC_CR_INVFILT) { in lan9118_filter()
528 return (s->mac_hashh >> (hash & 0x1f)) & 1; in lan9118_filter()
530 return (s->mac_hashl >> (hash & 0x1f)) & 1; in lan9118_filter()
538 lan9118_state *s = qemu_get_nic_opaque(nc); in lan9118_receive() local
548 if ((s->mac_cr & MAC_CR_RXEN) == 0) { in lan9118_receive()
549 return -1; in lan9118_receive()
553 return -1; in lan9118_receive()
557 if (s->rx_status_fifo_used == s->rx_status_fifo_size) { in lan9118_receive()
558 return -1; in lan9118_receive()
561 filter = lan9118_filter(s, buf); in lan9118_receive()
562 if (!filter && (s->mac_cr & MAC_CR_RXALL) == 0) { in lan9118_receive()
566 offset = (s->rx_cfg >> 8) & 0x1f; in lan9118_receive()
571 if (s->rx_fifo_size - s->rx_fifo_used < fifo_len) { in lan9118_receive()
572 return -1; in lan9118_receive()
575 DPRINTF("Got packet len:%d fifo:%d filter:%s\n", in lan9118_receive()
584 rx_fifo_push(s, val); in lan9118_receive()
589 val >>= ((4 - n) * 8); in lan9118_receive()
591 rx_fifo_push(s, val); in lan9118_receive()
592 val = crc >> ((4 - n) * 8); in lan9118_receive()
593 rx_fifo_push(s, val); in lan9118_receive()
595 rx_fifo_push(s, crc); in lan9118_receive()
597 n = s->rx_status_fifo_head + s->rx_status_fifo_used; in lan9118_receive()
598 if (n >= s->rx_status_fifo_size) { in lan9118_receive()
599 n -= s->rx_status_fifo_size; in lan9118_receive()
601 s->rx_packet_size[s->rx_packet_size_tail] = fifo_len; in lan9118_receive()
602 s->rx_packet_size_tail = (s->rx_packet_size_tail + 1023) & 1023; in lan9118_receive()
603 s->rx_status_fifo_used++; in lan9118_receive()
615 s->rx_status_fifo[n] = status; in lan9118_receive()
617 if (s->rx_status_fifo_used > (s->fifo_int & 0xff)) { in lan9118_receive()
618 s->int_sts |= RSFL_INT; in lan9118_receive()
620 lan9118_update(s); in lan9118_receive()
625 static uint32_t rx_fifo_pop(lan9118_state *s) in rx_fifo_pop() argument
630 if (s->rxp_size == 0 && s->rxp_pad == 0) { in rx_fifo_pop()
631 s->rxp_size = s->rx_packet_size[s->rx_packet_size_head]; in rx_fifo_pop()
632 s->rx_packet_size[s->rx_packet_size_head] = 0; in rx_fifo_pop()
633 if (s->rxp_size != 0) { in rx_fifo_pop()
634 s->rx_packet_size_head = (s->rx_packet_size_head + 1023) & 1023; in rx_fifo_pop()
635 s->rxp_offset = (s->rx_cfg >> 10) & 7; in rx_fifo_pop()
636 n = s->rxp_offset + s->rxp_size; in rx_fifo_pop()
637 switch (s->rx_cfg >> 30) { in rx_fifo_pop()
639 n = (-n) & 3; in rx_fifo_pop()
642 n = (-n) & 7; in rx_fifo_pop()
648 s->rxp_pad = n; in rx_fifo_pop()
650 s->rxp_size, s->rxp_offset, s->rxp_pad); in rx_fifo_pop()
653 if (s->rxp_offset > 0) { in rx_fifo_pop()
654 s->rxp_offset--; in rx_fifo_pop()
656 } else if (s->rxp_size > 0) { in rx_fifo_pop()
657 s->rxp_size--; in rx_fifo_pop()
658 val = s->rx_fifo[s->rx_fifo_head++]; in rx_fifo_pop()
659 if (s->rx_fifo_head >= s->rx_fifo_size) { in rx_fifo_pop()
660 s->rx_fifo_head -= s->rx_fifo_size; in rx_fifo_pop()
662 s->rx_fifo_used--; in rx_fifo_pop()
663 } else if (s->rxp_pad > 0) { in rx_fifo_pop()
664 s->rxp_pad--; in rx_fifo_pop()
668 s->int_sts |= RXE_INT; in rx_fifo_pop()
671 lan9118_update(s); in rx_fifo_pop()
675 static void do_tx_packet(lan9118_state *s) in do_tx_packet() argument
681 if (s->phy_control & 0x4000) { in do_tx_packet()
683 qemu_receive_packet(qemu_get_queue(s->nic), s->txp->data, s->txp->len); in do_tx_packet()
685 qemu_send_packet(qemu_get_queue(s->nic), s->txp->data, s->txp->len); in do_tx_packet()
687 s->txp->fifo_used = 0; in do_tx_packet()
689 if (s->tx_status_fifo_used == 512) { in do_tx_packet()
694 status = s->txp->cmd_b & 0xffff0000u; in do_tx_packet()
695 DPRINTF("Sent packet tag:%04x len %d\n", status >> 16, s->txp->len); in do_tx_packet()
696 n = (s->tx_status_fifo_head + s->tx_status_fifo_used) & 511; in do_tx_packet()
697 s->tx_status_fifo[n] = status; in do_tx_packet()
698 s->tx_status_fifo_used++; in do_tx_packet()
704 if (s->tx_status_fifo_used > ((s->fifo_int >> 16) & 0xff)) { in do_tx_packet()
705 s->int_sts |= TSFL_INT; in do_tx_packet()
707 if (s->tx_status_fifo_used == 512) { in do_tx_packet()
708 s->int_sts |= TSFF_INT; in do_tx_packet()
713 static uint32_t rx_status_fifo_pop(lan9118_state *s) in rx_status_fifo_pop() argument
717 val = s->rx_status_fifo[s->rx_status_fifo_head]; in rx_status_fifo_pop()
718 if (s->rx_status_fifo_used != 0) { in rx_status_fifo_pop()
719 s->rx_status_fifo_used--; in rx_status_fifo_pop()
720 s->rx_status_fifo_head++; in rx_status_fifo_pop()
721 if (s->rx_status_fifo_head >= s->rx_status_fifo_size) { in rx_status_fifo_pop()
722 s->rx_status_fifo_head -= s->rx_status_fifo_size; in rx_status_fifo_pop()
730 static uint32_t tx_status_fifo_pop(lan9118_state *s) in tx_status_fifo_pop() argument
734 val = s->tx_status_fifo[s->tx_status_fifo_head]; in tx_status_fifo_pop()
735 if (s->tx_status_fifo_used != 0) { in tx_status_fifo_pop()
736 s->tx_status_fifo_used--; in tx_status_fifo_pop()
737 s->tx_status_fifo_head = (s->tx_status_fifo_head + 1) & 511; in tx_status_fifo_pop()
743 static void tx_fifo_push(lan9118_state *s, uint32_t val) in tx_fifo_push() argument
747 if (s->txp->fifo_used == s->tx_fifo_size) { in tx_fifo_push()
748 s->int_sts |= TDFO_INT; in tx_fifo_push()
751 switch (s->txp->state) { in tx_fifo_push()
753 s->txp->cmd_a = val & 0x831f37ff; in tx_fifo_push()
754 s->txp->fifo_used++; in tx_fifo_push()
755 s->txp->state = TX_B; in tx_fifo_push()
756 s->txp->buffer_size = extract32(s->txp->cmd_a, 0, 11); in tx_fifo_push()
757 s->txp->offset = extract32(s->txp->cmd_a, 16, 5); in tx_fifo_push()
760 if (s->txp->cmd_a & 0x2000) { in tx_fifo_push()
762 s->txp->cmd_b = val; in tx_fifo_push()
763 s->txp->fifo_used++; in tx_fifo_push()
765 n = (s->txp->buffer_size + s->txp->offset + 3) >> 2; in tx_fifo_push()
768 n = (-n) & 3; in tx_fifo_push()
771 n = (-n) & 7; in tx_fifo_push()
776 s->txp->pad = n; in tx_fifo_push()
777 s->txp->len = 0; in tx_fifo_push()
780 s->txp->buffer_size, s->txp->offset, s->txp->pad, in tx_fifo_push()
781 s->txp->cmd_a); in tx_fifo_push()
782 s->txp->state = TX_DATA; in tx_fifo_push()
785 if (s->txp->offset >= 4) { in tx_fifo_push()
786 s->txp->offset -= 4; in tx_fifo_push()
789 if (s->txp->buffer_size <= 0 && s->txp->pad != 0) { in tx_fifo_push()
790 s->txp->pad--; in tx_fifo_push()
792 n = MIN(4, s->txp->buffer_size + s->txp->offset); in tx_fifo_push()
793 while (s->txp->offset) { in tx_fifo_push()
795 n--; in tx_fifo_push()
796 s->txp->offset--; in tx_fifo_push()
799 in FIFO words. Empirical results show it to be little-endian. in tx_fifo_push()
801 while (n--) { in tx_fifo_push()
802 if (s->txp->len == MIL_TXFIFO_SIZE) { in tx_fifo_push()
812 "MIL TX FIFO overrun, discarding %u byte%s\n", in tx_fifo_push()
813 n, n > 1 ? "s" : ""); in tx_fifo_push()
814 s->int_sts |= TXE_INT; in tx_fifo_push()
817 s->txp->data[s->txp->len] = val & 0xff; in tx_fifo_push()
818 s->txp->len++; in tx_fifo_push()
820 s->txp->buffer_size--; in tx_fifo_push()
822 s->txp->fifo_used++; in tx_fifo_push()
824 if (s->txp->buffer_size <= 0 && s->txp->pad == 0) { in tx_fifo_push()
825 if (s->txp->cmd_a & 0x1000) { in tx_fifo_push()
826 do_tx_packet(s); in tx_fifo_push()
828 if (s->txp->cmd_a & 0x80000000) { in tx_fifo_push()
829 s->int_sts |= TX_IOC_INT; in tx_fifo_push()
831 s->txp->state = TX_IDLE; in tx_fifo_push()
837 static uint32_t do_phy_read(lan9118_state *s, int reg) in do_phy_read() argument
843 return s->phy_control; in do_phy_read()
845 return s->phy_status; in do_phy_read()
850 case 4: /* Auto-neg advertisement */ in do_phy_read()
851 return s->phy_advertise; in do_phy_read()
852 case 5: /* Auto-neg Link Partner Ability */ in do_phy_read()
854 case 6: /* Auto-neg Expansion */ in do_phy_read()
858 val = s->phy_int; in do_phy_read()
859 s->phy_int = 0; in do_phy_read()
860 phy_update_irq(s); in do_phy_read()
863 return s->phy_int_mask; in do_phy_read()
871 static void do_phy_write(lan9118_state *s, int reg, uint32_t val) in do_phy_write() argument
876 phy_reset(s); in do_phy_write()
879 s->phy_control = val & 0x7980; in do_phy_write()
882 s->phy_status |= 0x0020; in do_phy_write()
885 case 4: /* Auto-neg advertisement */ in do_phy_write()
886 s->phy_advertise = (val & 0x2d7f) | 0x80; in do_phy_write()
890 s->phy_int_mask = val & 0xff; in do_phy_write()
891 phy_update_irq(s); in do_phy_write()
899 static void do_mac_write(lan9118_state *s, int reg, uint32_t val) in do_mac_write() argument
903 if ((s->mac_cr & MAC_CR_RXEN) != 0 && (val & MAC_CR_RXEN) == 0) { in do_mac_write()
904 s->int_sts |= RXSTOP_INT; in do_mac_write()
906 s->mac_cr = val & ~MAC_CR_RESERVED; in do_mac_write()
910 s->conf.macaddr.a[4] = val & 0xff; in do_mac_write()
911 s->conf.macaddr.a[5] = (val >> 8) & 0xff; in do_mac_write()
912 lan9118_mac_changed(s); in do_mac_write()
915 s->conf.macaddr.a[0] = val & 0xff; in do_mac_write()
916 s->conf.macaddr.a[1] = (val >> 8) & 0xff; in do_mac_write()
917 s->conf.macaddr.a[2] = (val >> 16) & 0xff; in do_mac_write()
918 s->conf.macaddr.a[3] = (val >> 24) & 0xff; in do_mac_write()
919 lan9118_mac_changed(s); in do_mac_write()
922 s->mac_hashh = val; in do_mac_write()
925 s->mac_hashl = val; in do_mac_write()
928 s->mac_mii_acc = val & 0xffc2; in do_mac_write()
931 (val >> 6) & 0x1f, s->mac_mii_data); in do_mac_write()
932 do_phy_write(s, (val >> 6) & 0x1f, s->mac_mii_data); in do_mac_write()
934 s->mac_mii_data = do_phy_read(s, (val >> 6) & 0x1f); in do_mac_write()
936 (val >> 6) & 0x1f, s->mac_mii_data); in do_mac_write()
940 s->mac_mii_data = val & 0xffff; in do_mac_write()
943 s->mac_flow = val & 0xffff0000; in do_mac_write()
954 s->mac_cmd & 0xf, val); in do_mac_write()
958 static uint32_t do_mac_read(lan9118_state *s, int reg) in do_mac_read() argument
962 return s->mac_cr; in do_mac_read()
964 return s->conf.macaddr.a[4] | (s->conf.macaddr.a[5] << 8); in do_mac_read()
966 return s->conf.macaddr.a[0] | (s->conf.macaddr.a[1] << 8) in do_mac_read()
967 | (s->conf.macaddr.a[2] << 16) | (s->conf.macaddr.a[3] << 24); in do_mac_read()
969 return s->mac_hashh; in do_mac_read()
971 return s->mac_hashl; in do_mac_read()
973 return s->mac_mii_acc; in do_mac_read()
975 return s->mac_mii_data; in do_mac_read()
977 return s->mac_flow; in do_mac_read()
981 s->mac_cmd & 0xf); in do_mac_read()
986 static void lan9118_eeprom_cmd(lan9118_state *s, int cmd, int addr) in lan9118_eeprom_cmd() argument
988 s->e2p_cmd = (s->e2p_cmd & E2P_CMD_MAC_ADDR_LOADED) | (cmd << 28) | addr; in lan9118_eeprom_cmd()
991 s->e2p_data = s->eeprom[addr]; in lan9118_eeprom_cmd()
992 DPRINTF("EEPROM Read %d = 0x%02x\n", addr, s->e2p_data); in lan9118_eeprom_cmd()
995 s->eeprom_writable = 0; in lan9118_eeprom_cmd()
999 s->eeprom_writable = 1; in lan9118_eeprom_cmd()
1003 if (s->eeprom_writable) { in lan9118_eeprom_cmd()
1004 s->eeprom[addr] &= s->e2p_data; in lan9118_eeprom_cmd()
1005 DPRINTF("EEPROM Write %d = 0x%02x\n", addr, s->e2p_data); in lan9118_eeprom_cmd()
1011 if (s->eeprom_writable) { in lan9118_eeprom_cmd()
1013 s->eeprom[addr] &= s->e2p_data; in lan9118_eeprom_cmd()
1015 DPRINTF("EEPROM Write All 0x%02x\n", s->e2p_data); in lan9118_eeprom_cmd()
1021 if (s->eeprom_writable) { in lan9118_eeprom_cmd()
1022 s->eeprom[addr] = 0xff; in lan9118_eeprom_cmd()
1029 if (s->eeprom_writable) { in lan9118_eeprom_cmd()
1030 memset(s->eeprom, 0xff, 128); in lan9118_eeprom_cmd()
1037 lan9118_reload_eeprom(s); in lan9118_eeprom_cmd()
1044 lan9118_state *s = (lan9118_state *)opaque; in lan9118_tick() local
1045 if (s->int_en & GPT_INT) { in lan9118_tick()
1046 s->int_sts |= GPT_INT; in lan9118_tick()
1048 lan9118_update(s); in lan9118_tick()
1054 lan9118_state *s = (lan9118_state *)opaque; in lan9118_writel() local
1061 tx_fifo_push(s, val); in lan9118_writel()
1068 s->irq_cfg = (s->irq_cfg & IRQ_INT) | val; in lan9118_writel()
1071 s->int_sts &= ~val; in lan9118_writel()
1074 s->int_en = val & ~RESERVED_INT; in lan9118_writel()
1075 s->int_sts |= val & SW_INT; in lan9118_writel()
1079 s->fifo_int = val; in lan9118_writel()
1084 s->rx_fifo_used = 0; in lan9118_writel()
1085 s->rx_status_fifo_used = 0; in lan9118_writel()
1086 s->rx_packet_size_tail = s->rx_packet_size_head; in lan9118_writel()
1087 s->rx_packet_size[s->rx_packet_size_head] = 0; in lan9118_writel()
1089 s->rx_cfg = val & 0xcfff1ff0; in lan9118_writel()
1093 s->tx_status_fifo_used = 0; in lan9118_writel()
1096 s->txp->state = TX_IDLE; in lan9118_writel()
1097 s->txp->fifo_used = 0; in lan9118_writel()
1098 s->txp->cmd_a = 0xffffffff; in lan9118_writel()
1100 s->tx_cfg = val & 6; in lan9118_writel()
1105 lan9118_reset(DEVICE(s)); in lan9118_writel()
1107 s->hw_cfg = (val & 0x003f300) | (s->hw_cfg & 0x4); in lan9118_writel()
1113 s->rxp_pad = 0; in lan9118_writel()
1114 s->rxp_offset = 0; in lan9118_writel()
1115 if (s->rxp_size == 0) { in lan9118_writel()
1117 rx_fifo_pop(s); in lan9118_writel()
1118 s->rxp_pad = 0; in lan9118_writel()
1119 s->rxp_offset = 0; in lan9118_writel()
1121 s->rx_fifo_head += s->rxp_size; in lan9118_writel()
1122 if (s->rx_fifo_head >= s->rx_fifo_size) { in lan9118_writel()
1123 s->rx_fifo_head -= s->rx_fifo_size; in lan9118_writel()
1129 phy_reset(s); in lan9118_writel()
1131 s->pmt_ctrl &= ~0x34e; in lan9118_writel()
1132 s->pmt_ctrl |= (val & 0x34e); in lan9118_writel()
1136 s->gpio_cfg = val & 0x7777071f; in lan9118_writel()
1139 if ((s->gpt_cfg ^ val) & GPT_TIMER_EN) { in lan9118_writel()
1140 ptimer_transaction_begin(s->timer); in lan9118_writel()
1142 ptimer_set_count(s->timer, val & 0xffff); in lan9118_writel()
1143 ptimer_run(s->timer, 0); in lan9118_writel()
1145 ptimer_stop(s->timer); in lan9118_writel()
1146 ptimer_set_count(s->timer, 0xffff); in lan9118_writel()
1148 ptimer_transaction_commit(s->timer); in lan9118_writel()
1150 s->gpt_cfg = val & (GPT_TIMER_EN | 0xffff); in lan9118_writel()
1153 /* Ignored because we're in 32-bit mode. */ in lan9118_writel()
1154 s->word_swap = val; in lan9118_writel()
1157 s->mac_cmd = val & 0x4000000f; in lan9118_writel()
1160 s->mac_data = do_mac_read(s, val & 0xf); in lan9118_writel()
1161 DPRINTF("MAC read %d = 0x%08x\n", val & 0xf, s->mac_data); in lan9118_writel()
1163 DPRINTF("MAC write %d = 0x%08x\n", val & 0xf, s->mac_data); in lan9118_writel()
1164 do_mac_write(s, val & 0xf, s->mac_data); in lan9118_writel()
1169 s->mac_data = val; in lan9118_writel()
1172 s->afc_cfg = val & 0x00ffffff; in lan9118_writel()
1175 lan9118_eeprom_cmd(s, (val >> 28) & 7, val & 0x7f); in lan9118_writel()
1178 s->e2p_data = val & 0xff; in lan9118_writel()
1186 lan9118_update(s); in lan9118_writel()
1192 lan9118_state *s = (lan9118_state *)opaque; in lan9118_writew() local
1195 if (s->write_word_prev_offset != (offset & ~0x3)) { in lan9118_writew()
1197 s->write_word_n = 0; in lan9118_writew()
1198 s->write_word_prev_offset = offset & ~0x3; in lan9118_writew()
1202 s->write_word_h = val; in lan9118_writew()
1204 s->write_word_l = val; in lan9118_writew()
1208 s->write_word_n++; in lan9118_writew()
1209 if (s->write_word_n == 2) { in lan9118_writew()
1210 s->write_word_n = 0; in lan9118_writew()
1211 lan9118_writel(s, offset & ~3, s->write_word_l + in lan9118_writew()
1212 (s->write_word_h << 16), 4); in lan9118_writew()
1235 lan9118_state *s = (lan9118_state *)opaque; in lan9118_readl() local
1240 return rx_fifo_pop(s); in lan9118_readl()
1244 return rx_status_fifo_pop(s); in lan9118_readl()
1246 return s->rx_status_fifo[s->rx_status_fifo_head]; in lan9118_readl()
1248 return tx_status_fifo_pop(s); in lan9118_readl()
1250 return s->tx_status_fifo[s->tx_status_fifo_head]; in lan9118_readl()
1254 return s->irq_cfg; in lan9118_readl()
1256 return s->int_sts; in lan9118_readl()
1258 return s->int_en; in lan9118_readl()
1262 return s->fifo_int; in lan9118_readl()
1264 return s->rx_cfg; in lan9118_readl()
1266 return s->tx_cfg; in lan9118_readl()
1268 return s->hw_cfg; in lan9118_readl()
1272 return (s->rx_status_fifo_used << 16) | (s->rx_fifo_used << 2); in lan9118_readl()
1274 return (s->tx_status_fifo_used << 16) in lan9118_readl()
1275 | (s->tx_fifo_size - s->txp->fifo_used); in lan9118_readl()
1277 return s->pmt_ctrl; in lan9118_readl()
1279 return s->gpio_cfg; in lan9118_readl()
1281 return s->gpt_cfg; in lan9118_readl()
1283 return ptimer_get_count(s->timer); in lan9118_readl()
1285 return s->word_swap; in lan9118_readl()
1287 return (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / 40) - s->free_timer_start; in lan9118_readl()
1292 return s->mac_cmd; in lan9118_readl()
1294 return s->mac_data; in lan9118_readl()
1296 return s->afc_cfg; in lan9118_readl()
1298 return s->e2p_cmd; in lan9118_readl()
1300 return s->e2p_data; in lan9118_readl()
1308 lan9118_state *s = (lan9118_state *)opaque; in lan9118_readw() local
1311 if (s->read_word_prev_offset != (offset & ~0x3)) { in lan9118_readw()
1313 s->read_word_n = 0; in lan9118_readw()
1314 s->read_word_prev_offset = offset & ~0x3; in lan9118_readw()
1317 s->read_word_n++; in lan9118_readw()
1318 if (s->read_word_n == 1) { in lan9118_readw()
1319 s->read_long = lan9118_readl(s, offset & ~3, 4); in lan9118_readw()
1321 s->read_word_n = 0; in lan9118_readw()
1325 val = s->read_long >> 16; in lan9118_readw()
1327 val = s->read_long & 0xFFFF; in lan9118_readw()
1371 lan9118_state *s = LAN9118(dev); in lan9118_realize() local
1374 s->mode_16bit ? &lan9118_16bit_mem_ops : &lan9118_mem_ops; in lan9118_realize()
1376 memory_region_init_io(&s->mmio, OBJECT(dev), mem_ops, s, in lan9118_realize()
1377 "lan9118-mmio", 0x100); in lan9118_realize()
1378 sysbus_init_mmio(sbd, &s->mmio); in lan9118_realize()
1379 sysbus_init_irq(sbd, &s->irq); in lan9118_realize()
1380 qemu_macaddr_default_if_unset(&s->conf.macaddr); in lan9118_realize()
1382 s->nic = qemu_new_nic(&net_lan9118_info, &s->conf, in lan9118_realize()
1383 object_get_typename(OBJECT(dev)), dev->id, in lan9118_realize()
1384 &dev->mem_reentrancy_guard, s); in lan9118_realize()
1385 qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); in lan9118_realize()
1386 s->eeprom[0] = 0xa5; in lan9118_realize()
1388 s->eeprom[i + 1] = s->conf.macaddr.a[i]; in lan9118_realize()
1390 s->pmt_ctrl = 1; in lan9118_realize()
1391 s->txp = &s->tx_packet; in lan9118_realize()
1393 s->timer = ptimer_init(lan9118_tick, s, PTIMER_POLICY_LEGACY); in lan9118_realize()
1394 ptimer_transaction_begin(s->timer); in lan9118_realize()
1395 ptimer_set_freq(s->timer, 10000); in lan9118_realize()
1396 ptimer_set_limit(s->timer, 0xffff, 1); in lan9118_realize()
1397 ptimer_transaction_commit(s->timer); in lan9118_realize()
1412 dc->vmsd = &vmstate_lan9118; in lan9118_class_init()
1413 dc->realize = lan9118_realize; in lan9118_class_init()
1433 SysBusDevice *s; in lan9118_init() local
1437 s = SYS_BUS_DEVICE(dev); in lan9118_init()
1438 sysbus_realize_and_unref(s, &error_fatal); in lan9118_init()
1439 sysbus_mmio_map(s, 0, base); in lan9118_init()
1440 sysbus_connect_irq(s, 0, irq); in lan9118_init()