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
;
70 typedef struct L2Header
{
71 struct eth_header eth
;
72 struct vlan_header vlan
;
76 igb_receive_internal(IGBCore
*core
, const struct iovec
*iov
, int iovcnt
,
77 bool has_vnet
, bool *external_tx
);
80 igb_set_interrupt_cause(IGBCore
*core
, uint32_t val
);
82 static void igb_update_interrupt_state(IGBCore
*core
);
83 static void igb_reset(IGBCore
*core
, bool sw
);
86 igb_raise_legacy_irq(IGBCore
*core
)
88 trace_e1000e_irq_legacy_notify(true);
89 e1000x_inc_reg_if_not_full(core
->mac
, IAC
);
90 pci_set_irq(core
->owner
, 1);
94 igb_lower_legacy_irq(IGBCore
*core
)
96 trace_e1000e_irq_legacy_notify(false);
97 pci_set_irq(core
->owner
, 0);
100 static void igb_msix_notify(IGBCore
*core
, unsigned int cause
)
102 PCIDevice
*dev
= core
->owner
;
104 uint32_t effective_eiac
;
107 vfn
= 8 - (cause
+ 2) / IGBVF_MSIX_VEC_NUM
;
108 if (vfn
< pcie_sriov_num_vfs(core
->owner
)) {
109 dev
= pcie_sriov_get_vf_at_index(core
->owner
, vfn
);
111 vector
= (cause
+ 2) % IGBVF_MSIX_VEC_NUM
;
112 } else if (cause
>= IGB_MSIX_VEC_NUM
) {
113 qemu_log_mask(LOG_GUEST_ERROR
,
114 "igb: Tried to use vector unavailable for PF");
120 msix_notify(dev
, vector
);
122 trace_e1000e_irq_icr_clear_eiac(core
->mac
[EICR
], core
->mac
[EIAC
]);
123 effective_eiac
= core
->mac
[EIAC
] & BIT(cause
);
124 core
->mac
[EICR
] &= ~effective_eiac
;
128 igb_intrmgr_rearm_timer(IGBIntrDelayTimer
*timer
)
130 int64_t delay_ns
= (int64_t) timer
->core
->mac
[timer
->delay_reg
] *
131 timer
->delay_resolution_ns
;
133 trace_e1000e_irq_rearm_timer(timer
->delay_reg
<< 2, delay_ns
);
135 timer_mod(timer
->timer
, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) + delay_ns
);
137 timer
->running
= true;
141 igb_intmgr_timer_resume(IGBIntrDelayTimer
*timer
)
143 if (timer
->running
) {
144 igb_intrmgr_rearm_timer(timer
);
149 igb_intmgr_timer_pause(IGBIntrDelayTimer
*timer
)
151 if (timer
->running
) {
152 timer_del(timer
->timer
);
157 igb_intrmgr_on_msix_throttling_timer(void *opaque
)
159 IGBIntrDelayTimer
*timer
= opaque
;
160 int idx
= timer
- &timer
->core
->eitr
[0];
162 timer
->running
= false;
164 trace_e1000e_irq_msix_notify_postponed_vec(idx
);
165 igb_msix_notify(timer
->core
, idx
);
169 igb_intrmgr_initialize_all_timers(IGBCore
*core
, bool create
)
173 for (i
= 0; i
< IGB_INTR_NUM
; i
++) {
174 core
->eitr
[i
].core
= core
;
175 core
->eitr
[i
].delay_reg
= EITR0
+ i
;
176 core
->eitr
[i
].delay_resolution_ns
= E1000_INTR_DELAY_NS_RES
;
183 for (i
= 0; i
< IGB_INTR_NUM
; i
++) {
184 core
->eitr
[i
].timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
,
185 igb_intrmgr_on_msix_throttling_timer
,
191 igb_intrmgr_resume(IGBCore
*core
)
195 for (i
= 0; i
< IGB_INTR_NUM
; i
++) {
196 igb_intmgr_timer_resume(&core
->eitr
[i
]);
201 igb_intrmgr_pause(IGBCore
*core
)
205 for (i
= 0; i
< IGB_INTR_NUM
; i
++) {
206 igb_intmgr_timer_pause(&core
->eitr
[i
]);
211 igb_intrmgr_reset(IGBCore
*core
)
215 for (i
= 0; i
< IGB_INTR_NUM
; i
++) {
216 if (core
->eitr
[i
].running
) {
217 timer_del(core
->eitr
[i
].timer
);
218 igb_intrmgr_on_msix_throttling_timer(&core
->eitr
[i
]);
224 igb_intrmgr_pci_unint(IGBCore
*core
)
228 for (i
= 0; i
< IGB_INTR_NUM
; i
++) {
229 timer_free(core
->eitr
[i
].timer
);
234 igb_intrmgr_pci_realize(IGBCore
*core
)
236 igb_intrmgr_initialize_all_timers(core
, true);
240 igb_rx_csum_enabled(IGBCore
*core
)
242 return (core
->mac
[RXCSUM
] & E1000_RXCSUM_PCSD
) ? false : true;
246 igb_rx_use_legacy_descriptor(IGBCore
*core
)
249 * TODO: If SRRCTL[n],DESCTYPE = 000b, the 82576 uses the legacy Rx
256 igb_rss_enabled(IGBCore
*core
)
258 return (core
->mac
[MRQC
] & 3) == E1000_MRQC_ENABLE_RSS_MQ
&&
259 !igb_rx_csum_enabled(core
) &&
260 !igb_rx_use_legacy_descriptor(core
);
263 typedef struct E1000E_RSSInfo_st
{
271 igb_rss_get_hash_type(IGBCore
*core
, struct NetRxPkt
*pkt
)
274 EthL4HdrProto l4hdr_proto
;
276 assert(igb_rss_enabled(core
));
278 net_rx_pkt_get_protocols(pkt
, &hasip4
, &hasip6
, &l4hdr_proto
);
281 trace_e1000e_rx_rss_ip4(l4hdr_proto
, core
->mac
[MRQC
],
282 E1000_MRQC_EN_TCPIPV4(core
->mac
[MRQC
]),
283 E1000_MRQC_EN_IPV4(core
->mac
[MRQC
]));
285 if (l4hdr_proto
== ETH_L4_HDR_PROTO_TCP
&&
286 E1000_MRQC_EN_TCPIPV4(core
->mac
[MRQC
])) {
287 return E1000_MRQ_RSS_TYPE_IPV4TCP
;
290 if (l4hdr_proto
== ETH_L4_HDR_PROTO_UDP
&&
291 (core
->mac
[MRQC
] & E1000_MRQC_RSS_FIELD_IPV4_UDP
)) {
292 return E1000_MRQ_RSS_TYPE_IPV4UDP
;
295 if (E1000_MRQC_EN_IPV4(core
->mac
[MRQC
])) {
296 return E1000_MRQ_RSS_TYPE_IPV4
;
299 eth_ip6_hdr_info
*ip6info
= net_rx_pkt_get_ip6_info(pkt
);
301 bool ex_dis
= core
->mac
[RFCTL
] & E1000_RFCTL_IPV6_EX_DIS
;
302 bool new_ex_dis
= core
->mac
[RFCTL
] & E1000_RFCTL_NEW_IPV6_EXT_DIS
;
305 * Following two traces must not be combined because resulting
306 * event will have 11 arguments totally and some trace backends
307 * (at least "ust") have limitation of maximum 10 arguments per
308 * event. Events with more arguments fail to compile for
309 * backends like these.
311 trace_e1000e_rx_rss_ip6_rfctl(core
->mac
[RFCTL
]);
312 trace_e1000e_rx_rss_ip6(ex_dis
, new_ex_dis
, l4hdr_proto
,
313 ip6info
->has_ext_hdrs
,
314 ip6info
->rss_ex_dst_valid
,
315 ip6info
->rss_ex_src_valid
,
317 E1000_MRQC_EN_TCPIPV6EX(core
->mac
[MRQC
]),
318 E1000_MRQC_EN_IPV6EX(core
->mac
[MRQC
]),
319 E1000_MRQC_EN_IPV6(core
->mac
[MRQC
]));
321 if ((!ex_dis
|| !ip6info
->has_ext_hdrs
) &&
322 (!new_ex_dis
|| !(ip6info
->rss_ex_dst_valid
||
323 ip6info
->rss_ex_src_valid
))) {
325 if (l4hdr_proto
== ETH_L4_HDR_PROTO_TCP
&&
326 E1000_MRQC_EN_TCPIPV6EX(core
->mac
[MRQC
])) {
327 return E1000_MRQ_RSS_TYPE_IPV6TCPEX
;
330 if (l4hdr_proto
== ETH_L4_HDR_PROTO_UDP
&&
331 (core
->mac
[MRQC
] & E1000_MRQC_RSS_FIELD_IPV6_UDP
)) {
332 return E1000_MRQ_RSS_TYPE_IPV6UDP
;
335 if (E1000_MRQC_EN_IPV6EX(core
->mac
[MRQC
])) {
336 return E1000_MRQ_RSS_TYPE_IPV6EX
;
341 if (E1000_MRQC_EN_IPV6(core
->mac
[MRQC
])) {
342 return E1000_MRQ_RSS_TYPE_IPV6
;
347 return E1000_MRQ_RSS_TYPE_NONE
;
351 igb_rss_calc_hash(IGBCore
*core
, struct NetRxPkt
*pkt
, E1000E_RSSInfo
*info
)
353 NetRxPktRssType type
;
355 assert(igb_rss_enabled(core
));
357 switch (info
->type
) {
358 case E1000_MRQ_RSS_TYPE_IPV4
:
359 type
= NetPktRssIpV4
;
361 case E1000_MRQ_RSS_TYPE_IPV4TCP
:
362 type
= NetPktRssIpV4Tcp
;
364 case E1000_MRQ_RSS_TYPE_IPV6TCPEX
:
365 type
= NetPktRssIpV6TcpEx
;
367 case E1000_MRQ_RSS_TYPE_IPV6
:
368 type
= NetPktRssIpV6
;
370 case E1000_MRQ_RSS_TYPE_IPV6EX
:
371 type
= NetPktRssIpV6Ex
;
373 case E1000_MRQ_RSS_TYPE_IPV4UDP
:
374 type
= NetPktRssIpV4Udp
;
376 case E1000_MRQ_RSS_TYPE_IPV6UDP
:
377 type
= NetPktRssIpV6Udp
;
384 return net_rx_pkt_calc_rss_hash(pkt
, type
, (uint8_t *) &core
->mac
[RSSRK
]);
388 igb_rss_parse_packet(IGBCore
*core
, struct NetRxPkt
*pkt
, bool tx
,
389 E1000E_RSSInfo
*info
)
391 trace_e1000e_rx_rss_started();
393 if (tx
|| !igb_rss_enabled(core
)) {
394 info
->enabled
= false;
398 trace_e1000e_rx_rss_disabled();
402 info
->enabled
= true;
404 info
->type
= igb_rss_get_hash_type(core
, pkt
);
406 trace_e1000e_rx_rss_type(info
->type
);
408 if (info
->type
== E1000_MRQ_RSS_TYPE_NONE
) {
414 info
->hash
= igb_rss_calc_hash(core
, pkt
, info
);
415 info
->queue
= E1000_RSS_QUEUE(&core
->mac
[RETA
], info
->hash
);
419 igb_tx_insert_vlan(IGBCore
*core
, uint16_t qn
, struct igb_tx
*tx
,
420 uint16_t vlan
, bool insert_vlan
)
422 if (core
->mac
[MRQC
] & 1) {
423 uint16_t pool
= qn
% IGB_NUM_VM_POOLS
;
425 if (core
->mac
[VMVIR0
+ pool
] & E1000_VMVIR_VLANA_DEFAULT
) {
426 /* always insert default VLAN */
428 vlan
= core
->mac
[VMVIR0
+ pool
] & 0xffff;
429 } else if (core
->mac
[VMVIR0
+ pool
] & E1000_VMVIR_VLANA_NEVER
) {
435 net_tx_pkt_setup_vlan_header_ex(tx
->tx_pkt
, vlan
,
436 core
->mac
[VET
] & 0xffff);
441 igb_setup_tx_offloads(IGBCore
*core
, struct igb_tx
*tx
)
443 uint32_t idx
= (tx
->first_olinfo_status
>> 4) & 1;
445 if (tx
->first_cmd_type_len
& E1000_ADVTXD_DCMD_TSE
) {
446 uint32_t mss
= tx
->ctx
[idx
].mss_l4len_idx
>> E1000_ADVTXD_MSS_SHIFT
;
447 if (!net_tx_pkt_build_vheader(tx
->tx_pkt
, true, true, mss
)) {
451 net_tx_pkt_update_ip_checksums(tx
->tx_pkt
);
452 e1000x_inc_reg_if_not_full(core
->mac
, TSCTC
);
456 if ((tx
->first_olinfo_status
& E1000_ADVTXD_POTS_TXSM
) &&
457 !((tx
->ctx
[idx
].type_tucmd_mlhl
& E1000_ADVTXD_TUCMD_L4T_SCTP
) ?
458 net_tx_pkt_update_sctp_checksum(tx
->tx_pkt
) :
459 net_tx_pkt_build_vheader(tx
->tx_pkt
, false, true, 0))) {
463 if (tx
->first_olinfo_status
& E1000_ADVTXD_POTS_IXSM
) {
464 net_tx_pkt_update_ip_hdr_checksum(tx
->tx_pkt
);
470 static void igb_tx_pkt_mac_callback(void *core
,
471 const struct iovec
*iov
,
473 const struct iovec
*virt_iov
,
476 igb_receive_internal(core
, virt_iov
, virt_iovcnt
, true, NULL
);
479 static void igb_tx_pkt_vmdq_callback(void *opaque
,
480 const struct iovec
*iov
,
482 const struct iovec
*virt_iov
,
485 IGBTxPktVmdqCallbackContext
*context
= opaque
;
488 igb_receive_internal(context
->core
, virt_iov
, virt_iovcnt
, true,
492 if (context
->core
->has_vnet
) {
493 qemu_sendv_packet(context
->nc
, virt_iov
, virt_iovcnt
);
495 qemu_sendv_packet(context
->nc
, iov
, iovcnt
);
500 /* TX Packets Switching (7.10.3.6) */
501 static bool igb_tx_pkt_switch(IGBCore
*core
, struct igb_tx
*tx
,
504 IGBTxPktVmdqCallbackContext context
;
506 /* TX switching is only used to serve VM to VM traffic. */
507 if (!(core
->mac
[MRQC
] & 1)) {
511 /* TX switching requires DTXSWC.Loopback_en bit enabled. */
512 if (!(core
->mac
[DTXSWC
] & E1000_DTXSWC_VMDQ_LOOPBACK_EN
)) {
519 return net_tx_pkt_send_custom(tx
->tx_pkt
, false,
520 igb_tx_pkt_vmdq_callback
, &context
);
523 return net_tx_pkt_send(tx
->tx_pkt
, nc
);
527 igb_tx_pkt_send(IGBCore
*core
, struct igb_tx
*tx
, int queue_index
)
529 int target_queue
= MIN(core
->max_queue_num
, queue_index
);
530 NetClientState
*queue
= qemu_get_subqueue(core
->owner_nic
, target_queue
);
532 if (!igb_setup_tx_offloads(core
, tx
)) {
536 net_tx_pkt_dump(tx
->tx_pkt
);
538 if ((core
->phy
[MII_BMCR
] & MII_BMCR_LOOPBACK
) ||
539 ((core
->mac
[RCTL
] & E1000_RCTL_LBM_MAC
) == E1000_RCTL_LBM_MAC
)) {
540 return net_tx_pkt_send_custom(tx
->tx_pkt
, false,
541 igb_tx_pkt_mac_callback
, core
);
543 return igb_tx_pkt_switch(core
, tx
, queue
);
548 igb_on_tx_done_update_stats(IGBCore
*core
, struct NetTxPkt
*tx_pkt
, int qn
)
550 static const int PTCregs
[6] = { PTC64
, PTC127
, PTC255
, PTC511
,
553 size_t tot_len
= net_tx_pkt_get_total_len(tx_pkt
) + 4;
555 e1000x_increase_size_stats(core
->mac
, PTCregs
, tot_len
);
556 e1000x_inc_reg_if_not_full(core
->mac
, TPT
);
557 e1000x_grow_8reg_if_not_full(core
->mac
, TOTL
, tot_len
);
559 switch (net_tx_pkt_get_packet_type(tx_pkt
)) {
561 e1000x_inc_reg_if_not_full(core
->mac
, BPTC
);
564 e1000x_inc_reg_if_not_full(core
->mac
, MPTC
);
569 g_assert_not_reached();
572 e1000x_inc_reg_if_not_full(core
->mac
, GPTC
);
573 e1000x_grow_8reg_if_not_full(core
->mac
, GOTCL
, tot_len
);
575 if (core
->mac
[MRQC
] & 1) {
576 uint16_t pool
= qn
% IGB_NUM_VM_POOLS
;
578 core
->mac
[PVFGOTC0
+ (pool
* 64)] += tot_len
;
579 core
->mac
[PVFGPTC0
+ (pool
* 64)]++;
584 igb_process_tx_desc(IGBCore
*core
,
587 union e1000_adv_tx_desc
*tx_desc
,
590 struct e1000_adv_tx_context_desc
*tx_ctx_desc
;
591 uint32_t cmd_type_len
;
593 uint64_t buffer_addr
;
596 cmd_type_len
= le32_to_cpu(tx_desc
->read
.cmd_type_len
);
598 if (cmd_type_len
& E1000_ADVTXD_DCMD_DEXT
) {
599 if ((cmd_type_len
& E1000_ADVTXD_DTYP_DATA
) ==
600 E1000_ADVTXD_DTYP_DATA
) {
601 /* advanced transmit data descriptor */
603 tx
->first_cmd_type_len
= cmd_type_len
;
604 tx
->first_olinfo_status
= le32_to_cpu(tx_desc
->read
.olinfo_status
);
607 } else if ((cmd_type_len
& E1000_ADVTXD_DTYP_CTXT
) ==
608 E1000_ADVTXD_DTYP_CTXT
) {
609 /* advanced transmit context descriptor */
610 tx_ctx_desc
= (struct e1000_adv_tx_context_desc
*)tx_desc
;
611 idx
= (le32_to_cpu(tx_ctx_desc
->mss_l4len_idx
) >> 4) & 1;
612 tx
->ctx
[idx
].vlan_macip_lens
= le32_to_cpu(tx_ctx_desc
->vlan_macip_lens
);
613 tx
->ctx
[idx
].seqnum_seed
= le32_to_cpu(tx_ctx_desc
->seqnum_seed
);
614 tx
->ctx
[idx
].type_tucmd_mlhl
= le32_to_cpu(tx_ctx_desc
->type_tucmd_mlhl
);
615 tx
->ctx
[idx
].mss_l4len_idx
= le32_to_cpu(tx_ctx_desc
->mss_l4len_idx
);
618 /* unknown descriptor type */
622 /* legacy descriptor */
624 /* TODO: Implement a support for legacy descriptors (7.2.2.1). */
627 buffer_addr
= le64_to_cpu(tx_desc
->read
.buffer_addr
);
628 length
= cmd_type_len
& 0xFFFF;
631 if (!net_tx_pkt_add_raw_fragment_pci(tx
->tx_pkt
, dev
,
632 buffer_addr
, length
)) {
637 if (cmd_type_len
& E1000_TXD_CMD_EOP
) {
638 if (!tx
->skip_cp
&& net_tx_pkt_parse(tx
->tx_pkt
)) {
639 idx
= (tx
->first_olinfo_status
>> 4) & 1;
640 igb_tx_insert_vlan(core
, queue_index
, tx
,
641 tx
->ctx
[idx
].vlan_macip_lens
>> IGB_TX_FLAGS_VLAN_SHIFT
,
642 !!(tx
->first_cmd_type_len
& E1000_TXD_CMD_VLE
));
644 if (igb_tx_pkt_send(core
, tx
, queue_index
)) {
645 igb_on_tx_done_update_stats(core
, tx
->tx_pkt
, queue_index
);
651 net_tx_pkt_reset(tx
->tx_pkt
, net_tx_pkt_unmap_frag_pci
, dev
);
655 static uint32_t igb_tx_wb_eic(IGBCore
*core
, int queue_idx
)
659 n
= igb_ivar_entry_tx(queue_idx
);
660 ent
= (core
->mac
[IVAR0
+ n
/ 4] >> (8 * (n
% 4))) & 0xff;
662 return (ent
& E1000_IVAR_VALID
) ? BIT(ent
& 0x1f) : 0;
665 static uint32_t igb_rx_wb_eic(IGBCore
*core
, int queue_idx
)
669 n
= igb_ivar_entry_rx(queue_idx
);
670 ent
= (core
->mac
[IVAR0
+ n
/ 4] >> (8 * (n
% 4))) & 0xff;
672 return (ent
& E1000_IVAR_VALID
) ? BIT(ent
& 0x1f) : 0;
675 typedef struct E1000E_RingInfo_st
{
685 igb_ring_empty(IGBCore
*core
, const E1000E_RingInfo
*r
)
687 return core
->mac
[r
->dh
] == core
->mac
[r
->dt
] ||
688 core
->mac
[r
->dt
] >= core
->mac
[r
->dlen
] / E1000_RING_DESC_LEN
;
691 static inline uint64_t
692 igb_ring_base(IGBCore
*core
, const E1000E_RingInfo
*r
)
694 uint64_t bah
= core
->mac
[r
->dbah
];
695 uint64_t bal
= core
->mac
[r
->dbal
];
697 return (bah
<< 32) + bal
;
700 static inline uint64_t
701 igb_ring_head_descr(IGBCore
*core
, const E1000E_RingInfo
*r
)
703 return igb_ring_base(core
, r
) + E1000_RING_DESC_LEN
* core
->mac
[r
->dh
];
707 igb_ring_advance(IGBCore
*core
, const E1000E_RingInfo
*r
, uint32_t count
)
709 core
->mac
[r
->dh
] += count
;
711 if (core
->mac
[r
->dh
] * E1000_RING_DESC_LEN
>= core
->mac
[r
->dlen
]) {
712 core
->mac
[r
->dh
] = 0;
716 static inline uint32_t
717 igb_ring_free_descr_num(IGBCore
*core
, const E1000E_RingInfo
*r
)
719 trace_e1000e_ring_free_space(r
->idx
, core
->mac
[r
->dlen
],
720 core
->mac
[r
->dh
], core
->mac
[r
->dt
]);
722 if (core
->mac
[r
->dh
] <= core
->mac
[r
->dt
]) {
723 return core
->mac
[r
->dt
] - core
->mac
[r
->dh
];
726 if (core
->mac
[r
->dh
] > core
->mac
[r
->dt
]) {
727 return core
->mac
[r
->dlen
] / E1000_RING_DESC_LEN
+
728 core
->mac
[r
->dt
] - core
->mac
[r
->dh
];
731 g_assert_not_reached();
736 igb_ring_enabled(IGBCore
*core
, const E1000E_RingInfo
*r
)
738 return core
->mac
[r
->dlen
] > 0;
741 typedef struct IGB_TxRing_st
{
742 const E1000E_RingInfo
*i
;
747 igb_mq_queue_idx(int base_reg_idx
, int reg_idx
)
749 return (reg_idx
- base_reg_idx
) / 16;
753 igb_tx_ring_init(IGBCore
*core
, IGB_TxRing
*txr
, int idx
)
755 static const E1000E_RingInfo i
[IGB_NUM_QUEUES
] = {
756 { TDBAH0
, TDBAL0
, TDLEN0
, TDH0
, TDT0
, 0 },
757 { TDBAH1
, TDBAL1
, TDLEN1
, TDH1
, TDT1
, 1 },
758 { TDBAH2
, TDBAL2
, TDLEN2
, TDH2
, TDT2
, 2 },
759 { TDBAH3
, TDBAL3
, TDLEN3
, TDH3
, TDT3
, 3 },
760 { TDBAH4
, TDBAL4
, TDLEN4
, TDH4
, TDT4
, 4 },
761 { TDBAH5
, TDBAL5
, TDLEN5
, TDH5
, TDT5
, 5 },
762 { TDBAH6
, TDBAL6
, TDLEN6
, TDH6
, TDT6
, 6 },
763 { TDBAH7
, TDBAL7
, TDLEN7
, TDH7
, TDT7
, 7 },
764 { TDBAH8
, TDBAL8
, TDLEN8
, TDH8
, TDT8
, 8 },
765 { TDBAH9
, TDBAL9
, TDLEN9
, TDH9
, TDT9
, 9 },
766 { TDBAH10
, TDBAL10
, TDLEN10
, TDH10
, TDT10
, 10 },
767 { TDBAH11
, TDBAL11
, TDLEN11
, TDH11
, TDT11
, 11 },
768 { TDBAH12
, TDBAL12
, TDLEN12
, TDH12
, TDT12
, 12 },
769 { TDBAH13
, TDBAL13
, TDLEN13
, TDH13
, TDT13
, 13 },
770 { TDBAH14
, TDBAL14
, TDLEN14
, TDH14
, TDT14
, 14 },
771 { TDBAH15
, TDBAL15
, TDLEN15
, TDH15
, TDT15
, 15 }
774 assert(idx
< ARRAY_SIZE(i
));
777 txr
->tx
= &core
->tx
[idx
];
780 typedef struct E1000E_RxRing_st
{
781 const E1000E_RingInfo
*i
;
785 igb_rx_ring_init(IGBCore
*core
, E1000E_RxRing
*rxr
, int idx
)
787 static const E1000E_RingInfo i
[IGB_NUM_QUEUES
] = {
788 { RDBAH0
, RDBAL0
, RDLEN0
, RDH0
, RDT0
, 0 },
789 { RDBAH1
, RDBAL1
, RDLEN1
, RDH1
, RDT1
, 1 },
790 { RDBAH2
, RDBAL2
, RDLEN2
, RDH2
, RDT2
, 2 },
791 { RDBAH3
, RDBAL3
, RDLEN3
, RDH3
, RDT3
, 3 },
792 { RDBAH4
, RDBAL4
, RDLEN4
, RDH4
, RDT4
, 4 },
793 { RDBAH5
, RDBAL5
, RDLEN5
, RDH5
, RDT5
, 5 },
794 { RDBAH6
, RDBAL6
, RDLEN6
, RDH6
, RDT6
, 6 },
795 { RDBAH7
, RDBAL7
, RDLEN7
, RDH7
, RDT7
, 7 },
796 { RDBAH8
, RDBAL8
, RDLEN8
, RDH8
, RDT8
, 8 },
797 { RDBAH9
, RDBAL9
, RDLEN9
, RDH9
, RDT9
, 9 },
798 { RDBAH10
, RDBAL10
, RDLEN10
, RDH10
, RDT10
, 10 },
799 { RDBAH11
, RDBAL11
, RDLEN11
, RDH11
, RDT11
, 11 },
800 { RDBAH12
, RDBAL12
, RDLEN12
, RDH12
, RDT12
, 12 },
801 { RDBAH13
, RDBAL13
, RDLEN13
, RDH13
, RDT13
, 13 },
802 { RDBAH14
, RDBAL14
, RDLEN14
, RDH14
, RDT14
, 14 },
803 { RDBAH15
, RDBAL15
, RDLEN15
, RDH15
, RDT15
, 15 }
806 assert(idx
< ARRAY_SIZE(i
));
812 igb_txdesc_writeback(IGBCore
*core
, dma_addr_t base
,
813 union e1000_adv_tx_desc
*tx_desc
,
814 const E1000E_RingInfo
*txi
)
817 uint32_t cmd_type_len
= le32_to_cpu(tx_desc
->read
.cmd_type_len
);
820 tdwba
= core
->mac
[E1000_TDWBAL(txi
->idx
) >> 2];
821 tdwba
|= (uint64_t)core
->mac
[E1000_TDWBAH(txi
->idx
) >> 2] << 32;
823 if (!(cmd_type_len
& E1000_TXD_CMD_RS
)) {
827 d
= pcie_sriov_get_vf_at_index(core
->owner
, txi
->idx
% 8);
833 uint32_t buffer
= cpu_to_le32(core
->mac
[txi
->dh
]);
834 pci_dma_write(d
, tdwba
& ~3, &buffer
, sizeof(buffer
));
836 uint32_t status
= le32_to_cpu(tx_desc
->wb
.status
) | E1000_TXD_STAT_DD
;
838 tx_desc
->wb
.status
= cpu_to_le32(status
);
839 pci_dma_write(d
, base
+ offsetof(union e1000_adv_tx_desc
, wb
),
840 &tx_desc
->wb
, sizeof(tx_desc
->wb
));
843 return igb_tx_wb_eic(core
, txi
->idx
);
847 igb_tx_enabled(IGBCore
*core
, const E1000E_RingInfo
*txi
)
849 bool vmdq
= core
->mac
[MRQC
] & 1;
850 uint16_t qn
= txi
->idx
;
851 uint16_t pool
= qn
% IGB_NUM_VM_POOLS
;
853 return (core
->mac
[TCTL
] & E1000_TCTL_EN
) &&
854 (!vmdq
|| core
->mac
[VFTE
] & BIT(pool
)) &&
855 (core
->mac
[TXDCTL0
+ (qn
* 16)] & E1000_TXDCTL_QUEUE_ENABLE
);
859 igb_start_xmit(IGBCore
*core
, const IGB_TxRing
*txr
)
863 union e1000_adv_tx_desc desc
;
864 const E1000E_RingInfo
*txi
= txr
->i
;
867 if (!igb_tx_enabled(core
, txi
)) {
868 trace_e1000e_tx_disabled();
872 d
= pcie_sriov_get_vf_at_index(core
->owner
, txi
->idx
% 8);
877 while (!igb_ring_empty(core
, txi
)) {
878 base
= igb_ring_head_descr(core
, txi
);
880 pci_dma_read(d
, base
, &desc
, sizeof(desc
));
882 trace_e1000e_tx_descr((void *)(intptr_t)desc
.read
.buffer_addr
,
883 desc
.read
.cmd_type_len
, desc
.wb
.status
);
885 igb_process_tx_desc(core
, d
, txr
->tx
, &desc
, txi
->idx
);
886 igb_ring_advance(core
, txi
, 1);
887 eic
|= igb_txdesc_writeback(core
, base
, &desc
, txi
);
891 core
->mac
[EICR
] |= eic
;
892 igb_set_interrupt_cause(core
, E1000_ICR_TXDW
);
895 net_tx_pkt_reset(txr
->tx
->tx_pkt
, net_tx_pkt_unmap_frag_pci
, d
);
899 igb_rxbufsize(IGBCore
*core
, const E1000E_RingInfo
*r
)
901 uint32_t srrctl
= core
->mac
[E1000_SRRCTL(r
->idx
) >> 2];
902 uint32_t bsizepkt
= srrctl
& E1000_SRRCTL_BSIZEPKT_MASK
;
904 return bsizepkt
<< E1000_SRRCTL_BSIZEPKT_SHIFT
;
907 return e1000x_rxbufsize(core
->mac
[RCTL
]);
911 igb_has_rxbufs(IGBCore
*core
, const E1000E_RingInfo
*r
, size_t total_size
)
913 uint32_t bufs
= igb_ring_free_descr_num(core
, r
);
914 uint32_t bufsize
= igb_rxbufsize(core
, r
);
916 trace_e1000e_rx_has_buffers(r
->idx
, bufs
, total_size
, bufsize
);
918 return total_size
<= bufs
/ (core
->rx_desc_len
/ E1000_MIN_RX_DESC_LEN
) *
923 igb_start_recv(IGBCore
*core
)
927 trace_e1000e_rx_start_recv();
929 for (i
= 0; i
<= core
->max_queue_num
; i
++) {
930 qemu_flush_queued_packets(qemu_get_subqueue(core
->owner_nic
, i
));
935 igb_can_receive(IGBCore
*core
)
939 if (!e1000x_rx_ready(core
->owner
, core
->mac
)) {
943 for (i
= 0; i
< IGB_NUM_QUEUES
; i
++) {
945 if (!(core
->mac
[RXDCTL0
+ (i
* 16)] & E1000_RXDCTL_QUEUE_ENABLE
)) {
949 igb_rx_ring_init(core
, &rxr
, i
);
950 if (igb_ring_enabled(core
, rxr
.i
) && igb_has_rxbufs(core
, rxr
.i
, 1)) {
951 trace_e1000e_rx_can_recv();
956 trace_e1000e_rx_can_recv_rings_full();
961 igb_receive(IGBCore
*core
, const uint8_t *buf
, size_t size
)
963 const struct iovec iov
= {
964 .iov_base
= (uint8_t *)buf
,
968 return igb_receive_iov(core
, &iov
, 1);
972 igb_rx_l3_cso_enabled(IGBCore
*core
)
974 return !!(core
->mac
[RXCSUM
] & E1000_RXCSUM_IPOFLD
);
978 igb_rx_l4_cso_enabled(IGBCore
*core
)
980 return !!(core
->mac
[RXCSUM
] & E1000_RXCSUM_TUOFLD
);
984 igb_rx_is_oversized(IGBCore
*core
, uint16_t qn
, size_t size
)
986 uint16_t pool
= qn
% IGB_NUM_VM_POOLS
;
987 bool lpe
= !!(core
->mac
[VMOLR0
+ pool
] & E1000_VMOLR_LPE
);
988 int max_ethernet_lpe_size
=
989 core
->mac
[VMOLR0
+ pool
] & E1000_VMOLR_RLPML_MASK
;
990 int max_ethernet_vlan_size
= 1522;
992 return size
> (lpe
? max_ethernet_lpe_size
: max_ethernet_vlan_size
);
995 static uint16_t igb_receive_assign(IGBCore
*core
, const L2Header
*l2_header
,
996 size_t size
, E1000E_RSSInfo
*rss_info
,
999 static const int ta_shift
[] = { 4, 3, 2, 0 };
1000 const struct eth_header
*ehdr
= &l2_header
->eth
;
1001 uint32_t f
, ra
[2], *macp
, rctl
= core
->mac
[RCTL
];
1002 uint16_t queues
= 0;
1003 uint16_t oversized
= 0;
1004 uint16_t vid
= be16_to_cpu(l2_header
->vlan
.h_tci
) & VLAN_VID_MASK
;
1007 memset(rss_info
, 0, sizeof(E1000E_RSSInfo
));
1010 *external_tx
= true;
1013 if (e1000x_is_vlan_packet(ehdr
, core
->mac
[VET
] & 0xffff) &&
1014 !e1000x_rx_vlan_filter(core
->mac
, PKT_GET_VLAN_HDR(ehdr
))) {
1018 if (core
->mac
[MRQC
] & 1) {
1019 if (is_broadcast_ether_addr(ehdr
->h_dest
)) {
1020 for (i
= 0; i
< IGB_NUM_VM_POOLS
; i
++) {
1021 if (core
->mac
[VMOLR0
+ i
] & E1000_VMOLR_BAM
) {
1026 for (macp
= core
->mac
+ RA
; macp
< core
->mac
+ RA
+ 32; macp
+= 2) {
1027 if (!(macp
[1] & E1000_RAH_AV
)) {
1030 ra
[0] = cpu_to_le32(macp
[0]);
1031 ra
[1] = cpu_to_le32(macp
[1]);
1032 if (!memcmp(ehdr
->h_dest
, (uint8_t *)ra
, ETH_ALEN
)) {
1033 queues
|= (macp
[1] & E1000_RAH_POOL_MASK
) / E1000_RAH_POOL_1
;
1037 for (macp
= core
->mac
+ RA2
; macp
< core
->mac
+ RA2
+ 16; macp
+= 2) {
1038 if (!(macp
[1] & E1000_RAH_AV
)) {
1041 ra
[0] = cpu_to_le32(macp
[0]);
1042 ra
[1] = cpu_to_le32(macp
[1]);
1043 if (!memcmp(ehdr
->h_dest
, (uint8_t *)ra
, ETH_ALEN
)) {
1044 queues
|= (macp
[1] & E1000_RAH_POOL_MASK
) / E1000_RAH_POOL_1
;
1049 macp
= core
->mac
+ (is_multicast_ether_addr(ehdr
->h_dest
) ? MTA
: UTA
);
1051 f
= ta_shift
[(rctl
>> E1000_RCTL_MO_SHIFT
) & 3];
1052 f
= (((ehdr
->h_dest
[5] << 8) | ehdr
->h_dest
[4]) >> f
) & 0xfff;
1053 if (macp
[f
>> 5] & (1 << (f
& 0x1f))) {
1054 for (i
= 0; i
< IGB_NUM_VM_POOLS
; i
++) {
1055 if (core
->mac
[VMOLR0
+ i
] & E1000_VMOLR_ROMPE
) {
1060 } else if (is_unicast_ether_addr(ehdr
->h_dest
) && external_tx
) {
1061 *external_tx
= false;
1065 if (e1000x_vlan_rx_filter_enabled(core
->mac
)) {
1068 if (e1000x_is_vlan_packet(ehdr
, core
->mac
[VET
] & 0xffff)) {
1069 for (i
= 0; i
< E1000_VLVF_ARRAY_SIZE
; i
++) {
1070 if ((core
->mac
[VLVF0
+ i
] & E1000_VLVF_VLANID_MASK
) == vid
&&
1071 (core
->mac
[VLVF0
+ i
] & E1000_VLVF_VLANID_ENABLE
)) {
1072 uint32_t poolsel
= core
->mac
[VLVF0
+ i
] & E1000_VLVF_POOLSEL_MASK
;
1073 mask
|= poolsel
>> E1000_VLVF_POOLSEL_SHIFT
;
1077 for (i
= 0; i
< IGB_NUM_VM_POOLS
; i
++) {
1078 if (core
->mac
[VMOLR0
+ i
] & E1000_VMOLR_AUPE
) {
1087 if (is_unicast_ether_addr(ehdr
->h_dest
) && !queues
&& !external_tx
&&
1088 !(core
->mac
[VT_CTL
] & E1000_VT_CTL_DISABLE_DEF_POOL
)) {
1089 uint32_t def_pl
= core
->mac
[VT_CTL
] & E1000_VT_CTL_DEFAULT_POOL_MASK
;
1090 queues
= BIT(def_pl
>> E1000_VT_CTL_DEFAULT_POOL_SHIFT
);
1093 queues
&= core
->mac
[VFRE
];
1095 for (i
= 0; i
< IGB_NUM_VM_POOLS
; i
++) {
1096 if ((queues
& BIT(i
)) && igb_rx_is_oversized(core
, i
, size
)) {
1097 oversized
|= BIT(i
);
1100 /* 8.19.37 increment ROC if packet is oversized for all queues */
1101 if (oversized
== queues
) {
1102 trace_e1000x_rx_oversized(size
);
1103 e1000x_inc_reg_if_not_full(core
->mac
, ROC
);
1105 queues
&= ~oversized
;
1109 igb_rss_parse_packet(core
, core
->rx_pkt
,
1110 external_tx
!= NULL
, rss_info
);
1111 /* Sec 8.26.1: PQn = VFn + VQn*8 */
1112 if (rss_info
->queue
& 1) {
1113 for (i
= 0; i
< IGB_NUM_VM_POOLS
; i
++) {
1114 if ((queues
& BIT(i
)) &&
1115 (core
->mac
[VMOLR0
+ i
] & E1000_VMOLR_RSSE
)) {
1116 queues
|= BIT(i
+ IGB_NUM_VM_POOLS
);
1123 bool accepted
= e1000x_rx_group_filter(core
->mac
, ehdr
);
1125 for (macp
= core
->mac
+ RA2
; macp
< core
->mac
+ RA2
+ 16; macp
+= 2) {
1126 if (!(macp
[1] & E1000_RAH_AV
)) {
1129 ra
[0] = cpu_to_le32(macp
[0]);
1130 ra
[1] = cpu_to_le32(macp
[1]);
1131 if (!memcmp(ehdr
->h_dest
, (uint8_t *)ra
, ETH_ALEN
)) {
1132 trace_e1000x_rx_flt_ucast_match((int)(macp
- core
->mac
- RA2
) / 2,
1133 MAC_ARG(ehdr
->h_dest
));
1142 igb_rss_parse_packet(core
, core
->rx_pkt
, false, rss_info
);
1143 queues
= BIT(rss_info
->queue
);
1151 igb_read_lgcy_rx_descr(IGBCore
*core
, struct e1000_rx_desc
*desc
,
1154 *buff_addr
= le64_to_cpu(desc
->buffer_addr
);
1158 igb_read_adv_rx_descr(IGBCore
*core
, union e1000_adv_rx_desc
*desc
,
1161 *buff_addr
= le64_to_cpu(desc
->read
.pkt_addr
);
1165 igb_read_rx_descr(IGBCore
*core
, union e1000_rx_desc_union
*desc
,
1168 if (igb_rx_use_legacy_descriptor(core
)) {
1169 igb_read_lgcy_rx_descr(core
, &desc
->legacy
, buff_addr
);
1171 igb_read_adv_rx_descr(core
, &desc
->adv
, buff_addr
);
1176 igb_verify_csum_in_sw(IGBCore
*core
,
1177 struct NetRxPkt
*pkt
,
1178 uint32_t *status_flags
,
1179 EthL4HdrProto l4hdr_proto
)
1182 uint32_t csum_error
;
1184 if (igb_rx_l3_cso_enabled(core
)) {
1185 if (!net_rx_pkt_validate_l3_csum(pkt
, &csum_valid
)) {
1186 trace_e1000e_rx_metadata_l3_csum_validation_failed();
1188 csum_error
= csum_valid
? 0 : E1000_RXDEXT_STATERR_IPE
;
1189 *status_flags
|= E1000_RXD_STAT_IPCS
| csum_error
;
1192 trace_e1000e_rx_metadata_l3_cso_disabled();
1195 if (!igb_rx_l4_cso_enabled(core
)) {
1196 trace_e1000e_rx_metadata_l4_cso_disabled();
1200 if (!net_rx_pkt_validate_l4_csum(pkt
, &csum_valid
)) {
1201 trace_e1000e_rx_metadata_l4_csum_validation_failed();
1205 csum_error
= csum_valid
? 0 : E1000_RXDEXT_STATERR_TCPE
;
1206 *status_flags
|= E1000_RXD_STAT_TCPCS
| csum_error
;
1208 if (l4hdr_proto
== ETH_L4_HDR_PROTO_UDP
) {
1209 *status_flags
|= E1000_RXD_STAT_UDPCS
;
1214 igb_build_rx_metadata(IGBCore
*core
,
1215 struct NetRxPkt
*pkt
,
1217 const E1000E_RSSInfo
*rss_info
,
1218 uint16_t *pkt_info
, uint16_t *hdr_info
,
1220 uint32_t *status_flags
,
1224 struct virtio_net_hdr
*vhdr
;
1225 bool hasip4
, hasip6
, csum_valid
;
1226 EthL4HdrProto l4hdr_proto
;
1228 *status_flags
= E1000_RXD_STAT_DD
;
1230 /* No additional metadata needed for non-EOP descriptors */
1231 /* TODO: EOP apply only to status so don't skip whole function. */
1236 *status_flags
|= E1000_RXD_STAT_EOP
;
1238 net_rx_pkt_get_protocols(pkt
, &hasip4
, &hasip6
, &l4hdr_proto
);
1239 trace_e1000e_rx_metadata_protocols(hasip4
, hasip6
, l4hdr_proto
);
1242 if (net_rx_pkt_is_vlan_stripped(pkt
)) {
1243 *status_flags
|= E1000_RXD_STAT_VP
;
1244 *vlan_tag
= cpu_to_le16(net_rx_pkt_get_vlan_tag(pkt
));
1245 trace_e1000e_rx_metadata_vlan(*vlan_tag
);
1248 /* Packet parsing results */
1249 if ((core
->mac
[RXCSUM
] & E1000_RXCSUM_PCSD
) != 0) {
1250 if (rss_info
->enabled
) {
1251 *rss
= cpu_to_le32(rss_info
->hash
);
1252 trace_igb_rx_metadata_rss(*rss
);
1254 } else if (hasip4
) {
1255 *status_flags
|= E1000_RXD_STAT_IPIDV
;
1256 *ip_id
= cpu_to_le16(net_rx_pkt_get_ip_id(pkt
));
1257 trace_e1000e_rx_metadata_ip_id(*ip_id
);
1260 if (l4hdr_proto
== ETH_L4_HDR_PROTO_TCP
&& net_rx_pkt_is_tcp_ack(pkt
)) {
1261 *status_flags
|= E1000_RXD_STAT_ACK
;
1262 trace_e1000e_rx_metadata_ack();
1266 *pkt_info
= rss_info
->enabled
? rss_info
->type
: 0;
1269 *pkt_info
|= E1000_ADVRXD_PKT_IP4
;
1273 *pkt_info
|= E1000_ADVRXD_PKT_IP6
;
1276 switch (l4hdr_proto
) {
1277 case ETH_L4_HDR_PROTO_TCP
:
1278 *pkt_info
|= E1000_ADVRXD_PKT_TCP
;
1281 case ETH_L4_HDR_PROTO_UDP
:
1282 *pkt_info
|= E1000_ADVRXD_PKT_UDP
;
1285 case ETH_L4_HDR_PROTO_SCTP
:
1286 *pkt_info
|= E1000_ADVRXD_PKT_SCTP
;
1298 /* RX CSO information */
1299 if (hasip6
&& (core
->mac
[RFCTL
] & E1000_RFCTL_IPV6_XSUM_DIS
)) {
1300 trace_e1000e_rx_metadata_ipv6_sum_disabled();
1304 vhdr
= net_rx_pkt_get_vhdr(pkt
);
1306 if (!(vhdr
->flags
& VIRTIO_NET_HDR_F_DATA_VALID
) &&
1307 !(vhdr
->flags
& VIRTIO_NET_HDR_F_NEEDS_CSUM
)) {
1308 trace_e1000e_rx_metadata_virthdr_no_csum_info();
1309 igb_verify_csum_in_sw(core
, pkt
, status_flags
, l4hdr_proto
);
1313 if (igb_rx_l3_cso_enabled(core
)) {
1314 *status_flags
|= hasip4
? E1000_RXD_STAT_IPCS
: 0;
1316 trace_e1000e_rx_metadata_l3_cso_disabled();
1319 if (igb_rx_l4_cso_enabled(core
)) {
1320 switch (l4hdr_proto
) {
1321 case ETH_L4_HDR_PROTO_SCTP
:
1322 if (!net_rx_pkt_validate_l4_csum(pkt
, &csum_valid
)) {
1323 trace_e1000e_rx_metadata_l4_csum_validation_failed();
1327 *status_flags
|= E1000_RXDEXT_STATERR_TCPE
;
1330 case ETH_L4_HDR_PROTO_TCP
:
1331 *status_flags
|= E1000_RXD_STAT_TCPCS
;
1334 case ETH_L4_HDR_PROTO_UDP
:
1335 *status_flags
|= E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
;
1342 trace_e1000e_rx_metadata_l4_cso_disabled();
1346 trace_e1000e_rx_metadata_status_flags(*status_flags
);
1347 *status_flags
= cpu_to_le32(*status_flags
);
1351 igb_write_lgcy_rx_descr(IGBCore
*core
, struct e1000_rx_desc
*desc
,
1352 struct NetRxPkt
*pkt
,
1353 const E1000E_RSSInfo
*rss_info
,
1356 uint32_t status_flags
, rss
;
1359 assert(!rss_info
->enabled
);
1360 desc
->length
= cpu_to_le16(length
);
1363 igb_build_rx_metadata(core
, pkt
, pkt
!= NULL
,
1366 &status_flags
, &ip_id
,
1368 desc
->errors
= (uint8_t) (le32_to_cpu(status_flags
) >> 24);
1369 desc
->status
= (uint8_t) le32_to_cpu(status_flags
);
1373 igb_write_adv_rx_descr(IGBCore
*core
, union e1000_adv_rx_desc
*desc
,
1374 struct NetRxPkt
*pkt
,
1375 const E1000E_RSSInfo
*rss_info
,
1378 memset(&desc
->wb
, 0, sizeof(desc
->wb
));
1380 desc
->wb
.upper
.length
= cpu_to_le16(length
);
1382 igb_build_rx_metadata(core
, pkt
, pkt
!= NULL
,
1384 &desc
->wb
.lower
.lo_dword
.pkt_info
,
1385 &desc
->wb
.lower
.lo_dword
.hdr_info
,
1386 &desc
->wb
.lower
.hi_dword
.rss
,
1387 &desc
->wb
.upper
.status_error
,
1388 &desc
->wb
.lower
.hi_dword
.csum_ip
.ip_id
,
1389 &desc
->wb
.upper
.vlan
);
1393 igb_write_rx_descr(IGBCore
*core
, union e1000_rx_desc_union
*desc
,
1394 struct NetRxPkt
*pkt
, const E1000E_RSSInfo
*rss_info
, uint16_t length
)
1396 if (igb_rx_use_legacy_descriptor(core
)) {
1397 igb_write_lgcy_rx_descr(core
, &desc
->legacy
, pkt
, rss_info
, length
);
1399 igb_write_adv_rx_descr(core
, &desc
->adv
, pkt
, rss_info
, length
);
1404 igb_pci_dma_write_rx_desc(IGBCore
*core
, PCIDevice
*dev
, dma_addr_t addr
,
1405 union e1000_rx_desc_union
*desc
, dma_addr_t len
)
1407 if (igb_rx_use_legacy_descriptor(core
)) {
1408 struct e1000_rx_desc
*d
= &desc
->legacy
;
1409 size_t offset
= offsetof(struct e1000_rx_desc
, status
);
1410 uint8_t status
= d
->status
;
1412 d
->status
&= ~E1000_RXD_STAT_DD
;
1413 pci_dma_write(dev
, addr
, desc
, len
);
1415 if (status
& E1000_RXD_STAT_DD
) {
1417 pci_dma_write(dev
, addr
+ offset
, &status
, sizeof(status
));
1420 union e1000_adv_rx_desc
*d
= &desc
->adv
;
1422 offsetof(union e1000_adv_rx_desc
, wb
.upper
.status_error
);
1423 uint32_t status
= d
->wb
.upper
.status_error
;
1425 d
->wb
.upper
.status_error
&= ~E1000_RXD_STAT_DD
;
1426 pci_dma_write(dev
, addr
, desc
, len
);
1428 if (status
& E1000_RXD_STAT_DD
) {
1429 d
->wb
.upper
.status_error
= status
;
1430 pci_dma_write(dev
, addr
+ offset
, &status
, sizeof(status
));
1436 igb_write_to_rx_buffers(IGBCore
*core
,
1441 dma_addr_t data_len
)
1443 trace_igb_rx_desc_buff_write(ba
, *written
, data
, data_len
);
1444 pci_dma_write(d
, ba
+ *written
, data
, data_len
);
1445 *written
+= data_len
;
1449 igb_update_rx_stats(IGBCore
*core
, const E1000E_RingInfo
*rxi
,
1450 size_t pkt_size
, size_t pkt_fcs_size
)
1452 eth_pkt_types_e pkt_type
= net_rx_pkt_get_packet_type(core
->rx_pkt
);
1453 e1000x_update_rx_total_stats(core
->mac
, pkt_type
, pkt_size
, pkt_fcs_size
);
1455 if (core
->mac
[MRQC
] & 1) {
1456 uint16_t pool
= rxi
->idx
% IGB_NUM_VM_POOLS
;
1458 core
->mac
[PVFGORC0
+ (pool
* 64)] += pkt_size
+ 4;
1459 core
->mac
[PVFGPRC0
+ (pool
* 64)]++;
1460 if (pkt_type
== ETH_PKT_MCAST
) {
1461 core
->mac
[PVFMPRC0
+ (pool
* 64)]++;
1467 igb_rx_descr_threshold_hit(IGBCore
*core
, const E1000E_RingInfo
*rxi
)
1469 return igb_ring_free_descr_num(core
, rxi
) ==
1470 ((core
->mac
[E1000_SRRCTL(rxi
->idx
) >> 2] >> 20) & 31) * 16;
1474 igb_write_packet_to_guest(IGBCore
*core
, struct NetRxPkt
*pkt
,
1475 const E1000E_RxRing
*rxr
,
1476 const E1000E_RSSInfo
*rss_info
)
1480 union e1000_rx_desc_union desc
;
1482 size_t desc_offset
= 0;
1485 struct iovec
*iov
= net_rx_pkt_get_iovec(pkt
);
1486 size_t size
= net_rx_pkt_get_total_len(pkt
);
1487 size_t total_size
= size
+ e1000x_fcs_len(core
->mac
);
1488 const E1000E_RingInfo
*rxi
= rxr
->i
;
1489 size_t bufsize
= igb_rxbufsize(core
, rxi
);
1491 d
= pcie_sriov_get_vf_at_index(core
->owner
, rxi
->idx
% 8);
1498 uint16_t written
= 0;
1499 bool is_last
= false;
1501 desc_size
= total_size
- desc_offset
;
1503 if (desc_size
> bufsize
) {
1504 desc_size
= bufsize
;
1507 if (igb_ring_empty(core
, rxi
)) {
1511 base
= igb_ring_head_descr(core
, rxi
);
1513 pci_dma_read(d
, base
, &desc
, core
->rx_desc_len
);
1515 trace_e1000e_rx_descr(rxi
->idx
, base
, core
->rx_desc_len
);
1517 igb_read_rx_descr(core
, &desc
, &ba
);
1520 if (desc_offset
< size
) {
1521 static const uint32_t fcs_pad
;
1523 size_t copy_size
= size
- desc_offset
;
1524 if (copy_size
> bufsize
) {
1525 copy_size
= bufsize
;
1528 /* Copy packet payload */
1530 iov_copy
= MIN(copy_size
, iov
->iov_len
- iov_ofs
);
1532 igb_write_to_rx_buffers(core
, d
, ba
, &written
,
1533 iov
->iov_base
+ iov_ofs
, iov_copy
);
1535 copy_size
-= iov_copy
;
1536 iov_ofs
+= iov_copy
;
1537 if (iov_ofs
== iov
->iov_len
) {
1543 if (desc_offset
+ desc_size
>= total_size
) {
1544 /* Simulate FCS checksum presence in the last descriptor */
1545 igb_write_to_rx_buffers(core
, d
, ba
, &written
,
1546 (const char *) &fcs_pad
, e1000x_fcs_len(core
->mac
));
1549 } else { /* as per intel docs; skip descriptors with null buf addr */
1550 trace_e1000e_rx_null_descriptor();
1552 desc_offset
+= desc_size
;
1553 if (desc_offset
>= total_size
) {
1557 igb_write_rx_descr(core
, &desc
, is_last
? core
->rx_pkt
: NULL
,
1559 igb_pci_dma_write_rx_desc(core
, d
, base
, &desc
, core
->rx_desc_len
);
1561 igb_ring_advance(core
, rxi
, core
->rx_desc_len
/ E1000_MIN_RX_DESC_LEN
);
1563 } while (desc_offset
< total_size
);
1565 igb_update_rx_stats(core
, rxi
, size
, total_size
);
1569 igb_rx_strip_vlan(IGBCore
*core
, const E1000E_RingInfo
*rxi
)
1571 if (core
->mac
[MRQC
] & 1) {
1572 uint16_t pool
= rxi
->idx
% IGB_NUM_VM_POOLS
;
1573 /* Sec 7.10.3.8: CTRL.VME is ignored, only VMOLR/RPLOLR is used */
1574 return (net_rx_pkt_get_packet_type(core
->rx_pkt
) == ETH_PKT_MCAST
) ?
1575 core
->mac
[RPLOLR
] & E1000_RPLOLR_STRVLAN
:
1576 core
->mac
[VMOLR0
+ pool
] & E1000_VMOLR_STRVLAN
;
1579 return e1000x_vlan_enabled(core
->mac
);
1583 igb_rx_fix_l4_csum(IGBCore
*core
, struct NetRxPkt
*pkt
)
1585 struct virtio_net_hdr
*vhdr
= net_rx_pkt_get_vhdr(pkt
);
1587 if (vhdr
->flags
& VIRTIO_NET_HDR_F_NEEDS_CSUM
) {
1588 net_rx_pkt_fix_l4_csum(pkt
);
1593 igb_receive_iov(IGBCore
*core
, const struct iovec
*iov
, int iovcnt
)
1595 return igb_receive_internal(core
, iov
, iovcnt
, core
->has_vnet
, NULL
);
1599 igb_receive_internal(IGBCore
*core
, const struct iovec
*iov
, int iovcnt
,
1600 bool has_vnet
, bool *external_tx
)
1602 uint16_t queues
= 0;
1603 uint32_t causes
= 0;
1606 uint8_t octets
[ETH_ZLEN
];
1608 struct iovec min_iov
;
1609 size_t size
, orig_size
;
1612 E1000E_RSSInfo rss_info
;
1614 int strip_vlan_index
;
1617 trace_e1000e_rx_receive_iov(iovcnt
);
1620 *external_tx
= true;
1623 if (!e1000x_hw_rx_enabled(core
->mac
)) {
1627 /* Pull virtio header in */
1629 net_rx_pkt_set_vhdr_iovec(core
->rx_pkt
, iov
, iovcnt
);
1630 iov_ofs
= sizeof(struct virtio_net_hdr
);
1632 net_rx_pkt_unset_vhdr(core
->rx_pkt
);
1635 orig_size
= iov_size(iov
, iovcnt
);
1636 size
= orig_size
- iov_ofs
;
1638 /* Pad to minimum Ethernet frame length */
1639 if (size
< sizeof(buf
)) {
1640 iov_to_buf(iov
, iovcnt
, iov_ofs
, &buf
, size
);
1641 memset(&buf
.octets
[size
], 0, sizeof(buf
) - size
);
1642 e1000x_inc_reg_if_not_full(core
->mac
, RUC
);
1643 min_iov
.iov_base
= &buf
;
1644 min_iov
.iov_len
= size
= sizeof(buf
);
1649 iov_to_buf(iov
, iovcnt
, iov_ofs
, &buf
, sizeof(buf
.l2_header
));
1652 /* Discard oversized packets if !LPE and !SBP. */
1653 if (e1000x_is_oversized(core
->mac
, size
)) {
1657 net_rx_pkt_set_packet_type(core
->rx_pkt
,
1658 get_eth_packet_type(&buf
.l2_header
.eth
));
1659 net_rx_pkt_set_protocols(core
->rx_pkt
, iov
, iovcnt
, iov_ofs
);
1661 queues
= igb_receive_assign(core
, &buf
.l2_header
, size
,
1662 &rss_info
, external_tx
);
1664 trace_e1000e_rx_flt_dropped();
1668 for (i
= 0; i
< IGB_NUM_QUEUES
; i
++) {
1669 if (!(queues
& BIT(i
)) ||
1670 !(core
->mac
[RXDCTL0
+ (i
* 16)] & E1000_RXDCTL_QUEUE_ENABLE
)) {
1674 igb_rx_ring_init(core
, &rxr
, i
);
1676 if (!igb_rx_strip_vlan(core
, rxr
.i
)) {
1677 strip_vlan_index
= -1;
1678 } else if (core
->mac
[CTRL_EXT
] & BIT(26)) {
1679 strip_vlan_index
= 1;
1681 strip_vlan_index
= 0;
1684 net_rx_pkt_attach_iovec_ex(core
->rx_pkt
, iov
, iovcnt
, iov_ofs
,
1686 core
->mac
[VET
] & 0xffff,
1687 core
->mac
[VET
] >> 16);
1689 total_size
= net_rx_pkt_get_total_len(core
->rx_pkt
) +
1690 e1000x_fcs_len(core
->mac
);
1692 if (!igb_has_rxbufs(core
, rxr
.i
, total_size
)) {
1693 causes
|= E1000_ICS_RXO
;
1694 trace_e1000e_rx_not_written_to_guest(rxr
.i
->idx
);
1698 causes
|= E1000_ICR_RXDW
;
1700 igb_rx_fix_l4_csum(core
, core
->rx_pkt
);
1701 igb_write_packet_to_guest(core
, core
->rx_pkt
, &rxr
, &rss_info
);
1703 /* Check if receive descriptor minimum threshold hit */
1704 if (igb_rx_descr_threshold_hit(core
, rxr
.i
)) {
1705 causes
|= E1000_ICS_RXDMT0
;
1708 core
->mac
[EICR
] |= igb_rx_wb_eic(core
, rxr
.i
->idx
);
1710 trace_e1000e_rx_written_to_guest(rxr
.i
->idx
);
1713 trace_e1000e_rx_interrupt_set(causes
);
1714 igb_set_interrupt_cause(core
, causes
);
1720 igb_have_autoneg(IGBCore
*core
)
1722 return core
->phy
[MII_BMCR
] & MII_BMCR_AUTOEN
;
1725 static void igb_update_flowctl_status(IGBCore
*core
)
1727 if (igb_have_autoneg(core
) && core
->phy
[MII_BMSR
] & MII_BMSR_AN_COMP
) {
1728 trace_e1000e_link_autoneg_flowctl(true);
1729 core
->mac
[CTRL
] |= E1000_CTRL_TFCE
| E1000_CTRL_RFCE
;
1731 trace_e1000e_link_autoneg_flowctl(false);
1736 igb_link_down(IGBCore
*core
)
1738 e1000x_update_regs_on_link_down(core
->mac
, core
->phy
);
1739 igb_update_flowctl_status(core
);
1743 igb_set_phy_ctrl(IGBCore
*core
, uint16_t val
)
1745 /* bits 0-5 reserved; MII_BMCR_[ANRESTART,RESET] are self clearing */
1746 core
->phy
[MII_BMCR
] = val
& ~(0x3f | MII_BMCR_RESET
| MII_BMCR_ANRESTART
);
1748 if ((val
& MII_BMCR_ANRESTART
) && igb_have_autoneg(core
)) {
1749 e1000x_restart_autoneg(core
->mac
, core
->phy
, core
->autoneg_timer
);
1753 void igb_core_set_link_status(IGBCore
*core
)
1755 NetClientState
*nc
= qemu_get_queue(core
->owner_nic
);
1756 uint32_t old_status
= core
->mac
[STATUS
];
1758 trace_e1000e_link_status_changed(nc
->link_down
? false : true);
1760 if (nc
->link_down
) {
1761 e1000x_update_regs_on_link_down(core
->mac
, core
->phy
);
1763 if (igb_have_autoneg(core
) &&
1764 !(core
->phy
[MII_BMSR
] & MII_BMSR_AN_COMP
)) {
1765 e1000x_restart_autoneg(core
->mac
, core
->phy
,
1766 core
->autoneg_timer
);
1768 e1000x_update_regs_on_link_up(core
->mac
, core
->phy
);
1769 igb_start_recv(core
);
1773 if (core
->mac
[STATUS
] != old_status
) {
1774 igb_set_interrupt_cause(core
, E1000_ICR_LSC
);
1779 igb_set_ctrl(IGBCore
*core
, int index
, uint32_t val
)
1781 trace_e1000e_core_ctrl_write(index
, val
);
1783 /* RST is self clearing */
1784 core
->mac
[CTRL
] = val
& ~E1000_CTRL_RST
;
1785 core
->mac
[CTRL_DUP
] = core
->mac
[CTRL
];
1787 trace_e1000e_link_set_params(
1788 !!(val
& E1000_CTRL_ASDE
),
1789 (val
& E1000_CTRL_SPD_SEL
) >> E1000_CTRL_SPD_SHIFT
,
1790 !!(val
& E1000_CTRL_FRCSPD
),
1791 !!(val
& E1000_CTRL_FRCDPX
),
1792 !!(val
& E1000_CTRL_RFCE
),
1793 !!(val
& E1000_CTRL_TFCE
));
1795 if (val
& E1000_CTRL_RST
) {
1796 trace_e1000e_core_ctrl_sw_reset();
1797 igb_reset(core
, true);
1800 if (val
& E1000_CTRL_PHY_RST
) {
1801 trace_e1000e_core_ctrl_phy_reset();
1802 core
->mac
[STATUS
] |= E1000_STATUS_PHYRA
;
1807 igb_set_rfctl(IGBCore
*core
, int index
, uint32_t val
)
1809 trace_e1000e_rx_set_rfctl(val
);
1811 if (!(val
& E1000_RFCTL_ISCSI_DIS
)) {
1812 trace_e1000e_wrn_iscsi_filtering_not_supported();
1815 if (!(val
& E1000_RFCTL_NFSW_DIS
)) {
1816 trace_e1000e_wrn_nfsw_filtering_not_supported();
1819 if (!(val
& E1000_RFCTL_NFSR_DIS
)) {
1820 trace_e1000e_wrn_nfsr_filtering_not_supported();
1823 core
->mac
[RFCTL
] = val
;
1827 igb_calc_rxdesclen(IGBCore
*core
)
1829 if (igb_rx_use_legacy_descriptor(core
)) {
1830 core
->rx_desc_len
= sizeof(struct e1000_rx_desc
);
1832 core
->rx_desc_len
= sizeof(union e1000_adv_rx_desc
);
1834 trace_e1000e_rx_desc_len(core
->rx_desc_len
);
1838 igb_set_rx_control(IGBCore
*core
, int index
, uint32_t val
)
1840 core
->mac
[RCTL
] = val
;
1841 trace_e1000e_rx_set_rctl(core
->mac
[RCTL
]);
1843 if (val
& E1000_RCTL_DTYP_MASK
) {
1844 qemu_log_mask(LOG_GUEST_ERROR
,
1845 "igb: RCTL.DTYP must be zero for compatibility");
1848 if (val
& E1000_RCTL_EN
) {
1849 igb_calc_rxdesclen(core
);
1850 igb_start_recv(core
);
1855 igb_clear_ims_bits(IGBCore
*core
, uint32_t bits
)
1857 trace_e1000e_irq_clear_ims(bits
, core
->mac
[IMS
], core
->mac
[IMS
] & ~bits
);
1858 core
->mac
[IMS
] &= ~bits
;
1862 igb_postpone_interrupt(IGBIntrDelayTimer
*timer
)
1864 if (timer
->running
) {
1865 trace_e1000e_irq_postponed_by_xitr(timer
->delay_reg
<< 2);
1870 if (timer
->core
->mac
[timer
->delay_reg
] != 0) {
1871 igb_intrmgr_rearm_timer(timer
);
1878 igb_eitr_should_postpone(IGBCore
*core
, int idx
)
1880 return igb_postpone_interrupt(&core
->eitr
[idx
]);
1883 static void igb_send_msix(IGBCore
*core
)
1885 uint32_t causes
= core
->mac
[EICR
] & core
->mac
[EIMS
];
1888 for (vector
= 0; vector
< IGB_INTR_NUM
; ++vector
) {
1889 if ((causes
& BIT(vector
)) && !igb_eitr_should_postpone(core
, vector
)) {
1891 trace_e1000e_irq_msix_notify_vec(vector
);
1892 igb_msix_notify(core
, vector
);
1898 igb_fix_icr_asserted(IGBCore
*core
)
1900 core
->mac
[ICR
] &= ~E1000_ICR_ASSERTED
;
1901 if (core
->mac
[ICR
]) {
1902 core
->mac
[ICR
] |= E1000_ICR_ASSERTED
;
1905 trace_e1000e_irq_fix_icr_asserted(core
->mac
[ICR
]);
1909 igb_update_interrupt_state(IGBCore
*core
)
1915 icr
= core
->mac
[ICR
] & core
->mac
[IMS
];
1917 if (core
->mac
[GPIE
] & E1000_GPIE_MSIX_MODE
) {
1920 if (icr
& E1000_ICR_DRSTA
) {
1921 int_alloc
= core
->mac
[IVAR_MISC
] & 0xff;
1922 if (int_alloc
& E1000_IVAR_VALID
) {
1923 causes
|= BIT(int_alloc
& 0x1f);
1926 /* Check if other bits (excluding the TCP Timer) are enabled. */
1927 if (icr
& ~E1000_ICR_DRSTA
) {
1928 int_alloc
= (core
->mac
[IVAR_MISC
] >> 8) & 0xff;
1929 if (int_alloc
& E1000_IVAR_VALID
) {
1930 causes
|= BIT(int_alloc
& 0x1f);
1932 trace_e1000e_irq_add_msi_other(core
->mac
[EICR
]);
1934 core
->mac
[EICR
] |= causes
;
1937 if ((core
->mac
[EICR
] & core
->mac
[EIMS
])) {
1938 igb_send_msix(core
);
1941 igb_fix_icr_asserted(core
);
1944 core
->mac
[EICR
] |= (icr
& E1000_ICR_DRSTA
) | E1000_EICR_OTHER
;
1946 core
->mac
[EICR
] &= ~E1000_EICR_OTHER
;
1949 trace_e1000e_irq_pending_interrupts(core
->mac
[ICR
] & core
->mac
[IMS
],
1950 core
->mac
[ICR
], core
->mac
[IMS
]);
1952 if (msix_enabled(core
->owner
)) {
1954 trace_e1000e_irq_msix_notify_vec(0);
1955 msix_notify(core
->owner
, 0);
1957 } else if (msi_enabled(core
->owner
)) {
1959 msi_notify(core
->owner
, 0);
1963 igb_raise_legacy_irq(core
);
1965 igb_lower_legacy_irq(core
);
1972 igb_set_interrupt_cause(IGBCore
*core
, uint32_t val
)
1974 trace_e1000e_irq_set_cause_entry(val
, core
->mac
[ICR
]);
1976 core
->mac
[ICR
] |= val
;
1978 trace_e1000e_irq_set_cause_exit(val
, core
->mac
[ICR
]);
1980 igb_update_interrupt_state(core
);
1983 static void igb_set_eics(IGBCore
*core
, int index
, uint32_t val
)
1985 bool msix
= !!(core
->mac
[GPIE
] & E1000_GPIE_MSIX_MODE
);
1987 trace_igb_irq_write_eics(val
, msix
);
1990 val
& (msix
? E1000_EICR_MSIX_MASK
: E1000_EICR_LEGACY_MASK
);
1993 * TODO: Move to igb_update_interrupt_state if EICS is modified in other
1996 core
->mac
[EICR
] = core
->mac
[EICS
];
1998 igb_update_interrupt_state(core
);
2001 static void igb_set_eims(IGBCore
*core
, int index
, uint32_t val
)
2003 bool msix
= !!(core
->mac
[GPIE
] & E1000_GPIE_MSIX_MODE
);
2005 trace_igb_irq_write_eims(val
, msix
);
2008 val
& (msix
? E1000_EICR_MSIX_MASK
: E1000_EICR_LEGACY_MASK
);
2010 igb_update_interrupt_state(core
);
2013 static void mailbox_interrupt_to_vf(IGBCore
*core
, uint16_t vfn
)
2015 uint32_t ent
= core
->mac
[VTIVAR_MISC
+ vfn
];
2017 if ((ent
& E1000_IVAR_VALID
)) {
2018 core
->mac
[EICR
] |= (ent
& 0x3) << (22 - vfn
* IGBVF_MSIX_VEC_NUM
);
2019 igb_update_interrupt_state(core
);
2023 static void mailbox_interrupt_to_pf(IGBCore
*core
)
2025 igb_set_interrupt_cause(core
, E1000_ICR_VMMB
);
2028 static void igb_set_pfmailbox(IGBCore
*core
, int index
, uint32_t val
)
2030 uint16_t vfn
= index
- P2VMAILBOX0
;
2032 trace_igb_set_pfmailbox(vfn
, val
);
2034 if (val
& E1000_P2VMAILBOX_STS
) {
2035 core
->mac
[V2PMAILBOX0
+ vfn
] |= E1000_V2PMAILBOX_PFSTS
;
2036 mailbox_interrupt_to_vf(core
, vfn
);
2039 if (val
& E1000_P2VMAILBOX_ACK
) {
2040 core
->mac
[V2PMAILBOX0
+ vfn
] |= E1000_V2PMAILBOX_PFACK
;
2041 mailbox_interrupt_to_vf(core
, vfn
);
2044 /* Buffer Taken by PF (can be set only if the VFU is cleared). */
2045 if (val
& E1000_P2VMAILBOX_PFU
) {
2046 if (!(core
->mac
[index
] & E1000_P2VMAILBOX_VFU
)) {
2047 core
->mac
[index
] |= E1000_P2VMAILBOX_PFU
;
2048 core
->mac
[V2PMAILBOX0
+ vfn
] |= E1000_V2PMAILBOX_PFU
;
2051 core
->mac
[index
] &= ~E1000_P2VMAILBOX_PFU
;
2052 core
->mac
[V2PMAILBOX0
+ vfn
] &= ~E1000_V2PMAILBOX_PFU
;
2055 if (val
& E1000_P2VMAILBOX_RVFU
) {
2056 core
->mac
[V2PMAILBOX0
+ vfn
] &= ~E1000_V2PMAILBOX_VFU
;
2057 core
->mac
[MBVFICR
] &= ~((E1000_MBVFICR_VFACK_VF1
<< vfn
) |
2058 (E1000_MBVFICR_VFREQ_VF1
<< vfn
));
2062 static void igb_set_vfmailbox(IGBCore
*core
, int index
, uint32_t val
)
2064 uint16_t vfn
= index
- V2PMAILBOX0
;
2066 trace_igb_set_vfmailbox(vfn
, val
);
2068 if (val
& E1000_V2PMAILBOX_REQ
) {
2069 core
->mac
[MBVFICR
] |= E1000_MBVFICR_VFREQ_VF1
<< vfn
;
2070 mailbox_interrupt_to_pf(core
);
2073 if (val
& E1000_V2PMAILBOX_ACK
) {
2074 core
->mac
[MBVFICR
] |= E1000_MBVFICR_VFACK_VF1
<< vfn
;
2075 mailbox_interrupt_to_pf(core
);
2078 /* Buffer Taken by VF (can be set only if the PFU is cleared). */
2079 if (val
& E1000_V2PMAILBOX_VFU
) {
2080 if (!(core
->mac
[index
] & E1000_V2PMAILBOX_PFU
)) {
2081 core
->mac
[index
] |= E1000_V2PMAILBOX_VFU
;
2082 core
->mac
[P2VMAILBOX0
+ vfn
] |= E1000_P2VMAILBOX_VFU
;
2085 core
->mac
[index
] &= ~E1000_V2PMAILBOX_VFU
;
2086 core
->mac
[P2VMAILBOX0
+ vfn
] &= ~E1000_P2VMAILBOX_VFU
;
2090 static void igb_vf_reset(IGBCore
*core
, uint16_t vfn
)
2093 uint16_t qn1
= vfn
+ IGB_NUM_VM_POOLS
;
2095 /* disable Rx and Tx for the VF*/
2096 core
->mac
[RXDCTL0
+ (qn0
* 16)] &= ~E1000_RXDCTL_QUEUE_ENABLE
;
2097 core
->mac
[RXDCTL0
+ (qn1
* 16)] &= ~E1000_RXDCTL_QUEUE_ENABLE
;
2098 core
->mac
[TXDCTL0
+ (qn0
* 16)] &= ~E1000_TXDCTL_QUEUE_ENABLE
;
2099 core
->mac
[TXDCTL0
+ (qn1
* 16)] &= ~E1000_TXDCTL_QUEUE_ENABLE
;
2100 core
->mac
[VFRE
] &= ~BIT(vfn
);
2101 core
->mac
[VFTE
] &= ~BIT(vfn
);
2102 /* indicate VF reset to PF */
2103 core
->mac
[VFLRE
] |= BIT(vfn
);
2104 /* VFLRE and mailbox use the same interrupt cause */
2105 mailbox_interrupt_to_pf(core
);
2108 static void igb_w1c(IGBCore
*core
, int index
, uint32_t val
)
2110 core
->mac
[index
] &= ~val
;
2113 static void igb_set_eimc(IGBCore
*core
, int index
, uint32_t val
)
2115 bool msix
= !!(core
->mac
[GPIE
] & E1000_GPIE_MSIX_MODE
);
2117 /* Interrupts are disabled via a write to EIMC and reflected in EIMS. */
2119 ~(val
& (msix
? E1000_EICR_MSIX_MASK
: E1000_EICR_LEGACY_MASK
));
2121 trace_igb_irq_write_eimc(val
, core
->mac
[EIMS
], msix
);
2122 igb_update_interrupt_state(core
);
2125 static void igb_set_eiac(IGBCore
*core
, int index
, uint32_t val
)
2127 bool msix
= !!(core
->mac
[GPIE
] & E1000_GPIE_MSIX_MODE
);
2130 trace_igb_irq_write_eiac(val
);
2133 * TODO: When using IOV, the bits that correspond to MSI-X vectors
2134 * that are assigned to a VF are read-only.
2136 core
->mac
[EIAC
] |= (val
& E1000_EICR_MSIX_MASK
);
2140 static void igb_set_eiam(IGBCore
*core
, int index
, uint32_t val
)
2142 bool msix
= !!(core
->mac
[GPIE
] & E1000_GPIE_MSIX_MODE
);
2145 * TODO: When using IOV, the bits that correspond to MSI-X vectors that
2146 * are assigned to a VF are read-only.
2149 ~(val
& (msix
? E1000_EICR_MSIX_MASK
: E1000_EICR_LEGACY_MASK
));
2151 trace_igb_irq_write_eiam(val
, msix
);
2154 static void igb_set_eicr(IGBCore
*core
, int index
, uint32_t val
)
2156 bool msix
= !!(core
->mac
[GPIE
] & E1000_GPIE_MSIX_MODE
);
2159 * TODO: In IOV mode, only bit zero of this vector is available for the PF
2163 ~(val
& (msix
? E1000_EICR_MSIX_MASK
: E1000_EICR_LEGACY_MASK
));
2165 trace_igb_irq_write_eicr(val
, msix
);
2166 igb_update_interrupt_state(core
);
2169 static void igb_set_vtctrl(IGBCore
*core
, int index
, uint32_t val
)
2173 if (val
& E1000_CTRL_RST
) {
2174 vfn
= (index
- PVTCTRL0
) / 0x40;
2175 igb_vf_reset(core
, vfn
);
2179 static void igb_set_vteics(IGBCore
*core
, int index
, uint32_t val
)
2181 uint16_t vfn
= (index
- PVTEICS0
) / 0x40;
2183 core
->mac
[index
] = val
;
2184 igb_set_eics(core
, EICS
, (val
& 0x7) << (22 - vfn
* IGBVF_MSIX_VEC_NUM
));
2187 static void igb_set_vteims(IGBCore
*core
, int index
, uint32_t val
)
2189 uint16_t vfn
= (index
- PVTEIMS0
) / 0x40;
2191 core
->mac
[index
] = val
;
2192 igb_set_eims(core
, EIMS
, (val
& 0x7) << (22 - vfn
* IGBVF_MSIX_VEC_NUM
));
2195 static void igb_set_vteimc(IGBCore
*core
, int index
, uint32_t val
)
2197 uint16_t vfn
= (index
- PVTEIMC0
) / 0x40;
2199 core
->mac
[index
] = val
;
2200 igb_set_eimc(core
, EIMC
, (val
& 0x7) << (22 - vfn
* IGBVF_MSIX_VEC_NUM
));
2203 static void igb_set_vteiac(IGBCore
*core
, int index
, uint32_t val
)
2205 uint16_t vfn
= (index
- PVTEIAC0
) / 0x40;
2207 core
->mac
[index
] = val
;
2208 igb_set_eiac(core
, EIAC
, (val
& 0x7) << (22 - vfn
* IGBVF_MSIX_VEC_NUM
));
2211 static void igb_set_vteiam(IGBCore
*core
, int index
, uint32_t val
)
2213 uint16_t vfn
= (index
- PVTEIAM0
) / 0x40;
2215 core
->mac
[index
] = val
;
2216 igb_set_eiam(core
, EIAM
, (val
& 0x7) << (22 - vfn
* IGBVF_MSIX_VEC_NUM
));
2219 static void igb_set_vteicr(IGBCore
*core
, int index
, uint32_t val
)
2221 uint16_t vfn
= (index
- PVTEICR0
) / 0x40;
2223 core
->mac
[index
] = val
;
2224 igb_set_eicr(core
, EICR
, (val
& 0x7) << (22 - vfn
* IGBVF_MSIX_VEC_NUM
));
2227 static void igb_set_vtivar(IGBCore
*core
, int index
, uint32_t val
)
2229 uint16_t vfn
= (index
- VTIVAR
);
2234 core
->mac
[index
] = val
;
2236 /* Get assigned vector associated with queue Rx#0. */
2237 if ((val
& E1000_IVAR_VALID
)) {
2238 n
= igb_ivar_entry_rx(qn
);
2239 ent
= E1000_IVAR_VALID
| (24 - vfn
* IGBVF_MSIX_VEC_NUM
- (2 - (val
& 0x7)));
2240 core
->mac
[IVAR0
+ n
/ 4] |= ent
<< 8 * (n
% 4);
2243 /* Get assigned vector associated with queue Tx#0 */
2245 if ((ent
& E1000_IVAR_VALID
)) {
2246 n
= igb_ivar_entry_tx(qn
);
2247 ent
= E1000_IVAR_VALID
| (24 - vfn
* IGBVF_MSIX_VEC_NUM
- (2 - (ent
& 0x7)));
2248 core
->mac
[IVAR0
+ n
/ 4] |= ent
<< 8 * (n
% 4);
2252 * Ignoring assigned vectors associated with queues Rx#1 and Tx#1 for now.
2257 igb_autoneg_timer(void *opaque
)
2259 IGBCore
*core
= opaque
;
2260 if (!qemu_get_queue(core
->owner_nic
)->link_down
) {
2261 e1000x_update_regs_on_autoneg_done(core
->mac
, core
->phy
);
2262 igb_start_recv(core
);
2264 igb_update_flowctl_status(core
);
2265 /* signal link status change to the guest */
2266 igb_set_interrupt_cause(core
, E1000_ICR_LSC
);
2270 static inline uint16_t
2271 igb_get_reg_index_with_offset(const uint16_t *mac_reg_access
, hwaddr addr
)
2273 uint16_t index
= (addr
& 0x1ffff) >> 2;
2274 return index
+ (mac_reg_access
[index
] & 0xfffe);
2277 static const char igb_phy_regcap
[MAX_PHY_REG_ADDRESS
+ 1] = {
2278 [MII_BMCR
] = PHY_RW
,
2280 [MII_PHYID1
] = PHY_R
,
2281 [MII_PHYID2
] = PHY_R
,
2282 [MII_ANAR
] = PHY_RW
,
2283 [MII_ANLPAR
] = PHY_R
,
2285 [MII_ANNP
] = PHY_RW
,
2286 [MII_ANLPRNP
] = PHY_R
,
2287 [MII_CTRL1000
] = PHY_RW
,
2288 [MII_STAT1000
] = PHY_R
,
2289 [MII_EXTSTAT
] = PHY_R
,
2291 [IGP01E1000_PHY_PORT_CONFIG
] = PHY_RW
,
2292 [IGP01E1000_PHY_PORT_STATUS
] = PHY_R
,
2293 [IGP01E1000_PHY_PORT_CTRL
] = PHY_RW
,
2294 [IGP01E1000_PHY_LINK_HEALTH
] = PHY_R
,
2295 [IGP02E1000_PHY_POWER_MGMT
] = PHY_RW
,
2296 [IGP01E1000_PHY_PAGE_SELECT
] = PHY_W
2300 igb_phy_reg_write(IGBCore
*core
, uint32_t addr
, uint16_t data
)
2302 assert(addr
<= MAX_PHY_REG_ADDRESS
);
2304 if (addr
== MII_BMCR
) {
2305 igb_set_phy_ctrl(core
, data
);
2307 core
->phy
[addr
] = data
;
2312 igb_set_mdic(IGBCore
*core
, int index
, uint32_t val
)
2314 uint32_t data
= val
& E1000_MDIC_DATA_MASK
;
2315 uint32_t addr
= ((val
& E1000_MDIC_REG_MASK
) >> E1000_MDIC_REG_SHIFT
);
2317 if ((val
& E1000_MDIC_PHY_MASK
) >> E1000_MDIC_PHY_SHIFT
!= 1) { /* phy # */
2318 val
= core
->mac
[MDIC
] | E1000_MDIC_ERROR
;
2319 } else if (val
& E1000_MDIC_OP_READ
) {
2320 if (!(igb_phy_regcap
[addr
] & PHY_R
)) {
2321 trace_igb_core_mdic_read_unhandled(addr
);
2322 val
|= E1000_MDIC_ERROR
;
2324 val
= (val
^ data
) | core
->phy
[addr
];
2325 trace_igb_core_mdic_read(addr
, val
);
2327 } else if (val
& E1000_MDIC_OP_WRITE
) {
2328 if (!(igb_phy_regcap
[addr
] & PHY_W
)) {
2329 trace_igb_core_mdic_write_unhandled(addr
);
2330 val
|= E1000_MDIC_ERROR
;
2332 trace_igb_core_mdic_write(addr
, data
);
2333 igb_phy_reg_write(core
, addr
, data
);
2336 core
->mac
[MDIC
] = val
| E1000_MDIC_READY
;
2338 if (val
& E1000_MDIC_INT_EN
) {
2339 igb_set_interrupt_cause(core
, E1000_ICR_MDAC
);
2344 igb_set_rdt(IGBCore
*core
, int index
, uint32_t val
)
2346 core
->mac
[index
] = val
& 0xffff;
2347 trace_e1000e_rx_set_rdt(igb_mq_queue_idx(RDT0
, index
), val
);
2348 igb_start_recv(core
);
2352 igb_set_status(IGBCore
*core
, int index
, uint32_t val
)
2354 if ((val
& E1000_STATUS_PHYRA
) == 0) {
2355 core
->mac
[index
] &= ~E1000_STATUS_PHYRA
;
2360 igb_set_ctrlext(IGBCore
*core
, int index
, uint32_t val
)
2362 trace_igb_link_set_ext_params(!!(val
& E1000_CTRL_EXT_ASDCHK
),
2363 !!(val
& E1000_CTRL_EXT_SPD_BYPS
),
2364 !!(val
& E1000_CTRL_EXT_PFRSTD
));
2366 /* Zero self-clearing bits */
2367 val
&= ~(E1000_CTRL_EXT_ASDCHK
| E1000_CTRL_EXT_EE_RST
);
2368 core
->mac
[CTRL_EXT
] = val
;
2370 if (core
->mac
[CTRL_EXT
] & E1000_CTRL_EXT_PFRSTD
) {
2371 for (int vfn
= 0; vfn
< IGB_MAX_VF_FUNCTIONS
; vfn
++) {
2372 core
->mac
[V2PMAILBOX0
+ vfn
] &= ~E1000_V2PMAILBOX_RSTI
;
2373 core
->mac
[V2PMAILBOX0
+ vfn
] |= E1000_V2PMAILBOX_RSTD
;
2379 igb_set_pbaclr(IGBCore
*core
, int index
, uint32_t val
)
2383 core
->mac
[PBACLR
] = val
& E1000_PBACLR_VALID_MASK
;
2385 if (!msix_enabled(core
->owner
)) {
2389 for (i
= 0; i
< IGB_INTR_NUM
; i
++) {
2390 if (core
->mac
[PBACLR
] & BIT(i
)) {
2391 msix_clr_pending(core
->owner
, i
);
2397 igb_set_fcrth(IGBCore
*core
, int index
, uint32_t val
)
2399 core
->mac
[FCRTH
] = val
& 0xFFF8;
2403 igb_set_fcrtl(IGBCore
*core
, int index
, uint32_t val
)
2405 core
->mac
[FCRTL
] = val
& 0x8000FFF8;
2408 #define IGB_LOW_BITS_SET_FUNC(num) \
2410 igb_set_##num##bit(IGBCore *core, int index, uint32_t val) \
2412 core->mac[index] = val & (BIT(num) - 1); \
2415 IGB_LOW_BITS_SET_FUNC(4)
2416 IGB_LOW_BITS_SET_FUNC(13)
2417 IGB_LOW_BITS_SET_FUNC(16)
2420 igb_set_dlen(IGBCore
*core
, int index
, uint32_t val
)
2422 core
->mac
[index
] = val
& 0xffff0;
2426 igb_set_dbal(IGBCore
*core
, int index
, uint32_t val
)
2428 core
->mac
[index
] = val
& E1000_XDBAL_MASK
;
2432 igb_set_tdt(IGBCore
*core
, int index
, uint32_t val
)
2435 int qn
= igb_mq_queue_idx(TDT0
, index
);
2437 core
->mac
[index
] = val
& 0xffff;
2439 igb_tx_ring_init(core
, &txr
, qn
);
2440 igb_start_xmit(core
, &txr
);
2444 igb_set_ics(IGBCore
*core
, int index
, uint32_t val
)
2446 trace_e1000e_irq_write_ics(val
);
2447 igb_set_interrupt_cause(core
, val
);
2451 igb_set_imc(IGBCore
*core
, int index
, uint32_t val
)
2453 trace_e1000e_irq_ims_clear_set_imc(val
);
2454 igb_clear_ims_bits(core
, val
);
2455 igb_update_interrupt_state(core
);
2459 igb_set_ims(IGBCore
*core
, int index
, uint32_t val
)
2461 uint32_t valid_val
= val
& 0x77D4FBFD;
2463 trace_e1000e_irq_set_ims(val
, core
->mac
[IMS
], core
->mac
[IMS
] | valid_val
);
2464 core
->mac
[IMS
] |= valid_val
;
2465 igb_update_interrupt_state(core
);
2468 static void igb_commit_icr(IGBCore
*core
)
2471 * If GPIE.NSICR = 0, then the clear of IMS will occur only if at
2472 * least one bit is set in the IMS and there is a true interrupt as
2473 * reflected in ICR.INTA.
2475 if ((core
->mac
[GPIE
] & E1000_GPIE_NSICR
) ||
2476 (core
->mac
[IMS
] && (core
->mac
[ICR
] & E1000_ICR_INT_ASSERTED
))) {
2477 igb_clear_ims_bits(core
, core
->mac
[IAM
]);
2480 igb_update_interrupt_state(core
);
2483 static void igb_set_icr(IGBCore
*core
, int index
, uint32_t val
)
2485 uint32_t icr
= core
->mac
[ICR
] & ~val
;
2487 trace_igb_irq_icr_write(val
, core
->mac
[ICR
], icr
);
2488 core
->mac
[ICR
] = icr
;
2489 igb_commit_icr(core
);
2493 igb_mac_readreg(IGBCore
*core
, int index
)
2495 return core
->mac
[index
];
2499 igb_mac_ics_read(IGBCore
*core
, int index
)
2501 trace_e1000e_irq_read_ics(core
->mac
[ICS
]);
2502 return core
->mac
[ICS
];
2506 igb_mac_ims_read(IGBCore
*core
, int index
)
2508 trace_e1000e_irq_read_ims(core
->mac
[IMS
]);
2509 return core
->mac
[IMS
];
2513 igb_mac_swsm_read(IGBCore
*core
, int index
)
2515 uint32_t val
= core
->mac
[SWSM
];
2516 core
->mac
[SWSM
] = val
| E1000_SWSM_SMBI
;
2521 igb_mac_eitr_read(IGBCore
*core
, int index
)
2523 return core
->eitr_guest_value
[index
- EITR0
];
2526 static uint32_t igb_mac_vfmailbox_read(IGBCore
*core
, int index
)
2528 uint32_t val
= core
->mac
[index
];
2530 core
->mac
[index
] &= ~(E1000_V2PMAILBOX_PFSTS
| E1000_V2PMAILBOX_PFACK
|
2531 E1000_V2PMAILBOX_RSTD
);
2537 igb_mac_icr_read(IGBCore
*core
, int index
)
2539 uint32_t ret
= core
->mac
[ICR
];
2540 trace_e1000e_irq_icr_read_entry(ret
);
2542 if (core
->mac
[GPIE
] & E1000_GPIE_NSICR
) {
2543 trace_igb_irq_icr_clear_gpie_nsicr();
2545 } else if (core
->mac
[IMS
] == 0) {
2546 trace_e1000e_irq_icr_clear_zero_ims();
2548 } else if (!msix_enabled(core
->owner
)) {
2549 trace_e1000e_irq_icr_clear_nonmsix_icr_read();
2553 trace_e1000e_irq_icr_read_exit(core
->mac
[ICR
]);
2554 igb_commit_icr(core
);
2559 igb_mac_read_clr4(IGBCore
*core
, int index
)
2561 uint32_t ret
= core
->mac
[index
];
2563 core
->mac
[index
] = 0;
2568 igb_mac_read_clr8(IGBCore
*core
, int index
)
2570 uint32_t ret
= core
->mac
[index
];
2572 core
->mac
[index
] = 0;
2573 core
->mac
[index
- 1] = 0;
2578 igb_get_ctrl(IGBCore
*core
, int index
)
2580 uint32_t val
= core
->mac
[CTRL
];
2582 trace_e1000e_link_read_params(
2583 !!(val
& E1000_CTRL_ASDE
),
2584 (val
& E1000_CTRL_SPD_SEL
) >> E1000_CTRL_SPD_SHIFT
,
2585 !!(val
& E1000_CTRL_FRCSPD
),
2586 !!(val
& E1000_CTRL_FRCDPX
),
2587 !!(val
& E1000_CTRL_RFCE
),
2588 !!(val
& E1000_CTRL_TFCE
));
2593 static uint32_t igb_get_status(IGBCore
*core
, int index
)
2595 uint32_t res
= core
->mac
[STATUS
];
2596 uint16_t num_vfs
= pcie_sriov_num_vfs(core
->owner
);
2598 if (core
->mac
[CTRL
] & E1000_CTRL_FRCDPX
) {
2599 res
|= (core
->mac
[CTRL
] & E1000_CTRL_FD
) ? E1000_STATUS_FD
: 0;
2601 res
|= E1000_STATUS_FD
;
2604 if ((core
->mac
[CTRL
] & E1000_CTRL_FRCSPD
) ||
2605 (core
->mac
[CTRL_EXT
] & E1000_CTRL_EXT_SPD_BYPS
)) {
2606 switch (core
->mac
[CTRL
] & E1000_CTRL_SPD_SEL
) {
2607 case E1000_CTRL_SPD_10
:
2608 res
|= E1000_STATUS_SPEED_10
;
2610 case E1000_CTRL_SPD_100
:
2611 res
|= E1000_STATUS_SPEED_100
;
2613 case E1000_CTRL_SPD_1000
:
2615 res
|= E1000_STATUS_SPEED_1000
;
2619 res
|= E1000_STATUS_SPEED_1000
;
2623 res
|= num_vfs
<< E1000_STATUS_NUM_VFS_SHIFT
;
2624 res
|= E1000_STATUS_IOV_MODE
;
2628 * Windows driver 12.18.9.23 resets if E1000_STATUS_GIO_MASTER_ENABLE is
2629 * left set after E1000_CTRL_LRST is set.
2631 if (!(core
->mac
[CTRL
] & E1000_CTRL_GIO_MASTER_DISABLE
) &&
2632 !(core
->mac
[CTRL
] & E1000_CTRL_LRST
)) {
2633 res
|= E1000_STATUS_GIO_MASTER_ENABLE
;
2640 igb_mac_writereg(IGBCore
*core
, int index
, uint32_t val
)
2642 core
->mac
[index
] = val
;
2646 igb_mac_setmacaddr(IGBCore
*core
, int index
, uint32_t val
)
2648 uint32_t macaddr
[2];
2650 core
->mac
[index
] = val
;
2652 macaddr
[0] = cpu_to_le32(core
->mac
[RA
]);
2653 macaddr
[1] = cpu_to_le32(core
->mac
[RA
+ 1]);
2654 qemu_format_nic_info_str(qemu_get_queue(core
->owner_nic
),
2655 (uint8_t *) macaddr
);
2657 trace_e1000e_mac_set_sw(MAC_ARG(macaddr
));
2661 igb_set_eecd(IGBCore
*core
, int index
, uint32_t val
)
2663 static const uint32_t ro_bits
= E1000_EECD_PRES
|
2664 E1000_EECD_AUTO_RD
|
2665 E1000_EECD_SIZE_EX_MASK
;
2667 core
->mac
[EECD
] = (core
->mac
[EECD
] & ro_bits
) | (val
& ~ro_bits
);
2671 igb_set_eerd(IGBCore
*core
, int index
, uint32_t val
)
2673 uint32_t addr
= (val
>> E1000_EERW_ADDR_SHIFT
) & E1000_EERW_ADDR_MASK
;
2677 if ((addr
< IGB_EEPROM_SIZE
) && (val
& E1000_EERW_START
)) {
2678 data
= core
->eeprom
[addr
];
2679 flags
= E1000_EERW_DONE
;
2682 core
->mac
[EERD
] = flags
|
2683 (addr
<< E1000_EERW_ADDR_SHIFT
) |
2684 (data
<< E1000_EERW_DATA_SHIFT
);
2688 igb_set_eitr(IGBCore
*core
, int index
, uint32_t val
)
2690 uint32_t eitr_num
= index
- EITR0
;
2692 trace_igb_irq_eitr_set(eitr_num
, val
);
2694 core
->eitr_guest_value
[eitr_num
] = val
& ~E1000_EITR_CNT_IGNR
;
2695 core
->mac
[index
] = val
& 0x7FFE;
2699 igb_update_rx_offloads(IGBCore
*core
)
2701 int cso_state
= igb_rx_l4_cso_enabled(core
);
2703 trace_e1000e_rx_set_cso(cso_state
);
2705 if (core
->has_vnet
) {
2706 qemu_set_offload(qemu_get_queue(core
->owner_nic
)->peer
,
2707 cso_state
, 0, 0, 0, 0);
2712 igb_set_rxcsum(IGBCore
*core
, int index
, uint32_t val
)
2714 core
->mac
[RXCSUM
] = val
;
2715 igb_update_rx_offloads(core
);
2719 igb_set_gcr(IGBCore
*core
, int index
, uint32_t val
)
2721 uint32_t ro_bits
= core
->mac
[GCR
] & E1000_GCR_RO_BITS
;
2722 core
->mac
[GCR
] = (val
& ~E1000_GCR_RO_BITS
) | ro_bits
;
2725 static uint32_t igb_get_systiml(IGBCore
*core
, int index
)
2727 e1000x_timestamp(core
->mac
, core
->timadj
, SYSTIML
, SYSTIMH
);
2728 return core
->mac
[SYSTIML
];
2731 static uint32_t igb_get_rxsatrh(IGBCore
*core
, int index
)
2733 core
->mac
[TSYNCRXCTL
] &= ~E1000_TSYNCRXCTL_VALID
;
2734 return core
->mac
[RXSATRH
];
2737 static uint32_t igb_get_txstmph(IGBCore
*core
, int index
)
2739 core
->mac
[TSYNCTXCTL
] &= ~E1000_TSYNCTXCTL_VALID
;
2740 return core
->mac
[TXSTMPH
];
2743 static void igb_set_timinca(IGBCore
*core
, int index
, uint32_t val
)
2745 e1000x_set_timinca(core
->mac
, &core
->timadj
, val
);
2748 static void igb_set_timadjh(IGBCore
*core
, int index
, uint32_t val
)
2750 core
->mac
[TIMADJH
] = val
;
2751 core
->timadj
+= core
->mac
[TIMADJL
] | ((int64_t)core
->mac
[TIMADJH
] << 32);
2754 #define igb_getreg(x) [x] = igb_mac_readreg
2755 typedef uint32_t (*readops
)(IGBCore
*, int);
2756 static const readops igb_macreg_readops
[] = {
2786 igb_getreg(RDBAH10
),
2787 igb_getreg(RDBAH11
),
2788 igb_getreg(RDBAH12
),
2789 igb_getreg(RDBAH13
),
2790 igb_getreg(RDBAH14
),
2791 igb_getreg(RDBAH15
),
2802 igb_getreg(TDBAL10
),
2803 igb_getreg(TDBAL11
),
2804 igb_getreg(TDBAL12
),
2805 igb_getreg(TDBAL13
),
2806 igb_getreg(TDBAL14
),
2807 igb_getreg(TDBAL15
),
2818 igb_getreg(RDLEN10
),
2819 igb_getreg(RDLEN11
),
2820 igb_getreg(RDLEN12
),
2821 igb_getreg(RDLEN13
),
2822 igb_getreg(RDLEN14
),
2823 igb_getreg(RDLEN15
),
2824 igb_getreg(SRRCTL0
),
2825 igb_getreg(SRRCTL1
),
2826 igb_getreg(SRRCTL2
),
2827 igb_getreg(SRRCTL3
),
2828 igb_getreg(SRRCTL4
),
2829 igb_getreg(SRRCTL5
),
2830 igb_getreg(SRRCTL6
),
2831 igb_getreg(SRRCTL7
),
2832 igb_getreg(SRRCTL8
),
2833 igb_getreg(SRRCTL9
),
2834 igb_getreg(SRRCTL10
),
2835 igb_getreg(SRRCTL11
),
2836 igb_getreg(SRRCTL12
),
2837 igb_getreg(SRRCTL13
),
2838 igb_getreg(SRRCTL14
),
2839 igb_getreg(SRRCTL15
),
2840 igb_getreg(LATECOL
),
2864 igb_getreg(RXSTMPH
),
2865 igb_getreg(TXSTMPL
),
2866 igb_getreg(TIMADJL
),
2904 igb_getreg(FLMNGCTL
),
2905 igb_getreg(FLMNGCNT
),
2906 igb_getreg(TSYNCTXCTL
),
2907 igb_getreg(EEMNGDATA
),
2908 igb_getreg(CTRL_EXT
),
2909 igb_getreg(SYSTIMH
),
2910 igb_getreg(EEMNGCTL
),
2911 igb_getreg(FLMNGDATA
),
2912 igb_getreg(TSYNCRXCTL
),
2915 igb_getreg(TCTL_EXT
),
2937 igb_getreg(XOFFTXC
),
2941 igb_getreg(TIMINCA
),
2947 igb_getreg(RXSATRL
),
2959 igb_getreg(TDLEN10
),
2960 igb_getreg(TDLEN11
),
2961 igb_getreg(TDLEN12
),
2962 igb_getreg(TDLEN13
),
2963 igb_getreg(TDLEN14
),
2964 igb_getreg(TDLEN15
),
2969 igb_getreg(TXDCTL0
),
2970 igb_getreg(TXDCTL1
),
2971 igb_getreg(TXDCTL2
),
2972 igb_getreg(TXDCTL3
),
2973 igb_getreg(TXDCTL4
),
2974 igb_getreg(TXDCTL5
),
2975 igb_getreg(TXDCTL6
),
2976 igb_getreg(TXDCTL7
),
2977 igb_getreg(TXDCTL8
),
2978 igb_getreg(TXDCTL9
),
2979 igb_getreg(TXDCTL10
),
2980 igb_getreg(TXDCTL11
),
2981 igb_getreg(TXDCTL12
),
2982 igb_getreg(TXDCTL13
),
2983 igb_getreg(TXDCTL14
),
2984 igb_getreg(TXDCTL15
),
2995 igb_getreg(TXCTL10
),
2996 igb_getreg(TXCTL11
),
2997 igb_getreg(TXCTL12
),
2998 igb_getreg(TXCTL13
),
2999 igb_getreg(TXCTL14
),
3000 igb_getreg(TXCTL15
),
3001 igb_getreg(TDWBAL0
),
3002 igb_getreg(TDWBAL1
),
3003 igb_getreg(TDWBAL2
),
3004 igb_getreg(TDWBAL3
),
3005 igb_getreg(TDWBAL4
),
3006 igb_getreg(TDWBAL5
),
3007 igb_getreg(TDWBAL6
),
3008 igb_getreg(TDWBAL7
),
3009 igb_getreg(TDWBAL8
),
3010 igb_getreg(TDWBAL9
),
3011 igb_getreg(TDWBAL10
),
3012 igb_getreg(TDWBAL11
),
3013 igb_getreg(TDWBAL12
),
3014 igb_getreg(TDWBAL13
),
3015 igb_getreg(TDWBAL14
),
3016 igb_getreg(TDWBAL15
),
3017 igb_getreg(TDWBAH0
),
3018 igb_getreg(TDWBAH1
),
3019 igb_getreg(TDWBAH2
),
3020 igb_getreg(TDWBAH3
),
3021 igb_getreg(TDWBAH4
),
3022 igb_getreg(TDWBAH5
),
3023 igb_getreg(TDWBAH6
),
3024 igb_getreg(TDWBAH7
),
3025 igb_getreg(TDWBAH8
),
3026 igb_getreg(TDWBAH9
),
3027 igb_getreg(TDWBAH10
),
3028 igb_getreg(TDWBAH11
),
3029 igb_getreg(TDWBAH12
),
3030 igb_getreg(TDWBAH13
),
3031 igb_getreg(TDWBAH14
),
3032 igb_getreg(TDWBAH15
),
3033 igb_getreg(PVTCTRL0
),
3034 igb_getreg(PVTCTRL1
),
3035 igb_getreg(PVTCTRL2
),
3036 igb_getreg(PVTCTRL3
),
3037 igb_getreg(PVTCTRL4
),
3038 igb_getreg(PVTCTRL5
),
3039 igb_getreg(PVTCTRL6
),
3040 igb_getreg(PVTCTRL7
),
3041 igb_getreg(PVTEIMS0
),
3042 igb_getreg(PVTEIMS1
),
3043 igb_getreg(PVTEIMS2
),
3044 igb_getreg(PVTEIMS3
),
3045 igb_getreg(PVTEIMS4
),
3046 igb_getreg(PVTEIMS5
),
3047 igb_getreg(PVTEIMS6
),
3048 igb_getreg(PVTEIMS7
),
3049 igb_getreg(PVTEIAC0
),
3050 igb_getreg(PVTEIAC1
),
3051 igb_getreg(PVTEIAC2
),
3052 igb_getreg(PVTEIAC3
),
3053 igb_getreg(PVTEIAC4
),
3054 igb_getreg(PVTEIAC5
),
3055 igb_getreg(PVTEIAC6
),
3056 igb_getreg(PVTEIAC7
),
3057 igb_getreg(PVTEIAM0
),
3058 igb_getreg(PVTEIAM1
),
3059 igb_getreg(PVTEIAM2
),
3060 igb_getreg(PVTEIAM3
),
3061 igb_getreg(PVTEIAM4
),
3062 igb_getreg(PVTEIAM5
),
3063 igb_getreg(PVTEIAM6
),
3064 igb_getreg(PVTEIAM7
),
3065 igb_getreg(PVFGPRC0
),
3066 igb_getreg(PVFGPRC1
),
3067 igb_getreg(PVFGPRC2
),
3068 igb_getreg(PVFGPRC3
),
3069 igb_getreg(PVFGPRC4
),
3070 igb_getreg(PVFGPRC5
),
3071 igb_getreg(PVFGPRC6
),
3072 igb_getreg(PVFGPRC7
),
3073 igb_getreg(PVFGPTC0
),
3074 igb_getreg(PVFGPTC1
),
3075 igb_getreg(PVFGPTC2
),
3076 igb_getreg(PVFGPTC3
),
3077 igb_getreg(PVFGPTC4
),
3078 igb_getreg(PVFGPTC5
),
3079 igb_getreg(PVFGPTC6
),
3080 igb_getreg(PVFGPTC7
),
3081 igb_getreg(PVFGORC0
),
3082 igb_getreg(PVFGORC1
),
3083 igb_getreg(PVFGORC2
),
3084 igb_getreg(PVFGORC3
),
3085 igb_getreg(PVFGORC4
),
3086 igb_getreg(PVFGORC5
),
3087 igb_getreg(PVFGORC6
),
3088 igb_getreg(PVFGORC7
),
3089 igb_getreg(PVFGOTC0
),
3090 igb_getreg(PVFGOTC1
),
3091 igb_getreg(PVFGOTC2
),
3092 igb_getreg(PVFGOTC3
),
3093 igb_getreg(PVFGOTC4
),
3094 igb_getreg(PVFGOTC5
),
3095 igb_getreg(PVFGOTC6
),
3096 igb_getreg(PVFGOTC7
),
3097 igb_getreg(PVFMPRC0
),
3098 igb_getreg(PVFMPRC1
),
3099 igb_getreg(PVFMPRC2
),
3100 igb_getreg(PVFMPRC3
),
3101 igb_getreg(PVFMPRC4
),
3102 igb_getreg(PVFMPRC5
),
3103 igb_getreg(PVFMPRC6
),
3104 igb_getreg(PVFMPRC7
),
3105 igb_getreg(PVFGPRLBC0
),
3106 igb_getreg(PVFGPRLBC1
),
3107 igb_getreg(PVFGPRLBC2
),
3108 igb_getreg(PVFGPRLBC3
),
3109 igb_getreg(PVFGPRLBC4
),
3110 igb_getreg(PVFGPRLBC5
),
3111 igb_getreg(PVFGPRLBC6
),
3112 igb_getreg(PVFGPRLBC7
),
3113 igb_getreg(PVFGPTLBC0
),
3114 igb_getreg(PVFGPTLBC1
),
3115 igb_getreg(PVFGPTLBC2
),
3116 igb_getreg(PVFGPTLBC3
),
3117 igb_getreg(PVFGPTLBC4
),
3118 igb_getreg(PVFGPTLBC5
),
3119 igb_getreg(PVFGPTLBC6
),
3120 igb_getreg(PVFGPTLBC7
),
3121 igb_getreg(PVFGORLBC0
),
3122 igb_getreg(PVFGORLBC1
),
3123 igb_getreg(PVFGORLBC2
),
3124 igb_getreg(PVFGORLBC3
),
3125 igb_getreg(PVFGORLBC4
),
3126 igb_getreg(PVFGORLBC5
),
3127 igb_getreg(PVFGORLBC6
),
3128 igb_getreg(PVFGORLBC7
),
3129 igb_getreg(PVFGOTLBC0
),
3130 igb_getreg(PVFGOTLBC1
),
3131 igb_getreg(PVFGOTLBC2
),
3132 igb_getreg(PVFGOTLBC3
),
3133 igb_getreg(PVFGOTLBC4
),
3134 igb_getreg(PVFGOTLBC5
),
3135 igb_getreg(PVFGOTLBC6
),
3136 igb_getreg(PVFGOTLBC7
),
3151 igb_getreg(RDBAL10
),
3152 igb_getreg(RDBAL11
),
3153 igb_getreg(RDBAL12
),
3154 igb_getreg(RDBAL13
),
3155 igb_getreg(RDBAL14
),
3156 igb_getreg(RDBAL15
),
3167 igb_getreg(TDBAH10
),
3168 igb_getreg(TDBAH11
),
3169 igb_getreg(TDBAH12
),
3170 igb_getreg(TDBAH13
),
3171 igb_getreg(TDBAH14
),
3172 igb_getreg(TDBAH15
),
3175 igb_getreg(XOFFRXC
),
3181 igb_getreg(FUNCTAG
),
3187 igb_getreg(RXDCTL0
),
3188 igb_getreg(RXDCTL1
),
3189 igb_getreg(RXDCTL2
),
3190 igb_getreg(RXDCTL3
),
3191 igb_getreg(RXDCTL4
),
3192 igb_getreg(RXDCTL5
),
3193 igb_getreg(RXDCTL6
),
3194 igb_getreg(RXDCTL7
),
3195 igb_getreg(RXDCTL8
),
3196 igb_getreg(RXDCTL9
),
3197 igb_getreg(RXDCTL10
),
3198 igb_getreg(RXDCTL11
),
3199 igb_getreg(RXDCTL12
),
3200 igb_getreg(RXDCTL13
),
3201 igb_getreg(RXDCTL14
),
3202 igb_getreg(RXDCTL15
),
3203 igb_getreg(RXSTMPL
),
3204 igb_getreg(TIMADJH
),
3214 [TOTH
] = igb_mac_read_clr8
,
3215 [GOTCH
] = igb_mac_read_clr8
,
3216 [PRC64
] = igb_mac_read_clr4
,
3217 [PRC255
] = igb_mac_read_clr4
,
3218 [PRC1023
] = igb_mac_read_clr4
,
3219 [PTC64
] = igb_mac_read_clr4
,
3220 [PTC255
] = igb_mac_read_clr4
,
3221 [PTC1023
] = igb_mac_read_clr4
,
3222 [GPRC
] = igb_mac_read_clr4
,
3223 [TPT
] = igb_mac_read_clr4
,
3224 [RUC
] = igb_mac_read_clr4
,
3225 [BPRC
] = igb_mac_read_clr4
,
3226 [MPTC
] = igb_mac_read_clr4
,
3227 [IAC
] = igb_mac_read_clr4
,
3228 [ICR
] = igb_mac_icr_read
,
3229 [STATUS
] = igb_get_status
,
3230 [ICS
] = igb_mac_ics_read
,
3232 * 8.8.10: Reading the IMC register returns the value of the IMS register.
3234 [IMC
] = igb_mac_ims_read
,
3235 [TORH
] = igb_mac_read_clr8
,
3236 [GORCH
] = igb_mac_read_clr8
,
3237 [PRC127
] = igb_mac_read_clr4
,
3238 [PRC511
] = igb_mac_read_clr4
,
3239 [PRC1522
] = igb_mac_read_clr4
,
3240 [PTC127
] = igb_mac_read_clr4
,
3241 [PTC511
] = igb_mac_read_clr4
,
3242 [PTC1522
] = igb_mac_read_clr4
,
3243 [GPTC
] = igb_mac_read_clr4
,
3244 [TPR
] = igb_mac_read_clr4
,
3245 [ROC
] = igb_mac_read_clr4
,
3246 [MPRC
] = igb_mac_read_clr4
,
3247 [BPTC
] = igb_mac_read_clr4
,
3248 [TSCTC
] = igb_mac_read_clr4
,
3249 [CTRL
] = igb_get_ctrl
,
3250 [SWSM
] = igb_mac_swsm_read
,
3251 [IMS
] = igb_mac_ims_read
,
3252 [SYSTIML
] = igb_get_systiml
,
3253 [RXSATRH
] = igb_get_rxsatrh
,
3254 [TXSTMPH
] = igb_get_txstmph
,
3256 [CRCERRS
... MPC
] = igb_mac_readreg
,
3257 [IP6AT
... IP6AT
+ 3] = igb_mac_readreg
,
3258 [IP4AT
... IP4AT
+ 6] = igb_mac_readreg
,
3259 [RA
... RA
+ 31] = igb_mac_readreg
,
3260 [RA2
... RA2
+ 31] = igb_mac_readreg
,
3261 [WUPM
... WUPM
+ 31] = igb_mac_readreg
,
3262 [MTA
... MTA
+ E1000_MC_TBL_SIZE
- 1] = igb_mac_readreg
,
3263 [VFTA
... VFTA
+ E1000_VLAN_FILTER_TBL_SIZE
- 1] = igb_mac_readreg
,
3264 [FFMT
... FFMT
+ 254] = igb_mac_readreg
,
3265 [MDEF
... MDEF
+ 7] = igb_mac_readreg
,
3266 [FTFT
... FTFT
+ 254] = igb_mac_readreg
,
3267 [RETA
... RETA
+ 31] = igb_mac_readreg
,
3268 [RSSRK
... RSSRK
+ 9] = igb_mac_readreg
,
3269 [MAVTV0
... MAVTV3
] = igb_mac_readreg
,
3270 [EITR0
... EITR0
+ IGB_INTR_NUM
- 1] = igb_mac_eitr_read
,
3271 [PVTEICR0
] = igb_mac_read_clr4
,
3272 [PVTEICR1
] = igb_mac_read_clr4
,
3273 [PVTEICR2
] = igb_mac_read_clr4
,
3274 [PVTEICR3
] = igb_mac_read_clr4
,
3275 [PVTEICR4
] = igb_mac_read_clr4
,
3276 [PVTEICR5
] = igb_mac_read_clr4
,
3277 [PVTEICR6
] = igb_mac_read_clr4
,
3278 [PVTEICR7
] = igb_mac_read_clr4
,
3281 [FWSM
] = igb_mac_readreg
,
3282 [SW_FW_SYNC
] = igb_mac_readreg
,
3283 [HTCBDPC
] = igb_mac_read_clr4
,
3284 [EICR
] = igb_mac_read_clr4
,
3285 [EIMS
] = igb_mac_readreg
,
3286 [EIAM
] = igb_mac_readreg
,
3287 [IVAR0
... IVAR0
+ 7] = igb_mac_readreg
,
3288 igb_getreg(IVAR_MISC
),
3290 [P2VMAILBOX0
... P2VMAILBOX7
] = igb_mac_readreg
,
3291 [V2PMAILBOX0
... V2PMAILBOX7
] = igb_mac_vfmailbox_read
,
3292 igb_getreg(MBVFICR
),
3293 [VMBMEM0
... VMBMEM0
+ 127] = igb_mac_readreg
,
3294 igb_getreg(MBVFIMR
),
3301 [VLVF0
... VLVF0
+ E1000_VLVF_ARRAY_SIZE
- 1] = igb_mac_readreg
,
3302 [VMVIR0
... VMVIR7
] = igb_mac_readreg
,
3303 [VMOLR0
... VMOLR7
] = igb_mac_readreg
,
3304 [WVBR
] = igb_mac_read_clr4
,
3305 [RQDPC0
] = igb_mac_read_clr4
,
3306 [RQDPC1
] = igb_mac_read_clr4
,
3307 [RQDPC2
] = igb_mac_read_clr4
,
3308 [RQDPC3
] = igb_mac_read_clr4
,
3309 [RQDPC4
] = igb_mac_read_clr4
,
3310 [RQDPC5
] = igb_mac_read_clr4
,
3311 [RQDPC6
] = igb_mac_read_clr4
,
3312 [RQDPC7
] = igb_mac_read_clr4
,
3313 [RQDPC8
] = igb_mac_read_clr4
,
3314 [RQDPC9
] = igb_mac_read_clr4
,
3315 [RQDPC10
] = igb_mac_read_clr4
,
3316 [RQDPC11
] = igb_mac_read_clr4
,
3317 [RQDPC12
] = igb_mac_read_clr4
,
3318 [RQDPC13
] = igb_mac_read_clr4
,
3319 [RQDPC14
] = igb_mac_read_clr4
,
3320 [RQDPC15
] = igb_mac_read_clr4
,
3321 [VTIVAR
... VTIVAR
+ 7] = igb_mac_readreg
,
3322 [VTIVAR_MISC
... VTIVAR_MISC
+ 7] = igb_mac_readreg
,
3324 enum { IGB_NREADOPS
= ARRAY_SIZE(igb_macreg_readops
) };
3326 #define igb_putreg(x) [x] = igb_mac_writereg
3327 typedef void (*writeops
)(IGBCore
*, int, uint32_t);
3328 static const writeops igb_macreg_writeops
[] = {
3341 igb_putreg(RDBAH10
),
3342 igb_putreg(RDBAH11
),
3343 igb_putreg(RDBAH12
),
3344 igb_putreg(RDBAH13
),
3345 igb_putreg(RDBAH14
),
3346 igb_putreg(RDBAH15
),
3347 igb_putreg(SRRCTL0
),
3348 igb_putreg(SRRCTL1
),
3349 igb_putreg(SRRCTL2
),
3350 igb_putreg(SRRCTL3
),
3351 igb_putreg(SRRCTL4
),
3352 igb_putreg(SRRCTL5
),
3353 igb_putreg(SRRCTL6
),
3354 igb_putreg(SRRCTL7
),
3355 igb_putreg(SRRCTL8
),
3356 igb_putreg(SRRCTL9
),
3357 igb_putreg(SRRCTL10
),
3358 igb_putreg(SRRCTL11
),
3359 igb_putreg(SRRCTL12
),
3360 igb_putreg(SRRCTL13
),
3361 igb_putreg(SRRCTL14
),
3362 igb_putreg(SRRCTL15
),
3363 igb_putreg(RXDCTL0
),
3364 igb_putreg(RXDCTL1
),
3365 igb_putreg(RXDCTL2
),
3366 igb_putreg(RXDCTL3
),
3367 igb_putreg(RXDCTL4
),
3368 igb_putreg(RXDCTL5
),
3369 igb_putreg(RXDCTL6
),
3370 igb_putreg(RXDCTL7
),
3371 igb_putreg(RXDCTL8
),
3372 igb_putreg(RXDCTL9
),
3373 igb_putreg(RXDCTL10
),
3374 igb_putreg(RXDCTL11
),
3375 igb_putreg(RXDCTL12
),
3376 igb_putreg(RXDCTL13
),
3377 igb_putreg(RXDCTL14
),
3378 igb_putreg(RXDCTL15
),
3381 igb_putreg(TCTL_EXT
),
3400 igb_putreg(TDBAH10
),
3401 igb_putreg(TDBAH11
),
3402 igb_putreg(TDBAH12
),
3403 igb_putreg(TDBAH13
),
3404 igb_putreg(TDBAH14
),
3405 igb_putreg(TDBAH15
),
3411 igb_putreg(FUNCTAG
),
3423 igb_putreg(TXDCTL0
),
3424 igb_putreg(TXDCTL1
),
3425 igb_putreg(TXDCTL2
),
3426 igb_putreg(TXDCTL3
),
3427 igb_putreg(TXDCTL4
),
3428 igb_putreg(TXDCTL5
),
3429 igb_putreg(TXDCTL6
),
3430 igb_putreg(TXDCTL7
),
3431 igb_putreg(TXDCTL8
),
3432 igb_putreg(TXDCTL9
),
3433 igb_putreg(TXDCTL10
),
3434 igb_putreg(TXDCTL11
),
3435 igb_putreg(TXDCTL12
),
3436 igb_putreg(TXDCTL13
),
3437 igb_putreg(TXDCTL14
),
3438 igb_putreg(TXDCTL15
),
3449 igb_putreg(TXCTL10
),
3450 igb_putreg(TXCTL11
),
3451 igb_putreg(TXCTL12
),
3452 igb_putreg(TXCTL13
),
3453 igb_putreg(TXCTL14
),
3454 igb_putreg(TXCTL15
),
3455 igb_putreg(TDWBAL0
),
3456 igb_putreg(TDWBAL1
),
3457 igb_putreg(TDWBAL2
),
3458 igb_putreg(TDWBAL3
),
3459 igb_putreg(TDWBAL4
),
3460 igb_putreg(TDWBAL5
),
3461 igb_putreg(TDWBAL6
),
3462 igb_putreg(TDWBAL7
),
3463 igb_putreg(TDWBAL8
),
3464 igb_putreg(TDWBAL9
),
3465 igb_putreg(TDWBAL10
),
3466 igb_putreg(TDWBAL11
),
3467 igb_putreg(TDWBAL12
),
3468 igb_putreg(TDWBAL13
),
3469 igb_putreg(TDWBAL14
),
3470 igb_putreg(TDWBAL15
),
3471 igb_putreg(TDWBAH0
),
3472 igb_putreg(TDWBAH1
),
3473 igb_putreg(TDWBAH2
),
3474 igb_putreg(TDWBAH3
),
3475 igb_putreg(TDWBAH4
),
3476 igb_putreg(TDWBAH5
),
3477 igb_putreg(TDWBAH6
),
3478 igb_putreg(TDWBAH7
),
3479 igb_putreg(TDWBAH8
),
3480 igb_putreg(TDWBAH9
),
3481 igb_putreg(TDWBAH10
),
3482 igb_putreg(TDWBAH11
),
3483 igb_putreg(TDWBAH12
),
3484 igb_putreg(TDWBAH13
),
3485 igb_putreg(TDWBAH14
),
3486 igb_putreg(TDWBAH15
),
3488 igb_putreg(RXSTMPH
),
3489 igb_putreg(RXSTMPL
),
3490 igb_putreg(RXSATRL
),
3491 igb_putreg(RXSATRH
),
3492 igb_putreg(TXSTMPL
),
3493 igb_putreg(TXSTMPH
),
3494 igb_putreg(SYSTIML
),
3495 igb_putreg(SYSTIMH
),
3496 igb_putreg(TIMADJL
),
3497 igb_putreg(TSYNCRXCTL
),
3498 igb_putreg(TSYNCTXCTL
),
3499 igb_putreg(EEMNGCTL
),
3505 [TDH0
] = igb_set_16bit
,
3506 [TDH1
] = igb_set_16bit
,
3507 [TDH2
] = igb_set_16bit
,
3508 [TDH3
] = igb_set_16bit
,
3509 [TDH4
] = igb_set_16bit
,
3510 [TDH5
] = igb_set_16bit
,
3511 [TDH6
] = igb_set_16bit
,
3512 [TDH7
] = igb_set_16bit
,
3513 [TDH8
] = igb_set_16bit
,
3514 [TDH9
] = igb_set_16bit
,
3515 [TDH10
] = igb_set_16bit
,
3516 [TDH11
] = igb_set_16bit
,
3517 [TDH12
] = igb_set_16bit
,
3518 [TDH13
] = igb_set_16bit
,
3519 [TDH14
] = igb_set_16bit
,
3520 [TDH15
] = igb_set_16bit
,
3521 [TDT0
] = igb_set_tdt
,
3522 [TDT1
] = igb_set_tdt
,
3523 [TDT2
] = igb_set_tdt
,
3524 [TDT3
] = igb_set_tdt
,
3525 [TDT4
] = igb_set_tdt
,
3526 [TDT5
] = igb_set_tdt
,
3527 [TDT6
] = igb_set_tdt
,
3528 [TDT7
] = igb_set_tdt
,
3529 [TDT8
] = igb_set_tdt
,
3530 [TDT9
] = igb_set_tdt
,
3531 [TDT10
] = igb_set_tdt
,
3532 [TDT11
] = igb_set_tdt
,
3533 [TDT12
] = igb_set_tdt
,
3534 [TDT13
] = igb_set_tdt
,
3535 [TDT14
] = igb_set_tdt
,
3536 [TDT15
] = igb_set_tdt
,
3537 [MDIC
] = igb_set_mdic
,
3538 [ICS
] = igb_set_ics
,
3539 [RDH0
] = igb_set_16bit
,
3540 [RDH1
] = igb_set_16bit
,
3541 [RDH2
] = igb_set_16bit
,
3542 [RDH3
] = igb_set_16bit
,
3543 [RDH4
] = igb_set_16bit
,
3544 [RDH5
] = igb_set_16bit
,
3545 [RDH6
] = igb_set_16bit
,
3546 [RDH7
] = igb_set_16bit
,
3547 [RDH8
] = igb_set_16bit
,
3548 [RDH9
] = igb_set_16bit
,
3549 [RDH10
] = igb_set_16bit
,
3550 [RDH11
] = igb_set_16bit
,
3551 [RDH12
] = igb_set_16bit
,
3552 [RDH13
] = igb_set_16bit
,
3553 [RDH14
] = igb_set_16bit
,
3554 [RDH15
] = igb_set_16bit
,
3555 [RDT0
] = igb_set_rdt
,
3556 [RDT1
] = igb_set_rdt
,
3557 [RDT2
] = igb_set_rdt
,
3558 [RDT3
] = igb_set_rdt
,
3559 [RDT4
] = igb_set_rdt
,
3560 [RDT5
] = igb_set_rdt
,
3561 [RDT6
] = igb_set_rdt
,
3562 [RDT7
] = igb_set_rdt
,
3563 [RDT8
] = igb_set_rdt
,
3564 [RDT9
] = igb_set_rdt
,
3565 [RDT10
] = igb_set_rdt
,
3566 [RDT11
] = igb_set_rdt
,
3567 [RDT12
] = igb_set_rdt
,
3568 [RDT13
] = igb_set_rdt
,
3569 [RDT14
] = igb_set_rdt
,
3570 [RDT15
] = igb_set_rdt
,
3571 [IMC
] = igb_set_imc
,
3572 [IMS
] = igb_set_ims
,
3573 [ICR
] = igb_set_icr
,
3574 [EECD
] = igb_set_eecd
,
3575 [RCTL
] = igb_set_rx_control
,
3576 [CTRL
] = igb_set_ctrl
,
3577 [EERD
] = igb_set_eerd
,
3578 [TDFH
] = igb_set_13bit
,
3579 [TDFT
] = igb_set_13bit
,
3580 [TDFHS
] = igb_set_13bit
,
3581 [TDFTS
] = igb_set_13bit
,
3582 [TDFPC
] = igb_set_13bit
,
3583 [RDFH
] = igb_set_13bit
,
3584 [RDFT
] = igb_set_13bit
,
3585 [RDFHS
] = igb_set_13bit
,
3586 [RDFTS
] = igb_set_13bit
,
3587 [RDFPC
] = igb_set_13bit
,
3588 [GCR
] = igb_set_gcr
,
3589 [RXCSUM
] = igb_set_rxcsum
,
3590 [TDLEN0
] = igb_set_dlen
,
3591 [TDLEN1
] = igb_set_dlen
,
3592 [TDLEN2
] = igb_set_dlen
,
3593 [TDLEN3
] = igb_set_dlen
,
3594 [TDLEN4
] = igb_set_dlen
,
3595 [TDLEN5
] = igb_set_dlen
,
3596 [TDLEN6
] = igb_set_dlen
,
3597 [TDLEN7
] = igb_set_dlen
,
3598 [TDLEN8
] = igb_set_dlen
,
3599 [TDLEN9
] = igb_set_dlen
,
3600 [TDLEN10
] = igb_set_dlen
,
3601 [TDLEN11
] = igb_set_dlen
,
3602 [TDLEN12
] = igb_set_dlen
,
3603 [TDLEN13
] = igb_set_dlen
,
3604 [TDLEN14
] = igb_set_dlen
,
3605 [TDLEN15
] = igb_set_dlen
,
3606 [RDLEN0
] = igb_set_dlen
,
3607 [RDLEN1
] = igb_set_dlen
,
3608 [RDLEN2
] = igb_set_dlen
,
3609 [RDLEN3
] = igb_set_dlen
,
3610 [RDLEN4
] = igb_set_dlen
,
3611 [RDLEN5
] = igb_set_dlen
,
3612 [RDLEN6
] = igb_set_dlen
,
3613 [RDLEN7
] = igb_set_dlen
,
3614 [RDLEN8
] = igb_set_dlen
,
3615 [RDLEN9
] = igb_set_dlen
,
3616 [RDLEN10
] = igb_set_dlen
,
3617 [RDLEN11
] = igb_set_dlen
,
3618 [RDLEN12
] = igb_set_dlen
,
3619 [RDLEN13
] = igb_set_dlen
,
3620 [RDLEN14
] = igb_set_dlen
,
3621 [RDLEN15
] = igb_set_dlen
,
3622 [TDBAL0
] = igb_set_dbal
,
3623 [TDBAL1
] = igb_set_dbal
,
3624 [TDBAL2
] = igb_set_dbal
,
3625 [TDBAL3
] = igb_set_dbal
,
3626 [TDBAL4
] = igb_set_dbal
,
3627 [TDBAL5
] = igb_set_dbal
,
3628 [TDBAL6
] = igb_set_dbal
,
3629 [TDBAL7
] = igb_set_dbal
,
3630 [TDBAL8
] = igb_set_dbal
,
3631 [TDBAL9
] = igb_set_dbal
,
3632 [TDBAL10
] = igb_set_dbal
,
3633 [TDBAL11
] = igb_set_dbal
,
3634 [TDBAL12
] = igb_set_dbal
,
3635 [TDBAL13
] = igb_set_dbal
,
3636 [TDBAL14
] = igb_set_dbal
,
3637 [TDBAL15
] = igb_set_dbal
,
3638 [RDBAL0
] = igb_set_dbal
,
3639 [RDBAL1
] = igb_set_dbal
,
3640 [RDBAL2
] = igb_set_dbal
,
3641 [RDBAL3
] = igb_set_dbal
,
3642 [RDBAL4
] = igb_set_dbal
,
3643 [RDBAL5
] = igb_set_dbal
,
3644 [RDBAL6
] = igb_set_dbal
,
3645 [RDBAL7
] = igb_set_dbal
,
3646 [RDBAL8
] = igb_set_dbal
,
3647 [RDBAL9
] = igb_set_dbal
,
3648 [RDBAL10
] = igb_set_dbal
,
3649 [RDBAL11
] = igb_set_dbal
,
3650 [RDBAL12
] = igb_set_dbal
,
3651 [RDBAL13
] = igb_set_dbal
,
3652 [RDBAL14
] = igb_set_dbal
,
3653 [RDBAL15
] = igb_set_dbal
,
3654 [STATUS
] = igb_set_status
,
3655 [PBACLR
] = igb_set_pbaclr
,
3656 [CTRL_EXT
] = igb_set_ctrlext
,
3657 [FCAH
] = igb_set_16bit
,
3658 [FCT
] = igb_set_16bit
,
3659 [FCTTV
] = igb_set_16bit
,
3660 [FCRTV
] = igb_set_16bit
,
3661 [FCRTH
] = igb_set_fcrth
,
3662 [FCRTL
] = igb_set_fcrtl
,
3663 [CTRL_DUP
] = igb_set_ctrl
,
3664 [RFCTL
] = igb_set_rfctl
,
3665 [TIMINCA
] = igb_set_timinca
,
3666 [TIMADJH
] = igb_set_timadjh
,
3668 [IP6AT
... IP6AT
+ 3] = igb_mac_writereg
,
3669 [IP4AT
... IP4AT
+ 6] = igb_mac_writereg
,
3670 [RA
] = igb_mac_writereg
,
3671 [RA
+ 1] = igb_mac_setmacaddr
,
3672 [RA
+ 2 ... RA
+ 31] = igb_mac_writereg
,
3673 [RA2
... RA2
+ 31] = igb_mac_writereg
,
3674 [WUPM
... WUPM
+ 31] = igb_mac_writereg
,
3675 [MTA
... MTA
+ E1000_MC_TBL_SIZE
- 1] = igb_mac_writereg
,
3676 [VFTA
... VFTA
+ E1000_VLAN_FILTER_TBL_SIZE
- 1] = igb_mac_writereg
,
3677 [FFMT
... FFMT
+ 254] = igb_set_4bit
,
3678 [MDEF
... MDEF
+ 7] = igb_mac_writereg
,
3679 [FTFT
... FTFT
+ 254] = igb_mac_writereg
,
3680 [RETA
... RETA
+ 31] = igb_mac_writereg
,
3681 [RSSRK
... RSSRK
+ 9] = igb_mac_writereg
,
3682 [MAVTV0
... MAVTV3
] = igb_mac_writereg
,
3683 [EITR0
... EITR0
+ IGB_INTR_NUM
- 1] = igb_set_eitr
,
3686 [FWSM
] = igb_mac_writereg
,
3687 [SW_FW_SYNC
] = igb_mac_writereg
,
3688 [EICR
] = igb_set_eicr
,
3689 [EICS
] = igb_set_eics
,
3690 [EIAC
] = igb_set_eiac
,
3691 [EIAM
] = igb_set_eiam
,
3692 [EIMC
] = igb_set_eimc
,
3693 [EIMS
] = igb_set_eims
,
3694 [IVAR0
... IVAR0
+ 7] = igb_mac_writereg
,
3695 igb_putreg(IVAR_MISC
),
3697 [P2VMAILBOX0
... P2VMAILBOX7
] = igb_set_pfmailbox
,
3698 [V2PMAILBOX0
... V2PMAILBOX7
] = igb_set_vfmailbox
,
3699 [MBVFICR
] = igb_w1c
,
3700 [VMBMEM0
... VMBMEM0
+ 127] = igb_mac_writereg
,
3701 igb_putreg(MBVFIMR
),
3708 [VLVF0
... VLVF0
+ E1000_VLVF_ARRAY_SIZE
- 1] = igb_mac_writereg
,
3709 [VMVIR0
... VMVIR7
] = igb_mac_writereg
,
3710 [VMOLR0
... VMOLR7
] = igb_mac_writereg
,
3711 [UTA
... UTA
+ E1000_MC_TBL_SIZE
- 1] = igb_mac_writereg
,
3712 [PVTCTRL0
] = igb_set_vtctrl
,
3713 [PVTCTRL1
] = igb_set_vtctrl
,
3714 [PVTCTRL2
] = igb_set_vtctrl
,
3715 [PVTCTRL3
] = igb_set_vtctrl
,
3716 [PVTCTRL4
] = igb_set_vtctrl
,
3717 [PVTCTRL5
] = igb_set_vtctrl
,
3718 [PVTCTRL6
] = igb_set_vtctrl
,
3719 [PVTCTRL7
] = igb_set_vtctrl
,
3720 [PVTEICS0
] = igb_set_vteics
,
3721 [PVTEICS1
] = igb_set_vteics
,
3722 [PVTEICS2
] = igb_set_vteics
,
3723 [PVTEICS3
] = igb_set_vteics
,
3724 [PVTEICS4
] = igb_set_vteics
,
3725 [PVTEICS5
] = igb_set_vteics
,
3726 [PVTEICS6
] = igb_set_vteics
,
3727 [PVTEICS7
] = igb_set_vteics
,
3728 [PVTEIMS0
] = igb_set_vteims
,
3729 [PVTEIMS1
] = igb_set_vteims
,
3730 [PVTEIMS2
] = igb_set_vteims
,
3731 [PVTEIMS3
] = igb_set_vteims
,
3732 [PVTEIMS4
] = igb_set_vteims
,
3733 [PVTEIMS5
] = igb_set_vteims
,
3734 [PVTEIMS6
] = igb_set_vteims
,
3735 [PVTEIMS7
] = igb_set_vteims
,
3736 [PVTEIMC0
] = igb_set_vteimc
,
3737 [PVTEIMC1
] = igb_set_vteimc
,
3738 [PVTEIMC2
] = igb_set_vteimc
,
3739 [PVTEIMC3
] = igb_set_vteimc
,
3740 [PVTEIMC4
] = igb_set_vteimc
,
3741 [PVTEIMC5
] = igb_set_vteimc
,
3742 [PVTEIMC6
] = igb_set_vteimc
,
3743 [PVTEIMC7
] = igb_set_vteimc
,
3744 [PVTEIAC0
] = igb_set_vteiac
,
3745 [PVTEIAC1
] = igb_set_vteiac
,
3746 [PVTEIAC2
] = igb_set_vteiac
,
3747 [PVTEIAC3
] = igb_set_vteiac
,
3748 [PVTEIAC4
] = igb_set_vteiac
,
3749 [PVTEIAC5
] = igb_set_vteiac
,
3750 [PVTEIAC6
] = igb_set_vteiac
,
3751 [PVTEIAC7
] = igb_set_vteiac
,
3752 [PVTEIAM0
] = igb_set_vteiam
,
3753 [PVTEIAM1
] = igb_set_vteiam
,
3754 [PVTEIAM2
] = igb_set_vteiam
,
3755 [PVTEIAM3
] = igb_set_vteiam
,
3756 [PVTEIAM4
] = igb_set_vteiam
,
3757 [PVTEIAM5
] = igb_set_vteiam
,
3758 [PVTEIAM6
] = igb_set_vteiam
,
3759 [PVTEIAM7
] = igb_set_vteiam
,
3760 [PVTEICR0
] = igb_set_vteicr
,
3761 [PVTEICR1
] = igb_set_vteicr
,
3762 [PVTEICR2
] = igb_set_vteicr
,
3763 [PVTEICR3
] = igb_set_vteicr
,
3764 [PVTEICR4
] = igb_set_vteicr
,
3765 [PVTEICR5
] = igb_set_vteicr
,
3766 [PVTEICR6
] = igb_set_vteicr
,
3767 [PVTEICR7
] = igb_set_vteicr
,
3768 [VTIVAR
... VTIVAR
+ 7] = igb_set_vtivar
,
3769 [VTIVAR_MISC
... VTIVAR_MISC
+ 7] = igb_mac_writereg
3771 enum { IGB_NWRITEOPS
= ARRAY_SIZE(igb_macreg_writeops
) };
3773 enum { MAC_ACCESS_PARTIAL
= 1 };
3776 * The array below combines alias offsets of the index values for the
3777 * MAC registers that have aliases, with the indication of not fully
3778 * implemented registers (lowest bit). This combination is possible
3779 * because all of the offsets are even.
3781 static const uint16_t mac_reg_access
[E1000E_MAC_SIZE
] = {
3782 /* Alias index offsets */
3784 [RDFH_A
] = 0xe904, [RDFT_A
] = 0xe904,
3785 [TDFH_A
] = 0xed00, [TDFT_A
] = 0xed00,
3786 [RA_A
... RA_A
+ 31] = 0x14f0,
3787 [VFTA_A
... VFTA_A
+ E1000_VLAN_FILTER_TBL_SIZE
- 1] = 0x1400,
3789 [RDBAL0_A
] = 0x2600,
3790 [RDBAH0_A
] = 0x2600,
3791 [RDLEN0_A
] = 0x2600,
3792 [SRRCTL0_A
] = 0x2600,
3795 [RXDCTL0_A
] = 0x2600,
3796 [RXCTL0_A
] = 0x2600,
3797 [RQDPC0_A
] = 0x2600,
3798 [RDBAL1_A
] = 0x25D0,
3799 [RDBAL2_A
] = 0x25A0,
3800 [RDBAL3_A
] = 0x2570,
3801 [RDBAH1_A
] = 0x25D0,
3802 [RDBAH2_A
] = 0x25A0,
3803 [RDBAH3_A
] = 0x2570,
3804 [RDLEN1_A
] = 0x25D0,
3805 [RDLEN2_A
] = 0x25A0,
3806 [RDLEN3_A
] = 0x2570,
3807 [SRRCTL1_A
] = 0x25D0,
3808 [SRRCTL2_A
] = 0x25A0,
3809 [SRRCTL3_A
] = 0x2570,
3816 [RXDCTL1_A
] = 0x25D0,
3817 [RXDCTL2_A
] = 0x25A0,
3818 [RXDCTL3_A
] = 0x2570,
3819 [RXCTL1_A
] = 0x25D0,
3820 [RXCTL2_A
] = 0x25A0,
3821 [RXCTL3_A
] = 0x2570,
3822 [RQDPC1_A
] = 0x25D0,
3823 [RQDPC2_A
] = 0x25A0,
3824 [RQDPC3_A
] = 0x2570,
3825 [TDBAL0_A
] = 0x2A00,
3826 [TDBAH0_A
] = 0x2A00,
3827 [TDLEN0_A
] = 0x2A00,
3830 [TXCTL0_A
] = 0x2A00,
3831 [TDWBAL0_A
] = 0x2A00,
3832 [TDWBAH0_A
] = 0x2A00,
3833 [TDBAL1_A
] = 0x29D0,
3834 [TDBAL2_A
] = 0x29A0,
3835 [TDBAL3_A
] = 0x2970,
3836 [TDBAH1_A
] = 0x29D0,
3837 [TDBAH2_A
] = 0x29A0,
3838 [TDBAH3_A
] = 0x2970,
3839 [TDLEN1_A
] = 0x29D0,
3840 [TDLEN2_A
] = 0x29A0,
3841 [TDLEN3_A
] = 0x2970,
3848 [TXDCTL0_A
] = 0x2A00,
3849 [TXDCTL1_A
] = 0x29D0,
3850 [TXDCTL2_A
] = 0x29A0,
3851 [TXDCTL3_A
] = 0x2970,
3852 [TXCTL1_A
] = 0x29D0,
3853 [TXCTL2_A
] = 0x29A0,
3854 [TXCTL3_A
] = 0x29D0,
3855 [TDWBAL1_A
] = 0x29D0,
3856 [TDWBAL2_A
] = 0x29A0,
3857 [TDWBAL3_A
] = 0x2970,
3858 [TDWBAH1_A
] = 0x29D0,
3859 [TDWBAH2_A
] = 0x29A0,
3860 [TDWBAH3_A
] = 0x2970,
3862 /* Access options */
3863 [RDFH
] = MAC_ACCESS_PARTIAL
, [RDFT
] = MAC_ACCESS_PARTIAL
,
3864 [RDFHS
] = MAC_ACCESS_PARTIAL
, [RDFTS
] = MAC_ACCESS_PARTIAL
,
3865 [RDFPC
] = MAC_ACCESS_PARTIAL
,
3866 [TDFH
] = MAC_ACCESS_PARTIAL
, [TDFT
] = MAC_ACCESS_PARTIAL
,
3867 [TDFHS
] = MAC_ACCESS_PARTIAL
, [TDFTS
] = MAC_ACCESS_PARTIAL
,
3868 [TDFPC
] = MAC_ACCESS_PARTIAL
, [EECD
] = MAC_ACCESS_PARTIAL
,
3869 [FLA
] = MAC_ACCESS_PARTIAL
,
3870 [FCAL
] = MAC_ACCESS_PARTIAL
, [FCAH
] = MAC_ACCESS_PARTIAL
,
3871 [FCT
] = MAC_ACCESS_PARTIAL
, [FCTTV
] = MAC_ACCESS_PARTIAL
,
3872 [FCRTV
] = MAC_ACCESS_PARTIAL
, [FCRTL
] = MAC_ACCESS_PARTIAL
,
3873 [FCRTH
] = MAC_ACCESS_PARTIAL
,
3874 [MAVTV0
... MAVTV3
] = MAC_ACCESS_PARTIAL
3878 igb_core_write(IGBCore
*core
, hwaddr addr
, uint64_t val
, unsigned size
)
3880 uint16_t index
= igb_get_reg_index_with_offset(mac_reg_access
, addr
);
3882 if (index
< IGB_NWRITEOPS
&& igb_macreg_writeops
[index
]) {
3883 if (mac_reg_access
[index
] & MAC_ACCESS_PARTIAL
) {
3884 trace_e1000e_wrn_regs_write_trivial(index
<< 2);
3886 trace_e1000e_core_write(index
<< 2, size
, val
);
3887 igb_macreg_writeops
[index
](core
, index
, val
);
3888 } else if (index
< IGB_NREADOPS
&& igb_macreg_readops
[index
]) {
3889 trace_e1000e_wrn_regs_write_ro(index
<< 2, size
, val
);
3891 trace_e1000e_wrn_regs_write_unknown(index
<< 2, size
, val
);
3896 igb_core_read(IGBCore
*core
, hwaddr addr
, unsigned size
)
3899 uint16_t index
= igb_get_reg_index_with_offset(mac_reg_access
, addr
);
3901 if (index
< IGB_NREADOPS
&& igb_macreg_readops
[index
]) {
3902 if (mac_reg_access
[index
] & MAC_ACCESS_PARTIAL
) {
3903 trace_e1000e_wrn_regs_read_trivial(index
<< 2);
3905 val
= igb_macreg_readops
[index
](core
, index
);
3906 trace_e1000e_core_read(index
<< 2, size
, val
);
3909 trace_e1000e_wrn_regs_read_unknown(index
<< 2, size
);
3915 igb_autoneg_pause(IGBCore
*core
)
3917 timer_del(core
->autoneg_timer
);
3921 igb_autoneg_resume(IGBCore
*core
)
3923 if (igb_have_autoneg(core
) &&
3924 !(core
->phy
[MII_BMSR
] & MII_BMSR_AN_COMP
)) {
3925 qemu_get_queue(core
->owner_nic
)->link_down
= false;
3926 timer_mod(core
->autoneg_timer
,
3927 qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL
) + 500);
3932 igb_vm_state_change(void *opaque
, bool running
, RunState state
)
3934 IGBCore
*core
= opaque
;
3937 trace_e1000e_vm_state_running();
3938 igb_intrmgr_resume(core
);
3939 igb_autoneg_resume(core
);
3941 trace_e1000e_vm_state_stopped();
3942 igb_autoneg_pause(core
);
3943 igb_intrmgr_pause(core
);
3948 igb_core_pci_realize(IGBCore
*core
,
3949 const uint16_t *eeprom_templ
,
3950 uint32_t eeprom_size
,
3951 const uint8_t *macaddr
)
3955 core
->autoneg_timer
= timer_new_ms(QEMU_CLOCK_VIRTUAL
,
3956 igb_autoneg_timer
, core
);
3957 igb_intrmgr_pci_realize(core
);
3959 core
->vmstate
= qemu_add_vm_change_state_handler(igb_vm_state_change
, core
);
3961 for (i
= 0; i
< IGB_NUM_QUEUES
; i
++) {
3962 net_tx_pkt_init(&core
->tx
[i
].tx_pkt
, E1000E_MAX_TX_FRAGS
);
3965 net_rx_pkt_init(&core
->rx_pkt
);
3967 e1000x_core_prepare_eeprom(core
->eeprom
,
3970 PCI_DEVICE_GET_CLASS(core
->owner
)->device_id
,
3972 igb_update_rx_offloads(core
);
3976 igb_core_pci_uninit(IGBCore
*core
)
3980 timer_free(core
->autoneg_timer
);
3982 igb_intrmgr_pci_unint(core
);
3984 qemu_del_vm_change_state_handler(core
->vmstate
);
3986 for (i
= 0; i
< IGB_NUM_QUEUES
; i
++) {
3987 net_tx_pkt_uninit(core
->tx
[i
].tx_pkt
);
3990 net_rx_pkt_uninit(core
->rx_pkt
);
3993 static const uint16_t
3994 igb_phy_reg_init
[] = {
3995 [MII_BMCR
] = MII_BMCR_SPEED1000
|
3999 [MII_BMSR
] = MII_BMSR_EXTCAP
|
4009 [MII_PHYID1
] = IGP03E1000_E_PHY_ID
>> 16,
4010 [MII_PHYID2
] = (IGP03E1000_E_PHY_ID
& 0xfff0) | 1,
4011 [MII_ANAR
] = MII_ANAR_CSMACD
| MII_ANAR_10
|
4012 MII_ANAR_10FD
| MII_ANAR_TX
|
4013 MII_ANAR_TXFD
| MII_ANAR_PAUSE
|
4014 MII_ANAR_PAUSE_ASYM
,
4015 [MII_ANLPAR
] = MII_ANLPAR_10
| MII_ANLPAR_10FD
|
4016 MII_ANLPAR_TX
| MII_ANLPAR_TXFD
|
4017 MII_ANLPAR_T4
| MII_ANLPAR_PAUSE
,
4018 [MII_ANER
] = MII_ANER_NP
| MII_ANER_NWAY
,
4019 [MII_ANNP
] = 0x1 | MII_ANNP_MP
,
4020 [MII_CTRL1000
] = MII_CTRL1000_HALF
| MII_CTRL1000_FULL
|
4021 MII_CTRL1000_PORT
| MII_CTRL1000_MASTER
,
4022 [MII_STAT1000
] = MII_STAT1000_HALF
| MII_STAT1000_FULL
|
4023 MII_STAT1000_ROK
| MII_STAT1000_LOK
,
4024 [MII_EXTSTAT
] = MII_EXTSTAT_1000T_HD
| MII_EXTSTAT_1000T_FD
,
4026 [IGP01E1000_PHY_PORT_CONFIG
] = BIT(5) | BIT(8),
4027 [IGP01E1000_PHY_PORT_STATUS
] = IGP01E1000_PSSR_SPEED_1000MBPS
,
4028 [IGP02E1000_PHY_POWER_MGMT
] = BIT(0) | BIT(3) | IGP02E1000_PM_D3_LPLU
|
4029 IGP01E1000_PSCFR_SMART_SPEED
4032 static const uint32_t igb_mac_reg_init
[] = {
4033 [LEDCTL
] = 2 | (3 << 8) | BIT(15) | (6 << 16) | (7 << 24),
4034 [EEMNGCTL
] = BIT(31),
4035 [TXDCTL0
] = E1000_TXDCTL_QUEUE_ENABLE
,
4036 [RXDCTL0
] = E1000_RXDCTL_QUEUE_ENABLE
| (1 << 16),
4037 [RXDCTL1
] = 1 << 16,
4038 [RXDCTL2
] = 1 << 16,
4039 [RXDCTL3
] = 1 << 16,
4040 [RXDCTL4
] = 1 << 16,
4041 [RXDCTL5
] = 1 << 16,
4042 [RXDCTL6
] = 1 << 16,
4043 [RXDCTL7
] = 1 << 16,
4044 [RXDCTL8
] = 1 << 16,
4045 [RXDCTL9
] = 1 << 16,
4046 [RXDCTL10
] = 1 << 16,
4047 [RXDCTL11
] = 1 << 16,
4048 [RXDCTL12
] = 1 << 16,
4049 [RXDCTL13
] = 1 << 16,
4050 [RXDCTL14
] = 1 << 16,
4051 [RXDCTL15
] = 1 << 16,
4052 [TIPG
] = 0x08 | (0x04 << 10) | (0x06 << 20),
4053 [CTRL
] = E1000_CTRL_FD
| E1000_CTRL_LRST
| E1000_CTRL_SPD_1000
|
4054 E1000_CTRL_ADVD3WUC
,
4055 [STATUS
] = E1000_STATUS_PHYRA
| BIT(31),
4056 [EECD
] = E1000_EECD_FWE_DIS
| E1000_EECD_PRES
|
4057 (2 << E1000_EECD_SIZE_EX_SHIFT
),
4058 [GCR
] = E1000_L0S_ADJUST
|
4059 E1000_GCR_CMPL_TMOUT_RESEND
|
4060 E1000_GCR_CAP_VER2
|
4061 E1000_L1_ENTRY_LATENCY_MSB
|
4062 E1000_L1_ENTRY_LATENCY_LSB
,
4063 [RXCSUM
] = E1000_RXCSUM_IPOFLD
| E1000_RXCSUM_TUOFLD
,
4066 [TCTL
] = E1000_TCTL_PSP
| (0xF << E1000_CT_SHIFT
) |
4067 (0x40 << E1000_COLD_SHIFT
) | (0x1 << 26) | (0xA << 28),
4068 [TCTL_EXT
] = 0x40 | (0x42 << 10),
4069 [DTXCTL
] = E1000_DTXCTL_8023LL
| E1000_DTXCTL_SPOOF_INT
,
4070 [VET
] = ETH_P_VLAN
| (ETH_P_VLAN
<< 16),
4072 [V2PMAILBOX0
... V2PMAILBOX0
+ IGB_MAX_VF_FUNCTIONS
- 1] = E1000_V2PMAILBOX_RSTI
,
4076 [VMOLR0
... VMOLR0
+ 7] = 0x2600 | E1000_VMOLR_STRCRC
,
4077 [RPLOLR
] = E1000_RPLOLR_STRCRC
,
4079 [TXCTL0
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4080 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4081 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4082 [TXCTL1
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4083 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4084 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4085 [TXCTL2
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4086 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4087 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4088 [TXCTL3
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4089 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4090 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4091 [TXCTL4
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4092 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4093 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4094 [TXCTL5
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4095 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4096 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4097 [TXCTL6
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4098 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4099 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4100 [TXCTL7
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4101 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4102 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4103 [TXCTL8
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4104 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4105 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4106 [TXCTL9
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4107 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4108 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4109 [TXCTL10
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4110 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4111 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4112 [TXCTL11
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4113 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4114 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4115 [TXCTL12
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4116 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4117 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4118 [TXCTL13
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4119 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4120 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4121 [TXCTL14
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4122 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4123 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4124 [TXCTL15
] = E1000_DCA_TXCTRL_DATA_RRO_EN
|
4125 E1000_DCA_TXCTRL_TX_WB_RO_EN
|
4126 E1000_DCA_TXCTRL_DESC_RRO_EN
,
4129 static void igb_reset(IGBCore
*core
, bool sw
)
4134 timer_del(core
->autoneg_timer
);
4136 igb_intrmgr_reset(core
);
4138 memset(core
->phy
, 0, sizeof core
->phy
);
4139 memcpy(core
->phy
, igb_phy_reg_init
, sizeof igb_phy_reg_init
);
4141 for (i
= 0; i
< E1000E_MAC_SIZE
; i
++) {
4143 (i
== RXPBS
|| i
== TXPBS
||
4144 (i
>= EITR0
&& i
< EITR0
+ IGB_INTR_NUM
))) {
4148 core
->mac
[i
] = i
< ARRAY_SIZE(igb_mac_reg_init
) ?
4149 igb_mac_reg_init
[i
] : 0;
4152 if (qemu_get_queue(core
->owner_nic
)->link_down
) {
4153 igb_link_down(core
);
4156 e1000x_reset_mac_addr(core
->owner_nic
, core
->mac
, core
->permanent_mac
);
4158 for (int vfn
= 0; vfn
< IGB_MAX_VF_FUNCTIONS
; vfn
++) {
4159 /* Set RSTI, so VF can identify a PF reset is in progress */
4160 core
->mac
[V2PMAILBOX0
+ vfn
] |= E1000_V2PMAILBOX_RSTI
;
4163 for (i
= 0; i
< ARRAY_SIZE(core
->tx
); i
++) {
4165 memset(tx
->ctx
, 0, sizeof(tx
->ctx
));
4167 tx
->skip_cp
= false;
4172 igb_core_reset(IGBCore
*core
)
4174 igb_reset(core
, false);
4177 void igb_core_pre_save(IGBCore
*core
)
4180 NetClientState
*nc
= qemu_get_queue(core
->owner_nic
);
4183 * If link is down and auto-negotiation is supported and ongoing,
4184 * complete auto-negotiation immediately. This allows us to look
4185 * at MII_BMSR_AN_COMP to infer link status on load.
4187 if (nc
->link_down
&& igb_have_autoneg(core
)) {
4188 core
->phy
[MII_BMSR
] |= MII_BMSR_AN_COMP
;
4189 igb_update_flowctl_status(core
);
4192 for (i
= 0; i
< ARRAY_SIZE(core
->tx
); i
++) {
4193 if (net_tx_pkt_has_fragments(core
->tx
[i
].tx_pkt
)) {
4194 core
->tx
[i
].skip_cp
= true;
4200 igb_core_post_load(IGBCore
*core
)
4202 NetClientState
*nc
= qemu_get_queue(core
->owner_nic
);
4205 * nc.link_down can't be migrated, so infer link_down according
4206 * to link status bit in core.mac[STATUS].
4208 nc
->link_down
= (core
->mac
[STATUS
] & E1000_STATUS_LU
) == 0;