2 * Core code for QEMU igb emulation
5 * https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/82576eg-gbe-datasheet.pdf
7 * Copyright (c) 2020-2023 Red Hat, Inc.
8 * Copyright (c) 2015 Ravello Systems LTD (http://ravellosystems.com)
9 * Developed by Daynix Computing LTD (http://www.daynix.com)
12 * Akihiko Odaki <akihiko.odaki@daynix.com>
13 * Gal Hammmer <gal.hammer@sap.com>
14 * Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
15 * Dmitry Fleytman <dmitry@daynix.com>
16 * Leonid Bloch <leonid@daynix.com>
17 * Yan Vugenfirer <yan@daynix.com>
19 * Based on work done by:
20 * Nir Peleg, Tutis Systems Ltd. for Qumranet Inc.
21 * Copyright (c) 2008 Qumranet
22 * Based on work done by:
23 * Copyright (c) 2007 Dan Aloni
24 * Copyright (c) 2004 Antony T Curtis
26 * This library is free software; you can redistribute it and/or
27 * modify it under the terms of the GNU Lesser General Public
28 * License as published by the Free Software Foundation; either
29 * version 2.1 of the License, or (at your option) any later version.
31 * This library is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34 * Lesser General Public License for more details.
36 * You should have received a copy of the GNU Lesser General Public
37 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
40 #include "qemu/osdep.h"
44 #include "hw/net/mii.h"
45 #include "hw/pci/msi.h"
46 #include "hw/pci/msix.h"
47 #include "sysemu/runstate.h"
49 #include "net_tx_pkt.h"
50 #include "net_rx_pkt.h"
52 #include "igb_common.h"
53 #include "e1000x_common.h"
58 #define E1000E_MAX_TX_FRAGS (64)
60 union e1000_rx_desc_union
{
61 struct e1000_rx_desc legacy
;
62 union e1000_adv_rx_desc adv
;
65 typedef struct IGBTxPktVmdqCallbackContext
{
68 } IGBTxPktVmdqCallbackContext
;
71 igb_receive_internal(IGBCore
*core
, const struct iovec
*iov
, int iovcnt
,
72 bool has_vnet
, bool *external_tx
);
75 igb_set_interrupt_cause(IGBCore
*core
, uint32_t val
);
77 static void igb_update_interrupt_state(IGBCore
*core
);
78 static void igb_reset(IGBCore
*core
, bool sw
);
81 igb_raise_legacy_irq(IGBCore
*core
)
83 trace_e1000e_irq_legacy_notify(true);
84 e1000x_inc_reg_if_not_full(core
->mac
, IAC
);
85 pci_set_irq(core
->owner
, 1);
89 igb_lower_legacy_irq(IGBCore
*core
)
91 trace_e1000e_irq_legacy_notify(false);
92 pci_set_irq(core
->owner
, 0);
95 static void igb_msix_notify(IGBCore
*core
, unsigned int vector
)
97 PCIDevice
*dev
= core
->owner
;
100 vfn
= 8 - (vector
+ 2) / IGBVF_MSIX_VEC_NUM
;
101 if (vfn
< pcie_sriov_num_vfs(core
->owner
)) {
102 dev
= pcie_sriov_get_vf_at_index(core
->owner
, vfn
);
104 vector
= (vector
+ 2) % IGBVF_MSIX_VEC_NUM
;
105 } else if (vector
>= IGB_MSIX_VEC_NUM
) {
106 qemu_log_mask(LOG_GUEST_ERROR
,
107 "igb: Tried to use vector unavailable for PF");
111 msix_notify(dev
, vector
);
115 igb_intrmgr_rearm_timer(IGBIntrDelayTimer
*timer
)
117 int64_t delay_ns
= (int64_t) timer
->core
->mac
[timer
->delay_reg
] *
118 timer
->delay_resolution_ns
;
120 trace_e1000e_irq_rearm_timer(timer
->delay_reg
<< 2, delay_ns
);
122 timer_mod(timer
->timer
, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) + delay_ns
);
124 timer
->running
= true;
128 igb_intmgr_timer_resume(IGBIntrDelayTimer
*timer
)
130 if (timer
->running
) {
131 igb_intrmgr_rearm_timer(timer
);
136 igb_intmgr_timer_pause(IGBIntrDelayTimer
*timer
)
138 if (timer
->running
) {
139 timer_del(timer
->timer
);
144 igb_intrmgr_on_msix_throttling_timer(void *opaque
)
146 IGBIntrDelayTimer
*timer
= opaque
;
147 int idx
= timer
- &timer
->core
->eitr
[0];
149 timer
->running
= false;
151 trace_e1000e_irq_msix_notify_postponed_vec(idx
);
152 igb_msix_notify(timer
->core
, idx
);
156 igb_intrmgr_initialize_all_timers(IGBCore
*core
, bool create
)
160 for (i
= 0; i
< IGB_INTR_NUM
; i
++) {
161 core
->eitr
[i
].core
= core
;
162 core
->eitr
[i
].delay_reg
= EITR0
+ i
;
163 core
->eitr
[i
].delay_resolution_ns
= E1000_INTR_DELAY_NS_RES
;
170 for (i
= 0; i
< IGB_INTR_NUM
; i
++) {
171 core
->eitr
[i
].timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
,
172 igb_intrmgr_on_msix_throttling_timer
,
178 igb_intrmgr_resume(IGBCore
*core
)
182 for (i
= 0; i
< IGB_INTR_NUM
; i
++) {
183 igb_intmgr_timer_resume(&core
->eitr
[i
]);
188 igb_intrmgr_pause(IGBCore
*core
)
192 for (i
= 0; i
< IGB_INTR_NUM
; i
++) {
193 igb_intmgr_timer_pause(&core
->eitr
[i
]);
198 igb_intrmgr_reset(IGBCore
*core
)
202 for (i
= 0; i
< IGB_INTR_NUM
; i
++) {
203 if (core
->eitr
[i
].running
) {
204 timer_del(core
->eitr
[i
].timer
);
205 igb_intrmgr_on_msix_throttling_timer(&core
->eitr
[i
]);
211 igb_intrmgr_pci_unint(IGBCore
*core
)
215 for (i
= 0; i
< IGB_INTR_NUM
; i
++) {
216 timer_free(core
->eitr
[i
].timer
);
221 igb_intrmgr_pci_realize(IGBCore
*core
)
223 igb_intrmgr_initialize_all_timers(core
, true);
227 igb_rx_csum_enabled(IGBCore
*core
)
229 return (core
->mac
[RXCSUM
] & E1000_RXCSUM_PCSD
) ? false : true;
233 igb_rx_use_legacy_descriptor(IGBCore
*core
)
236 * TODO: If SRRCTL[n],DESCTYPE = 000b, the 82576 uses the legacy Rx
243 igb_rss_enabled(IGBCore
*core
)
245 return (core
->mac
[MRQC
] & 3) == E1000_MRQC_ENABLE_RSS_MQ
&&
246 !igb_rx_csum_enabled(core
) &&
247 !igb_rx_use_legacy_descriptor(core
);
250 typedef struct E1000E_RSSInfo_st
{
258 igb_rss_get_hash_type(IGBCore
*core
, struct NetRxPkt
*pkt
)
261 EthL4HdrProto l4hdr_proto
;
263 assert(igb_rss_enabled(core
));
265 net_rx_pkt_get_protocols(pkt
, &hasip4
, &hasip6
, &l4hdr_proto
);
268 trace_e1000e_rx_rss_ip4(l4hdr_proto
, core
->mac
[MRQC
],
269 E1000_MRQC_EN_TCPIPV4(core
->mac
[MRQC
]),
270 E1000_MRQC_EN_IPV4(core
->mac
[MRQC
]));
272 if (l4hdr_proto
== ETH_L4_HDR_PROTO_TCP
&&
273 E1000_MRQC_EN_TCPIPV4(core
->mac
[MRQC
])) {
274 return E1000_MRQ_RSS_TYPE_IPV4TCP
;
277 if (E1000_MRQC_EN_IPV4(core
->mac
[MRQC
])) {
278 return E1000_MRQ_RSS_TYPE_IPV4
;
281 eth_ip6_hdr_info
*ip6info
= net_rx_pkt_get_ip6_info(pkt
);
283 bool ex_dis
= core
->mac
[RFCTL
] & E1000_RFCTL_IPV6_EX_DIS
;
284 bool new_ex_dis
= core
->mac
[RFCTL
] & E1000_RFCTL_NEW_IPV6_EXT_DIS
;
287 * Following two traces must not be combined because resulting
288 * event will have 11 arguments totally and some trace backends
289 * (at least "ust") have limitation of maximum 10 arguments per
290 * event. Events with more arguments fail to compile for
291 * backends like these.
293 trace_e1000e_rx_rss_ip6_rfctl(core
->mac
[RFCTL
]);
294 trace_e1000e_rx_rss_ip6(ex_dis
, new_ex_dis
, l4hdr_proto
,
295 ip6info
->has_ext_hdrs
,
296 ip6info
->rss_ex_dst_valid
,
297 ip6info
->rss_ex_src_valid
,
299 E1000_MRQC_EN_TCPIPV6(core
->mac
[MRQC
]),
300 E1000_MRQC_EN_IPV6EX(core
->mac
[MRQC
]),
301 E1000_MRQC_EN_IPV6(core
->mac
[MRQC
]));
303 if ((!ex_dis
|| !ip6info
->has_ext_hdrs
) &&
304 (!new_ex_dis
|| !(ip6info
->rss_ex_dst_valid
||
305 ip6info
->rss_ex_src_valid
))) {
307 if (l4hdr_proto
== ETH_L4_HDR_PROTO_TCP
&&
308 E1000_MRQC_EN_TCPIPV6(core
->mac
[MRQC
])) {
309 return E1000_MRQ_RSS_TYPE_IPV6TCP
;
312 if (E1000_MRQC_EN_IPV6EX(core
->mac
[MRQC
])) {
313 return E1000_MRQ_RSS_TYPE_IPV6EX
;
318 if (E1000_MRQC_EN_IPV6(core
->mac
[MRQC
])) {
319 return E1000_MRQ_RSS_TYPE_IPV6
;
324 return E1000_MRQ_RSS_TYPE_NONE
;
328 igb_rss_calc_hash(IGBCore
*core
, struct NetRxPkt
*pkt
, E1000E_RSSInfo
*info
)
330 NetRxPktRssType type
;
332 assert(igb_rss_enabled(core
));
334 switch (info
->type
) {
335 case E1000_MRQ_RSS_TYPE_IPV4
:
336 type
= NetPktRssIpV4
;
338 case E1000_MRQ_RSS_TYPE_IPV4TCP
:
339 type
= NetPktRssIpV4Tcp
;
341 case E1000_MRQ_RSS_TYPE_IPV6TCP
:
342 type
= NetPktRssIpV6TcpEx
;
344 case E1000_MRQ_RSS_TYPE_IPV6
:
345 type
= NetPktRssIpV6
;
347 case E1000_MRQ_RSS_TYPE_IPV6EX
:
348 type
= NetPktRssIpV6Ex
;
355 return net_rx_pkt_calc_rss_hash(pkt
, type
, (uint8_t *) &core
->mac
[RSSRK
]);
359 igb_rss_parse_packet(IGBCore
*core
, struct NetRxPkt
*pkt
, bool tx
,
360 E1000E_RSSInfo
*info
)
362 trace_e1000e_rx_rss_started();
364 if (tx
|| !igb_rss_enabled(core
)) {
365 info
->enabled
= false;
369 trace_e1000e_rx_rss_disabled();
373 info
->enabled
= true;
375 info
->type
= igb_rss_get_hash_type(core
, pkt
);
377 trace_e1000e_rx_rss_type(info
->type
);
379 if (info
->type
== E1000_MRQ_RSS_TYPE_NONE
) {
385 info
->hash
= igb_rss_calc_hash(core
, pkt
, info
);
386 info
->queue
= E1000_RSS_QUEUE(&core
->mac
[RETA
], info
->hash
);
390 igb_setup_tx_offloads(IGBCore
*core
, struct igb_tx
*tx
)
392 if (tx
->first_cmd_type_len
& E1000_ADVTXD_DCMD_TSE
) {
393 uint32_t idx
= (tx
->first_olinfo_status
>> 4) & 1;
394 uint32_t mss
= tx
->ctx
[idx
].mss_l4len_idx
>> 16;
395 if (!net_tx_pkt_build_vheader(tx
->tx_pkt
, true, true, mss
)) {
399 net_tx_pkt_update_ip_checksums(tx
->tx_pkt
);
400 e1000x_inc_reg_if_not_full(core
->mac
, TSCTC
);
404 if (tx
->first_olinfo_status
& E1000_ADVTXD_POTS_TXSM
) {
405 if (!net_tx_pkt_build_vheader(tx
->tx_pkt
, false, true, 0)) {
410 if (tx
->first_olinfo_status
& E1000_ADVTXD_POTS_IXSM
) {
411 net_tx_pkt_update_ip_hdr_checksum(tx
->tx_pkt
);
417 static void igb_tx_pkt_mac_callback(void *core
,
418 const struct iovec
*iov
,
420 const struct iovec
*virt_iov
,
423 igb_receive_internal(core
, virt_iov
, virt_iovcnt
, true, NULL
);
426 static void igb_tx_pkt_vmdq_callback(void *opaque
,
427 const struct iovec
*iov
,
429 const struct iovec
*virt_iov
,
432 IGBTxPktVmdqCallbackContext
*context
= opaque
;
435 igb_receive_internal(context
->core
, virt_iov
, virt_iovcnt
, true,
439 if (context
->core
->has_vnet
) {
440 qemu_sendv_packet(context
->nc
, virt_iov
, virt_iovcnt
);
442 qemu_sendv_packet(context
->nc
, iov
, iovcnt
);
447 /* TX Packets Switching (7.10.3.6) */
448 static bool igb_tx_pkt_switch(IGBCore
*core
, struct igb_tx
*tx
,
451 IGBTxPktVmdqCallbackContext context
;
453 /* TX switching is only used to serve VM to VM traffic. */
454 if (!(core
->mac
[MRQC
] & 1)) {
458 /* TX switching requires DTXSWC.Loopback_en bit enabled. */
459 if (!(core
->mac
[DTXSWC
] & E1000_DTXSWC_VMDQ_LOOPBACK_EN
)) {
466 return net_tx_pkt_send_custom(tx
->tx_pkt
, false,
467 igb_tx_pkt_vmdq_callback
, &context
);
470 return net_tx_pkt_send(tx
->tx_pkt
, nc
);
474 igb_tx_pkt_send(IGBCore
*core
, struct igb_tx
*tx
, int queue_index
)
476 int target_queue
= MIN(core
->max_queue_num
, queue_index
);
477 NetClientState
*queue
= qemu_get_subqueue(core
->owner_nic
, target_queue
);
479 if (!igb_setup_tx_offloads(core
, tx
)) {
483 net_tx_pkt_dump(tx
->tx_pkt
);
485 if ((core
->phy
[MII_BMCR
] & MII_BMCR_LOOPBACK
) ||
486 ((core
->mac
[RCTL
] & E1000_RCTL_LBM_MAC
) == E1000_RCTL_LBM_MAC
)) {
487 return net_tx_pkt_send_custom(tx
->tx_pkt
, false,
488 igb_tx_pkt_mac_callback
, core
);
490 return igb_tx_pkt_switch(core
, tx
, queue
);
495 igb_on_tx_done_update_stats(IGBCore
*core
, struct NetTxPkt
*tx_pkt
)
497 static const int PTCregs
[6] = { PTC64
, PTC127
, PTC255
, PTC511
,
500 size_t tot_len
= net_tx_pkt_get_total_len(tx_pkt
) + 4;
502 e1000x_increase_size_stats(core
->mac
, PTCregs
, tot_len
);
503 e1000x_inc_reg_if_not_full(core
->mac
, TPT
);
504 e1000x_grow_8reg_if_not_full(core
->mac
, TOTL
, tot_len
);
506 switch (net_tx_pkt_get_packet_type(tx_pkt
)) {
508 e1000x_inc_reg_if_not_full(core
->mac
, BPTC
);
511 e1000x_inc_reg_if_not_full(core
->mac
, MPTC
);
516 g_assert_not_reached();
519 core
->mac
[GPTC
] = core
->mac
[TPT
];
520 core
->mac
[GOTCL
] = core
->mac
[TOTL
];
521 core
->mac
[GOTCH
] = core
->mac
[TOTH
];
525 igb_process_tx_desc(IGBCore
*core
,
528 union e1000_adv_tx_desc
*tx_desc
,
531 struct e1000_adv_tx_context_desc
*tx_ctx_desc
;
532 uint32_t cmd_type_len
;
534 uint64_t buffer_addr
;
537 cmd_type_len
= le32_to_cpu(tx_desc
->read
.cmd_type_len
);
539 if (cmd_type_len
& E1000_ADVTXD_DCMD_DEXT
) {
540 if ((cmd_type_len
& E1000_ADVTXD_DTYP_DATA
) ==
541 E1000_ADVTXD_DTYP_DATA
) {
542 /* advanced transmit data descriptor */
544 tx
->first_cmd_type_len
= cmd_type_len
;
545 tx
->first_olinfo_status
= le32_to_cpu(tx_desc
->read
.olinfo_status
);
548 } else if ((cmd_type_len
& E1000_ADVTXD_DTYP_CTXT
) ==
549 E1000_ADVTXD_DTYP_CTXT
) {
550 /* advanced transmit context descriptor */
551 tx_ctx_desc
= (struct e1000_adv_tx_context_desc
*)tx_desc
;
552 idx
= (le32_to_cpu(tx_ctx_desc
->mss_l4len_idx
) >> 4) & 1;
553 tx
->ctx
[idx
].vlan_macip_lens
= le32_to_cpu(tx_ctx_desc
->vlan_macip_lens
);
554 tx
->ctx
[idx
].seqnum_seed
= le32_to_cpu(tx_ctx_desc
->seqnum_seed
);
555 tx
->ctx
[idx
].type_tucmd_mlhl
= le32_to_cpu(tx_ctx_desc
->type_tucmd_mlhl
);
556 tx
->ctx
[idx
].mss_l4len_idx
= le32_to_cpu(tx_ctx_desc
->mss_l4len_idx
);
559 /* unknown descriptor type */
563 /* legacy descriptor */
565 /* TODO: Implement a support for legacy descriptors (7.2.2.1). */
568 buffer_addr
= le64_to_cpu(tx_desc
->read
.buffer_addr
);
569 length
= cmd_type_len
& 0xFFFF;
572 if (!net_tx_pkt_add_raw_fragment(tx
->tx_pkt
, buffer_addr
, length
)) {
577 if (cmd_type_len
& E1000_TXD_CMD_EOP
) {
578 if (!tx
->skip_cp
&& net_tx_pkt_parse(tx
->tx_pkt
)) {
579 if (cmd_type_len
& E1000_TXD_CMD_VLE
) {
580 idx
= (tx
->first_olinfo_status
>> 4) & 1;
581 uint16_t vlan
= tx
->ctx
[idx
].vlan_macip_lens
>> 16;
582 uint16_t vet
= core
->mac
[VET
] & 0xffff;
583 net_tx_pkt_setup_vlan_header_ex(tx
->tx_pkt
, vlan
, vet
);
585 if (igb_tx_pkt_send(core
, tx
, queue_index
)) {
586 igb_on_tx_done_update_stats(core
, tx
->tx_pkt
);
592 net_tx_pkt_reset(tx
->tx_pkt
, dev
);
596 static uint32_t igb_tx_wb_eic(IGBCore
*core
, int queue_idx
)
600 n
= igb_ivar_entry_tx(queue_idx
);
601 ent
= (core
->mac
[IVAR0
+ n
/ 4] >> (8 * (n
% 4))) & 0xff;
603 return (ent
& E1000_IVAR_VALID
) ? BIT(ent
& 0x1f) : 0;
606 static uint32_t igb_rx_wb_eic(IGBCore
*core
, int queue_idx
)
610 n
= igb_ivar_entry_rx(queue_idx
);
611 ent
= (core
->mac
[IVAR0
+ n
/ 4] >> (8 * (n
% 4))) & 0xff;
613 return (ent
& E1000_IVAR_VALID
) ? BIT(ent
& 0x1f) : 0;
616 typedef struct E1000E_RingInfo_st
{
626 igb_ring_empty(IGBCore
*core
, const E1000E_RingInfo
*r
)
628 return core
->mac
[r
->dh
] == core
->mac
[r
->dt
] ||
629 core
->mac
[r
->dt
] >= core
->mac
[r
->dlen
] / E1000_RING_DESC_LEN
;
632 static inline uint64_t
633 igb_ring_base(IGBCore
*core
, const E1000E_RingInfo
*r
)
635 uint64_t bah
= core
->mac
[r
->dbah
];
636 uint64_t bal
= core
->mac
[r
->dbal
];
638 return (bah
<< 32) + bal
;
641 static inline uint64_t
642 igb_ring_head_descr(IGBCore
*core
, const E1000E_RingInfo
*r
)
644 return igb_ring_base(core
, r
) + E1000_RING_DESC_LEN
* core
->mac
[r
->dh
];
648 igb_ring_advance(IGBCore
*core
, const E1000E_RingInfo
*r
, uint32_t count
)
650 core
->mac
[r
->dh
] += count
;
652 if (core
->mac
[r
->dh
] * E1000_RING_DESC_LEN
>= core
->mac
[r
->dlen
]) {
653 core
->mac
[r
->dh
] = 0;
657 static inline uint32_t
658 igb_ring_free_descr_num(IGBCore
*core
, const E1000E_RingInfo
*r
)
660 trace_e1000e_ring_free_space(r
->idx
, core
->mac
[r
->dlen
],
661 core
->mac
[r
->dh
], core
->mac
[r
->dt
]);
663 if (core
->mac
[r
->dh
] <= core
->mac
[r
->dt
]) {
664 return core
->mac
[r
->dt
] - core
->mac
[r
->dh
];
667 if (core
->mac
[r
->dh
] > core
->mac
[r
->dt
]) {
668 return core
->mac
[r
->dlen
] / E1000_RING_DESC_LEN
+
669 core
->mac
[r
->dt
] - core
->mac
[r
->dh
];
672 g_assert_not_reached();
677 igb_ring_enabled(IGBCore
*core
, const E1000E_RingInfo
*r
)
679 return core
->mac
[r
->dlen
] > 0;
682 typedef struct IGB_TxRing_st
{
683 const E1000E_RingInfo
*i
;
688 igb_mq_queue_idx(int base_reg_idx
, int reg_idx
)
690 return (reg_idx
- base_reg_idx
) / 16;
694 igb_tx_ring_init(IGBCore
*core
, IGB_TxRing
*txr
, int idx
)
696 static const E1000E_RingInfo i
[IGB_NUM_QUEUES
] = {
697 { TDBAH0
, TDBAL0
, TDLEN0
, TDH0
, TDT0
, 0 },
698 { TDBAH1
, TDBAL1
, TDLEN1
, TDH1
, TDT1
, 1 },
699 { TDBAH2
, TDBAL2
, TDLEN2
, TDH2
, TDT2
, 2 },
700 { TDBAH3
, TDBAL3
, TDLEN3
, TDH3
, TDT3
, 3 },
701 { TDBAH4
, TDBAL4
, TDLEN4
, TDH4
, TDT4
, 4 },
702 { TDBAH5
, TDBAL5
, TDLEN5
, TDH5
, TDT5
, 5 },
703 { TDBAH6
, TDBAL6
, TDLEN6
, TDH6
, TDT6
, 6 },
704 { TDBAH7
, TDBAL7
, TDLEN7
, TDH7
, TDT7
, 7 },
705 { TDBAH8
, TDBAL8
, TDLEN8
, TDH8
, TDT8
, 8 },
706 { TDBAH9
, TDBAL9
, TDLEN9
, TDH9
, TDT9
, 9 },
707 { TDBAH10
, TDBAL10
, TDLEN10
, TDH10
, TDT10
, 10 },
708 { TDBAH11
, TDBAL11
, TDLEN11
, TDH11
, TDT11
, 11 },
709 { TDBAH12
, TDBAL12
, TDLEN12
, TDH12
, TDT12
, 12 },
710 { TDBAH13
, TDBAL13
, TDLEN13
, TDH13
, TDT13
, 13 },
711 { TDBAH14
, TDBAL14
, TDLEN14
, TDH14
, TDT14
, 14 },
712 { TDBAH15
, TDBAL15
, TDLEN15
, TDH15
, TDT15
, 15 }
715 assert(idx
< ARRAY_SIZE(i
));
718 txr
->tx
= &core
->tx
[idx
];
721 typedef struct E1000E_RxRing_st
{
722 const E1000E_RingInfo
*i
;
726 igb_rx_ring_init(IGBCore
*core
, E1000E_RxRing
*rxr
, int idx
)
728 static const E1000E_RingInfo i
[IGB_NUM_QUEUES
] = {
729 { RDBAH0
, RDBAL0
, RDLEN0
, RDH0
, RDT0
, 0 },
730 { RDBAH1
, RDBAL1
, RDLEN1
, RDH1
, RDT1
, 1 },
731 { RDBAH2
, RDBAL2
, RDLEN2
, RDH2
, RDT2
, 2 },
732 { RDBAH3
, RDBAL3
, RDLEN3
, RDH3
, RDT3
, 3 },
733 { RDBAH4
, RDBAL4
, RDLEN4
, RDH4
, RDT4
, 4 },
734 { RDBAH5
, RDBAL5
, RDLEN5
, RDH5
, RDT5
, 5 },
735 { RDBAH6
, RDBAL6
, RDLEN6
, RDH6
, RDT6
, 6 },
736 { RDBAH7
, RDBAL7
, RDLEN7
, RDH7
, RDT7
, 7 },
737 { RDBAH8
, RDBAL8
, RDLEN8
, RDH8
, RDT8
, 8 },
738 { RDBAH9
, RDBAL9
, RDLEN9
, RDH9
, RDT9
, 9 },
739 { RDBAH10
, RDBAL10
, RDLEN10
, RDH10
, RDT10
, 10 },
740 { RDBAH11
, RDBAL11
, RDLEN11
, RDH11
, RDT11
, 11 },
741 { RDBAH12
, RDBAL12
, RDLEN12
, RDH12
, RDT12
, 12 },
742 { RDBAH13
, RDBAL13
, RDLEN13
, RDH13
, RDT13
, 13 },
743 { RDBAH14
, RDBAL14
, RDLEN14
, RDH14
, RDT14
, 14 },
744 { RDBAH15
, RDBAL15
, RDLEN15
, RDH15
, RDT15
, 15 }
747 assert(idx
< ARRAY_SIZE(i
));
753 igb_txdesc_writeback(IGBCore
*core
, dma_addr_t base
,
754 union e1000_adv_tx_desc
*tx_desc
,
755 const E1000E_RingInfo
*txi
)
758 uint32_t cmd_type_len
= le32_to_cpu(tx_desc
->read
.cmd_type_len
);
761 tdwba
= core
->mac
[E1000_TDWBAL(txi
->idx
) >> 2];
762 tdwba
|= (uint64_t)core
->mac
[E1000_TDWBAH(txi
->idx
) >> 2] << 32;
764 if (!(cmd_type_len
& E1000_TXD_CMD_RS
)) {
768 d
= pcie_sriov_get_vf_at_index(core
->owner
, txi
->idx
% 8);
774 uint32_t buffer
= cpu_to_le32(core
->mac
[txi
->dh
]);
775 pci_dma_write(d
, tdwba
& ~3, &buffer
, sizeof(buffer
));
777 uint32_t status
= le32_to_cpu(tx_desc
->wb
.status
) | E1000_TXD_STAT_DD
;
779 tx_desc
->wb
.status
= cpu_to_le32(status
);
780 pci_dma_write(d
, base
+ offsetof(union e1000_adv_tx_desc
, wb
),
781 &tx_desc
->wb
, sizeof(tx_desc
->wb
));
784 return igb_tx_wb_eic(core
, txi
->idx
);
788 igb_start_xmit(IGBCore
*core
, const IGB_TxRing
*txr
)
792 union e1000_adv_tx_desc desc
;
793 const E1000E_RingInfo
*txi
= txr
->i
;
796 /* TODO: check if the queue itself is enabled too. */
797 if (!(core
->mac
[TCTL
] & E1000_TCTL_EN
)) {
798 trace_e1000e_tx_disabled();
802 d
= pcie_sriov_get_vf_at_index(core
->owner
, txi
->idx
% 8);
807 net_tx_pkt_reset(txr
->tx
->tx_pkt
, d
);
809 while (!igb_ring_empty(core
, txi
)) {
810 base
= igb_ring_head_descr(core
, txi
);
812 pci_dma_read(d
, base
, &desc
, sizeof(desc
));
814 trace_e1000e_tx_descr((void *)(intptr_t)desc
.read
.buffer_addr
,
815 desc
.read
.cmd_type_len
, desc
.wb
.status
);
817 igb_process_tx_desc(core
, d
, txr
->tx
, &desc
, txi
->idx
);
818 igb_ring_advance(core
, txi
, 1);
819 eic
|= igb_txdesc_writeback(core
, base
, &desc
, txi
);
823 core
->mac
[EICR
] |= eic
;
824 igb_set_interrupt_cause(core
, E1000_ICR_TXDW
);
829 igb_rxbufsize(IGBCore
*core
, const E1000E_RingInfo
*r
)
831 uint32_t srrctl
= core
->mac
[E1000_SRRCTL(r
->idx
) >> 2];
832 uint32_t bsizepkt
= srrctl
& E1000_SRRCTL_BSIZEPKT_MASK
;
834 return bsizepkt
<< E1000_SRRCTL_BSIZEPKT_SHIFT
;
837 return e1000x_rxbufsize(core
->mac
[RCTL
]);
841 igb_has_rxbufs(IGBCore
*core
, const E1000E_RingInfo
*r
, size_t total_size
)
843 uint32_t bufs
= igb_ring_free_descr_num(core
, r
);
844 uint32_t bufsize
= igb_rxbufsize(core
, r
);
846 trace_e1000e_rx_has_buffers(r
->idx
, bufs
, total_size
, bufsize
);
848 return total_size
<= bufs
/ (core
->rx_desc_len
/ E1000_MIN_RX_DESC_LEN
) *
853 igb_start_recv(IGBCore
*core
)
857 trace_e1000e_rx_start_recv();
859 for (i
= 0; i
<= core
->max_queue_num
; i
++) {
860 qemu_flush_queued_packets(qemu_get_subqueue(core
->owner_nic
, i
));
865 igb_can_receive(IGBCore
*core
)
869 if (!e1000x_rx_ready(core
->owner
, core
->mac
)) {
873 for (i
= 0; i
< IGB_NUM_QUEUES
; i
++) {
876 igb_rx_ring_init(core
, &rxr
, i
);
877 if (igb_ring_enabled(core
, rxr
.i
) && igb_has_rxbufs(core
, rxr
.i
, 1)) {
878 trace_e1000e_rx_can_recv();
883 trace_e1000e_rx_can_recv_rings_full();
888 igb_receive(IGBCore
*core
, const uint8_t *buf
, size_t size
)
890 const struct iovec iov
= {
891 .iov_base
= (uint8_t *)buf
,
895 return igb_receive_iov(core
, &iov
, 1);
899 igb_rx_l3_cso_enabled(IGBCore
*core
)
901 return !!(core
->mac
[RXCSUM
] & E1000_RXCSUM_IPOFLD
);
905 igb_rx_l4_cso_enabled(IGBCore
*core
)
907 return !!(core
->mac
[RXCSUM
] & E1000_RXCSUM_TUOFLD
);
910 static uint16_t igb_receive_assign(IGBCore
*core
, const struct eth_header
*ehdr
,
911 E1000E_RSSInfo
*rss_info
, bool *external_tx
)
913 static const int ta_shift
[] = { 4, 3, 2, 0 };
914 uint32_t f
, ra
[2], *macp
, rctl
= core
->mac
[RCTL
];
916 uint16_t vid
= lduw_be_p(&PKT_GET_VLAN_HDR(ehdr
)->h_tci
) & VLAN_VID_MASK
;
917 bool accepted
= false;
920 memset(rss_info
, 0, sizeof(E1000E_RSSInfo
));
926 if (e1000x_is_vlan_packet(ehdr
, core
->mac
[VET
] & 0xffff) &&
927 e1000x_vlan_rx_filter_enabled(core
->mac
)) {
929 ldl_le_p((uint32_t *)(core
->mac
+ VFTA
) +
930 ((vid
>> E1000_VFTA_ENTRY_SHIFT
) & E1000_VFTA_ENTRY_MASK
));
931 if ((vfta
& (1 << (vid
& E1000_VFTA_ENTRY_BIT_SHIFT_MASK
))) == 0) {
932 trace_e1000e_rx_flt_vlan_mismatch(vid
);
935 trace_e1000e_rx_flt_vlan_match(vid
);
939 if (core
->mac
[MRQC
] & 1) {
940 if (is_broadcast_ether_addr(ehdr
->h_dest
)) {
941 for (i
= 0; i
< 8; i
++) {
942 if (core
->mac
[VMOLR0
+ i
] & E1000_VMOLR_BAM
) {
947 for (macp
= core
->mac
+ RA
; macp
< core
->mac
+ RA
+ 32; macp
+= 2) {
948 if (!(macp
[1] & E1000_RAH_AV
)) {
951 ra
[0] = cpu_to_le32(macp
[0]);
952 ra
[1] = cpu_to_le32(macp
[1]);
953 if (!memcmp(ehdr
->h_dest
, (uint8_t *)ra
, ETH_ALEN
)) {
954 queues
|= (macp
[1] & E1000_RAH_POOL_MASK
) / E1000_RAH_POOL_1
;
958 for (macp
= core
->mac
+ RA2
; macp
< core
->mac
+ RA2
+ 16; macp
+= 2) {
959 if (!(macp
[1] & E1000_RAH_AV
)) {
962 ra
[0] = cpu_to_le32(macp
[0]);
963 ra
[1] = cpu_to_le32(macp
[1]);
964 if (!memcmp(ehdr
->h_dest
, (uint8_t *)ra
, ETH_ALEN
)) {
965 queues
|= (macp
[1] & E1000_RAH_POOL_MASK
) / E1000_RAH_POOL_1
;
970 macp
= core
->mac
+ (is_multicast_ether_addr(ehdr
->h_dest
) ? MTA
: UTA
);
972 f
= ta_shift
[(rctl
>> E1000_RCTL_MO_SHIFT
) & 3];
973 f
= (((ehdr
->h_dest
[5] << 8) | ehdr
->h_dest
[4]) >> f
) & 0xfff;
974 if (macp
[f
>> 5] & (1 << (f
& 0x1f))) {
975 for (i
= 0; i
< 8; i
++) {
976 if (core
->mac
[VMOLR0
+ i
] & E1000_VMOLR_ROMPE
) {
981 } else if (is_unicast_ether_addr(ehdr
->h_dest
) && external_tx
) {
982 *external_tx
= false;
986 if (e1000x_vlan_rx_filter_enabled(core
->mac
)) {
989 if (e1000x_is_vlan_packet(ehdr
, core
->mac
[VET
] & 0xffff)) {
990 for (i
= 0; i
< E1000_VLVF_ARRAY_SIZE
; i
++) {
991 if ((core
->mac
[VLVF0
+ i
] & E1000_VLVF_VLANID_MASK
) == vid
&&
992 (core
->mac
[VLVF0
+ i
] & E1000_VLVF_VLANID_ENABLE
)) {
993 uint32_t poolsel
= core
->mac
[VLVF0
+ i
] & E1000_VLVF_POOLSEL_MASK
;
994 mask
|= poolsel
>> E1000_VLVF_POOLSEL_SHIFT
;
998 for (i
= 0; i
< 8; i
++) {
999 if (core
->mac
[VMOLR0
+ i
] & E1000_VMOLR_AUPE
) {
1008 if (is_unicast_ether_addr(ehdr
->h_dest
) && !queues
&& !external_tx
&&
1009 !(core
->mac
[VT_CTL
] & E1000_VT_CTL_DISABLE_DEF_POOL
)) {
1010 uint32_t def_pl
= core
->mac
[VT_CTL
] & E1000_VT_CTL_DEFAULT_POOL_MASK
;
1011 queues
= BIT(def_pl
>> E1000_VT_CTL_DEFAULT_POOL_SHIFT
);
1014 igb_rss_parse_packet(core
, core
->rx_pkt
, external_tx
!= NULL
, rss_info
);
1015 if (rss_info
->queue
& 1) {
1019 switch (net_rx_pkt_get_packet_type(core
->rx_pkt
)) {
1021 if (rctl
& E1000_RCTL_UPE
) {
1022 accepted
= true; /* promiscuous ucast */
1027 if (rctl
& E1000_RCTL_BAM
) {
1028 accepted
= true; /* broadcast enabled */
1033 if (rctl
& E1000_RCTL_MPE
) {
1034 accepted
= true; /* promiscuous mcast */
1039 g_assert_not_reached();
1043 accepted
= e1000x_rx_group_filter(core
->mac
, ehdr
->h_dest
);
1047 for (macp
= core
->mac
+ RA2
; macp
< core
->mac
+ RA2
+ 16; macp
+= 2) {
1048 if (!(macp
[1] & E1000_RAH_AV
)) {
1051 ra
[0] = cpu_to_le32(macp
[0]);
1052 ra
[1] = cpu_to_le32(macp
[1]);
1053 if (!memcmp(ehdr
->h_dest
, (uint8_t *)ra
, ETH_ALEN
)) {
1054 trace_e1000x_rx_flt_ucast_match((int)(macp
- core
->mac
- RA2
) / 2,
1055 MAC_ARG(ehdr
->h_dest
));
1064 igb_rss_parse_packet(core
, core
->rx_pkt
, false, rss_info
);
1065 queues
= BIT(rss_info
->queue
);
1073 igb_read_lgcy_rx_descr(IGBCore
*core
, struct e1000_rx_desc
*desc
,
1076 *buff_addr
= le64_to_cpu(desc
->buffer_addr
);
1080 igb_read_adv_rx_descr(IGBCore
*core
, union e1000_adv_rx_desc
*desc
,
1083 *buff_addr
= le64_to_cpu(desc
->read
.pkt_addr
);
1087 igb_read_rx_descr(IGBCore
*core
, union e1000_rx_desc_union
*desc
,
1090 if (igb_rx_use_legacy_descriptor(core
)) {
1091 igb_read_lgcy_rx_descr(core
, &desc
->legacy
, buff_addr
);
1093 igb_read_adv_rx_descr(core
, &desc
->adv
, buff_addr
);
1098 igb_verify_csum_in_sw(IGBCore
*core
,
1099 struct NetRxPkt
*pkt
,
1100 uint32_t *status_flags
,
1101 EthL4HdrProto l4hdr_proto
)
1104 uint32_t csum_error
;
1106 if (igb_rx_l3_cso_enabled(core
)) {
1107 if (!net_rx_pkt_validate_l3_csum(pkt
, &csum_valid
)) {
1108 trace_e1000e_rx_metadata_l3_csum_validation_failed();
1110 csum_error
= csum_valid
? 0 : E1000_RXDEXT_STATERR_IPE
;
1111 *status_flags
|= E1000_RXD_STAT_IPCS
| csum_error
;
1114 trace_e1000e_rx_metadata_l3_cso_disabled();
1117 if (!igb_rx_l4_cso_enabled(core
)) {
1118 trace_e1000e_rx_metadata_l4_cso_disabled();
1122 if (!net_rx_pkt_validate_l4_csum(pkt
, &csum_valid
)) {
1123 trace_e1000e_rx_metadata_l4_csum_validation_failed();
1127 csum_error
= csum_valid
? 0 : E1000_RXDEXT_STATERR_TCPE
;
1128 *status_flags
|= E1000_RXD_STAT_TCPCS
| csum_error
;
1130 if (l4hdr_proto
== ETH_L4_HDR_PROTO_UDP
) {
1131 *status_flags
|= E1000_RXD_STAT_UDPCS
;
1136 igb_build_rx_metadata(IGBCore
*core
,
1137 struct NetRxPkt
*pkt
,
1139 const E1000E_RSSInfo
*rss_info
,
1140 uint16_t *pkt_info
, uint16_t *hdr_info
,
1142 uint32_t *status_flags
,
1146 struct virtio_net_hdr
*vhdr
;
1147 bool hasip4
, hasip6
;
1148 EthL4HdrProto l4hdr_proto
;
1151 *status_flags
= E1000_RXD_STAT_DD
;
1153 /* No additional metadata needed for non-EOP descriptors */
1154 /* TODO: EOP apply only to status so don't skip whole function. */
1159 *status_flags
|= E1000_RXD_STAT_EOP
;
1161 net_rx_pkt_get_protocols(pkt
, &hasip4
, &hasip6
, &l4hdr_proto
);
1162 trace_e1000e_rx_metadata_protocols(hasip4
, hasip6
, l4hdr_proto
);
1165 if (net_rx_pkt_is_vlan_stripped(pkt
)) {
1166 *status_flags
|= E1000_RXD_STAT_VP
;
1167 *vlan_tag
= cpu_to_le16(net_rx_pkt_get_vlan_tag(pkt
));
1168 trace_e1000e_rx_metadata_vlan(*vlan_tag
);
1171 /* Packet parsing results */
1172 if ((core
->mac
[RXCSUM
] & E1000_RXCSUM_PCSD
) != 0) {
1173 if (rss_info
->enabled
) {
1174 *rss
= cpu_to_le32(rss_info
->hash
);
1175 trace_igb_rx_metadata_rss(*rss
);
1177 } else if (hasip4
) {
1178 *status_flags
|= E1000_RXD_STAT_IPIDV
;
1179 *ip_id
= cpu_to_le16(net_rx_pkt_get_ip_id(pkt
));
1180 trace_e1000e_rx_metadata_ip_id(*ip_id
);
1183 if (l4hdr_proto
== ETH_L4_HDR_PROTO_TCP
&& net_rx_pkt_is_tcp_ack(pkt
)) {
1184 *status_flags
|= E1000_RXD_STAT_ACK
;
1185 trace_e1000e_rx_metadata_ack();
1188 if (hasip6
&& (core
->mac
[RFCTL
] & E1000_RFCTL_IPV6_DIS
)) {
1189 trace_e1000e_rx_metadata_ipv6_filtering_disabled();
1190 pkt_type
= E1000_RXD_PKT_MAC
;
1191 } else if (l4hdr_proto
== ETH_L4_HDR_PROTO_TCP
||
1192 l4hdr_proto
== ETH_L4_HDR_PROTO_UDP
) {
1193 pkt_type
= hasip4
? E1000_RXD_PKT_IP4_XDP
: E1000_RXD_PKT_IP6_XDP
;
1194 } else if (hasip4
|| hasip6
) {
1195 pkt_type
= hasip4
? E1000_RXD_PKT_IP4
: E1000_RXD_PKT_IP6
;
1197 pkt_type
= E1000_RXD_PKT_MAC
;
1200 trace_e1000e_rx_metadata_pkt_type(pkt_type
);
1203 if (rss_info
->enabled
) {
1204 *pkt_info
= rss_info
->type
;
1207 *pkt_info
|= (pkt_type
<< 4);
1209 *status_flags
|= E1000_RXD_PKT_TYPE(pkt_type
);
1216 /* RX CSO information */
1217 if (hasip6
&& (core
->mac
[RFCTL
] & E1000_RFCTL_IPV6_XSUM_DIS
)) {
1218 trace_e1000e_rx_metadata_ipv6_sum_disabled();
1222 vhdr
= net_rx_pkt_get_vhdr(pkt
);
1224 if (!(vhdr
->flags
& VIRTIO_NET_HDR_F_DATA_VALID
) &&
1225 !(vhdr
->flags
& VIRTIO_NET_HDR_F_NEEDS_CSUM
)) {
1226 trace_e1000e_rx_metadata_virthdr_no_csum_info();
1227 igb_verify_csum_in_sw(core
, pkt
, status_flags
, l4hdr_proto
);
1231 if (igb_rx_l3_cso_enabled(core
)) {
1232 *status_flags
|= hasip4
? E1000_RXD_STAT_IPCS
: 0;
1234 trace_e1000e_rx_metadata_l3_cso_disabled();
1237 if (igb_rx_l4_cso_enabled(core
)) {
1238 switch (l4hdr_proto
) {
1239 case ETH_L4_HDR_PROTO_TCP
:
1240 *status_flags
|= E1000_RXD_STAT_TCPCS
;
1243 case ETH_L4_HDR_PROTO_UDP
:
1244 *status_flags
|= E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
;
1251 trace_e1000e_rx_metadata_l4_cso_disabled();
1254 trace_e1000e_rx_metadata_status_flags(*status_flags
);
1257 *status_flags
= cpu_to_le32(*status_flags
);
1261 igb_write_lgcy_rx_descr(IGBCore
*core
, struct e1000_rx_desc
*desc
,
1262 struct NetRxPkt
*pkt
,
1263 const E1000E_RSSInfo
*rss_info
,
1266 uint32_t status_flags
, rss
;
1269 assert(!rss_info
->enabled
);
1270 desc
->length
= cpu_to_le16(length
);
1273 igb_build_rx_metadata(core
, pkt
, pkt
!= NULL
,
1276 &status_flags
, &ip_id
,
1278 desc
->errors
= (uint8_t) (le32_to_cpu(status_flags
) >> 24);
1279 desc
->status
= (uint8_t) le32_to_cpu(status_flags
);
1283 igb_write_adv_rx_descr(IGBCore
*core
, union e1000_adv_rx_desc
*desc
,
1284 struct NetRxPkt
*pkt
,
1285 const E1000E_RSSInfo
*rss_info
,
1288 memset(&desc
->wb
, 0, sizeof(desc
->wb
));
1290 desc
->wb
.upper
.length
= cpu_to_le16(length
);
1292 igb_build_rx_metadata(core
, pkt
, pkt
!= NULL
,
1294 &desc
->wb
.lower
.lo_dword
.pkt_info
,
1295 &desc
->wb
.lower
.lo_dword
.hdr_info
,
1296 &desc
->wb
.lower
.hi_dword
.rss
,
1297 &desc
->wb
.upper
.status_error
,
1298 &desc
->wb
.lower
.hi_dword
.csum_ip
.ip_id
,
1299 &desc
->wb
.upper
.vlan
);
1303 igb_write_rx_descr(IGBCore
*core
, union e1000_rx_desc_union
*desc
,
1304 struct NetRxPkt
*pkt
, const E1000E_RSSInfo
*rss_info
, uint16_t length
)
1306 if (igb_rx_use_legacy_descriptor(core
)) {
1307 igb_write_lgcy_rx_descr(core
, &desc
->legacy
, pkt
, rss_info
, length
);
1309 igb_write_adv_rx_descr(core
, &desc
->adv
, pkt
, rss_info
, length
);
1314 igb_pci_dma_write_rx_desc(IGBCore
*core
, PCIDevice
*dev
, dma_addr_t addr
,
1315 union e1000_rx_desc_union
*desc
, dma_addr_t len
)
1317 if (igb_rx_use_legacy_descriptor(core
)) {
1318 struct e1000_rx_desc
*d
= &desc
->legacy
;
1319 size_t offset
= offsetof(struct e1000_rx_desc
, status
);
1320 uint8_t status
= d
->status
;
1322 d
->status
&= ~E1000_RXD_STAT_DD
;
1323 pci_dma_write(dev
, addr
, desc
, len
);
1325 if (status
& E1000_RXD_STAT_DD
) {
1327 pci_dma_write(dev
, addr
+ offset
, &status
, sizeof(status
));
1330 union e1000_adv_rx_desc
*d
= &desc
->adv
;
1332 offsetof(union e1000_adv_rx_desc
, wb
.upper
.status_error
);
1333 uint32_t status
= d
->wb
.upper
.status_error
;
1335 d
->wb
.upper
.status_error
&= ~E1000_RXD_STAT_DD
;
1336 pci_dma_write(dev
, addr
, desc
, len
);
1338 if (status
& E1000_RXD_STAT_DD
) {
1339 d
->wb
.upper
.status_error
= status
;
1340 pci_dma_write(dev
, addr
+ offset
, &status
, sizeof(status
));
1346 igb_write_to_rx_buffers(IGBCore
*core
,
1351 dma_addr_t data_len
)
1353 trace_igb_rx_desc_buff_write(ba
, *written
, data
, data_len
);
1354 pci_dma_write(d
, ba
+ *written
, data
, data_len
);
1355 *written
+= data_len
;
1359 igb_update_rx_stats(IGBCore
*core
, size_t data_size
, size_t data_fcs_size
)
1361 e1000x_update_rx_total_stats(core
->mac
, data_size
, data_fcs_size
);
1363 switch (net_rx_pkt_get_packet_type(core
->rx_pkt
)) {
1365 e1000x_inc_reg_if_not_full(core
->mac
, BPRC
);
1369 e1000x_inc_reg_if_not_full(core
->mac
, MPRC
);
1378 igb_rx_descr_threshold_hit(IGBCore
*core
, const E1000E_RingInfo
*rxi
)
1380 return igb_ring_free_descr_num(core
, rxi
) ==
1381 ((core
->mac
[E1000_SRRCTL(rxi
->idx
) >> 2] >> 20) & 31) * 16;
1385 igb_write_packet_to_guest(IGBCore
*core
, struct NetRxPkt
*pkt
,
1386 const E1000E_RxRing
*rxr
,
1387 const E1000E_RSSInfo
*rss_info
)
1391 union e1000_rx_desc_union desc
;
1393 size_t desc_offset
= 0;
1396 struct iovec
*iov
= net_rx_pkt_get_iovec(pkt
);
1397 size_t size
= net_rx_pkt_get_total_len(pkt
);
1398 size_t total_size
= size
+ e1000x_fcs_len(core
->mac
);
1399 const E1000E_RingInfo
*rxi
= rxr
->i
;
1400 size_t bufsize
= igb_rxbufsize(core
, rxi
);
1402 d
= pcie_sriov_get_vf_at_index(core
->owner
, rxi
->idx
% 8);
1409 uint16_t written
= 0;
1410 bool is_last
= false;
1412 desc_size
= total_size
- desc_offset
;
1414 if (desc_size
> bufsize
) {
1415 desc_size
= bufsize
;
1418 if (igb_ring_empty(core
, rxi
)) {
1422 base
= igb_ring_head_descr(core
, rxi
);
1424 pci_dma_read(d
, base
, &desc
, core
->rx_desc_len
);
1426 trace_e1000e_rx_descr(rxi
->idx
, base
, core
->rx_desc_len
);
1428 igb_read_rx_descr(core
, &desc
, &ba
);
1431 if (desc_offset
< size
) {
1432 static const uint32_t fcs_pad
;
1434 size_t copy_size
= size
- desc_offset
;
1435 if (copy_size
> bufsize
) {
1436 copy_size
= bufsize
;
1439 /* Copy packet payload */
1441 iov_copy
= MIN(copy_size
, iov
->iov_len
- iov_ofs
);
1443 igb_write_to_rx_buffers(core
, d
, ba
, &written
,
1444 iov
->iov_base
+ iov_ofs
, iov_copy
);
1446 copy_size
-= iov_copy
;
1447 iov_ofs
+= iov_copy
;
1448 if (iov_ofs
== iov
->iov_len
) {
1454 if (desc_offset
+ desc_size
>= total_size
) {
1455 /* Simulate FCS checksum presence in the last descriptor */
1456 igb_write_to_rx_buffers(core
, d
, ba
, &written
,
1457 (const char *) &fcs_pad
, e1000x_fcs_len(core
->mac
));
1460 } else { /* as per intel docs; skip descriptors with null buf addr */
1461 trace_e1000e_rx_null_descriptor();
1463 desc_offset
+= desc_size
;
1464 if (desc_offset
>= total_size
) {
1468 igb_write_rx_descr(core
, &desc
, is_last
? core
->rx_pkt
: NULL
,
1470 igb_pci_dma_write_rx_desc(core
, d
, base
, &desc
, core
->rx_desc_len
);
1472 igb_ring_advance(core
, rxi
, core
->rx_desc_len
/ E1000_MIN_RX_DESC_LEN
);
1474 } while (desc_offset
< total_size
);
1476 igb_update_rx_stats(core
, size
, total_size
);
1480 igb_rx_fix_l4_csum(IGBCore
*core
, struct NetRxPkt
*pkt
)
1482 struct virtio_net_hdr
*vhdr
= net_rx_pkt_get_vhdr(pkt
);
1484 if (vhdr
->flags
& VIRTIO_NET_HDR_F_NEEDS_CSUM
) {
1485 net_rx_pkt_fix_l4_csum(pkt
);
1490 igb_receive_iov(IGBCore
*core
, const struct iovec
*iov
, int iovcnt
)
1492 return igb_receive_internal(core
, iov
, iovcnt
, core
->has_vnet
, NULL
);
1496 igb_receive_internal(IGBCore
*core
, const struct iovec
*iov
, int iovcnt
,
1497 bool has_vnet
, bool *external_tx
)
1499 static const int maximum_ethernet_hdr_len
= (ETH_HLEN
+ 4);
1501 uint16_t queues
= 0;
1503 uint8_t min_buf
[ETH_ZLEN
];
1504 struct iovec min_iov
;
1505 struct eth_header
*ehdr
;
1506 uint8_t *filter_buf
;
1507 size_t size
, orig_size
;
1510 E1000E_RSSInfo rss_info
;
1514 trace_e1000e_rx_receive_iov(iovcnt
);
1517 *external_tx
= true;
1520 if (!e1000x_hw_rx_enabled(core
->mac
)) {
1524 /* Pull virtio header in */
1526 net_rx_pkt_set_vhdr_iovec(core
->rx_pkt
, iov
, iovcnt
);
1527 iov_ofs
= sizeof(struct virtio_net_hdr
);
1529 net_rx_pkt_unset_vhdr(core
->rx_pkt
);
1532 filter_buf
= iov
->iov_base
+ iov_ofs
;
1533 orig_size
= iov_size(iov
, iovcnt
);
1534 size
= orig_size
- iov_ofs
;
1536 /* Pad to minimum Ethernet frame length */
1537 if (size
< sizeof(min_buf
)) {
1538 iov_to_buf(iov
, iovcnt
, iov_ofs
, min_buf
, size
);
1539 memset(&min_buf
[size
], 0, sizeof(min_buf
) - size
);
1540 e1000x_inc_reg_if_not_full(core
->mac
, RUC
);
1541 min_iov
.iov_base
= filter_buf
= min_buf
;
1542 min_iov
.iov_len
= size
= sizeof(min_buf
);
1546 } else if (iov
->iov_len
< maximum_ethernet_hdr_len
) {
1547 /* This is very unlikely, but may happen. */
1548 iov_to_buf(iov
, iovcnt
, iov_ofs
, min_buf
, maximum_ethernet_hdr_len
);
1549 filter_buf
= min_buf
;
1552 /* Discard oversized packets if !LPE and !SBP. */
1553 if (e1000x_is_oversized(core
->mac
, size
)) {
1557 ehdr
= PKT_GET_ETH_HDR(filter_buf
);
1558 net_rx_pkt_set_packet_type(core
->rx_pkt
, get_eth_packet_type(ehdr
));
1560 net_rx_pkt_attach_iovec_ex(core
->rx_pkt
, iov
, iovcnt
, iov_ofs
,
1561 e1000x_vlan_enabled(core
->mac
),
1562 core
->mac
[VET
] & 0xffff);
1564 queues
= igb_receive_assign(core
, ehdr
, &rss_info
, external_tx
);
1566 trace_e1000e_rx_flt_dropped();
1570 total_size
= net_rx_pkt_get_total_len(core
->rx_pkt
) +
1571 e1000x_fcs_len(core
->mac
);
1573 for (i
= 0; i
< IGB_NUM_QUEUES
; i
++) {
1574 if (!(queues
& BIT(i
))) {
1578 igb_rx_ring_init(core
, &rxr
, i
);
1580 if (!igb_has_rxbufs(core
, rxr
.i
, total_size
)) {
1582 trace_e1000e_rx_not_written_to_guest(rxr
.i
->idx
);
1586 n
|= E1000_ICR_RXDW
;
1588 igb_rx_fix_l4_csum(core
, core
->rx_pkt
);
1589 igb_write_packet_to_guest(core
, core
->rx_pkt
, &rxr
, &rss_info
);
1591 /* Check if receive descriptor minimum threshold hit */
1592 if (igb_rx_descr_threshold_hit(core
, rxr
.i
)) {
1593 n
|= E1000_ICS_RXDMT0
;
1596 core
->mac
[EICR
] |= igb_rx_wb_eic(core
, rxr
.i
->idx
);
1598 trace_e1000e_rx_written_to_guest(rxr
.i
->idx
);
1601 trace_e1000e_rx_interrupt_set(n
);
1602 igb_set_interrupt_cause(core
, n
);
1608 igb_have_autoneg(IGBCore
*core
)
1610 return core
->phy
[MII_BMCR
] & MII_BMCR_AUTOEN
;
1613 static void igb_update_flowctl_status(IGBCore
*core
)
1615 if (igb_have_autoneg(core
) && core
->phy
[MII_BMSR
] & MII_BMSR_AN_COMP
) {
1616 trace_e1000e_link_autoneg_flowctl(true);
1617 core
->mac
[CTRL
] |= E1000_CTRL_TFCE
| E1000_CTRL_RFCE
;
1619 trace_e1000e_link_autoneg_flowctl(false);
1624 igb_link_down(IGBCore
*core
)
1626 e1000x_update_regs_on_link_down(core
->mac
, core
->phy
);
1627 igb_update_flowctl_status(core
);
1631 igb_set_phy_ctrl(IGBCore
*core
, uint16_t val
)
1633 /* bits 0-5 reserved; MII_BMCR_[ANRESTART,RESET] are self clearing */
1634 core
->phy
[MII_BMCR
] = val
& ~(0x3f | MII_BMCR_RESET
| MII_BMCR_ANRESTART
);
1636 if ((val
& MII_BMCR_ANRESTART
) && igb_have_autoneg(core
)) {
1637 e1000x_restart_autoneg(core
->mac
, core
->phy
, core
->autoneg_timer
);
1641 void igb_core_set_link_status(IGBCore
*core
)
1643 NetClientState
*nc
= qemu_get_queue(core
->owner_nic
);
1644 uint32_t old_status
= core
->mac
[STATUS
];
1646 trace_e1000e_link_status_changed(nc
->link_down
? false : true);
1648 if (nc
->link_down
) {
1649 e1000x_update_regs_on_link_down(core
->mac
, core
->phy
);
1651 if (igb_have_autoneg(core
) &&
1652 !(core
->phy
[MII_BMSR
] & MII_BMSR_AN_COMP
)) {
1653 e1000x_restart_autoneg(core
->mac
, core
->phy
,
1654 core
->autoneg_timer
);
1656 e1000x_update_regs_on_link_up(core
->mac
, core
->phy
);
1657 igb_start_recv(core
);
1661 if (core
->mac
[STATUS
] != old_status
) {
1662 igb_set_interrupt_cause(core
, E1000_ICR_LSC
);
1667 igb_set_ctrl(IGBCore
*core
, int index
, uint32_t val
)
1669 trace_e1000e_core_ctrl_write(index
, val
);
1671 /* RST is self clearing */
1672 core
->mac
[CTRL
] = val
& ~E1000_CTRL_RST
;
1673 core
->mac
[CTRL_DUP
] = core
->mac
[CTRL
];
1675 trace_e1000e_link_set_params(
1676 !!(val
& E1000_CTRL_ASDE
),
1677 (val
& E1000_CTRL_SPD_SEL
) >> E1000_CTRL_SPD_SHIFT
,
1678 !!(val
& E1000_CTRL_FRCSPD
),
1679 !!(val
& E1000_CTRL_FRCDPX
),
1680 !!(val
& E1000_CTRL_RFCE
),
1681 !!(val
& E1000_CTRL_TFCE
));
1683 if (val
& E1000_CTRL_RST
) {
1684 trace_e1000e_core_ctrl_sw_reset();
1685 igb_reset(core
, true);
1688 if (val
& E1000_CTRL_PHY_RST
) {
1689 trace_e1000e_core_ctrl_phy_reset();
1690 core
->mac
[STATUS
] |= E1000_STATUS_PHYRA
;
1695 igb_set_rfctl(IGBCore
*core
, int index
, uint32_t val
)
1697 trace_e1000e_rx_set_rfctl(val
);
1699 if (!(val
& E1000_RFCTL_ISCSI_DIS
)) {
1700 trace_e1000e_wrn_iscsi_filtering_not_supported();
1703 if (!(val
& E1000_RFCTL_NFSW_DIS
)) {
1704 trace_e1000e_wrn_nfsw_filtering_not_supported();
1707 if (!(val
& E1000_RFCTL_NFSR_DIS
)) {
1708 trace_e1000e_wrn_nfsr_filtering_not_supported();
1711 core
->mac
[RFCTL
] = val
;
1715 igb_calc_rxdesclen(IGBCore
*core
)
1717 if (igb_rx_use_legacy_descriptor(core
)) {
1718 core
->rx_desc_len
= sizeof(struct e1000_rx_desc
);
1720 core
->rx_desc_len
= sizeof(union e1000_adv_rx_desc
);
1722 trace_e1000e_rx_desc_len(core
->rx_desc_len
);
1726 igb_set_rx_control(IGBCore
*core
, int index
, uint32_t val
)
1728 core
->mac
[RCTL
] = val
;
1729 trace_e1000e_rx_set_rctl(core
->mac
[RCTL
]);
1731 if (val
& E1000_RCTL_DTYP_MASK
) {
1732 qemu_log_mask(LOG_GUEST_ERROR
,
1733 "igb: RCTL.DTYP must be zero for compatibility");
1736 if (val
& E1000_RCTL_EN
) {
1737 igb_calc_rxdesclen(core
);
1738 igb_start_recv(core
);
1743 igb_clear_ims_bits(IGBCore
*core
, uint32_t bits
)
1745 trace_e1000e_irq_clear_ims(bits
, core
->mac
[IMS
], core
->mac
[IMS
] & ~bits
);
1746 core
->mac
[IMS
] &= ~bits
;
1750 igb_postpone_interrupt(IGBIntrDelayTimer
*timer
)
1752 if (timer
->running
) {
1753 trace_e1000e_irq_postponed_by_xitr(timer
->delay_reg
<< 2);
1758 if (timer
->core
->mac
[timer
->delay_reg
] != 0) {
1759 igb_intrmgr_rearm_timer(timer
);
1766 igb_eitr_should_postpone(IGBCore
*core
, int idx
)
1768 return igb_postpone_interrupt(&core
->eitr
[idx
]);
1771 static void igb_send_msix(IGBCore
*core
)
1773 uint32_t causes
= core
->mac
[EICR
] & core
->mac
[EIMS
];
1774 uint32_t effective_eiac
;
1777 for (vector
= 0; vector
< IGB_INTR_NUM
; ++vector
) {
1778 if ((causes
& BIT(vector
)) && !igb_eitr_should_postpone(core
, vector
)) {
1780 trace_e1000e_irq_msix_notify_vec(vector
);
1781 igb_msix_notify(core
, vector
);
1783 trace_e1000e_irq_icr_clear_eiac(core
->mac
[EICR
], core
->mac
[EIAC
]);
1784 effective_eiac
= core
->mac
[EIAC
] & BIT(vector
);
1785 core
->mac
[EICR
] &= ~effective_eiac
;
1791 igb_fix_icr_asserted(IGBCore
*core
)
1793 core
->mac
[ICR
] &= ~E1000_ICR_ASSERTED
;
1794 if (core
->mac
[ICR
]) {
1795 core
->mac
[ICR
] |= E1000_ICR_ASSERTED
;
1798 trace_e1000e_irq_fix_icr_asserted(core
->mac
[ICR
]);
1802 igb_update_interrupt_state(IGBCore
*core
)
1808 icr
= core
->mac
[ICR
] & core
->mac
[IMS
];
1810 if (msix_enabled(core
->owner
)) {
1813 if (icr
& E1000_ICR_DRSTA
) {
1814 int_alloc
= core
->mac
[IVAR_MISC
] & 0xff;
1815 if (int_alloc
& E1000_IVAR_VALID
) {
1816 causes
|= BIT(int_alloc
& 0x1f);
1819 /* Check if other bits (excluding the TCP Timer) are enabled. */
1820 if (icr
& ~E1000_ICR_DRSTA
) {
1821 int_alloc
= (core
->mac
[IVAR_MISC
] >> 8) & 0xff;
1822 if (int_alloc
& E1000_IVAR_VALID
) {
1823 causes
|= BIT(int_alloc
& 0x1f);
1825 trace_e1000e_irq_add_msi_other(core
->mac
[EICR
]);
1827 core
->mac
[EICR
] |= causes
;
1830 if ((core
->mac
[EICR
] & core
->mac
[EIMS
])) {
1831 igb_send_msix(core
);
1834 igb_fix_icr_asserted(core
);
1837 core
->mac
[EICR
] |= (icr
& E1000_ICR_DRSTA
) | E1000_EICR_OTHER
;
1839 core
->mac
[EICR
] &= ~E1000_EICR_OTHER
;
1842 trace_e1000e_irq_pending_interrupts(core
->mac
[ICR
] & core
->mac
[IMS
],
1843 core
->mac
[ICR
], core
->mac
[IMS
]);
1845 if (msi_enabled(core
->owner
)) {
1847 msi_notify(core
->owner
, 0);
1851 igb_raise_legacy_irq(core
);
1853 igb_lower_legacy_irq(core
);
1860 igb_set_interrupt_cause(IGBCore
*core
, uint32_t val
)
1862 trace_e1000e_irq_set_cause_entry(val
, core
->mac
[ICR
]);
1864 core
->mac
[ICR
] |= val
;
1866 trace_e1000e_irq_set_cause_exit(val
, core
->mac
[ICR
]);
1868 igb_update_interrupt_state(core
);
1871 static void igb_set_eics(IGBCore
*core
, int index
, uint32_t val
)
1873 bool msix
= !!(core
->mac
[GPIE
] & E1000_GPIE_MSIX_MODE
);
1875 trace_igb_irq_write_eics(val
, msix
);
1878 val
& (msix
? E1000_EICR_MSIX_MASK
: E1000_EICR_LEGACY_MASK
);
1881 * TODO: Move to igb_update_interrupt_state if EICS is modified in other
1884 core
->mac
[EICR
] = core
->mac
[EICS
];
1886 igb_update_interrupt_state(core
);
1889 static void igb_set_eims(IGBCore
*core
, int index
, uint32_t val
)
1891 bool msix
= !!(core
->mac
[GPIE
] & E1000_GPIE_MSIX_MODE
);
1893 trace_igb_irq_write_eims(val
, msix
);
1896 val
& (msix
? E1000_EICR_MSIX_MASK
: E1000_EICR_LEGACY_MASK
);
1898 igb_update_interrupt_state(core
);
1901 static void mailbox_interrupt_to_vf(IGBCore
*core
, uint16_t vfn
)
1903 uint32_t ent
= core
->mac
[VTIVAR_MISC
+ vfn
];
1905 if ((ent
& E1000_IVAR_VALID
)) {
1906 core
->mac
[EICR
] |= (ent
& 0x3) << (22 - vfn
* IGBVF_MSIX_VEC_NUM
);
1907 igb_update_interrupt_state(core
);
1911 static void mailbox_interrupt_to_pf(IGBCore
*core
)
1913 igb_set_interrupt_cause(core
, E1000_ICR_VMMB
);
1916 static void igb_set_pfmailbox(IGBCore
*core
, int index
, uint32_t val
)
1918 uint16_t vfn
= index
- P2VMAILBOX0
;
1920 trace_igb_set_pfmailbox(vfn
, val
);
1922 if (val
& E1000_P2VMAILBOX_STS
) {
1923 core
->mac
[V2PMAILBOX0
+ vfn
] |= E1000_V2PMAILBOX_PFSTS
;
1924 mailbox_interrupt_to_vf(core
, vfn
);
1927 if (val
& E1000_P2VMAILBOX_ACK
) {
1928 core
->mac
[V2PMAILBOX0
+ vfn
] |= E1000_V2PMAILBOX_PFACK
;
1929 mailbox_interrupt_to_vf(core
, vfn
);
1932 /* Buffer Taken by PF (can be set only if the VFU is cleared). */
1933 if (val
& E1000_P2VMAILBOX_PFU
) {
1934 if (!(core
->mac
[index
] & E1000_P2VMAILBOX_VFU
)) {
1935 core
->mac
[index
] |= E1000_P2VMAILBOX_PFU
;
1936 core
->mac
[V2PMAILBOX0
+ vfn
] |= E1000_V2PMAILBOX_PFU
;
1939 core
->mac
[index
] &= ~E1000_P2VMAILBOX_PFU
;
1940 core
->mac
[V2PMAILBOX0
+ vfn
] &= ~E1000_V2PMAILBOX_PFU
;
1943 if (val
& E1000_P2VMAILBOX_RVFU
) {
1944 core
->mac
[V2PMAILBOX0
+ vfn
] &= ~E1000_V2PMAILBOX_VFU
;
1945 core
->mac
[MBVFICR
] &= ~((E1000_MBVFICR_VFACK_VF1
<< vfn
) |
1946 (E1000_MBVFICR_VFREQ_VF1
<< vfn
));
1950 static void igb_set_vfmailbox(IGBCore
*core
, int index
, uint32_t val
)
1952 uint16_t vfn
= index
- V2PMAILBOX0
;
1954 trace_igb_set_vfmailbox(vfn
, val
);
1956 if (val
& E1000_V2PMAILBOX_REQ
) {
1957 core
->mac
[MBVFICR
] |= E1000_MBVFICR_VFREQ_VF1
<< vfn
;
1958 mailbox_interrupt_to_pf(core
);
1961 if (val
& E1000_V2PMAILBOX_ACK
) {
1962 core
->mac
[MBVFICR
] |= E1000_MBVFICR_VFACK_VF1
<< vfn
;
1963 mailbox_interrupt_to_pf(core
);
1966 /* Buffer Taken by VF (can be set only if the PFU is cleared). */
1967 if (val
& E1000_V2PMAILBOX_VFU
) {
1968 if (!(core
->mac
[index
] & E1000_V2PMAILBOX_PFU
)) {
1969 core
->mac
[index
] |= E1000_V2PMAILBOX_VFU
;
1970 core
->mac
[P2VMAILBOX0
+ vfn
] |= E1000_P2VMAILBOX_VFU
;
1973 core
->mac
[index
] &= ~E1000_V2PMAILBOX_VFU
;
1974 core
->mac
[P2VMAILBOX0
+ vfn
] &= ~E1000_P2VMAILBOX_VFU
;
1978 static void igb_vf_reset(IGBCore
*core
, uint16_t vfn
)
1980 /* disable Rx and Tx for the VF*/
1981 core
->mac
[VFTE
] &= ~BIT(vfn
);
1982 core
->mac
[VFRE
] &= ~BIT(vfn
);
1983 /* indicate VF reset to PF */
1984 core
->mac
[VFLRE
] |= BIT(vfn
);
1985 /* VFLRE and mailbox use the same interrupt cause */
1986 mailbox_interrupt_to_pf(core
);
1989 static void igb_w1c(IGBCore
*core
, int index
, uint32_t val
)
1991 core
->mac
[index
] &= ~val
;
1994 static void igb_set_eimc(IGBCore
*core
, int index
, uint32_t val
)
1996 bool msix
= !!(core
->mac
[GPIE
] & E1000_GPIE_MSIX_MODE
);
1998 /* Interrupts are disabled via a write to EIMC and reflected in EIMS. */
2000 ~(val
& (msix
? E1000_EICR_MSIX_MASK
: E1000_EICR_LEGACY_MASK
));
2002 trace_igb_irq_write_eimc(val
, core
->mac
[EIMS
], msix
);
2003 igb_update_interrupt_state(core
);
2006 static void igb_set_eiac(IGBCore
*core
, int index
, uint32_t val
)
2008 bool msix
= !!(core
->mac
[GPIE
] & E1000_GPIE_MSIX_MODE
);
2011 trace_igb_irq_write_eiac(val
);
2014 * TODO: When using IOV, the bits that correspond to MSI-X vectors
2015 * that are assigned to a VF are read-only.
2017 core
->mac
[EIAC
] |= (val
& E1000_EICR_MSIX_MASK
);
2021 static void igb_set_eiam(IGBCore
*core
, int index
, uint32_t val
)
2023 bool msix
= !!(core
->mac
[GPIE
] & E1000_GPIE_MSIX_MODE
);
2026 * TODO: When using IOV, the bits that correspond to MSI-X vectors that
2027 * are assigned to a VF are read-only.
2030 ~(val
& (msix
? E1000_EICR_MSIX_MASK
: E1000_EICR_LEGACY_MASK
));
2032 trace_igb_irq_write_eiam(val
, msix
);
2035 static void igb_set_eicr(IGBCore
*core
, int index
, uint32_t val
)
2037 bool msix
= !!(core
->mac
[GPIE
] & E1000_GPIE_MSIX_MODE
);
2040 * TODO: In IOV mode, only bit zero of this vector is available for the PF
2044 ~(val
& (msix
? E1000_EICR_MSIX_MASK
: E1000_EICR_LEGACY_MASK
));
2046 trace_igb_irq_write_eicr(val
, msix
);
2047 igb_update_interrupt_state(core
);
2050 static void igb_set_vtctrl(IGBCore
*core
, int index
, uint32_t val
)
2054 if (val
& E1000_CTRL_RST
) {
2055 vfn
= (index
- PVTCTRL0
) / 0x40;
2056 igb_vf_reset(core
, vfn
);
2060 static void igb_set_vteics(IGBCore
*core
, int index
, uint32_t val
)
2062 uint16_t vfn
= (index
- PVTEICS0
) / 0x40;
2064 core
->mac
[index
] = val
;
2065 igb_set_eics(core
, EICS
, (val
& 0x7) << (22 - vfn
* IGBVF_MSIX_VEC_NUM
));
2068 static void igb_set_vteims(IGBCore
*core
, int index
, uint32_t val
)
2070 uint16_t vfn
= (index
- PVTEIMS0
) / 0x40;
2072 core
->mac
[index
] = val
;
2073 igb_set_eims(core
, EIMS
, (val
& 0x7) << (22 - vfn
* IGBVF_MSIX_VEC_NUM
));
2076 static void igb_set_vteimc(IGBCore
*core
, int index
, uint32_t val
)
2078 uint16_t vfn
= (index
- PVTEIMC0
) / 0x40;
2080 core
->mac
[index
] = val
;
2081 igb_set_eimc(core
, EIMC
, (val
& 0x7) << (22 - vfn
* IGBVF_MSIX_VEC_NUM
));
2084 static void igb_set_vteiac(IGBCore
*core
, int index
, uint32_t val
)
2086 uint16_t vfn
= (index
- PVTEIAC0
) / 0x40;
2088 core
->mac
[index
] = val
;
2089 igb_set_eiac(core
, EIAC
, (val
& 0x7) << (22 - vfn
* IGBVF_MSIX_VEC_NUM
));
2092 static void igb_set_vteiam(IGBCore
*core
, int index
, uint32_t val
)
2094 uint16_t vfn
= (index
- PVTEIAM0
) / 0x40;
2096 core
->mac
[index
] = val
;
2097 igb_set_eiam(core
, EIAM
, (val
& 0x7) << (22 - vfn
* IGBVF_MSIX_VEC_NUM
));
2100 static void igb_set_vteicr(IGBCore
*core
, int index
, uint32_t val
)
2102 uint16_t vfn
= (index
- PVTEICR0
) / 0x40;
2104 core
->mac
[index
] = val
;
2105 igb_set_eicr(core
, EICR
, (val
& 0x7) << (22 - vfn
* IGBVF_MSIX_VEC_NUM
));
2108 static void igb_set_vtivar(IGBCore
*core
, int index
, uint32_t val
)
2110 uint16_t vfn
= (index
- VTIVAR
);
2115 core
->mac
[index
] = val
;
2117 /* Get assigned vector associated with queue Rx#0. */
2118 if ((val
& E1000_IVAR_VALID
)) {
2119 n
= igb_ivar_entry_rx(qn
);
2120 ent
= E1000_IVAR_VALID
| (24 - vfn
* IGBVF_MSIX_VEC_NUM
- (2 - (val
& 0x7)));
2121 core
->mac
[IVAR0
+ n
/ 4] |= ent
<< 8 * (n
% 4);
2124 /* Get assigned vector associated with queue Tx#0 */
2126 if ((ent
& E1000_IVAR_VALID
)) {
2127 n
= igb_ivar_entry_tx(qn
);
2128 ent
= E1000_IVAR_VALID
| (24 - vfn
* IGBVF_MSIX_VEC_NUM
- (2 - (ent
& 0x7)));
2129 core
->mac
[IVAR0
+ n
/ 4] |= ent
<< 8 * (n
% 4);
2133 * Ignoring assigned vectors associated with queues Rx#1 and Tx#1 for now.
2138 igb_autoneg_timer(void *opaque
)
2140 IGBCore
*core
= opaque
;
2141 if (!qemu_get_queue(core
->owner_nic
)->link_down
) {
2142 e1000x_update_regs_on_autoneg_done(core
->mac
, core
->phy
);
2143 igb_start_recv(core
);
2145 igb_update_flowctl_status(core
);
2146 /* signal link status change to the guest */
2147 igb_set_interrupt_cause(core
, E1000_ICR_LSC
);
2151 static inline uint16_t
2152 igb_get_reg_index_with_offset(const uint16_t *mac_reg_access
, hwaddr addr
)
2154 uint16_t index
= (addr
& 0x1ffff) >> 2;
2155 return index
+ (mac_reg_access
[index
] & 0xfffe);
2158 static const char igb_phy_regcap
[MAX_PHY_REG_ADDRESS
+ 1] = {
2159 [MII_BMCR
] = PHY_RW
,
2161 [MII_PHYID1
] = PHY_R
,
2162 [MII_PHYID2
] = PHY_R
,
2163 [MII_ANAR
] = PHY_RW
,
2164 [MII_ANLPAR
] = PHY_R
,
2166 [MII_ANNP
] = PHY_RW
,
2167 [MII_ANLPRNP
] = PHY_R
,
2168 [MII_CTRL1000
] = PHY_RW
,
2169 [MII_STAT1000
] = PHY_R
,
2170 [MII_EXTSTAT
] = PHY_R
,
2172 [IGP01E1000_PHY_PORT_CONFIG
] = PHY_RW
,
2173 [IGP01E1000_PHY_PORT_STATUS
] = PHY_R
,
2174 [IGP01E1000_PHY_PORT_CTRL
] = PHY_RW
,
2175 [IGP01E1000_PHY_LINK_HEALTH
] = PHY_R
,
2176 [IGP02E1000_PHY_POWER_MGMT
] = PHY_RW
,
2177 [IGP01E1000_PHY_PAGE_SELECT
] = PHY_W
2181 igb_phy_reg_write(IGBCore
*core
, uint32_t addr
, uint16_t data
)
2183 assert(addr
<= MAX_PHY_REG_ADDRESS
);
2185 if (addr
== MII_BMCR
) {
2186 igb_set_phy_ctrl(core
, data
);
2188 core
->phy
[addr
] = data
;
2193 igb_set_mdic(IGBCore
*core
, int index
, uint32_t val
)
2195 uint32_t data
= val
& E1000_MDIC_DATA_MASK
;
2196 uint32_t addr
= ((val
& E1000_MDIC_REG_MASK
) >> E1000_MDIC_REG_SHIFT
);
2198 if ((val
& E1000_MDIC_PHY_MASK
) >> E1000_MDIC_PHY_SHIFT
!= 1) { /* phy # */
2199 val
= core
->mac
[MDIC
] | E1000_MDIC_ERROR
;
2200 } else if (val
& E1000_MDIC_OP_READ
) {
2201 if (!(igb_phy_regcap
[addr
] & PHY_R
)) {
2202 trace_igb_core_mdic_read_unhandled(addr
);
2203 val
|= E1000_MDIC_ERROR
;
2205 val
= (val
^ data
) | core
->phy
[addr
];
2206 trace_igb_core_mdic_read(addr
, val
);
2208 } else if (val
& E1000_MDIC_OP_WRITE
) {
2209 if (!(igb_phy_regcap
[addr
] & PHY_W
)) {
2210 trace_igb_core_mdic_write_unhandled(addr
);
2211 val
|= E1000_MDIC_ERROR
;
2213 trace_igb_core_mdic_write(addr
, data
);
2214 igb_phy_reg_write(core
, addr
, data
);
2217 core
->mac
[MDIC
] = val
| E1000_MDIC_READY
;
2219 if (val
& E1000_MDIC_INT_EN
) {
2220 igb_set_interrupt_cause(core
, E1000_ICR_MDAC
);
2225 igb_set_rdt(IGBCore
*core
, int index
, uint32_t val
)
2227 core
->mac
[index
] = val
& 0xffff;
2228 trace_e1000e_rx_set_rdt(igb_mq_queue_idx(RDT0
, index
), val
);
2229 igb_start_recv(core
);
2233 igb_set_status(IGBCore
*core
, int index
, uint32_t val
)
2235 if ((val
& E1000_STATUS_PHYRA
) == 0) {
2236 core
->mac
[index
] &= ~E1000_STATUS_PHYRA
;
2241 igb_set_ctrlext(IGBCore
*core
, int index
, uint32_t val
)
2243 trace_igb_link_set_ext_params(!!(val
& E1000_CTRL_EXT_ASDCHK
),
2244 !!(val
& E1000_CTRL_EXT_SPD_BYPS
),
2245 !!(val
& E1000_CTRL_EXT_PFRSTD
));
2247 /* Zero self-clearing bits */
2248 val
&= ~(E1000_CTRL_EXT_ASDCHK
| E1000_CTRL_EXT_EE_RST
);
2249 core
->mac
[CTRL_EXT
] = val
;
2251 if (core
->mac
[CTRL_EXT
] & E1000_CTRL_EXT_PFRSTD
) {
2252 for (int vfn
= 0; vfn
< IGB_MAX_VF_FUNCTIONS
; vfn
++) {
2253 core
->mac
[V2PMAILBOX0
+ vfn
] &= ~E1000_V2PMAILBOX_RSTI
;
2254 core
->mac
[V2PMAILBOX0
+ vfn
] |= E1000_V2PMAILBOX_RSTD
;
2260 igb_set_pbaclr(IGBCore
*core
, int index
, uint32_t val
)
2264 core
->mac
[PBACLR
] = val
& E1000_PBACLR_VALID_MASK
;
2266 if (!msix_enabled(core
->owner
)) {
2270 for (i
= 0; i
< IGB_INTR_NUM
; i
++) {
2271 if (core
->mac
[PBACLR
] & BIT(i
)) {
2272 msix_clr_pending(core
->owner
, i
);
2278 igb_set_fcrth(IGBCore
*core
, int index
, uint32_t val
)
2280 core
->mac
[FCRTH
] = val
& 0xFFF8;
2284 igb_set_fcrtl(IGBCore
*core
, int index
, uint32_t val
)
2286 core
->mac
[FCRTL
] = val
& 0x8000FFF8;
2289 #define IGB_LOW_BITS_SET_FUNC(num) \
2291 igb_set_##num##bit(IGBCore *core, int index, uint32_t val) \
2293 core->mac[index] = val & (BIT(num) - 1); \
2296 IGB_LOW_BITS_SET_FUNC(4)
2297 IGB_LOW_BITS_SET_FUNC(13)
2298 IGB_LOW_BITS_SET_FUNC(16)
2301 igb_set_dlen(IGBCore
*core
, int index
, uint32_t val
)
2303 core
->mac
[index
] = val
& 0xffff0;
2307 igb_set_dbal(IGBCore
*core
, int index
, uint32_t val
)
2309 core
->mac
[index
] = val
& E1000_XDBAL_MASK
;
2313 igb_set_tdt(IGBCore
*core
, int index
, uint32_t val
)
2316 int qn
= igb_mq_queue_idx(TDT0
, index
);
2318 core
->mac
[index
] = val
& 0xffff;
2320 igb_tx_ring_init(core
, &txr
, qn
);
2321 igb_start_xmit(core
, &txr
);
2325 igb_set_ics(IGBCore
*core
, int index
, uint32_t val
)
2327 trace_e1000e_irq_write_ics(val
);
2328 igb_set_interrupt_cause(core
, val
);
2332 igb_set_imc(IGBCore
*core
, int index
, uint32_t val
)
2334 trace_e1000e_irq_ims_clear_set_imc(val
);
2335 igb_clear_ims_bits(core
, val
);
2336 igb_update_interrupt_state(core
);
2340 igb_set_ims(IGBCore
*core
, int index
, uint32_t val
)
2342 uint32_t valid_val
= val
& 0x77D4FBFD;
2344 trace_e1000e_irq_set_ims(val
, core
->mac
[IMS
], core
->mac
[IMS
] | valid_val
);
2345 core
->mac
[IMS
] |= valid_val
;
2346 igb_update_interrupt_state(core
);
2349 static void igb_commit_icr(IGBCore
*core
)
2352 * If GPIE.NSICR = 0, then the copy of IAM to IMS will occur only if at
2353 * least one bit is set in the IMS and there is a true interrupt as
2354 * reflected in ICR.INTA.
2356 if ((core
->mac
[GPIE
] & E1000_GPIE_NSICR
) ||
2357 (core
->mac
[IMS
] && (core
->mac
[ICR
] & E1000_ICR_INT_ASSERTED
))) {
2358 igb_set_ims(core
, IMS
, core
->mac
[IAM
]);
2360 igb_update_interrupt_state(core
);
2364 static void igb_set_icr(IGBCore
*core
, int index
, uint32_t val
)
2366 uint32_t icr
= core
->mac
[ICR
] & ~val
;
2368 trace_igb_irq_icr_write(val
, core
->mac
[ICR
], icr
);
2369 core
->mac
[ICR
] = icr
;
2370 igb_commit_icr(core
);
2374 igb_mac_readreg(IGBCore
*core
, int index
)
2376 return core
->mac
[index
];
2380 igb_mac_ics_read(IGBCore
*core
, int index
)
2382 trace_e1000e_irq_read_ics(core
->mac
[ICS
]);
2383 return core
->mac
[ICS
];
2387 igb_mac_ims_read(IGBCore
*core
, int index
)
2389 trace_e1000e_irq_read_ims(core
->mac
[IMS
]);
2390 return core
->mac
[IMS
];
2394 igb_mac_swsm_read(IGBCore
*core
, int index
)
2396 uint32_t val
= core
->mac
[SWSM
];
2397 core
->mac
[SWSM
] = val
| E1000_SWSM_SMBI
;
2402 igb_mac_eitr_read(IGBCore
*core
, int index
)
2404 return core
->eitr_guest_value
[index
- EITR0
];
2407 static uint32_t igb_mac_vfmailbox_read(IGBCore
*core
, int index
)
2409 uint32_t val
= core
->mac
[index
];
2411 core
->mac
[index
] &= ~(E1000_V2PMAILBOX_PFSTS
| E1000_V2PMAILBOX_PFACK
|
2412 E1000_V2PMAILBOX_RSTD
);
2418 igb_mac_icr_read(IGBCore
*core
, int index
)
2420 uint32_t ret
= core
->mac
[ICR
];
2421 trace_e1000e_irq_icr_read_entry(ret
);
2423 if (core
->mac
[GPIE
] & E1000_GPIE_NSICR
) {
2424 trace_igb_irq_icr_clear_gpie_nsicr();
2426 } else if (core
->mac
[IMS
] == 0) {
2427 trace_e1000e_irq_icr_clear_zero_ims();
2429 } else if (!msix_enabled(core
->owner
)) {
2430 trace_e1000e_irq_icr_clear_nonmsix_icr_read();
2434 trace_e1000e_irq_icr_read_exit(core
->mac
[ICR
]);
2435 igb_commit_icr(core
);
2440 igb_mac_read_clr4(IGBCore
*core
, int index
)
2442 uint32_t ret
= core
->mac
[index
];
2444 core
->mac
[index
] = 0;
2449 igb_mac_read_clr8(IGBCore
*core
, int index
)
2451 uint32_t ret
= core
->mac
[index
];
2453 core
->mac
[index
] = 0;
2454 core
->mac
[index
- 1] = 0;
2459 igb_get_ctrl(IGBCore
*core
, int index
)
2461 uint32_t val
= core
->mac
[CTRL
];
2463 trace_e1000e_link_read_params(
2464 !!(val
& E1000_CTRL_ASDE
),
2465 (val
& E1000_CTRL_SPD_SEL
) >> E1000_CTRL_SPD_SHIFT
,
2466 !!(val
& E1000_CTRL_FRCSPD
),
2467 !!(val
& E1000_CTRL_FRCDPX
),
2468 !!(val
& E1000_CTRL_RFCE
),
2469 !!(val
& E1000_CTRL_TFCE
));
2474 static uint32_t igb_get_status(IGBCore
*core
, int index
)
2476 uint32_t res
= core
->mac
[STATUS
];
2477 uint16_t num_vfs
= pcie_sriov_num_vfs(core
->owner
);
2479 if (core
->mac
[CTRL
] & E1000_CTRL_FRCDPX
) {
2480 res
|= (core
->mac
[CTRL
] & E1000_CTRL_FD
) ? E1000_STATUS_FD
: 0;
2482 res
|= E1000_STATUS_FD
;
2485 if ((core
->mac
[CTRL
] & E1000_CTRL_FRCSPD
) ||
2486 (core
->mac
[CTRL_EXT
] & E1000_CTRL_EXT_SPD_BYPS
)) {
2487 switch (core
->mac
[CTRL
] & E1000_CTRL_SPD_SEL
) {
2488 case E1000_CTRL_SPD_10
:
2489 res
|= E1000_STATUS_SPEED_10
;
2491 case E1000_CTRL_SPD_100
:
2492 res
|= E1000_STATUS_SPEED_100
;
2494 case E1000_CTRL_SPD_1000
:
2496 res
|= E1000_STATUS_SPEED_1000
;
2500 res
|= E1000_STATUS_SPEED_1000
;
2504 res
|= num_vfs
<< E1000_STATUS_NUM_VFS_SHIFT
;
2505 res
|= E1000_STATUS_IOV_MODE
;
2509 * Windows driver 12.18.9.23 resets if E1000_STATUS_GIO_MASTER_ENABLE is
2510 * left set after E1000_CTRL_LRST is set.
2512 if (!(core
->mac
[CTRL
] & E1000_CTRL_GIO_MASTER_DISABLE
) &&
2513 !(core
->mac
[CTRL
] & E1000_CTRL_LRST
)) {
2514 res
|= E1000_STATUS_GIO_MASTER_ENABLE
;
2521 igb_mac_writereg(IGBCore
*core
, int index
, uint32_t val
)
2523 core
->mac
[index
] = val
;
2527 igb_mac_setmacaddr(IGBCore
*core
, int index
, uint32_t val
)
2529 uint32_t macaddr
[2];
2531 core
->mac
[index
] = val
;
2533 macaddr
[0] = cpu_to_le32(core
->mac
[RA
]);
2534 macaddr
[1] = cpu_to_le32(core
->mac
[RA
+ 1]);
2535 qemu_format_nic_info_str(qemu_get_queue(core
->owner_nic
),
2536 (uint8_t *) macaddr
);
2538 trace_e1000e_mac_set_sw(MAC_ARG(macaddr
));
2542 igb_set_eecd(IGBCore
*core
, int index
, uint32_t val
)
2544 static const uint32_t ro_bits
= E1000_EECD_PRES
|
2545 E1000_EECD_AUTO_RD
|
2546 E1000_EECD_SIZE_EX_MASK
;
2548 core
->mac
[EECD
] = (core
->mac
[EECD
] & ro_bits
) | (val
& ~ro_bits
);
2552 igb_set_eerd(IGBCore
*core
, int index
, uint32_t val
)
2554 uint32_t addr
= (val
>> E1000_EERW_ADDR_SHIFT
) & E1000_EERW_ADDR_MASK
;
2558 if ((addr
< IGB_EEPROM_SIZE
) && (val
& E1000_EERW_START
)) {
2559 data
= core
->eeprom
[addr
];
2560 flags
= E1000_EERW_DONE
;
2563 core
->mac
[EERD
] = flags
|
2564 (addr
<< E1000_EERW_ADDR_SHIFT
) |
2565 (data
<< E1000_EERW_DATA_SHIFT
);
2569 igb_set_eitr(IGBCore
*core
, int index
, uint32_t val
)
2571 uint32_t eitr_num
= index
- EITR0
;
2573 trace_igb_irq_eitr_set(eitr_num
, val
);
2575 core
->eitr_guest_value
[eitr_num
] = val
& ~E1000_EITR_CNT_IGNR
;
2576 core
->mac
[index
] = val
& 0x7FFE;
2580 igb_update_rx_offloads(IGBCore
*core
)
2582 int cso_state
= igb_rx_l4_cso_enabled(core
);
2584 trace_e1000e_rx_set_cso(cso_state
);
2586 if (core
->has_vnet
) {
2587 qemu_set_offload(qemu_get_queue(core
->owner_nic
)->peer
,
2588 cso_state
, 0, 0, 0, 0);
2593 igb_set_rxcsum(IGBCore
*core
, int index
, uint32_t val
)
2595 core
->mac
[RXCSUM
] = val
;
2596 igb_update_rx_offloads(core
);
2600 igb_set_gcr(IGBCore
*core
, int index
, uint32_t val
)
2602 uint32_t ro_bits
= core
->mac
[GCR
] & E1000_GCR_RO_BITS
;
2603 core
->mac
[GCR
] = (val
& ~E1000_GCR_RO_BITS
) | ro_bits
;
2606 static uint32_t igb_get_systiml(IGBCore
*core
, int index
)
2608 e1000x_timestamp(core
->mac
, core
->timadj
, SYSTIML
, SYSTIMH
);
2609 return core
->mac
[SYSTIML
];
2612 static uint32_t igb_get_rxsatrh(IGBCore
*core
, int index
)
2614 core
->mac
[TSYNCRXCTL
] &= ~E1000_TSYNCRXCTL_VALID
;
2615 return core
->mac
[RXSATRH
];
2618 static uint32_t igb_get_txstmph(IGBCore
*core
, int index
)
2620 core
->mac
[TSYNCTXCTL
] &= ~E1000_TSYNCTXCTL_VALID
;
2621 return core
->mac
[TXSTMPH
];
2624 static void igb_set_timinca(IGBCore
*core
, int index
, uint32_t val
)
2626 e1000x_set_timinca(core
->mac
, &core
->timadj
, val
);
2629 static void igb_set_timadjh(IGBCore
*core
, int index
, uint32_t val
)
2631 core
->mac
[TIMADJH
] = val
;
2632 core
->timadj
+= core
->mac
[TIMADJL
] | ((int64_t)core
->mac
[TIMADJH
] << 32);
2635 #define igb_getreg(x) [x] = igb_mac_readreg
2636 typedef uint32_t (*readops
)(IGBCore
*, int);
2637 static const readops igb_macreg_readops
[] = {
2667 igb_getreg(RDBAH10
),
2668 igb_getreg(RDBAH11
),
2669 igb_getreg(RDBAH12
),
2670 igb_getreg(RDBAH13
),
2671 igb_getreg(RDBAH14
),
2672 igb_getreg(RDBAH15
),
2683 igb_getreg(TDBAL10
),
2684 igb_getreg(TDBAL11
),
2685 igb_getreg(TDBAL12
),
2686 igb_getreg(TDBAL13
),
2687 igb_getreg(TDBAL14
),
2688 igb_getreg(TDBAL15
),
2699 igb_getreg(RDLEN10
),
2700 igb_getreg(RDLEN11
),
2701 igb_getreg(RDLEN12
),
2702 igb_getreg(RDLEN13
),
2703 igb_getreg(RDLEN14
),
2704 igb_getreg(RDLEN15
),
2705 igb_getreg(SRRCTL0
),
2706 igb_getreg(SRRCTL1
),
2707 igb_getreg(SRRCTL2
),
2708 igb_getreg(SRRCTL3
),
2709 igb_getreg(SRRCTL4
),
2710 igb_getreg(SRRCTL5
),
2711 igb_getreg(SRRCTL6
),
2712 igb_getreg(SRRCTL7
),
2713 igb_getreg(SRRCTL8
),
2714 igb_getreg(SRRCTL9
),
2715 igb_getreg(SRRCTL10
),
2716 igb_getreg(SRRCTL11
),
2717 igb_getreg(SRRCTL12
),
2718 igb_getreg(SRRCTL13
),
2719 igb_getreg(SRRCTL14
),
2720 igb_getreg(SRRCTL15
),
2721 igb_getreg(LATECOL
),
2745 igb_getreg(RXSTMPH
),
2746 igb_getreg(TXSTMPL
),
2747 igb_getreg(TIMADJL
),
2785 igb_getreg(FLMNGCTL
),
2786 igb_getreg(FLMNGCNT
),
2787 igb_getreg(TSYNCTXCTL
),
2788 igb_getreg(EEMNGDATA
),
2789 igb_getreg(CTRL_EXT
),
2790 igb_getreg(SYSTIMH
),
2791 igb_getreg(EEMNGCTL
),
2792 igb_getreg(FLMNGDATA
),
2793 igb_getreg(TSYNCRXCTL
),
2796 igb_getreg(TCTL_EXT
),
2818 igb_getreg(XOFFTXC
),
2822 igb_getreg(TIMINCA
),
2828 igb_getreg(RXSATRL
),
2840 igb_getreg(TDLEN10
),
2841 igb_getreg(TDLEN11
),
2842 igb_getreg(TDLEN12
),
2843 igb_getreg(TDLEN13
),
2844 igb_getreg(TDLEN14
),
2845 igb_getreg(TDLEN15
),
2850 igb_getreg(TXDCTL0
),
2851 igb_getreg(TXDCTL1
),
2852 igb_getreg(TXDCTL2
),
2853 igb_getreg(TXDCTL3
),
2854 igb_getreg(TXDCTL4
),
2855 igb_getreg(TXDCTL5
),
2856 igb_getreg(TXDCTL6
),
2857 igb_getreg(TXDCTL7
),
2858 igb_getreg(TXDCTL8
),
2859 igb_getreg(TXDCTL9
),
2860 igb_getreg(TXDCTL10
),
2861 igb_getreg(TXDCTL11
),
2862 igb_getreg(TXDCTL12
),
2863 igb_getreg(TXDCTL13
),
2864 igb_getreg(TXDCTL14
),
2865 igb_getreg(TXDCTL15
),
2876 igb_getreg(TXCTL10
),
2877 igb_getreg(TXCTL11
),
2878 igb_getreg(TXCTL12
),
2879 igb_getreg(TXCTL13
),
2880 igb_getreg(TXCTL14
),
2881 igb_getreg(TXCTL15
),
2882 igb_getreg(TDWBAL0
),
2883 igb_getreg(TDWBAL1
),
2884 igb_getreg(TDWBAL2
),
2885 igb_getreg(TDWBAL3
),
2886 igb_getreg(TDWBAL4
),
2887 igb_getreg(TDWBAL5
),
2888 igb_getreg(TDWBAL6
),
2889 igb_getreg(TDWBAL7
),
2890 igb_getreg(TDWBAL8
),
2891 igb_getreg(TDWBAL9
),
2892 igb_getreg(TDWBAL10
),
2893 igb_getreg(TDWBAL11
),
2894 igb_getreg(TDWBAL12
),
2895 igb_getreg(TDWBAL13
),
2896 igb_getreg(TDWBAL14
),
2897 igb_getreg(TDWBAL15
),
2898 igb_getreg(TDWBAH0
),
2899 igb_getreg(TDWBAH1
),
2900 igb_getreg(TDWBAH2
),
2901 igb_getreg(TDWBAH3
),
2902 igb_getreg(TDWBAH4
),
2903 igb_getreg(TDWBAH5
),
2904 igb_getreg(TDWBAH6
),
2905 igb_getreg(TDWBAH7
),
2906 igb_getreg(TDWBAH8
),
2907 igb_getreg(TDWBAH9
),
2908 igb_getreg(TDWBAH10
),
2909 igb_getreg(TDWBAH11
),
2910 igb_getreg(TDWBAH12
),
2911 igb_getreg(TDWBAH13
),
2912 igb_getreg(TDWBAH14
),
2913 igb_getreg(TDWBAH15
),
2914 igb_getreg(PVTCTRL0
),
2915 igb_getreg(PVTCTRL1
),
2916 igb_getreg(PVTCTRL2
),
2917 igb_getreg(PVTCTRL3
),
2918 igb_getreg(PVTCTRL4
),
2919 igb_getreg(PVTCTRL5
),
2920 igb_getreg(PVTCTRL6
),
2921 igb_getreg(PVTCTRL7
),
2922 igb_getreg(PVTEIMS0
),
2923 igb_getreg(PVTEIMS1
),
2924 igb_getreg(PVTEIMS2
),
2925 igb_getreg(PVTEIMS3
),
2926 igb_getreg(PVTEIMS4
),
2927 igb_getreg(PVTEIMS5
),
2928 igb_getreg(PVTEIMS6
),
2929 igb_getreg(PVTEIMS7
),
2930 igb_getreg(PVTEIAC0
),
2931 igb_getreg(PVTEIAC1
),
2932 igb_getreg(PVTEIAC2
),
2933 igb_getreg(PVTEIAC3
),
2934 igb_getreg(PVTEIAC4
),
2935 igb_getreg(PVTEIAC5
),
2936 igb_getreg(PVTEIAC6
),
2937 igb_getreg(PVTEIAC7
),
2938 igb_getreg(PVTEIAM0
),
2939 igb_getreg(PVTEIAM1
),
2940 igb_getreg(PVTEIAM2
),
2941 igb_getreg(PVTEIAM3
),
2942 igb_getreg(PVTEIAM4
),
2943 igb_getreg(PVTEIAM5
),
2944 igb_getreg(PVTEIAM6
),
2945 igb_getreg(PVTEIAM7
),
2946 igb_getreg(PVFGPRC0
),
2947 igb_getreg(PVFGPRC1
),
2948 igb_getreg(PVFGPRC2
),
2949 igb_getreg(PVFGPRC3
),
2950 igb_getreg(PVFGPRC4
),
2951 igb_getreg(PVFGPRC5
),
2952 igb_getreg(PVFGPRC6
),
2953 igb_getreg(PVFGPRC7
),
2954 igb_getreg(PVFGPTC0
),
2955 igb_getreg(PVFGPTC1
),
2956 igb_getreg(PVFGPTC2
),
2957 igb_getreg(PVFGPTC3
),
2958 igb_getreg(PVFGPTC4
),
2959 igb_getreg(PVFGPTC5
),
2960 igb_getreg(PVFGPTC6
),
2961 igb_getreg(PVFGPTC7
),
2962 igb_getreg(PVFGORC0
),
2963 igb_getreg(PVFGORC1
),
2964 igb_getreg(PVFGORC2
),
2965 igb_getreg(PVFGORC3
),
2966 igb_getreg(PVFGORC4
),
2967 igb_getreg(PVFGORC5
),
2968 igb_getreg(PVFGORC6
),
2969 igb_getreg(PVFGORC7
),
2970 igb_getreg(PVFGOTC0
),
2971 igb_getreg(PVFGOTC1
),
2972 igb_getreg(PVFGOTC2
),
2973 igb_getreg(PVFGOTC3
),
2974 igb_getreg(PVFGOTC4
),
2975 igb_getreg(PVFGOTC5
),
2976 igb_getreg(PVFGOTC6
),
2977 igb_getreg(PVFGOTC7
),
2978 igb_getreg(PVFMPRC0
),
2979 igb_getreg(PVFMPRC1
),
2980 igb_getreg(PVFMPRC2
),
2981 igb_getreg(PVFMPRC3
),
2982 igb_getreg(PVFMPRC4
),
2983 igb_getreg(PVFMPRC5
),
2984 igb_getreg(PVFMPRC6
),
2985 igb_getreg(PVFMPRC7
),
2986 igb_getreg(PVFGPRLBC0
),
2987 igb_getreg(PVFGPRLBC1
),
2988 igb_getreg(PVFGPRLBC2
),
2989 igb_getreg(PVFGPRLBC3
),
2990 igb_getreg(PVFGPRLBC4
),
2991 igb_getreg(PVFGPRLBC5
),
2992 igb_getreg(PVFGPRLBC6
),
2993 igb_getreg(PVFGPRLBC7
),
2994 igb_getreg(PVFGPTLBC0
),
2995 igb_getreg(PVFGPTLBC1
),
2996 igb_getreg(PVFGPTLBC2
),
2997 igb_getreg(PVFGPTLBC3
),
2998 igb_getreg(PVFGPTLBC4
),
2999 igb_getreg(PVFGPTLBC5
),
3000 igb_getreg(PVFGPTLBC6
),
3001 igb_getreg(PVFGPTLBC7
),
3002 igb_getreg(PVFGORLBC0
),
3003 igb_getreg(PVFGORLBC1
),
3004 igb_getreg(PVFGORLBC2
),
3005 igb_getreg(PVFGORLBC3
),
3006 igb_getreg(PVFGORLBC4
),
3007 igb_getreg(PVFGORLBC5
),
3008 igb_getreg(PVFGORLBC6
),
3009 igb_getreg(PVFGORLBC7
),
3010 igb_getreg(PVFGOTLBC0
),
3011 igb_getreg(PVFGOTLBC1
),
3012 igb_getreg(PVFGOTLBC2
),
3013 igb_getreg(PVFGOTLBC3
),
3014 igb_getreg(PVFGOTLBC4
),
3015 igb_getreg(PVFGOTLBC5
),
3016 igb_getreg(PVFGOTLBC6
),
3017 igb_getreg(PVFGOTLBC7
),
3032 igb_getreg(RDBAL10
),
3033 igb_getreg(RDBAL11
),
3034 igb_getreg(RDBAL12
),
3035 igb_getreg(RDBAL13
),
3036 igb_getreg(RDBAL14
),
3037 igb_getreg(RDBAL15
),
3048 igb_getreg(TDBAH10
),
3049 igb_getreg(TDBAH11
),
3050 igb_getreg(TDBAH12
),
3051 igb_getreg(TDBAH13
),
3052 igb_getreg(TDBAH14
),
3053 igb_getreg(TDBAH15
),
3056 igb_getreg(XOFFRXC
),
3062 igb_getreg(FUNCTAG
),
3068 igb_getreg(RXDCTL0
),
3069 igb_getreg(RXDCTL1
),
3070 igb_getreg(RXDCTL2
),
3071 igb_getreg(RXDCTL3
),
3072 igb_getreg(RXDCTL4
),
3073 igb_getreg(RXDCTL5
),
3074 igb_getreg(RXDCTL6
),
3075 igb_getreg(RXDCTL7
),
3076 igb_getreg(RXDCTL8
),
3077 igb_getreg(RXDCTL9
),
3078 igb_getreg(RXDCTL10
),
3079 igb_getreg(RXDCTL11
),
3080 igb_getreg(RXDCTL12
),
3081 igb_getreg(RXDCTL13
),
3082 igb_getreg(RXDCTL14
),
3083 igb_getreg(RXDCTL15
),
3084 igb_getreg(RXSTMPL
),
3085 igb_getreg(TIMADJH
),
3095 [TOTH
] = igb_mac_read_clr8
,
3096 [GOTCH
] = igb_mac_read_clr8
,
3097 [PRC64
] = igb_mac_read_clr4
,
3098 [PRC255
] = igb_mac_read_clr4
,
3099 [PRC1023
] = igb_mac_read_clr4
,
3100 [PTC64
] = igb_mac_read_clr4
,
3101 [PTC255
] = igb_mac_read_clr4
,
3102 [PTC1023
] = igb_mac_read_clr4
,
3103 [GPRC
] = igb_mac_read_clr4
,
3104 [TPT
] = igb_mac_read_clr4
,
3105 [RUC
] = igb_mac_read_clr4
,
3106 [BPRC
] = igb_mac_read_clr4
,
3107 [MPTC
] = igb_mac_read_clr4
,
3108 [IAC
] = igb_mac_read_clr4
,
3109 [ICR
] = igb_mac_icr_read
,
3110 [STATUS
] = igb_get_status
,
3111 [ICS
] = igb_mac_ics_read
,
3113 * 8.8.10: Reading the IMC register returns the value of the IMS register.
3115 [IMC
] = igb_mac_ims_read
,
3116 [TORH
] = igb_mac_read_clr8
,
3117 [GORCH
] = igb_mac_read_clr8
,
3118 [PRC127
] = igb_mac_read_clr4
,
3119 [PRC511
] = igb_mac_read_clr4
,
3120 [PRC1522
] = igb_mac_read_clr4
,
3121 [PTC127
] = igb_mac_read_clr4
,
3122 [PTC511
] = igb_mac_read_clr4
,
3123 [PTC1522
] = igb_mac_read_clr4
,
3124 [GPTC
] = igb_mac_read_clr4
,
3125 [TPR
] = igb_mac_read_clr4
,
3126 [ROC
] = igb_mac_read_clr4
,
3127 [MPRC
] = igb_mac_read_clr4
,
3128 [BPTC
] = igb_mac_read_clr4
,
3129 [TSCTC
] = igb_mac_read_clr4
,
3130 [CTRL
] = igb_get_ctrl
,
3131 [SWSM
] = igb_mac_swsm_read
,
3132 [IMS
] = igb_mac_ims_read
,
3133 [SYSTIML
] = igb_get_systiml
,
3134 [RXSATRH
] = igb_get_rxsatrh
,
3135 [TXSTMPH
] = igb_get_txstmph
,
3137 [CRCERRS
... MPC
] = igb_mac_readreg
,
3138 [IP6AT
... IP6AT
+ 3] = igb_mac_readreg
,
3139 [IP4AT
... IP4AT
+ 6] = igb_mac_readreg
,
3140 [RA
... RA
+ 31] = igb_mac_readreg
,
3141 [RA2
... RA2
+ 31] = igb_mac_readreg
,
3142 [WUPM
... WUPM
+ 31] = igb_mac_readreg
,
3143 [MTA
... MTA
+ E1000_MC_TBL_SIZE
- 1] = igb_mac_readreg
,
3144 [VFTA
... VFTA
+ E1000_VLAN_FILTER_TBL_SIZE
- 1] = igb_mac_readreg
,
3145 [FFMT
... FFMT
+ 254] = igb_mac_readreg
,
3146 [MDEF
... MDEF
+ 7] = igb_mac_readreg
,
3147 [FTFT
... FTFT
+ 254] = igb_mac_readreg
,
3148 [RETA
... RETA
+ 31] = igb_mac_readreg
,
3149 [RSSRK
... RSSRK
+ 9] = igb_mac_readreg
,
3150 [MAVTV0
... MAVTV3
] = igb_mac_readreg
,
3151 [EITR0
... EITR0
+ IGB_INTR_NUM
- 1] = igb_mac_eitr_read
,
3152 [PVTEICR0
] = igb_mac_read_clr4
,
3153 [PVTEICR1
] = igb_mac_read_clr4
,
3154 [PVTEICR2
] = igb_mac_read_clr4
,
3155 [PVTEICR3
] = igb_mac_read_clr4
,
3156 [PVTEICR4
] = igb_mac_read_clr4
,
3157 [PVTEICR5
] = igb_mac_read_clr4
,
3158 [PVTEICR6
] = igb_mac_read_clr4
,
3159 [PVTEICR7
] = igb_mac_read_clr4
,
3162 [FWSM
] = igb_mac_readreg
,
3163 [SW_FW_SYNC
] = igb_mac_readreg
,
3164 [HTCBDPC
] = igb_mac_read_clr4
,
3165 [EICR
] = igb_mac_read_clr4
,
3166 [EIMS
] = igb_mac_readreg
,
3167 [EIAM
] = igb_mac_readreg
,
3168 [IVAR0
... IVAR0
+ 7] = igb_mac_readreg
,
3169 igb_getreg(IVAR_MISC
),
3171 [P2VMAILBOX0
... P2VMAILBOX7
] = igb_mac_readreg
,
3172 [V2PMAILBOX0
... V2PMAILBOX7
] = igb_mac_vfmailbox_read
,
3173 igb_getreg(MBVFICR
),
3174 [VMBMEM0
... VMBMEM0
+ 127] = igb_mac_readreg
,
3175 igb_getreg(MBVFIMR
),
3182 [VLVF0
... VLVF0
+ E1000_VLVF_ARRAY_SIZE
- 1] = igb_mac_readreg
,
3183 [VMVIR0
... VMVIR7
] = igb_mac_readreg
,
3184 [VMOLR0
... VMOLR7
] = igb_mac_readreg
,
3185 [WVBR
] = igb_mac_read_clr4
,
3186 [RQDPC0
] = igb_mac_read_clr4
,
3187 [RQDPC1
] = igb_mac_read_clr4
,
3188 [RQDPC2
] = igb_mac_read_clr4
,
3189 [RQDPC3
] = igb_mac_read_clr4
,
3190 [RQDPC4
] = igb_mac_read_clr4
,
3191 [RQDPC5
] = igb_mac_read_clr4
,
3192 [RQDPC6
] = igb_mac_read_clr4
,
3193 [RQDPC7
] = igb_mac_read_clr4
,
3194 [RQDPC8
] = igb_mac_read_clr4
,
3195 [RQDPC9
] = igb_mac_read_clr4
,
3196 [RQDPC10
] = igb_mac_read_clr4
,
3197 [RQDPC11
] = igb_mac_read_clr4
,
3198 [RQDPC12
] = igb_mac_read_clr4
,
3199 [RQDPC13
] = igb_mac_read_clr4
,
3200 [RQDPC14
] = igb_mac_read_clr4
,
3201 [RQDPC15
] = igb_mac_read_clr4
,
3202 [VTIVAR
... VTIVAR
+ 7] = igb_mac_readreg
,
3203 [VTIVAR_MISC
... VTIVAR_MISC
+ 7] = igb_mac_readreg
,
3205 enum { IGB_NREADOPS
= ARRAY_SIZE(igb_macreg_readops
) };
3207 #define igb_putreg(x) [x] = igb_mac_writereg
3208 typedef void (*writeops
)(IGBCore
*, int, uint32_t);
3209 static const writeops igb_macreg_writeops
[] = {
3222 igb_putreg(RDBAH10
),
3223 igb_putreg(RDBAH11
),
3224 igb_putreg(RDBAH12
),
3225 igb_putreg(RDBAH13
),
3226 igb_putreg(RDBAH14
),
3227 igb_putreg(RDBAH15
),
3228 igb_putreg(SRRCTL0
),
3229 igb_putreg(SRRCTL1
),
3230 igb_putreg(SRRCTL2
),
3231 igb_putreg(SRRCTL3
),
3232 igb_putreg(SRRCTL4
),
3233 igb_putreg(SRRCTL5
),
3234 igb_putreg(SRRCTL6
),
3235 igb_putreg(SRRCTL7
),
3236 igb_putreg(SRRCTL8
),
3237 igb_putreg(SRRCTL9
),
3238 igb_putreg(SRRCTL10
),
3239 igb_putreg(SRRCTL11
),
3240 igb_putreg(SRRCTL12
),
3241 igb_putreg(SRRCTL13
),
3242 igb_putreg(SRRCTL14
),
3243 igb_putreg(SRRCTL15
),
3244 igb_putreg(RXDCTL0
),
3245 igb_putreg(RXDCTL1
),
3246 igb_putreg(RXDCTL2
),
3247 igb_putreg(RXDCTL3
),
3248 igb_putreg(RXDCTL4
),
3249 igb_putreg(RXDCTL5
),
3250 igb_putreg(RXDCTL6
),
3251 igb_putreg(RXDCTL7
),
3252 igb_putreg(RXDCTL8
),
3253 igb_putreg(RXDCTL9
),
3254 igb_putreg(RXDCTL10
),
3255 igb_putreg(RXDCTL11
),
3256 igb_putreg(RXDCTL12
),
3257 igb_putreg(RXDCTL13
),
3258 igb_putreg(RXDCTL14
),
3259 igb_putreg(RXDCTL15
),
3262 igb_putreg(TCTL_EXT
),
3281 igb_putreg(TDBAH10
),
3282 igb_putreg(TDBAH11
),
3283 igb_putreg(TDBAH12
),
3284 igb_putreg(TDBAH13
),
3285 igb_putreg(TDBAH14
),
3286 igb_putreg(TDBAH15
),
3292 igb_putreg(FUNCTAG
),
3304 igb_putreg(TXDCTL0
),
3305 igb_putreg(TXDCTL1
),
3306 igb_putreg(TXDCTL2
),
3307 igb_putreg(TXDCTL3
),
3308 igb_putreg(TXDCTL4
),
3309 igb_putreg(TXDCTL5
),
3310 igb_putreg(TXDCTL6
),
3311 igb_putreg(TXDCTL7
),
3312 igb_putreg(TXDCTL8
),
3313 igb_putreg(TXDCTL9
),
3314 igb_putreg(TXDCTL10
),
3315 igb_putreg(TXDCTL11
),
3316 igb_putreg(TXDCTL12
),
3317 igb_putreg(TXDCTL13
),
3318 igb_putreg(TXDCTL14
),
3319 igb_putreg(TXDCTL15
),
3330 igb_putreg(TXCTL10
),
3331 igb_putreg(TXCTL11
),
3332 igb_putreg(TXCTL12
),
3333 igb_putreg(TXCTL13
),
3334 igb_putreg(TXCTL14
),
3335 igb_putreg(TXCTL15
),
3336 igb_putreg(TDWBAL0
),
3337 igb_putreg(TDWBAL1
),
3338 igb_putreg(TDWBAL2
),
3339 igb_putreg(TDWBAL3
),
3340 igb_putreg(TDWBAL4
),
3341 igb_putreg(TDWBAL5
),
3342 igb_putreg(TDWBAL6
),
3343 igb_putreg(TDWBAL7
),
3344 igb_putreg(TDWBAL8
),
3345 igb_putreg(TDWBAL9
),
3346 igb_putreg(TDWBAL10
),
3347 igb_putreg(TDWBAL11
),
3348 igb_putreg(TDWBAL12
),
3349 igb_putreg(TDWBAL13
),
3350 igb_putreg(TDWBAL14
),
3351 igb_putreg(TDWBAL15
),
3352 igb_putreg(TDWBAH0
),
3353 igb_putreg(TDWBAH1
),
3354 igb_putreg(TDWBAH2
),
3355 igb_putreg(TDWBAH3
),
3356 igb_putreg(TDWBAH4
),
3357 igb_putreg(TDWBAH5
),
3358 igb_putreg(TDWBAH6
),
3359 igb_putreg(TDWBAH7
),
3360 igb_putreg(TDWBAH8
),
3361 igb_putreg(TDWBAH9
),
3362 igb_putreg(TDWBAH10
),
3363 igb_putreg(TDWBAH11
),
3364 igb_putreg(TDWBAH12
),
3365 igb_putreg(TDWBAH13
),
3366 igb_putreg(TDWBAH14
),
3367 igb_putreg(TDWBAH15
),
3369 igb_putreg(RXSTMPH
),
3370 igb_putreg(RXSTMPL
),
3371 igb_putreg(RXSATRL
),
3372 igb_putreg(RXSATRH
),
3373 igb_putreg(TXSTMPL
),
3374 igb_putreg(TXSTMPH
),
3375 igb_putreg(SYSTIML
),
3376 igb_putreg(SYSTIMH
),
3377 igb_putreg(TIMADJL
),
3378 igb_putreg(TSYNCRXCTL
),
3379 igb_putreg(TSYNCTXCTL
),
3380 igb_putreg(EEMNGCTL
),
3386 [TDH0
] = igb_set_16bit
,
3387 [TDH1
] = igb_set_16bit
,
3388 [TDH2
] = igb_set_16bit
,
3389 [TDH3
] = igb_set_16bit
,
3390 [TDH4
] = igb_set_16bit
,
3391 [TDH5
] = igb_set_16bit
,
3392 [TDH6
] = igb_set_16bit
,
3393 [TDH7
] = igb_set_16bit
,
3394 [TDH8
] = igb_set_16bit
,
3395 [TDH9
] = igb_set_16bit
,
3396 [TDH10
] = igb_set_16bit
,
3397 [TDH11
] = igb_set_16bit
,
3398 [TDH12
] = igb_set_16bit
,
3399 [TDH13
] = igb_set_16bit
,
3400 [TDH14
] = igb_set_16bit
,
3401 [TDH15
] = igb_set_16bit
,
3402 [TDT0
] = igb_set_tdt
,
3403 [TDT1
] = igb_set_tdt
,
3404 [TDT2
] = igb_set_tdt
,
3405 [TDT3
] = igb_set_tdt
,
3406 [TDT4
] = igb_set_tdt
,
3407 [TDT5
] = igb_set_tdt
,
3408 [TDT6
] = igb_set_tdt
,
3409 [TDT7
] = igb_set_tdt
,
3410 [TDT8
] = igb_set_tdt
,
3411 [TDT9
] = igb_set_tdt
,
3412 [TDT10
] = igb_set_tdt
,
3413 [TDT11
] = igb_set_tdt
,
3414 [TDT12
] = igb_set_tdt
,
3415 [TDT13
] = igb_set_tdt
,
3416 [TDT14
] = igb_set_tdt
,
3417 [TDT15
] = igb_set_tdt
,
3418 [MDIC
] = igb_set_mdic
,
3419 [ICS
] = igb_set_ics
,
3420 [RDH0
] = igb_set_16bit
,
3421 [RDH1
] = igb_set_16bit
,
3422 [RDH2
] = igb_set_16bit
,
3423 [RDH3
] = igb_set_16bit
,
3424 [RDH4
] = igb_set_16bit
,
3425 [RDH5
] = igb_set_16bit
,
3426 [RDH6
] = igb_set_16bit
,
3427 [RDH7
] = igb_set_16bit
,
3428 [RDH8
] = igb_set_16bit
,
3429 [RDH9
] = igb_set_16bit
,
3430 [RDH10
] = igb_set_16bit
,
3431 [RDH11
] = igb_set_16bit
,
3432 [RDH12
] = igb_set_16bit
,
3433 [RDH13
] = igb_set_16bit
,
3434 [RDH14
] = igb_set_16bit
,
3435 [RDH15
] = igb_set_16bit
,
3436 [RDT0
] = igb_set_rdt
,
3437 [RDT1
] = igb_set_rdt
,
3438 [RDT2
] = igb_set_rdt
,
3439 [RDT3
] = igb_set_rdt
,
3440 [RDT4
] = igb_set_rdt
,
3441 [RDT5
] = igb_set_rdt
,
3442 [RDT6
] = igb_set_rdt
,
3443 [RDT7
] = igb_set_rdt
,
3444 [RDT8
] = igb_set_rdt
,
3445 [RDT9
] = igb_set_rdt
,
3446 [RDT10
] = igb_set_rdt
,
3447 [RDT11
] = igb_set_rdt
,
3448 [RDT12
] = igb_set_rdt
,
3449 [RDT13
] = igb_set_rdt
,
3450 [RDT14
] = igb_set_rdt
,
3451 [RDT15
] = igb_set_rdt
,
3452 [IMC
] = igb_set_imc
,
3453 [IMS
] = igb_set_ims
,
3454 [ICR
] = igb_set_icr
,
3455 [EECD
] = igb_set_eecd
,
3456 [RCTL
] = igb_set_rx_control
,
3457 [CTRL
] = igb_set_ctrl
,
3458 [EERD
] = igb_set_eerd
,
3459 [TDFH
] = igb_set_13bit
,
3460 [TDFT
] = igb_set_13bit
,
3461 [TDFHS
] = igb_set_13bit
,
3462 [TDFTS
] = igb_set_13bit
,
3463 [TDFPC
] = igb_set_13bit
,
3464 [RDFH
] = igb_set_13bit
,
3465 [RDFT
] = igb_set_13bit
,
3466 [RDFHS
] = igb_set_13bit
,
3467 [RDFTS
] = igb_set_13bit
,
3468 [RDFPC
] = igb_set_13bit
,
3469 [GCR
] = igb_set_gcr
,
3470 [RXCSUM
] = igb_set_rxcsum
,
3471 [TDLEN0
] = igb_set_dlen
,
3472 [TDLEN1
] = igb_set_dlen
,
3473 [TDLEN2
] = igb_set_dlen
,
3474 [TDLEN3
] = igb_set_dlen
,
3475 [TDLEN4
] = igb_set_dlen
,
3476 [TDLEN5
] = igb_set_dlen
,
3477 [TDLEN6
] = igb_set_dlen
,
3478 [TDLEN7
] = igb_set_dlen
,
3479 [TDLEN8
] = igb_set_dlen
,
3480 [TDLEN9
] = igb_set_dlen
,
3481 [TDLEN10
] = igb_set_dlen
,
3482 [TDLEN11
] = igb_set_dlen
,
3483 [TDLEN12
] = igb_set_dlen
,
3484 [TDLEN13
] = igb_set_dlen
,
3485 [TDLEN14
] = igb_set_dlen
,
3486 [TDLEN15
] = igb_set_dlen
,
3487 [RDLEN0
] = igb_set_dlen
,
3488 [RDLEN1
] = igb_set_dlen
,
3489 [RDLEN2
] = igb_set_dlen
,
3490 [RDLEN3
] = igb_set_dlen
,
3491 [RDLEN4
] = igb_set_dlen
,
3492 [RDLEN5
] = igb_set_dlen
,
3493 [RDLEN6
] = igb_set_dlen
,
3494 [RDLEN7
] = igb_set_dlen
,
3495 [RDLEN8
] = igb_set_dlen
,
3496 [RDLEN9
] = igb_set_dlen
,
3497 [RDLEN10
] = igb_set_dlen
,
3498 [RDLEN11
] = igb_set_dlen
,
3499 [RDLEN12
] = igb_set_dlen
,
3500 [RDLEN13
] = igb_set_dlen
,
3501 [RDLEN14
] = igb_set_dlen
,
3502 [RDLEN15
] = igb_set_dlen
,
3503 [TDBAL0
] = igb_set_dbal
,
3504 [TDBAL1
] = igb_set_dbal
,
3505 [TDBAL2
] = igb_set_dbal
,
3506 [TDBAL3
] = igb_set_dbal
,
3507 [TDBAL4
] = igb_set_dbal
,
3508 [TDBAL5
] = igb_set_dbal
,
3509 [TDBAL6
] = igb_set_dbal
,
3510 [TDBAL7
] = igb_set_dbal
,
3511 [TDBAL8
] = igb_set_dbal
,
3512 [TDBAL9
] = igb_set_dbal
,
3513 [TDBAL10
] = igb_set_dbal
,
3514 [TDBAL11
] = igb_set_dbal
,
3515 [TDBAL12
] = igb_set_dbal
,
3516 [TDBAL13
] = igb_set_dbal
,
3517 [TDBAL14
] = igb_set_dbal
,
3518 [TDBAL15
] = igb_set_dbal
,
3519 [RDBAL0
] = igb_set_dbal
,
3520 [RDBAL1
] = igb_set_dbal
,
3521 [RDBAL2
] = igb_set_dbal
,
3522 [RDBAL3
] = igb_set_dbal
,
3523 [RDBAL4
] = igb_set_dbal
,
3524 [RDBAL5
] = igb_set_dbal
,
3525 [RDBAL6
] = igb_set_dbal
,
3526 [RDBAL7
] = igb_set_dbal
,
3527 [RDBAL8
] = igb_set_dbal
,
3528 [RDBAL9
] = igb_set_dbal
,
3529 [RDBAL10
] = igb_set_dbal
,
3530 [RDBAL11
] = igb_set_dbal
,
3531 [RDBAL12
] = igb_set_dbal
,
3532 [RDBAL13
] = igb_set_dbal
,
3533 [RDBAL14
] = igb_set_dbal
,
3534 [RDBAL15
] = igb_set_dbal
,
3535 [STATUS
] = igb_set_status
,
3536 [PBACLR
] = igb_set_pbaclr
,
3537 [CTRL_EXT
] = igb_set_ctrlext
,
3538 [FCAH
] = igb_set_16bit
,
3539 [FCT
] = igb_set_16bit
,
3540 [FCTTV
] = igb_set_16bit
,
3541 [FCRTV
] = igb_set_16bit
,
3542 [FCRTH
] = igb_set_fcrth
,
3543 [FCRTL
] = igb_set_fcrtl
,
3544 [CTRL_DUP
] = igb_set_ctrl
,
3545 [RFCTL
] = igb_set_rfctl
,
3546 [TIMINCA
] = igb_set_timinca
,
3547 [TIMADJH
] = igb_set_timadjh
,
3549 [IP6AT
... IP6AT
+ 3] = igb_mac_writereg
,
3550 [IP4AT
... IP4AT
+ 6] = igb_mac_writereg
,
3551 [RA
] = igb_mac_writereg
,
3552 [RA
+ 1] = igb_mac_setmacaddr
,
3553 [RA
+ 2 ... RA
+ 31] = igb_mac_writereg
,
3554 [RA2
... RA2
+ 31] = igb_mac_writereg
,
3555 [WUPM
... WUPM
+ 31] = igb_mac_writereg
,
3556 [MTA
... MTA
+ E1000_MC_TBL_SIZE
- 1] = igb_mac_writereg
,
3557 [VFTA
... VFTA
+ E1000_VLAN_FILTER_TBL_SIZE
- 1] = igb_mac_writereg
,
3558 [FFMT
... FFMT
+ 254] = igb_set_4bit
,
3559 [MDEF
... MDEF
+ 7] = igb_mac_writereg
,
3560 [FTFT
... FTFT
+ 254] = igb_mac_writereg
,
3561 [RETA
... RETA
+ 31] = igb_mac_writereg
,
3562 [RSSRK
... RSSRK
+ 9] = igb_mac_writereg
,
3563 [MAVTV0
... MAVTV3
] = igb_mac_writereg
,
3564 [EITR0
... EITR0
+ IGB_INTR_NUM
- 1] = igb_set_eitr
,
3567 [FWSM
] = igb_mac_writereg
,
3568 [SW_FW_SYNC
] = igb_mac_writereg
,
3569 [EICR
] = igb_set_eicr
,
3570 [EICS
] = igb_set_eics
,
3571 [EIAC
] = igb_set_eiac
,
3572 [EIAM
] = igb_set_eiam
,
3573 [EIMC
] = igb_set_eimc
,
3574 [EIMS
] = igb_set_eims
,
3575 [IVAR0
... IVAR0
+ 7] = igb_mac_writereg
,
3576 igb_putreg(IVAR_MISC
),
3578 [P2VMAILBOX0
... P2VMAILBOX7
] = igb_set_pfmailbox
,
3579 [V2PMAILBOX0
... V2PMAILBOX7
] = igb_set_vfmailbox
,
3580 [MBVFICR
] = igb_w1c
,
3581 [VMBMEM0
... VMBMEM0
+ 127] = igb_mac_writereg
,
3582 igb_putreg(MBVFIMR
),
3589 [VLVF0
... VLVF0
+ E1000_VLVF_ARRAY_SIZE
- 1] = igb_mac_writereg
,
3590 [VMVIR0
... VMVIR7
] = igb_mac_writereg
,
3591 [VMOLR0
... VMOLR7
] = igb_mac_writereg
,
3592 [UTA
... UTA
+ E1000_MC_TBL_SIZE
- 1] = igb_mac_writereg
,
3593 [PVTCTRL0
] = igb_set_vtctrl
,
3594 [PVTCTRL1
] = igb_set_vtctrl
,
3595 [PVTCTRL2
] = igb_set_vtctrl
,
3596 [PVTCTRL3
] = igb_set_vtctrl
,
3597 [PVTCTRL4
] = igb_set_vtctrl
,
3598 [PVTCTRL5
] = igb_set_vtctrl
,
3599 [PVTCTRL6
] = igb_set_vtctrl
,
3600 [PVTCTRL7
] = igb_set_vtctrl
,
3601 [PVTEICS0
] = igb_set_vteics
,
3602 [PVTEICS1
] = igb_set_vteics
,
3603 [PVTEICS2
] = igb_set_vteics
,
3604 [PVTEICS3
] = igb_set_vteics
,
3605 [PVTEICS4
] = igb_set_vteics
,
3606 [PVTEICS5
] = igb_set_vteics
,
3607 [PVTEICS6
] = igb_set_vteics
,
3608 [PVTEICS7
] = igb_set_vteics
,
3609 [PVTEIMS0
] = igb_set_vteims
,
3610 [PVTEIMS1
] = igb_set_vteims
,
3611 [PVTEIMS2
] = igb_set_vteims
,
3612 [PVTEIMS3
] = igb_set_vteims
,
3613 [PVTEIMS4
] = igb_set_vteims
,
3614 [PVTEIMS5
] = igb_set_vteims
,
3615 [PVTEIMS6
] = igb_set_vteims
,
3616 [PVTEIMS7
] = igb_set_vteims
,
3617 [PVTEIMC0
] = igb_set_vteimc
,
3618 [PVTEIMC1
] = igb_set_vteimc
,
3619 [PVTEIMC2
] = igb_set_vteimc
,
3620 [PVTEIMC3
] = igb_set_vteimc
,
3621 [PVTEIMC4
] = igb_set_vteimc
,
3622 [PVTEIMC5
] = igb_set_vteimc
,
3623 [PVTEIMC6
] = igb_set_vteimc
,
3624 [PVTEIMC7
] = igb_set_vteimc
,
3625 [PVTEIAC0
] = igb_set_vteiac
,
3626 [PVTEIAC1
] = igb_set_vteiac
,
3627 [PVTEIAC2
] = igb_set_vteiac
,
3628 [PVTEIAC3
] = igb_set_vteiac
,
3629 [PVTEIAC4
] = igb_set_vteiac
,
3630 [PVTEIAC5
] = igb_set_vteiac
,
3631 [PVTEIAC6
] = igb_set_vteiac
,
3632 [PVTEIAC7
] = igb_set_vteiac
,
3633 [PVTEIAM0
] = igb_set_vteiam
,
3634 [PVTEIAM1
] = igb_set_vteiam
,
3635 [PVTEIAM2
] = igb_set_vteiam
,
3636 [PVTEIAM3
] = igb_set_vteiam
,
3637 [PVTEIAM4
] = igb_set_vteiam
,
3638 [PVTEIAM5
] = igb_set_vteiam
,
3639 [PVTEIAM6
] = igb_set_vteiam
,
3640 [PVTEIAM7
] = igb_set_vteiam
,
3641 [PVTEICR0
] = igb_set_vteicr
,
3642 [PVTEICR1
] = igb_set_vteicr
,
3643 [PVTEICR2
] = igb_set_vteicr
,
3644 [PVTEICR3
] = igb_set_vteicr
,
3645 [PVTEICR4
] = igb_set_vteicr
,
3646 [PVTEICR5
] = igb_set_vteicr
,
3647 [PVTEICR6
] = igb_set_vteicr
,
3648 [PVTEICR7
] = igb_set_vteicr
,
3649 [VTIVAR
... VTIVAR
+ 7] = igb_set_vtivar
,
3650 [VTIVAR_MISC
... VTIVAR_MISC
+ 7] = igb_mac_writereg
3652 enum { IGB_NWRITEOPS
= ARRAY_SIZE(igb_macreg_writeops
) };
3654 enum { MAC_ACCESS_PARTIAL
= 1 };
3657 * The array below combines alias offsets of the index values for the
3658 * MAC registers that have aliases, with the indication of not fully
3659 * implemented registers (lowest bit). This combination is possible
3660 * because all of the offsets are even.
3662 static const uint16_t mac_reg_access
[E1000E_MAC_SIZE
] = {
3663 /* Alias index offsets */
3665 [RDFH_A
] = 0xe904, [RDFT_A
] = 0xe904,
3666 [TDFH_A
] = 0xed00, [TDFT_A
] = 0xed00,
3667 [RA_A
... RA_A
+ 31] = 0x14f0,
3668 [VFTA_A
... VFTA_A
+ E1000_VLAN_FILTER_TBL_SIZE
- 1] = 0x1400,
3670 [RDBAL0_A
] = 0x2600,
3671 [RDBAH0_A
] = 0x2600,
3672 [RDLEN0_A
] = 0x2600,
3673 [SRRCTL0_A
] = 0x2600,
3676 [RXDCTL0_A
] = 0x2600,
3677 [RXCTL0_A
] = 0x2600,
3678 [RQDPC0_A
] = 0x2600,
3679 [RDBAL1_A
] = 0x25D0,
3680 [RDBAL2_A
] = 0x25A0,
3681 [RDBAL3_A
] = 0x2570,
3682 [RDBAH1_A
] = 0x25D0,
3683 [RDBAH2_A
] = 0x25A0,
3684 [RDBAH3_A
] = 0x2570,
3685 [RDLEN1_A
] = 0x25D0,
3686 [RDLEN2_A
] = 0x25A0,
3687 [RDLEN3_A
] = 0x2570,
3688 [SRRCTL1_A
] = 0x25D0,
3689 [SRRCTL2_A
] = 0x25A0,
3690 [SRRCTL3_A
] = 0x2570,
3697 [RXDCTL1_A
] = 0x25D0,
3698 [RXDCTL2_A
] = 0x25A0,
3699 [RXDCTL3_A
] = 0x2570,
3700 [RXCTL1_A
] = 0x25D0,
3701 [RXCTL2_A
] = 0x25A0,
3702 [RXCTL3_A
] = 0x2570,
3703 [RQDPC1_A
] = 0x25D0,
3704 [RQDPC2_A
] = 0x25A0,
3705 [RQDPC3_A
] = 0x2570,
3706 [TDBAL0_A
] = 0x2A00,
3707 [TDBAH0_A
] = 0x2A00,
3708 [TDLEN0_A
] = 0x2A00,
3711 [TXCTL0_A
] = 0x2A00,
3712 [TDWBAL0_A
] = 0x2A00,
3713 [TDWBAH0_A
] = 0x2A00,
3714 [TDBAL1_A
] = 0x29D0,
3715 [TDBAL2_A
] = 0x29A0,
3716 [TDBAL3_A
] = 0x2970,
3717 [TDBAH1_A
] = 0x29D0,
3718 [TDBAH2_A
] = 0x29A0,
3719 [TDBAH3_A
] = 0x2970,
3720 [TDLEN1_A
] = 0x29D0,
3721 [TDLEN2_A
] = 0x29A0,
3722 [TDLEN3_A
] = 0x2970,
3729 [TXDCTL0_A
] = 0x2A00,
3730 [TXDCTL1_A
] = 0x29D0,
3731 [TXDCTL2_A
] = 0x29A0,
3732 [TXDCTL3_A
] = 0x2970,
3733 [TXCTL1_A
] = 0x29D0,
3734 [TXCTL2_A
] = 0x29A0,
3735 [TXCTL3_A
] = 0x29D0,
3736 [TDWBAL1_A
] = 0x29D0,
3737 [TDWBAL2_A
] = 0x29A0,
3738 [TDWBAL3_A
] = 0x2970,
3739 [TDWBAH1_A
] = 0x29D0,
3740 [TDWBAH2_A
] = 0x29A0,
3741 [TDWBAH3_A
] = 0x2970,
3743 /* Access options */
3744 [RDFH
] = MAC_ACCESS_PARTIAL
, [RDFT
] = MAC_ACCESS_PARTIAL
,
3745 [RDFHS
] = MAC_ACCESS_PARTIAL
, [RDFTS
] = MAC_ACCESS_PARTIAL
,
3746 [RDFPC
] = MAC_ACCESS_PARTIAL
,
3747 [TDFH
] = MAC_ACCESS_PARTIAL
, [TDFT
] = MAC_ACCESS_PARTIAL
,
3748 [TDFHS
] = MAC_ACCESS_PARTIAL
, [TDFTS
] = MAC_ACCESS_PARTIAL
,
3749 [TDFPC
] = MAC_ACCESS_PARTIAL
, [EECD
] = MAC_ACCESS_PARTIAL
,
3750 [FLA
] = MAC_ACCESS_PARTIAL
,
3751 [FCAL
] = MAC_ACCESS_PARTIAL
, [FCAH
] = MAC_ACCESS_PARTIAL
,
3752 [FCT
] = MAC_ACCESS_PARTIAL
, [FCTTV
] = MAC_ACCESS_PARTIAL
,
3753 [FCRTV
] = MAC_ACCESS_PARTIAL
, [FCRTL
] = MAC_ACCESS_PARTIAL
,
3754 [FCRTH
] = MAC_ACCESS_PARTIAL
,
3755 [MAVTV0
... MAVTV3
] = MAC_ACCESS_PARTIAL
3759 igb_core_write(IGBCore
*core
, hwaddr addr
, uint64_t val
, unsigned size
)
3761 uint16_t index
= igb_get_reg_index_with_offset(mac_reg_access
, addr
);
3763 if (index
< IGB_NWRITEOPS
&& igb_macreg_writeops
[index
]) {
3764 if (mac_reg_access
[index
] & MAC_ACCESS_PARTIAL
) {
3765 trace_e1000e_wrn_regs_write_trivial(index
<< 2);
3767 trace_e1000e_core_write(index
<< 2, size
, val
);
3768 igb_macreg_writeops
[index
](core
, index
, val
);
3769 } else if (index
< IGB_NREADOPS
&& igb_macreg_readops
[index
]) {
3770 trace_e1000e_wrn_regs_write_ro(index
<< 2, size
, val
);
3772 trace_e1000e_wrn_regs_write_unknown(index
<< 2, size
, val
);
3777 igb_core_read(IGBCore
*core
, hwaddr addr
, unsigned size
)
3780 uint16_t index
= igb_get_reg_index_with_offset(mac_reg_access
, addr
);
3782 if (index
< IGB_NREADOPS
&& igb_macreg_readops
[index
]) {
3783 if (mac_reg_access
[index
] & MAC_ACCESS_PARTIAL
) {
3784 trace_e1000e_wrn_regs_read_trivial(index
<< 2);
3786 val
= igb_macreg_readops
[index
](core
, index
);
3787 trace_e1000e_core_read(index
<< 2, size
, val
);
3790 trace_e1000e_wrn_regs_read_unknown(index
<< 2, size
);
3796 igb_autoneg_pause(IGBCore
*core
)
3798 timer_del(core
->autoneg_timer
);
3802 igb_autoneg_resume(IGBCore
*core
)
3804 if (igb_have_autoneg(core
) &&
3805 !(core
->phy
[MII_BMSR
] & MII_BMSR_AN_COMP
)) {
3806 qemu_get_queue(core
->owner_nic
)->link_down
= false;
3807 timer_mod(core
->autoneg_timer
,
3808 qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL
) + 500);
3813 igb_vm_state_change(void *opaque
, bool running
, RunState state
)
3815 IGBCore
*core
= opaque
;
3818 trace_e1000e_vm_state_running();
3819 igb_intrmgr_resume(core
);
3820 igb_autoneg_resume(core
);
3822 trace_e1000e_vm_state_stopped();
3823 igb_autoneg_pause(core
);
3824 igb_intrmgr_pause(core
);
3829 igb_core_pci_realize(IGBCore
*core
,
3830 const uint16_t *eeprom_templ
,
3831 uint32_t eeprom_size
,
3832 const uint8_t *macaddr
)
3836 core
->autoneg_timer
= timer_new_ms(QEMU_CLOCK_VIRTUAL
,
3837 igb_autoneg_timer
, core
);
3838 igb_intrmgr_pci_realize(core
);
3840 core
->vmstate
= qemu_add_vm_change_state_handler(igb_vm_state_change
, core
);
3842 for (i
= 0; i
< IGB_NUM_QUEUES
; i
++) {
3843 net_tx_pkt_init(&core
->tx
[i
].tx_pkt
, NULL
, E1000E_MAX_TX_FRAGS
);
3846 net_rx_pkt_init(&core
->rx_pkt
);
3848 e1000x_core_prepare_eeprom(core
->eeprom
,
3851 PCI_DEVICE_GET_CLASS(core
->owner
)->device_id
,
3853 igb_update_rx_offloads(core
);
3857 igb_core_pci_uninit(IGBCore
*core
)
3861 timer_free(core
->autoneg_timer
);
3863 igb_intrmgr_pci_unint(core
);
3865 qemu_del_vm_change_state_handler(core
->vmstate
);
3867 for (i
= 0; i
< IGB_NUM_QUEUES
; i
++) {
3868 net_tx_pkt_reset(core
->tx
[i
].tx_pkt
, NULL
);
3869 net_tx_pkt_uninit(core
->tx
[i
].tx_pkt
);
3872 net_rx_pkt_uninit(core
->rx_pkt
);
3875 static const uint16_t
3876 igb_phy_reg_init
[] = {
3877 [MII_BMCR
] = MII_BMCR_SPEED1000
|
3881 [MII_BMSR
] = MII_BMSR_EXTCAP
|
3891 [MII_PHYID1
] = IGP03E1000_E_PHY_ID
>> 16,
3892 [MII_PHYID2
] = (IGP03E1000_E_PHY_ID
& 0xfff0) | 1,
3893 [MII_ANAR
] = MII_ANAR_CSMACD
| MII_ANAR_10
|
3894 MII_ANAR_10FD
| MII_ANAR_TX
|
3895 MII_ANAR_TXFD
| MII_ANAR_PAUSE
|
3896 MII_ANAR_PAUSE_ASYM
,
3897 [MII_ANLPAR
] = MII_ANLPAR_10
| MII_ANLPAR_10FD
|
3898 MII_ANLPAR_TX
| MII_ANLPAR_TXFD
|
3899 MII_ANLPAR_T4
| MII_ANLPAR_PAUSE
,
3900 [MII_ANER
] = MII_ANER_NP
| MII_ANER_NWAY
,
3901 [MII_ANNP
] = 0x1 | MII_ANNP_MP
,
3902 [MII_CTRL1000
] = MII_CTRL1000_HALF
| MII_CTRL1000_FULL
|
3903 MII_CTRL1000_PORT
| MII_CTRL1000_MASTER
,
3904 [MII_STAT1000
] = MII_STAT1000_HALF
| MII_STAT1000_FULL
|
3905 MII_STAT1000_ROK
| MII_STAT1000_LOK
,
3906 [MII_EXTSTAT
] = MII_EXTSTAT_1000T_HD
| MII_EXTSTAT_1000T_FD
,
3908 [IGP01E1000_PHY_PORT_CONFIG
] = BIT(5) | BIT(8),
3909 [IGP01E1000_PHY_PORT_STATUS
] = IGP01E1000_PSSR_SPEED_1000MBPS
,
3910 [IGP02E1000_PHY_POWER_MGMT
] = BIT(0) | BIT(3) | IGP02E1000_PM_D3_LPLU
|
3911 IGP01E1000_PSCFR_SMART_SPEED
3914 static const uint32_t igb_mac_reg_init
[] = {
3915 [LEDCTL
] = 2 | (3 << 8) | BIT(15) | (6 << 16) | (7 << 24),
3916 [EEMNGCTL
] = BIT(31),
3917 [RXDCTL0
] = E1000_RXDCTL_QUEUE_ENABLE
| (1 << 16),
3918 [RXDCTL1
] = 1 << 16,
3919 [RXDCTL2
] = 1 << 16,
3920 [RXDCTL3
] = 1 << 16,
3921 [RXDCTL4
] = 1 << 16,
3922 [RXDCTL5
] = 1 << 16,
3923 [RXDCTL6
] = 1 << 16,
3924 [RXDCTL7
] = 1 << 16,
3925 [RXDCTL8
] = 1 << 16,
3926 [RXDCTL9
] = 1 << 16,
3927 [RXDCTL10
] = 1 << 16,
3928 [RXDCTL11
] = 1 << 16,
3929 [RXDCTL12
] = 1 << 16,
3930 [RXDCTL13
] = 1 << 16,
3931 [RXDCTL14
] = 1 << 16,
3932 [RXDCTL15
] = 1 << 16,
3933 [TIPG
] = 0x08 | (0x04 << 10) | (0x06 << 20),
3934 [CTRL
] = E1000_CTRL_FD
| E1000_CTRL_LRST
| E1000_CTRL_SPD_1000
|
3935 E1000_CTRL_ADVD3WUC
,
3936 [STATUS
] = E1000_STATUS_PHYRA
| BIT(31),
3937 [EECD
] = E1000_EECD_FWE_DIS
| E1000_EECD_PRES
|
3938 (2 << E1000_EECD_SIZE_EX_SHIFT
),
3939 [GCR
] = E1000_L0S_ADJUST
|
3940 E1000_GCR_CMPL_TMOUT_RESEND
|
3941 E1000_GCR_CAP_VER2
|
3942 E1000_L1_ENTRY_LATENCY_MSB
|
3943 E1000_L1_ENTRY_LATENCY_LSB
,
3944 [RXCSUM
] = E1000_RXCSUM_IPOFLD
| E1000_RXCSUM_TUOFLD
,
3947 [TCTL
] = E1000_TCTL_PSP
| (0xF << E1000_CT_SHIFT
) |
3948 (0x40 << E1000_COLD_SHIFT
) | (0x1 << 26) | (0xA << 28),
3949 [TCTL_EXT
] = 0x40 | (0x42 << 10),
3950 [DTXCTL
] = E1000_DTXCTL_8023LL
| E1000_DTXCTL_SPOOF_INT
,
3951 [VET
] = ETH_P_VLAN
| (ETH_P_VLAN
<< 16),
3953 [V2PMAILBOX0
... V2PMAILBOX0
+ IGB_MAX_VF_FUNCTIONS
- 1] = E1000_V2PMAILBOX_RSTI
,
3957 [VMOLR0
... VMOLR0
+ 7] = 0x2600 | E1000_VMOLR_STRCRC
,
3958 [RPLOLR
] = E1000_RPLOLR_STRCRC
,
3960 [TXCTL0
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
3961 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
3962 E1000_DCA_TXCTRL_DESC_RRO_EN
,
3963 [TXCTL1
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
3964 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
3965 E1000_DCA_TXCTRL_DESC_RRO_EN
,
3966 [TXCTL2
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
3967 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
3968 E1000_DCA_TXCTRL_DESC_RRO_EN
,
3969 [TXCTL3
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
3970 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
3971 E1000_DCA_TXCTRL_DESC_RRO_EN
,
3972 [TXCTL4
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
3973 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
3974 E1000_DCA_TXCTRL_DESC_RRO_EN
,
3975 [TXCTL5
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
3976 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
3977 E1000_DCA_TXCTRL_DESC_RRO_EN
,
3978 [TXCTL6
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
3979 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
3980 E1000_DCA_TXCTRL_DESC_RRO_EN
,
3981 [TXCTL7
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
3982 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
3983 E1000_DCA_TXCTRL_DESC_RRO_EN
,
3984 [TXCTL8
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
3985 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
3986 E1000_DCA_TXCTRL_DESC_RRO_EN
,
3987 [TXCTL9
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
3988 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
3989 E1000_DCA_TXCTRL_DESC_RRO_EN
,
3990 [TXCTL10
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
3991 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
3992 E1000_DCA_TXCTRL_DESC_RRO_EN
,
3993 [TXCTL11
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
3994 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
3995 E1000_DCA_TXCTRL_DESC_RRO_EN
,
3996 [TXCTL12
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
3997 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
3998 E1000_DCA_TXCTRL_DESC_RRO_EN
,
3999 [TXCTL13
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4000 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4001 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4002 [TXCTL14
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4003 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4004 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4005 [TXCTL15
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4006 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4007 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4010 static void igb_reset(IGBCore
*core
, bool sw
)
4015 timer_del(core
->autoneg_timer
);
4017 igb_intrmgr_reset(core
);
4019 memset(core
->phy
, 0, sizeof core
->phy
);
4020 memcpy(core
->phy
, igb_phy_reg_init
, sizeof igb_phy_reg_init
);
4022 for (i
= 0; i
< E1000E_MAC_SIZE
; i
++) {
4024 (i
== RXPBS
|| i
== TXPBS
||
4025 (i
>= EITR0
&& i
< EITR0
+ IGB_INTR_NUM
))) {
4029 core
->mac
[i
] = i
< ARRAY_SIZE(igb_mac_reg_init
) ?
4030 igb_mac_reg_init
[i
] : 0;
4033 if (qemu_get_queue(core
->owner_nic
)->link_down
) {
4034 igb_link_down(core
);
4037 e1000x_reset_mac_addr(core
->owner_nic
, core
->mac
, core
->permanent_mac
);
4039 for (int vfn
= 0; vfn
< IGB_MAX_VF_FUNCTIONS
; vfn
++) {
4040 /* Set RSTI, so VF can identify a PF reset is in progress */
4041 core
->mac
[V2PMAILBOX0
+ vfn
] |= E1000_V2PMAILBOX_RSTI
;
4044 for (i
= 0; i
< ARRAY_SIZE(core
->tx
); i
++) {
4046 net_tx_pkt_reset(tx
->tx_pkt
, NULL
);
4047 memset(tx
->ctx
, 0, sizeof(tx
->ctx
));
4049 tx
->skip_cp
= false;
4054 igb_core_reset(IGBCore
*core
)
4056 igb_reset(core
, false);
4059 void igb_core_pre_save(IGBCore
*core
)
4062 NetClientState
*nc
= qemu_get_queue(core
->owner_nic
);
4065 * If link is down and auto-negotiation is supported and ongoing,
4066 * complete auto-negotiation immediately. This allows us to look
4067 * at MII_BMSR_AN_COMP to infer link status on load.
4069 if (nc
->link_down
&& igb_have_autoneg(core
)) {
4070 core
->phy
[MII_BMSR
] |= MII_BMSR_AN_COMP
;
4071 igb_update_flowctl_status(core
);
4074 for (i
= 0; i
< ARRAY_SIZE(core
->tx
); i
++) {
4075 if (net_tx_pkt_has_fragments(core
->tx
[i
].tx_pkt
)) {
4076 core
->tx
[i
].skip_cp
= true;
4082 igb_core_post_load(IGBCore
*core
)
4084 NetClientState
*nc
= qemu_get_queue(core
->owner_nic
);
4087 * nc.link_down can't be migrated, so infer link_down according
4088 * to link status bit in core.mac[STATUS].
4090 nc
->link_down
= (core
->mac
[STATUS
] & E1000_STATUS_LU
) == 0;