]> git.proxmox.com Git - mirror_qemu.git/blame - hw/net/e1000x_common.h
hw/net: pcnet: Remove the logic of padding short frames in the receive path
[mirror_qemu.git] / hw / net / e1000x_common.h
CommitLineData
093454e2 1/*
0eadd56b
AO
2 * QEMU e1000(e) emulation - shared code
3 *
4 * Copyright (c) 2008 Qumranet
5 *
6 * Based on work done by:
7 * Nir Peleg, Tutis Systems Ltd. for Qumranet Inc.
8 * Copyright (c) 2007 Dan Aloni
9 * Copyright (c) 2004 Antony T Curtis
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
23 */
093454e2 24
f91005e1
MA
25#ifndef HW_NET_E1000X_COMMON_H
26#define HW_NET_E1000X_COMMON_H
27
093454e2
DF
28static inline void
29e1000x_inc_reg_if_not_full(uint32_t *mac, int index)
30{
2fe63579 31 if (mac[index] != UINT32_MAX) {
093454e2
DF
32 mac[index]++;
33 }
34}
35
36static inline void
37e1000x_grow_8reg_if_not_full(uint32_t *mac, int index, int size)
38{
39 uint64_t sum = mac[index] | (uint64_t)mac[index + 1] << 32;
40
41 if (sum + size < sum) {
42 sum = ~0ULL;
43 } else {
44 sum += size;
45 }
46 mac[index] = sum;
47 mac[index + 1] = sum >> 32;
48}
49
50static inline int
51e1000x_vlan_enabled(uint32_t *mac)
52{
53 return ((mac[CTRL] & E1000_CTRL_VME) != 0);
54}
55
56static inline int
57e1000x_is_vlan_txd(uint32_t txd_lower)
58{
59 return ((txd_lower & E1000_TXD_CMD_VLE) != 0);
60}
61
62static inline int
63e1000x_vlan_rx_filter_enabled(uint32_t *mac)
64{
65 return ((mac[RCTL] & E1000_RCTL_VFE) != 0);
66}
67
68static inline int
69e1000x_fcs_len(uint32_t *mac)
70{
71 /* FCS aka Ethernet CRC-32. We don't get it from backends and can't
72 * fill it in, just pad descriptor length by 4 bytes unless guest
73 * told us to strip it off the packet. */
74 return (mac[RCTL] & E1000_RCTL_SECRC) ? 0 : 4;
75}
76
77static inline void
78e1000x_update_regs_on_link_down(uint32_t *mac, uint16_t *phy)
79{
80 mac[STATUS] &= ~E1000_STATUS_LU;
b7728c9f
AO
81 phy[MII_BMSR] &= ~MII_BMSR_LINK_ST;
82 phy[MII_BMSR] &= ~MII_BMSR_AN_COMP;
83 phy[MII_ANLPAR] &= ~MII_ANLPAR_ACK;
093454e2
DF
84}
85
86static inline void
87e1000x_update_regs_on_link_up(uint32_t *mac, uint16_t *phy)
88{
89 mac[STATUS] |= E1000_STATUS_LU;
b7728c9f 90 phy[MII_BMSR] |= MII_BMSR_LINK_ST;
093454e2
DF
91}
92
93void e1000x_update_rx_total_stats(uint32_t *mac,
f3f9b726
AO
94 eth_pkt_types_e pkt_type,
95 size_t pkt_size,
96 size_t pkt_fcs_size);
093454e2
DF
97
98void e1000x_core_prepare_eeprom(uint16_t *eeprom,
99 const uint16_t *templ,
100 uint32_t templ_size,
101 uint16_t dev_id,
102 const uint8_t *macaddr);
103
104uint32_t e1000x_rxbufsize(uint32_t rctl);
105
106bool e1000x_rx_ready(PCIDevice *d, uint32_t *mac);
107
d921db0a 108bool e1000x_is_vlan_packet(const void *buf, uint16_t vet);
093454e2 109
e9e5b930
AO
110bool e1000x_rx_vlan_filter(uint32_t *mac, const struct vlan_header *vhdr);
111
112bool e1000x_rx_group_filter(uint32_t *mac, const struct eth_header *ehdr);
093454e2
DF
113
114bool e1000x_hw_rx_enabled(uint32_t *mac);
115
116bool e1000x_is_oversized(uint32_t *mac, size_t size);
117
118void e1000x_restart_autoneg(uint32_t *mac, uint16_t *phy, QEMUTimer *timer);
119
120void e1000x_reset_mac_addr(NICState *nic, uint32_t *mac_regs,
121 uint8_t *mac_addr);
122
123void e1000x_update_regs_on_autoneg_done(uint32_t *mac, uint16_t *phy);
124
125void e1000x_increase_size_stats(uint32_t *mac, const int *size_regs, int size);
126
127typedef struct e1000x_txd_props {
093454e2
DF
128 uint8_t ipcss;
129 uint8_t ipcso;
130 uint16_t ipcse;
131 uint8_t tucss;
132 uint8_t tucso;
133 uint16_t tucse;
134 uint32_t paylen;
135 uint8_t hdr_len;
136 uint16_t mss;
137 int8_t ip;
138 int8_t tcp;
139 bool tse;
093454e2
DF
140} e1000x_txd_props;
141
142void e1000x_read_tx_ctx_descr(struct e1000_context_desc *d,
143 e1000x_txd_props *props);
f91005e1 144
5fb7d149
AO
145void e1000x_timestamp(uint32_t *mac, int64_t timadj, size_t lo, size_t hi);
146void e1000x_set_timinca(uint32_t *mac, int64_t *timadj, uint32_t val);
147
f91005e1 148#endif