2 * Core code for QEMU e1000e emulation
4 * Software developer's manuals:
5 * http://www.intel.com/content/dam/doc/datasheet/82574l-gbe-controller-datasheet.pdf
7 * Copyright (c) 2015 Ravello Systems LTD (http://ravellosystems.com)
8 * Developed by Daynix Computing LTD (http://www.daynix.com)
11 * Dmitry Fleytman <dmitry@daynix.com>
12 * Leonid Bloch <leonid@daynix.com>
13 * Yan Vugenfirer <yan@daynix.com>
15 * Based on work done by:
16 * Nir Peleg, Tutis Systems Ltd. for Qumranet Inc.
17 * Copyright (c) 2008 Qumranet
18 * Based on work done by:
19 * Copyright (c) 2007 Dan Aloni
20 * Copyright (c) 2004 Antony T Curtis
22 * This library is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU Lesser General Public
24 * License as published by the Free Software Foundation; either
25 * version 2 of the License, or (at your option) any later version.
27 * This library is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 * Lesser General Public License for more details.
32 * You should have received a copy of the GNU Lesser General Public
33 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
36 #include "qemu/osdep.h"
37 #include "sysemu/sysemu.h"
40 #include "hw/pci/msi.h"
41 #include "hw/pci/msix.h"
43 #include "net_tx_pkt.h"
44 #include "net_rx_pkt.h"
46 #include "e1000x_common.h"
47 #include "e1000e_core.h"
51 #define E1000E_MIN_XITR (500) /* No more then 7813 interrupts per
52 second according to spec 10.2.4.2 */
53 #define E1000E_MAX_TX_FRAGS (64)
56 e1000e_set_interrupt_cause(E1000ECore
*core
, uint32_t val
);
59 e1000e_process_ts_option(E1000ECore
*core
, struct e1000_tx_desc
*dp
)
61 if (le32_to_cpu(dp
->upper
.data
) & E1000_TXD_EXTCMD_TSTAMP
) {
62 trace_e1000e_wrn_no_ts_support();
67 e1000e_process_snap_option(E1000ECore
*core
, uint32_t cmd_and_length
)
69 if (cmd_and_length
& E1000_TXD_CMD_SNAP
) {
70 trace_e1000e_wrn_no_snap_support();
75 e1000e_raise_legacy_irq(E1000ECore
*core
)
77 trace_e1000e_irq_legacy_notify(true);
78 e1000x_inc_reg_if_not_full(core
->mac
, IAC
);
79 pci_set_irq(core
->owner
, 1);
83 e1000e_lower_legacy_irq(E1000ECore
*core
)
85 trace_e1000e_irq_legacy_notify(false);
86 pci_set_irq(core
->owner
, 0);
90 e1000e_intrmgr_rearm_timer(E1000IntrDelayTimer
*timer
)
92 int64_t delay_ns
= (int64_t) timer
->core
->mac
[timer
->delay_reg
] *
93 timer
->delay_resolution_ns
;
95 trace_e1000e_irq_rearm_timer(timer
->delay_reg
<< 2, delay_ns
);
97 timer_mod(timer
->timer
, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) + delay_ns
);
99 timer
->running
= true;
103 e1000e_intmgr_timer_resume(E1000IntrDelayTimer
*timer
)
105 if (timer
->running
) {
106 e1000e_intrmgr_rearm_timer(timer
);
111 e1000e_intmgr_timer_pause(E1000IntrDelayTimer
*timer
)
113 if (timer
->running
) {
114 timer_del(timer
->timer
);
119 e1000e_intrmgr_stop_timer(E1000IntrDelayTimer
*timer
)
121 if (timer
->running
) {
122 timer_del(timer
->timer
);
123 timer
->running
= false;
128 e1000e_intrmgr_fire_delayed_interrupts(E1000ECore
*core
)
130 trace_e1000e_irq_fire_delayed_interrupts();
131 e1000e_set_interrupt_cause(core
, 0);
135 e1000e_intrmgr_on_timer(void *opaque
)
137 E1000IntrDelayTimer
*timer
= opaque
;
139 trace_e1000e_irq_throttling_timer(timer
->delay_reg
<< 2);
141 timer
->running
= false;
142 e1000e_intrmgr_fire_delayed_interrupts(timer
->core
);
146 e1000e_intrmgr_on_throttling_timer(void *opaque
)
148 E1000IntrDelayTimer
*timer
= opaque
;
150 assert(!msix_enabled(timer
->core
->owner
));
152 timer
->running
= false;
154 if (!timer
->core
->itr_intr_pending
) {
155 trace_e1000e_irq_throttling_no_pending_interrupts();
159 if (msi_enabled(timer
->core
->owner
)) {
160 trace_e1000e_irq_msi_notify_postponed();
161 e1000e_set_interrupt_cause(timer
->core
, 0);
163 trace_e1000e_irq_legacy_notify_postponed();
164 e1000e_set_interrupt_cause(timer
->core
, 0);
169 e1000e_intrmgr_on_msix_throttling_timer(void *opaque
)
171 E1000IntrDelayTimer
*timer
= opaque
;
172 int idx
= timer
- &timer
->core
->eitr
[0];
174 assert(msix_enabled(timer
->core
->owner
));
176 timer
->running
= false;
178 if (!timer
->core
->eitr_intr_pending
[idx
]) {
179 trace_e1000e_irq_throttling_no_pending_vec(idx
);
183 trace_e1000e_irq_msix_notify_postponed_vec(idx
);
184 msix_notify(timer
->core
->owner
, idx
);
188 e1000e_intrmgr_initialize_all_timers(E1000ECore
*core
, bool create
)
192 core
->radv
.delay_reg
= RADV
;
193 core
->rdtr
.delay_reg
= RDTR
;
194 core
->raid
.delay_reg
= RAID
;
195 core
->tadv
.delay_reg
= TADV
;
196 core
->tidv
.delay_reg
= TIDV
;
198 core
->radv
.delay_resolution_ns
= E1000_INTR_DELAY_NS_RES
;
199 core
->rdtr
.delay_resolution_ns
= E1000_INTR_DELAY_NS_RES
;
200 core
->raid
.delay_resolution_ns
= E1000_INTR_DELAY_NS_RES
;
201 core
->tadv
.delay_resolution_ns
= E1000_INTR_DELAY_NS_RES
;
202 core
->tidv
.delay_resolution_ns
= E1000_INTR_DELAY_NS_RES
;
204 core
->radv
.core
= core
;
205 core
->rdtr
.core
= core
;
206 core
->raid
.core
= core
;
207 core
->tadv
.core
= core
;
208 core
->tidv
.core
= core
;
210 core
->itr
.core
= core
;
211 core
->itr
.delay_reg
= ITR
;
212 core
->itr
.delay_resolution_ns
= E1000_INTR_THROTTLING_NS_RES
;
214 for (i
= 0; i
< E1000E_MSIX_VEC_NUM
; i
++) {
215 core
->eitr
[i
].core
= core
;
216 core
->eitr
[i
].delay_reg
= EITR
+ i
;
217 core
->eitr
[i
].delay_resolution_ns
= E1000_INTR_THROTTLING_NS_RES
;
225 timer_new_ns(QEMU_CLOCK_VIRTUAL
, e1000e_intrmgr_on_timer
, &core
->radv
);
227 timer_new_ns(QEMU_CLOCK_VIRTUAL
, e1000e_intrmgr_on_timer
, &core
->rdtr
);
229 timer_new_ns(QEMU_CLOCK_VIRTUAL
, e1000e_intrmgr_on_timer
, &core
->raid
);
232 timer_new_ns(QEMU_CLOCK_VIRTUAL
, e1000e_intrmgr_on_timer
, &core
->tadv
);
234 timer_new_ns(QEMU_CLOCK_VIRTUAL
, e1000e_intrmgr_on_timer
, &core
->tidv
);
236 core
->itr
.timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
,
237 e1000e_intrmgr_on_throttling_timer
,
240 for (i
= 0; i
< E1000E_MSIX_VEC_NUM
; i
++) {
241 core
->eitr
[i
].timer
=
242 timer_new_ns(QEMU_CLOCK_VIRTUAL
,
243 e1000e_intrmgr_on_msix_throttling_timer
,
249 e1000e_intrmgr_stop_delay_timers(E1000ECore
*core
)
251 e1000e_intrmgr_stop_timer(&core
->radv
);
252 e1000e_intrmgr_stop_timer(&core
->rdtr
);
253 e1000e_intrmgr_stop_timer(&core
->raid
);
254 e1000e_intrmgr_stop_timer(&core
->tidv
);
255 e1000e_intrmgr_stop_timer(&core
->tadv
);
259 e1000e_intrmgr_delay_rx_causes(E1000ECore
*core
, uint32_t *causes
)
261 uint32_t delayable_causes
;
262 uint32_t rdtr
= core
->mac
[RDTR
];
263 uint32_t radv
= core
->mac
[RADV
];
264 uint32_t raid
= core
->mac
[RAID
];
266 if (msix_enabled(core
->owner
)) {
270 delayable_causes
= E1000_ICR_RXQ0
|
274 if (!(core
->mac
[RFCTL
] & E1000_RFCTL_ACK_DIS
)) {
275 delayable_causes
|= E1000_ICR_ACK
;
278 /* Clean up all causes that may be delayed */
279 core
->delayed_causes
|= *causes
& delayable_causes
;
280 *causes
&= ~delayable_causes
;
282 /* Check if delayed RX interrupts disabled by client
283 or if there are causes that cannot be delayed */
284 if ((rdtr
== 0) || (*causes
!= 0)) {
288 /* Check if delayed RX ACK interrupts disabled by client
289 and there is an ACK packet received */
290 if ((raid
== 0) && (core
->delayed_causes
& E1000_ICR_ACK
)) {
294 /* All causes delayed */
295 e1000e_intrmgr_rearm_timer(&core
->rdtr
);
297 if (!core
->radv
.running
&& (radv
!= 0)) {
298 e1000e_intrmgr_rearm_timer(&core
->radv
);
301 if (!core
->raid
.running
&& (core
->delayed_causes
& E1000_ICR_ACK
)) {
302 e1000e_intrmgr_rearm_timer(&core
->raid
);
309 e1000e_intrmgr_delay_tx_causes(E1000ECore
*core
, uint32_t *causes
)
311 static const uint32_t delayable_causes
= E1000_ICR_TXQ0
|
316 if (msix_enabled(core
->owner
)) {
320 /* Clean up all causes that may be delayed */
321 core
->delayed_causes
|= *causes
& delayable_causes
;
322 *causes
&= ~delayable_causes
;
324 /* If there are causes that cannot be delayed */
329 /* All causes delayed */
330 e1000e_intrmgr_rearm_timer(&core
->tidv
);
332 if (!core
->tadv
.running
&& (core
->mac
[TADV
] != 0)) {
333 e1000e_intrmgr_rearm_timer(&core
->tadv
);
340 e1000e_intmgr_collect_delayed_causes(E1000ECore
*core
)
344 if (msix_enabled(core
->owner
)) {
345 assert(core
->delayed_causes
== 0);
349 res
= core
->delayed_causes
;
350 core
->delayed_causes
= 0;
352 e1000e_intrmgr_stop_delay_timers(core
);
358 e1000e_intrmgr_fire_all_timers(E1000ECore
*core
)
361 uint32_t val
= e1000e_intmgr_collect_delayed_causes(core
);
363 trace_e1000e_irq_adding_delayed_causes(val
, core
->mac
[ICR
]);
364 core
->mac
[ICR
] |= val
;
366 if (core
->itr
.running
) {
367 timer_del(core
->itr
.timer
);
368 e1000e_intrmgr_on_throttling_timer(&core
->itr
);
371 for (i
= 0; i
< E1000E_MSIX_VEC_NUM
; i
++) {
372 if (core
->eitr
[i
].running
) {
373 timer_del(core
->eitr
[i
].timer
);
374 e1000e_intrmgr_on_msix_throttling_timer(&core
->eitr
[i
]);
380 e1000e_intrmgr_resume(E1000ECore
*core
)
384 e1000e_intmgr_timer_resume(&core
->radv
);
385 e1000e_intmgr_timer_resume(&core
->rdtr
);
386 e1000e_intmgr_timer_resume(&core
->raid
);
387 e1000e_intmgr_timer_resume(&core
->tidv
);
388 e1000e_intmgr_timer_resume(&core
->tadv
);
390 e1000e_intmgr_timer_resume(&core
->itr
);
392 for (i
= 0; i
< E1000E_MSIX_VEC_NUM
; i
++) {
393 e1000e_intmgr_timer_resume(&core
->eitr
[i
]);
398 e1000e_intrmgr_pause(E1000ECore
*core
)
402 e1000e_intmgr_timer_pause(&core
->radv
);
403 e1000e_intmgr_timer_pause(&core
->rdtr
);
404 e1000e_intmgr_timer_pause(&core
->raid
);
405 e1000e_intmgr_timer_pause(&core
->tidv
);
406 e1000e_intmgr_timer_pause(&core
->tadv
);
408 e1000e_intmgr_timer_pause(&core
->itr
);
410 for (i
= 0; i
< E1000E_MSIX_VEC_NUM
; i
++) {
411 e1000e_intmgr_timer_pause(&core
->eitr
[i
]);
416 e1000e_intrmgr_reset(E1000ECore
*core
)
420 core
->delayed_causes
= 0;
422 e1000e_intrmgr_stop_delay_timers(core
);
424 e1000e_intrmgr_stop_timer(&core
->itr
);
426 for (i
= 0; i
< E1000E_MSIX_VEC_NUM
; i
++) {
427 e1000e_intrmgr_stop_timer(&core
->eitr
[i
]);
432 e1000e_intrmgr_pci_unint(E1000ECore
*core
)
436 timer_del(core
->radv
.timer
);
437 timer_free(core
->radv
.timer
);
438 timer_del(core
->rdtr
.timer
);
439 timer_free(core
->rdtr
.timer
);
440 timer_del(core
->raid
.timer
);
441 timer_free(core
->raid
.timer
);
443 timer_del(core
->tadv
.timer
);
444 timer_free(core
->tadv
.timer
);
445 timer_del(core
->tidv
.timer
);
446 timer_free(core
->tidv
.timer
);
448 timer_del(core
->itr
.timer
);
449 timer_free(core
->itr
.timer
);
451 for (i
= 0; i
< E1000E_MSIX_VEC_NUM
; i
++) {
452 timer_del(core
->eitr
[i
].timer
);
453 timer_free(core
->eitr
[i
].timer
);
458 e1000e_intrmgr_pci_realize(E1000ECore
*core
)
460 e1000e_intrmgr_initialize_all_timers(core
, true);
464 e1000e_rx_csum_enabled(E1000ECore
*core
)
466 return (core
->mac
[RXCSUM
] & E1000_RXCSUM_PCSD
) ? false : true;
470 e1000e_rx_use_legacy_descriptor(E1000ECore
*core
)
472 return (core
->mac
[RFCTL
] & E1000_RFCTL_EXTEN
) ? false : true;
476 e1000e_rx_use_ps_descriptor(E1000ECore
*core
)
478 return !e1000e_rx_use_legacy_descriptor(core
) &&
479 (core
->mac
[RCTL
] & E1000_RCTL_DTYP_PS
);
483 e1000e_rss_enabled(E1000ECore
*core
)
485 return E1000_MRQC_ENABLED(core
->mac
[MRQC
]) &&
486 !e1000e_rx_csum_enabled(core
) &&
487 !e1000e_rx_use_legacy_descriptor(core
);
490 typedef struct E1000E_RSSInfo_st
{
498 e1000e_rss_get_hash_type(E1000ECore
*core
, struct NetRxPkt
*pkt
)
500 bool isip4
, isip6
, isudp
, istcp
;
502 assert(e1000e_rss_enabled(core
));
504 net_rx_pkt_get_protocols(pkt
, &isip4
, &isip6
, &isudp
, &istcp
);
507 bool fragment
= net_rx_pkt_get_ip4_info(pkt
)->fragment
;
509 trace_e1000e_rx_rss_ip4(fragment
, istcp
, core
->mac
[MRQC
],
510 E1000_MRQC_EN_TCPIPV4(core
->mac
[MRQC
]),
511 E1000_MRQC_EN_IPV4(core
->mac
[MRQC
]));
513 if (!fragment
&& istcp
&& E1000_MRQC_EN_TCPIPV4(core
->mac
[MRQC
])) {
514 return E1000_MRQ_RSS_TYPE_IPV4TCP
;
517 if (E1000_MRQC_EN_IPV4(core
->mac
[MRQC
])) {
518 return E1000_MRQ_RSS_TYPE_IPV4
;
521 eth_ip6_hdr_info
*ip6info
= net_rx_pkt_get_ip6_info(pkt
);
523 bool ex_dis
= core
->mac
[RFCTL
] & E1000_RFCTL_IPV6_EX_DIS
;
524 bool new_ex_dis
= core
->mac
[RFCTL
] & E1000_RFCTL_NEW_IPV6_EXT_DIS
;
527 * Following two traces must not be combined because resulting
528 * event will have 11 arguments totally and some trace backends
529 * (at least "ust") have limitation of maximum 10 arguments per
530 * event. Events with more arguments fail to compile for
531 * backends like these.
533 trace_e1000e_rx_rss_ip6_rfctl(core
->mac
[RFCTL
]);
534 trace_e1000e_rx_rss_ip6(ex_dis
, new_ex_dis
, istcp
,
535 ip6info
->has_ext_hdrs
,
536 ip6info
->rss_ex_dst_valid
,
537 ip6info
->rss_ex_src_valid
,
539 E1000_MRQC_EN_TCPIPV6(core
->mac
[MRQC
]),
540 E1000_MRQC_EN_IPV6EX(core
->mac
[MRQC
]),
541 E1000_MRQC_EN_IPV6(core
->mac
[MRQC
]));
543 if ((!ex_dis
|| !ip6info
->has_ext_hdrs
) &&
544 (!new_ex_dis
|| !(ip6info
->rss_ex_dst_valid
||
545 ip6info
->rss_ex_src_valid
))) {
547 if (istcp
&& !ip6info
->fragment
&&
548 E1000_MRQC_EN_TCPIPV6(core
->mac
[MRQC
])) {
549 return E1000_MRQ_RSS_TYPE_IPV6TCP
;
552 if (E1000_MRQC_EN_IPV6EX(core
->mac
[MRQC
])) {
553 return E1000_MRQ_RSS_TYPE_IPV6EX
;
558 if (E1000_MRQC_EN_IPV6(core
->mac
[MRQC
])) {
559 return E1000_MRQ_RSS_TYPE_IPV6
;
564 return E1000_MRQ_RSS_TYPE_NONE
;
568 e1000e_rss_calc_hash(E1000ECore
*core
,
569 struct NetRxPkt
*pkt
,
570 E1000E_RSSInfo
*info
)
572 NetRxPktRssType type
;
574 assert(e1000e_rss_enabled(core
));
576 switch (info
->type
) {
577 case E1000_MRQ_RSS_TYPE_IPV4
:
578 type
= NetPktRssIpV4
;
580 case E1000_MRQ_RSS_TYPE_IPV4TCP
:
581 type
= NetPktRssIpV4Tcp
;
583 case E1000_MRQ_RSS_TYPE_IPV6TCP
:
584 type
= NetPktRssIpV6Tcp
;
586 case E1000_MRQ_RSS_TYPE_IPV6
:
587 type
= NetPktRssIpV6
;
589 case E1000_MRQ_RSS_TYPE_IPV6EX
:
590 type
= NetPktRssIpV6Ex
;
597 return net_rx_pkt_calc_rss_hash(pkt
, type
, (uint8_t *) &core
->mac
[RSSRK
]);
601 e1000e_rss_parse_packet(E1000ECore
*core
,
602 struct NetRxPkt
*pkt
,
603 E1000E_RSSInfo
*info
)
605 trace_e1000e_rx_rss_started();
607 if (!e1000e_rss_enabled(core
)) {
608 info
->enabled
= false;
612 trace_e1000e_rx_rss_disabled();
616 info
->enabled
= true;
618 info
->type
= e1000e_rss_get_hash_type(core
, pkt
);
620 trace_e1000e_rx_rss_type(info
->type
);
622 if (info
->type
== E1000_MRQ_RSS_TYPE_NONE
) {
628 info
->hash
= e1000e_rss_calc_hash(core
, pkt
, info
);
629 info
->queue
= E1000_RSS_QUEUE(&core
->mac
[RETA
], info
->hash
);
633 e1000e_setup_tx_offloads(E1000ECore
*core
, struct e1000e_tx
*tx
)
635 if (tx
->props
.tse
&& tx
->props
.cptse
) {
636 net_tx_pkt_build_vheader(tx
->tx_pkt
, true, true, tx
->props
.mss
);
637 net_tx_pkt_update_ip_checksums(tx
->tx_pkt
);
638 e1000x_inc_reg_if_not_full(core
->mac
, TSCTC
);
642 if (tx
->props
.sum_needed
& E1000_TXD_POPTS_TXSM
) {
643 net_tx_pkt_build_vheader(tx
->tx_pkt
, false, true, 0);
646 if (tx
->props
.sum_needed
& E1000_TXD_POPTS_IXSM
) {
647 net_tx_pkt_update_ip_hdr_checksum(tx
->tx_pkt
);
652 e1000e_tx_pkt_send(E1000ECore
*core
, struct e1000e_tx
*tx
, int queue_index
)
654 int target_queue
= MIN(core
->max_queue_num
, queue_index
);
655 NetClientState
*queue
= qemu_get_subqueue(core
->owner_nic
, target_queue
);
657 e1000e_setup_tx_offloads(core
, tx
);
659 net_tx_pkt_dump(tx
->tx_pkt
);
661 if ((core
->phy
[0][PHY_CTRL
] & MII_CR_LOOPBACK
) ||
662 ((core
->mac
[RCTL
] & E1000_RCTL_LBM_MAC
) == E1000_RCTL_LBM_MAC
)) {
663 return net_tx_pkt_send_loopback(tx
->tx_pkt
, queue
);
665 return net_tx_pkt_send(tx
->tx_pkt
, queue
);
670 e1000e_on_tx_done_update_stats(E1000ECore
*core
, struct NetTxPkt
*tx_pkt
)
672 static const int PTCregs
[6] = { PTC64
, PTC127
, PTC255
, PTC511
,
675 size_t tot_len
= net_tx_pkt_get_total_len(tx_pkt
);
677 e1000x_increase_size_stats(core
->mac
, PTCregs
, tot_len
);
678 e1000x_inc_reg_if_not_full(core
->mac
, TPT
);
679 e1000x_grow_8reg_if_not_full(core
->mac
, TOTL
, tot_len
);
681 switch (net_tx_pkt_get_packet_type(tx_pkt
)) {
683 e1000x_inc_reg_if_not_full(core
->mac
, BPTC
);
686 e1000x_inc_reg_if_not_full(core
->mac
, MPTC
);
691 g_assert_not_reached();
694 core
->mac
[GPTC
] = core
->mac
[TPT
];
695 core
->mac
[GOTCL
] = core
->mac
[TOTL
];
696 core
->mac
[GOTCH
] = core
->mac
[TOTH
];
700 e1000e_process_tx_desc(E1000ECore
*core
,
701 struct e1000e_tx
*tx
,
702 struct e1000_tx_desc
*dp
,
705 uint32_t txd_lower
= le32_to_cpu(dp
->lower
.data
);
706 uint32_t dtype
= txd_lower
& (E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
);
707 unsigned int split_size
= txd_lower
& 0xffff;
709 struct e1000_context_desc
*xp
= (struct e1000_context_desc
*)dp
;
710 bool eop
= txd_lower
& E1000_TXD_CMD_EOP
;
712 if (dtype
== E1000_TXD_CMD_DEXT
) { /* context descriptor */
713 e1000x_read_tx_ctx_descr(xp
, &tx
->props
);
714 e1000e_process_snap_option(core
, le32_to_cpu(xp
->cmd_and_length
));
716 } else if (dtype
== (E1000_TXD_CMD_DEXT
| E1000_TXD_DTYP_D
)) {
717 /* data descriptor */
718 tx
->props
.sum_needed
= le32_to_cpu(dp
->upper
.data
) >> 8;
719 tx
->props
.cptse
= (txd_lower
& E1000_TXD_CMD_TSE
) ? 1 : 0;
720 e1000e_process_ts_option(core
, dp
);
722 /* legacy descriptor */
723 e1000e_process_ts_option(core
, dp
);
727 addr
= le64_to_cpu(dp
->buffer_addr
);
730 if (!net_tx_pkt_add_raw_fragment(tx
->tx_pkt
, addr
, split_size
)) {
736 if (!tx
->skip_cp
&& net_tx_pkt_parse(tx
->tx_pkt
)) {
737 if (e1000x_vlan_enabled(core
->mac
) &&
738 e1000x_is_vlan_txd(txd_lower
)) {
739 net_tx_pkt_setup_vlan_header_ex(tx
->tx_pkt
,
740 le16_to_cpu(dp
->upper
.fields
.special
), core
->vet
);
742 if (e1000e_tx_pkt_send(core
, tx
, queue_index
)) {
743 e1000e_on_tx_done_update_stats(core
, tx
->tx_pkt
);
748 net_tx_pkt_reset(tx
->tx_pkt
);
750 tx
->props
.sum_needed
= 0;
755 static inline uint32_t
756 e1000e_tx_wb_interrupt_cause(E1000ECore
*core
, int queue_idx
)
758 if (!msix_enabled(core
->owner
)) {
759 return E1000_ICR_TXDW
;
762 return (queue_idx
== 0) ? E1000_ICR_TXQ0
: E1000_ICR_TXQ1
;
765 static inline uint32_t
766 e1000e_rx_wb_interrupt_cause(E1000ECore
*core
, int queue_idx
,
767 bool min_threshold_hit
)
769 if (!msix_enabled(core
->owner
)) {
770 return E1000_ICS_RXT0
| (min_threshold_hit
? E1000_ICS_RXDMT0
: 0);
773 return (queue_idx
== 0) ? E1000_ICR_RXQ0
: E1000_ICR_RXQ1
;
777 e1000e_txdesc_writeback(E1000ECore
*core
, dma_addr_t base
,
778 struct e1000_tx_desc
*dp
, bool *ide
, int queue_idx
)
780 uint32_t txd_upper
, txd_lower
= le32_to_cpu(dp
->lower
.data
);
782 if (!(txd_lower
& E1000_TXD_CMD_RS
) &&
783 !(core
->mac
[IVAR
] & E1000_IVAR_TX_INT_EVERY_WB
)) {
787 *ide
= (txd_lower
& E1000_TXD_CMD_IDE
) ? true : false;
789 txd_upper
= le32_to_cpu(dp
->upper
.data
) | E1000_TXD_STAT_DD
;
791 dp
->upper
.data
= cpu_to_le32(txd_upper
);
792 pci_dma_write(core
->owner
, base
+ ((char *)&dp
->upper
- (char *)dp
),
793 &dp
->upper
, sizeof(dp
->upper
));
794 return e1000e_tx_wb_interrupt_cause(core
, queue_idx
);
797 typedef struct E1000E_RingInfo_st
{
807 e1000e_ring_empty(E1000ECore
*core
, const E1000E_RingInfo
*r
)
809 return core
->mac
[r
->dh
] == core
->mac
[r
->dt
] ||
810 core
->mac
[r
->dt
] >= core
->mac
[r
->dlen
] / E1000_RING_DESC_LEN
;
813 static inline uint64_t
814 e1000e_ring_base(E1000ECore
*core
, const E1000E_RingInfo
*r
)
816 uint64_t bah
= core
->mac
[r
->dbah
];
817 uint64_t bal
= core
->mac
[r
->dbal
];
819 return (bah
<< 32) + bal
;
822 static inline uint64_t
823 e1000e_ring_head_descr(E1000ECore
*core
, const E1000E_RingInfo
*r
)
825 return e1000e_ring_base(core
, r
) + E1000_RING_DESC_LEN
* core
->mac
[r
->dh
];
829 e1000e_ring_advance(E1000ECore
*core
, const E1000E_RingInfo
*r
, uint32_t count
)
831 core
->mac
[r
->dh
] += count
;
833 if (core
->mac
[r
->dh
] * E1000_RING_DESC_LEN
>= core
->mac
[r
->dlen
]) {
834 core
->mac
[r
->dh
] = 0;
838 static inline uint32_t
839 e1000e_ring_free_descr_num(E1000ECore
*core
, const E1000E_RingInfo
*r
)
841 trace_e1000e_ring_free_space(r
->idx
, core
->mac
[r
->dlen
],
842 core
->mac
[r
->dh
], core
->mac
[r
->dt
]);
844 if (core
->mac
[r
->dh
] <= core
->mac
[r
->dt
]) {
845 return core
->mac
[r
->dt
] - core
->mac
[r
->dh
];
848 if (core
->mac
[r
->dh
] > core
->mac
[r
->dt
]) {
849 return core
->mac
[r
->dlen
] / E1000_RING_DESC_LEN
+
850 core
->mac
[r
->dt
] - core
->mac
[r
->dh
];
853 g_assert_not_reached();
858 e1000e_ring_enabled(E1000ECore
*core
, const E1000E_RingInfo
*r
)
860 return core
->mac
[r
->dlen
] > 0;
863 static inline uint32_t
864 e1000e_ring_len(E1000ECore
*core
, const E1000E_RingInfo
*r
)
866 return core
->mac
[r
->dlen
];
869 typedef struct E1000E_TxRing_st
{
870 const E1000E_RingInfo
*i
;
871 struct e1000e_tx
*tx
;
875 e1000e_mq_queue_idx(int base_reg_idx
, int reg_idx
)
877 return (reg_idx
- base_reg_idx
) / (0x100 >> 2);
881 e1000e_tx_ring_init(E1000ECore
*core
, E1000E_TxRing
*txr
, int idx
)
883 static const E1000E_RingInfo i
[E1000E_NUM_QUEUES
] = {
884 { TDBAH
, TDBAL
, TDLEN
, TDH
, TDT
, 0 },
885 { TDBAH1
, TDBAL1
, TDLEN1
, TDH1
, TDT1
, 1 }
888 assert(idx
< ARRAY_SIZE(i
));
891 txr
->tx
= &core
->tx
[idx
];
894 typedef struct E1000E_RxRing_st
{
895 const E1000E_RingInfo
*i
;
899 e1000e_rx_ring_init(E1000ECore
*core
, E1000E_RxRing
*rxr
, int idx
)
901 static const E1000E_RingInfo i
[E1000E_NUM_QUEUES
] = {
902 { RDBAH0
, RDBAL0
, RDLEN0
, RDH0
, RDT0
, 0 },
903 { RDBAH1
, RDBAL1
, RDLEN1
, RDH1
, RDT1
, 1 }
906 assert(idx
< ARRAY_SIZE(i
));
912 e1000e_start_xmit(E1000ECore
*core
, const E1000E_TxRing
*txr
)
915 struct e1000_tx_desc desc
;
917 const E1000E_RingInfo
*txi
= txr
->i
;
918 uint32_t cause
= E1000_ICS_TXQE
;
920 if (!(core
->mac
[TCTL
] & E1000_TCTL_EN
)) {
921 trace_e1000e_tx_disabled();
925 while (!e1000e_ring_empty(core
, txi
)) {
926 base
= e1000e_ring_head_descr(core
, txi
);
928 pci_dma_read(core
->owner
, base
, &desc
, sizeof(desc
));
930 trace_e1000e_tx_descr((void *)(intptr_t)desc
.buffer_addr
,
931 desc
.lower
.data
, desc
.upper
.data
);
933 e1000e_process_tx_desc(core
, txr
->tx
, &desc
, txi
->idx
);
934 cause
|= e1000e_txdesc_writeback(core
, base
, &desc
, &ide
, txi
->idx
);
936 e1000e_ring_advance(core
, txi
, 1);
939 if (!ide
|| !e1000e_intrmgr_delay_tx_causes(core
, &cause
)) {
940 e1000e_set_interrupt_cause(core
, cause
);
945 e1000e_has_rxbufs(E1000ECore
*core
, const E1000E_RingInfo
*r
,
948 uint32_t bufs
= e1000e_ring_free_descr_num(core
, r
);
950 trace_e1000e_rx_has_buffers(r
->idx
, bufs
, total_size
,
951 core
->rx_desc_buf_size
);
953 return total_size
<= bufs
/ (core
->rx_desc_len
/ E1000_MIN_RX_DESC_LEN
) *
954 core
->rx_desc_buf_size
;
958 e1000e_start_recv(E1000ECore
*core
)
962 trace_e1000e_rx_start_recv();
964 for (i
= 0; i
<= core
->max_queue_num
; i
++) {
965 qemu_flush_queued_packets(qemu_get_subqueue(core
->owner_nic
, i
));
970 e1000e_can_receive(E1000ECore
*core
)
974 if (!e1000x_rx_ready(core
->owner
, core
->mac
)) {
978 for (i
= 0; i
< E1000E_NUM_QUEUES
; i
++) {
981 e1000e_rx_ring_init(core
, &rxr
, i
);
982 if (e1000e_ring_enabled(core
, rxr
.i
) &&
983 e1000e_has_rxbufs(core
, rxr
.i
, 1)) {
984 trace_e1000e_rx_can_recv();
989 trace_e1000e_rx_can_recv_rings_full();
994 e1000e_receive(E1000ECore
*core
, const uint8_t *buf
, size_t size
)
996 const struct iovec iov
= {
997 .iov_base
= (uint8_t *)buf
,
1001 return e1000e_receive_iov(core
, &iov
, 1);
1005 e1000e_rx_l3_cso_enabled(E1000ECore
*core
)
1007 return !!(core
->mac
[RXCSUM
] & E1000_RXCSUM_IPOFLD
);
1011 e1000e_rx_l4_cso_enabled(E1000ECore
*core
)
1013 return !!(core
->mac
[RXCSUM
] & E1000_RXCSUM_TUOFLD
);
1017 e1000e_receive_filter(E1000ECore
*core
, const uint8_t *buf
, int size
)
1019 uint32_t rctl
= core
->mac
[RCTL
];
1021 if (e1000x_is_vlan_packet(buf
, core
->vet
) &&
1022 e1000x_vlan_rx_filter_enabled(core
->mac
)) {
1023 uint16_t vid
= lduw_be_p(buf
+ 14);
1024 uint32_t vfta
= ldl_le_p((uint32_t *)(core
->mac
+ VFTA
) +
1025 ((vid
>> 5) & 0x7f));
1026 if ((vfta
& (1 << (vid
& 0x1f))) == 0) {
1027 trace_e1000e_rx_flt_vlan_mismatch(vid
);
1030 trace_e1000e_rx_flt_vlan_match(vid
);
1034 switch (net_rx_pkt_get_packet_type(core
->rx_pkt
)) {
1036 if (rctl
& E1000_RCTL_UPE
) {
1037 return true; /* promiscuous ucast */
1042 if (rctl
& E1000_RCTL_BAM
) {
1043 return true; /* broadcast enabled */
1048 if (rctl
& E1000_RCTL_MPE
) {
1049 return true; /* promiscuous mcast */
1054 g_assert_not_reached();
1057 return e1000x_rx_group_filter(core
->mac
, buf
);
1061 e1000e_read_lgcy_rx_descr(E1000ECore
*core
, uint8_t *desc
, hwaddr
*buff_addr
)
1063 struct e1000_rx_desc
*d
= (struct e1000_rx_desc
*) desc
;
1064 *buff_addr
= le64_to_cpu(d
->buffer_addr
);
1068 e1000e_read_ext_rx_descr(E1000ECore
*core
, uint8_t *desc
, hwaddr
*buff_addr
)
1070 union e1000_rx_desc_extended
*d
= (union e1000_rx_desc_extended
*) desc
;
1071 *buff_addr
= le64_to_cpu(d
->read
.buffer_addr
);
1075 e1000e_read_ps_rx_descr(E1000ECore
*core
, uint8_t *desc
,
1076 hwaddr (*buff_addr
)[MAX_PS_BUFFERS
])
1079 union e1000_rx_desc_packet_split
*d
=
1080 (union e1000_rx_desc_packet_split
*) desc
;
1082 for (i
= 0; i
< MAX_PS_BUFFERS
; i
++) {
1083 (*buff_addr
)[i
] = le64_to_cpu(d
->read
.buffer_addr
[i
]);
1086 trace_e1000e_rx_desc_ps_read((*buff_addr
)[0], (*buff_addr
)[1],
1087 (*buff_addr
)[2], (*buff_addr
)[3]);
1091 e1000e_read_rx_descr(E1000ECore
*core
, uint8_t *desc
,
1092 hwaddr (*buff_addr
)[MAX_PS_BUFFERS
])
1094 if (e1000e_rx_use_legacy_descriptor(core
)) {
1095 e1000e_read_lgcy_rx_descr(core
, desc
, &(*buff_addr
)[0]);
1096 (*buff_addr
)[1] = (*buff_addr
)[2] = (*buff_addr
)[3] = 0;
1098 if (core
->mac
[RCTL
] & E1000_RCTL_DTYP_PS
) {
1099 e1000e_read_ps_rx_descr(core
, desc
, buff_addr
);
1101 e1000e_read_ext_rx_descr(core
, desc
, &(*buff_addr
)[0]);
1102 (*buff_addr
)[1] = (*buff_addr
)[2] = (*buff_addr
)[3] = 0;
1108 e1000e_verify_csum_in_sw(E1000ECore
*core
,
1109 struct NetRxPkt
*pkt
,
1110 uint32_t *status_flags
,
1111 bool istcp
, bool isudp
)
1114 uint32_t csum_error
;
1116 if (e1000e_rx_l3_cso_enabled(core
)) {
1117 if (!net_rx_pkt_validate_l3_csum(pkt
, &csum_valid
)) {
1118 trace_e1000e_rx_metadata_l3_csum_validation_failed();
1120 csum_error
= csum_valid
? 0 : E1000_RXDEXT_STATERR_IPE
;
1121 *status_flags
|= E1000_RXD_STAT_IPCS
| csum_error
;
1124 trace_e1000e_rx_metadata_l3_cso_disabled();
1127 if (!e1000e_rx_l4_cso_enabled(core
)) {
1128 trace_e1000e_rx_metadata_l4_cso_disabled();
1132 if (!net_rx_pkt_validate_l4_csum(pkt
, &csum_valid
)) {
1133 trace_e1000e_rx_metadata_l4_csum_validation_failed();
1137 csum_error
= csum_valid
? 0 : E1000_RXDEXT_STATERR_TCPE
;
1140 *status_flags
|= E1000_RXD_STAT_TCPCS
|
1143 *status_flags
|= E1000_RXD_STAT_TCPCS
|
1144 E1000_RXD_STAT_UDPCS
|
1150 e1000e_is_tcp_ack(E1000ECore
*core
, struct NetRxPkt
*rx_pkt
)
1152 if (!net_rx_pkt_is_tcp_ack(rx_pkt
)) {
1156 if (core
->mac
[RFCTL
] & E1000_RFCTL_ACK_DATA_DIS
) {
1157 return !net_rx_pkt_has_tcp_data(rx_pkt
);
1164 e1000e_build_rx_metadata(E1000ECore
*core
,
1165 struct NetRxPkt
*pkt
,
1167 const E1000E_RSSInfo
*rss_info
,
1168 uint32_t *rss
, uint32_t *mrq
,
1169 uint32_t *status_flags
,
1173 struct virtio_net_hdr
*vhdr
;
1174 bool isip4
, isip6
, istcp
, isudp
;
1177 *status_flags
= E1000_RXD_STAT_DD
;
1179 /* No additional metadata needed for non-EOP descriptors */
1184 *status_flags
|= E1000_RXD_STAT_EOP
;
1186 net_rx_pkt_get_protocols(pkt
, &isip4
, &isip6
, &isudp
, &istcp
);
1187 trace_e1000e_rx_metadata_protocols(isip4
, isip6
, isudp
, istcp
);
1190 if (net_rx_pkt_is_vlan_stripped(pkt
)) {
1191 *status_flags
|= E1000_RXD_STAT_VP
;
1192 *vlan_tag
= cpu_to_le16(net_rx_pkt_get_vlan_tag(pkt
));
1193 trace_e1000e_rx_metadata_vlan(*vlan_tag
);
1196 /* Packet parsing results */
1197 if ((core
->mac
[RXCSUM
] & E1000_RXCSUM_PCSD
) != 0) {
1198 if (rss_info
->enabled
) {
1199 *rss
= cpu_to_le32(rss_info
->hash
);
1200 *mrq
= cpu_to_le32(rss_info
->type
| (rss_info
->queue
<< 8));
1201 trace_e1000e_rx_metadata_rss(*rss
, *mrq
);
1204 *status_flags
|= E1000_RXD_STAT_IPIDV
;
1205 *ip_id
= cpu_to_le16(net_rx_pkt_get_ip_id(pkt
));
1206 trace_e1000e_rx_metadata_ip_id(*ip_id
);
1209 if (istcp
&& e1000e_is_tcp_ack(core
, pkt
)) {
1210 *status_flags
|= E1000_RXD_STAT_ACK
;
1211 trace_e1000e_rx_metadata_ack();
1214 if (isip6
&& (core
->mac
[RFCTL
] & E1000_RFCTL_IPV6_DIS
)) {
1215 trace_e1000e_rx_metadata_ipv6_filtering_disabled();
1216 pkt_type
= E1000_RXD_PKT_MAC
;
1217 } else if (istcp
|| isudp
) {
1218 pkt_type
= isip4
? E1000_RXD_PKT_IP4_XDP
: E1000_RXD_PKT_IP6_XDP
;
1219 } else if (isip4
|| isip6
) {
1220 pkt_type
= isip4
? E1000_RXD_PKT_IP4
: E1000_RXD_PKT_IP6
;
1222 pkt_type
= E1000_RXD_PKT_MAC
;
1225 *status_flags
|= E1000_RXD_PKT_TYPE(pkt_type
);
1226 trace_e1000e_rx_metadata_pkt_type(pkt_type
);
1228 /* RX CSO information */
1229 if (isip6
&& (core
->mac
[RFCTL
] & E1000_RFCTL_IPV6_XSUM_DIS
)) {
1230 trace_e1000e_rx_metadata_ipv6_sum_disabled();
1234 if (!net_rx_pkt_has_virt_hdr(pkt
)) {
1235 trace_e1000e_rx_metadata_no_virthdr();
1236 e1000e_verify_csum_in_sw(core
, pkt
, status_flags
, istcp
, isudp
);
1240 vhdr
= net_rx_pkt_get_vhdr(pkt
);
1242 if (!(vhdr
->flags
& VIRTIO_NET_HDR_F_DATA_VALID
) &&
1243 !(vhdr
->flags
& VIRTIO_NET_HDR_F_NEEDS_CSUM
)) {
1244 trace_e1000e_rx_metadata_virthdr_no_csum_info();
1245 e1000e_verify_csum_in_sw(core
, pkt
, status_flags
, istcp
, isudp
);
1249 if (e1000e_rx_l3_cso_enabled(core
)) {
1250 *status_flags
|= isip4
? E1000_RXD_STAT_IPCS
: 0;
1252 trace_e1000e_rx_metadata_l3_cso_disabled();
1255 if (e1000e_rx_l4_cso_enabled(core
)) {
1257 *status_flags
|= E1000_RXD_STAT_TCPCS
;
1259 *status_flags
|= E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
;
1262 trace_e1000e_rx_metadata_l4_cso_disabled();
1265 trace_e1000e_rx_metadata_status_flags(*status_flags
);
1268 *status_flags
= cpu_to_le32(*status_flags
);
1272 e1000e_write_lgcy_rx_descr(E1000ECore
*core
, uint8_t *desc
,
1273 struct NetRxPkt
*pkt
,
1274 const E1000E_RSSInfo
*rss_info
,
1277 uint32_t status_flags
, rss
, mrq
;
1280 struct e1000_rx_desc
*d
= (struct e1000_rx_desc
*) desc
;
1282 assert(!rss_info
->enabled
);
1284 d
->length
= cpu_to_le16(length
);
1287 e1000e_build_rx_metadata(core
, pkt
, pkt
!= NULL
,
1290 &status_flags
, &ip_id
,
1292 d
->errors
= (uint8_t) (le32_to_cpu(status_flags
) >> 24);
1293 d
->status
= (uint8_t) le32_to_cpu(status_flags
);
1298 e1000e_write_ext_rx_descr(E1000ECore
*core
, uint8_t *desc
,
1299 struct NetRxPkt
*pkt
,
1300 const E1000E_RSSInfo
*rss_info
,
1303 union e1000_rx_desc_extended
*d
= (union e1000_rx_desc_extended
*) desc
;
1305 memset(&d
->wb
, 0, sizeof(d
->wb
));
1307 d
->wb
.upper
.length
= cpu_to_le16(length
);
1309 e1000e_build_rx_metadata(core
, pkt
, pkt
!= NULL
,
1311 &d
->wb
.lower
.hi_dword
.rss
,
1313 &d
->wb
.upper
.status_error
,
1314 &d
->wb
.lower
.hi_dword
.csum_ip
.ip_id
,
1319 e1000e_write_ps_rx_descr(E1000ECore
*core
, uint8_t *desc
,
1320 struct NetRxPkt
*pkt
,
1321 const E1000E_RSSInfo
*rss_info
,
1323 uint16_t(*written
)[MAX_PS_BUFFERS
])
1326 union e1000_rx_desc_packet_split
*d
=
1327 (union e1000_rx_desc_packet_split
*) desc
;
1329 memset(&d
->wb
, 0, sizeof(d
->wb
));
1331 d
->wb
.middle
.length0
= cpu_to_le16((*written
)[0]);
1333 for (i
= 0; i
< PS_PAGE_BUFFERS
; i
++) {
1334 d
->wb
.upper
.length
[i
] = cpu_to_le16((*written
)[i
+ 1]);
1337 e1000e_build_rx_metadata(core
, pkt
, pkt
!= NULL
,
1339 &d
->wb
.lower
.hi_dword
.rss
,
1341 &d
->wb
.middle
.status_error
,
1342 &d
->wb
.lower
.hi_dword
.csum_ip
.ip_id
,
1343 &d
->wb
.middle
.vlan
);
1345 d
->wb
.upper
.header_status
=
1346 cpu_to_le16(ps_hdr_len
| (ps_hdr_len
? E1000_RXDPS_HDRSTAT_HDRSP
: 0));
1348 trace_e1000e_rx_desc_ps_write((*written
)[0], (*written
)[1],
1349 (*written
)[2], (*written
)[3]);
1353 e1000e_write_rx_descr(E1000ECore
*core
, uint8_t *desc
,
1354 struct NetRxPkt
*pkt
, const E1000E_RSSInfo
*rss_info
,
1355 size_t ps_hdr_len
, uint16_t(*written
)[MAX_PS_BUFFERS
])
1357 if (e1000e_rx_use_legacy_descriptor(core
)) {
1358 assert(ps_hdr_len
== 0);
1359 e1000e_write_lgcy_rx_descr(core
, desc
, pkt
, rss_info
, (*written
)[0]);
1361 if (core
->mac
[RCTL
] & E1000_RCTL_DTYP_PS
) {
1362 e1000e_write_ps_rx_descr(core
, desc
, pkt
, rss_info
,
1363 ps_hdr_len
, written
);
1365 assert(ps_hdr_len
== 0);
1366 e1000e_write_ext_rx_descr(core
, desc
, pkt
, rss_info
,
1372 typedef struct e1000e_ba_state_st
{
1373 uint16_t written
[MAX_PS_BUFFERS
];
1378 e1000e_write_hdr_to_rx_buffers(E1000ECore
*core
,
1379 hwaddr (*ba
)[MAX_PS_BUFFERS
],
1380 e1000e_ba_state
*bastate
,
1382 dma_addr_t data_len
)
1384 assert(data_len
<= core
->rxbuf_sizes
[0] - bastate
->written
[0]);
1386 pci_dma_write(core
->owner
, (*ba
)[0] + bastate
->written
[0], data
, data_len
);
1387 bastate
->written
[0] += data_len
;
1389 bastate
->cur_idx
= 1;
1393 e1000e_write_to_rx_buffers(E1000ECore
*core
,
1394 hwaddr (*ba
)[MAX_PS_BUFFERS
],
1395 e1000e_ba_state
*bastate
,
1397 dma_addr_t data_len
)
1399 while (data_len
> 0) {
1400 uint32_t cur_buf_len
= core
->rxbuf_sizes
[bastate
->cur_idx
];
1401 uint32_t cur_buf_bytes_left
= cur_buf_len
-
1402 bastate
->written
[bastate
->cur_idx
];
1403 uint32_t bytes_to_write
= MIN(data_len
, cur_buf_bytes_left
);
1405 trace_e1000e_rx_desc_buff_write(bastate
->cur_idx
,
1406 (*ba
)[bastate
->cur_idx
],
1407 bastate
->written
[bastate
->cur_idx
],
1411 pci_dma_write(core
->owner
,
1412 (*ba
)[bastate
->cur_idx
] + bastate
->written
[bastate
->cur_idx
],
1413 data
, bytes_to_write
);
1415 bastate
->written
[bastate
->cur_idx
] += bytes_to_write
;
1416 data
+= bytes_to_write
;
1417 data_len
-= bytes_to_write
;
1419 if (bastate
->written
[bastate
->cur_idx
] == cur_buf_len
) {
1423 assert(bastate
->cur_idx
< MAX_PS_BUFFERS
);
1428 e1000e_update_rx_stats(E1000ECore
*core
,
1430 size_t data_fcs_size
)
1432 e1000x_update_rx_total_stats(core
->mac
, data_size
, data_fcs_size
);
1434 switch (net_rx_pkt_get_packet_type(core
->rx_pkt
)) {
1436 e1000x_inc_reg_if_not_full(core
->mac
, BPRC
);
1440 e1000x_inc_reg_if_not_full(core
->mac
, MPRC
);
1449 e1000e_rx_descr_threshold_hit(E1000ECore
*core
, const E1000E_RingInfo
*rxi
)
1451 return e1000e_ring_free_descr_num(core
, rxi
) ==
1452 e1000e_ring_len(core
, rxi
) >> core
->rxbuf_min_shift
;
1456 e1000e_do_ps(E1000ECore
*core
, struct NetRxPkt
*pkt
, size_t *hdr_len
)
1458 bool isip4
, isip6
, isudp
, istcp
;
1461 if (!e1000e_rx_use_ps_descriptor(core
)) {
1465 net_rx_pkt_get_protocols(pkt
, &isip4
, &isip6
, &isudp
, &istcp
);
1468 fragment
= net_rx_pkt_get_ip4_info(pkt
)->fragment
;
1470 fragment
= net_rx_pkt_get_ip6_info(pkt
)->fragment
;
1475 if (fragment
&& (core
->mac
[RFCTL
] & E1000_RFCTL_IPFRSP_DIS
)) {
1479 if (!fragment
&& (isudp
|| istcp
)) {
1480 *hdr_len
= net_rx_pkt_get_l5_hdr_offset(pkt
);
1482 *hdr_len
= net_rx_pkt_get_l4_hdr_offset(pkt
);
1485 if ((*hdr_len
> core
->rxbuf_sizes
[0]) ||
1486 (*hdr_len
> net_rx_pkt_get_total_len(pkt
))) {
1494 e1000e_write_packet_to_guest(E1000ECore
*core
, struct NetRxPkt
*pkt
,
1495 const E1000E_RxRing
*rxr
,
1496 const E1000E_RSSInfo
*rss_info
)
1498 PCIDevice
*d
= core
->owner
;
1500 uint8_t desc
[E1000_MAX_RX_DESC_LEN
];
1502 size_t desc_offset
= 0;
1505 struct iovec
*iov
= net_rx_pkt_get_iovec(pkt
);
1506 size_t size
= net_rx_pkt_get_total_len(pkt
);
1507 size_t total_size
= size
+ e1000x_fcs_len(core
->mac
);
1508 const E1000E_RingInfo
*rxi
;
1509 size_t ps_hdr_len
= 0;
1510 bool do_ps
= e1000e_do_ps(core
, pkt
, &ps_hdr_len
);
1511 bool is_first
= true;
1516 hwaddr ba
[MAX_PS_BUFFERS
];
1517 e1000e_ba_state bastate
= { { 0 } };
1518 bool is_last
= false;
1520 desc_size
= total_size
- desc_offset
;
1522 if (desc_size
> core
->rx_desc_buf_size
) {
1523 desc_size
= core
->rx_desc_buf_size
;
1526 if (e1000e_ring_empty(core
, rxi
)) {
1530 base
= e1000e_ring_head_descr(core
, rxi
);
1532 pci_dma_read(d
, base
, &desc
, core
->rx_desc_len
);
1534 trace_e1000e_rx_descr(rxi
->idx
, base
, core
->rx_desc_len
);
1536 e1000e_read_rx_descr(core
, desc
, &ba
);
1539 if (desc_offset
< size
) {
1540 static const uint32_t fcs_pad
;
1542 size_t copy_size
= size
- desc_offset
;
1543 if (copy_size
> core
->rx_desc_buf_size
) {
1544 copy_size
= core
->rx_desc_buf_size
;
1547 /* For PS mode copy the packet header first */
1550 size_t ps_hdr_copied
= 0;
1552 iov_copy
= MIN(ps_hdr_len
- ps_hdr_copied
,
1553 iov
->iov_len
- iov_ofs
);
1555 e1000e_write_hdr_to_rx_buffers(core
, &ba
, &bastate
,
1556 iov
->iov_base
, iov_copy
);
1558 copy_size
-= iov_copy
;
1559 ps_hdr_copied
+= iov_copy
;
1561 iov_ofs
+= iov_copy
;
1562 if (iov_ofs
== iov
->iov_len
) {
1566 } while (ps_hdr_copied
< ps_hdr_len
);
1570 /* Leave buffer 0 of each descriptor except first */
1571 /* empty as per spec 7.1.5.1 */
1572 e1000e_write_hdr_to_rx_buffers(core
, &ba
, &bastate
,
1577 /* Copy packet payload */
1579 iov_copy
= MIN(copy_size
, iov
->iov_len
- iov_ofs
);
1581 e1000e_write_to_rx_buffers(core
, &ba
, &bastate
,
1582 iov
->iov_base
+ iov_ofs
, iov_copy
);
1584 copy_size
-= iov_copy
;
1585 iov_ofs
+= iov_copy
;
1586 if (iov_ofs
== iov
->iov_len
) {
1592 if (desc_offset
+ desc_size
>= total_size
) {
1593 /* Simulate FCS checksum presence in the last descriptor */
1594 e1000e_write_to_rx_buffers(core
, &ba
, &bastate
,
1595 (const char *) &fcs_pad
, e1000x_fcs_len(core
->mac
));
1598 desc_offset
+= desc_size
;
1599 if (desc_offset
>= total_size
) {
1602 } else { /* as per intel docs; skip descriptors with null buf addr */
1603 trace_e1000e_rx_null_descriptor();
1606 e1000e_write_rx_descr(core
, desc
, is_last
? core
->rx_pkt
: NULL
,
1607 rss_info
, do_ps
? ps_hdr_len
: 0, &bastate
.written
);
1608 pci_dma_write(d
, base
, &desc
, core
->rx_desc_len
);
1610 e1000e_ring_advance(core
, rxi
,
1611 core
->rx_desc_len
/ E1000_MIN_RX_DESC_LEN
);
1613 } while (desc_offset
< total_size
);
1615 e1000e_update_rx_stats(core
, size
, total_size
);
1619 e1000e_rx_fix_l4_csum(E1000ECore
*core
, struct NetRxPkt
*pkt
)
1621 if (net_rx_pkt_has_virt_hdr(pkt
)) {
1622 struct virtio_net_hdr
*vhdr
= net_rx_pkt_get_vhdr(pkt
);
1624 if (vhdr
->flags
& VIRTIO_NET_HDR_F_NEEDS_CSUM
) {
1625 net_rx_pkt_fix_l4_csum(pkt
);
1631 e1000e_receive_iov(E1000ECore
*core
, const struct iovec
*iov
, int iovcnt
)
1633 static const int maximum_ethernet_hdr_len
= (14 + 4);
1634 /* Min. octets in an ethernet frame sans FCS */
1635 static const int min_buf_size
= 60;
1638 uint8_t min_buf
[min_buf_size
];
1639 struct iovec min_iov
;
1640 uint8_t *filter_buf
;
1641 size_t size
, orig_size
;
1644 E1000E_RSSInfo rss_info
;
1649 trace_e1000e_rx_receive_iov(iovcnt
);
1651 if (!e1000x_hw_rx_enabled(core
->mac
)) {
1655 /* Pull virtio header in */
1656 if (core
->has_vnet
) {
1657 net_rx_pkt_set_vhdr_iovec(core
->rx_pkt
, iov
, iovcnt
);
1658 iov_ofs
= sizeof(struct virtio_net_hdr
);
1661 filter_buf
= iov
->iov_base
+ iov_ofs
;
1662 orig_size
= iov_size(iov
, iovcnt
);
1663 size
= orig_size
- iov_ofs
;
1665 /* Pad to minimum Ethernet frame length */
1666 if (size
< sizeof(min_buf
)) {
1667 iov_to_buf(iov
, iovcnt
, iov_ofs
, min_buf
, size
);
1668 memset(&min_buf
[size
], 0, sizeof(min_buf
) - size
);
1669 e1000x_inc_reg_if_not_full(core
->mac
, RUC
);
1670 min_iov
.iov_base
= filter_buf
= min_buf
;
1671 min_iov
.iov_len
= size
= sizeof(min_buf
);
1675 } else if (iov
->iov_len
< maximum_ethernet_hdr_len
) {
1676 /* This is very unlikely, but may happen. */
1677 iov_to_buf(iov
, iovcnt
, iov_ofs
, min_buf
, maximum_ethernet_hdr_len
);
1678 filter_buf
= min_buf
;
1681 /* Discard oversized packets if !LPE and !SBP. */
1682 if (e1000x_is_oversized(core
->mac
, size
)) {
1686 net_rx_pkt_set_packet_type(core
->rx_pkt
,
1687 get_eth_packet_type(PKT_GET_ETH_HDR(filter_buf
)));
1689 if (!e1000e_receive_filter(core
, filter_buf
, size
)) {
1690 trace_e1000e_rx_flt_dropped();
1694 net_rx_pkt_attach_iovec_ex(core
->rx_pkt
, iov
, iovcnt
, iov_ofs
,
1695 e1000x_vlan_enabled(core
->mac
), core
->vet
);
1697 e1000e_rss_parse_packet(core
, core
->rx_pkt
, &rss_info
);
1698 e1000e_rx_ring_init(core
, &rxr
, rss_info
.queue
);
1700 trace_e1000e_rx_rss_dispatched_to_queue(rxr
.i
->idx
);
1702 total_size
= net_rx_pkt_get_total_len(core
->rx_pkt
) +
1703 e1000x_fcs_len(core
->mac
);
1705 if (e1000e_has_rxbufs(core
, rxr
.i
, total_size
)) {
1706 e1000e_rx_fix_l4_csum(core
, core
->rx_pkt
);
1708 e1000e_write_packet_to_guest(core
, core
->rx_pkt
, &rxr
, &rss_info
);
1712 /* Perform small receive detection (RSRPD) */
1713 if (total_size
< core
->mac
[RSRPD
]) {
1714 n
|= E1000_ICS_SRPD
;
1717 /* Perform ACK receive detection */
1718 if (!(core
->mac
[RFCTL
] & E1000_RFCTL_ACK_DIS
) &&
1719 (e1000e_is_tcp_ack(core
, core
->rx_pkt
))) {
1723 /* Check if receive descriptor minimum threshold hit */
1724 rdmts_hit
= e1000e_rx_descr_threshold_hit(core
, rxr
.i
);
1725 n
|= e1000e_rx_wb_interrupt_cause(core
, rxr
.i
->idx
, rdmts_hit
);
1727 trace_e1000e_rx_written_to_guest(n
);
1732 trace_e1000e_rx_not_written_to_guest(n
);
1735 if (!e1000e_intrmgr_delay_rx_causes(core
, &n
)) {
1736 trace_e1000e_rx_interrupt_set(n
);
1737 e1000e_set_interrupt_cause(core
, n
);
1739 trace_e1000e_rx_interrupt_delayed(n
);
1746 e1000e_have_autoneg(E1000ECore
*core
)
1748 return core
->phy
[0][PHY_CTRL
] & MII_CR_AUTO_NEG_EN
;
1751 static void e1000e_update_flowctl_status(E1000ECore
*core
)
1753 if (e1000e_have_autoneg(core
) &&
1754 core
->phy
[0][PHY_STATUS
] & MII_SR_AUTONEG_COMPLETE
) {
1755 trace_e1000e_link_autoneg_flowctl(true);
1756 core
->mac
[CTRL
] |= E1000_CTRL_TFCE
| E1000_CTRL_RFCE
;
1758 trace_e1000e_link_autoneg_flowctl(false);
1763 e1000e_link_down(E1000ECore
*core
)
1765 e1000x_update_regs_on_link_down(core
->mac
, core
->phy
[0]);
1766 e1000e_update_flowctl_status(core
);
1770 e1000e_set_phy_ctrl(E1000ECore
*core
, int index
, uint16_t val
)
1772 /* bits 0-5 reserved; MII_CR_[RESTART_AUTO_NEG,RESET] are self clearing */
1773 core
->phy
[0][PHY_CTRL
] = val
& ~(0x3f |
1775 MII_CR_RESTART_AUTO_NEG
);
1777 if ((val
& MII_CR_RESTART_AUTO_NEG
) &&
1778 e1000e_have_autoneg(core
)) {
1779 e1000x_restart_autoneg(core
->mac
, core
->phy
[0], core
->autoneg_timer
);
1784 e1000e_set_phy_oem_bits(E1000ECore
*core
, int index
, uint16_t val
)
1786 core
->phy
[0][PHY_OEM_BITS
] = val
& ~BIT(10);
1788 if (val
& BIT(10)) {
1789 e1000x_restart_autoneg(core
->mac
, core
->phy
[0], core
->autoneg_timer
);
1794 e1000e_set_phy_page(E1000ECore
*core
, int index
, uint16_t val
)
1796 core
->phy
[0][PHY_PAGE
] = val
& PHY_PAGE_RW_MASK
;
1800 e1000e_core_set_link_status(E1000ECore
*core
)
1802 NetClientState
*nc
= qemu_get_queue(core
->owner_nic
);
1803 uint32_t old_status
= core
->mac
[STATUS
];
1805 trace_e1000e_link_status_changed(nc
->link_down
? false : true);
1807 if (nc
->link_down
) {
1808 e1000x_update_regs_on_link_down(core
->mac
, core
->phy
[0]);
1810 if (e1000e_have_autoneg(core
) &&
1811 !(core
->phy
[0][PHY_STATUS
] & MII_SR_AUTONEG_COMPLETE
)) {
1812 e1000x_restart_autoneg(core
->mac
, core
->phy
[0],
1813 core
->autoneg_timer
);
1815 e1000x_update_regs_on_link_up(core
->mac
, core
->phy
[0]);
1816 e1000e_start_recv(core
);
1820 if (core
->mac
[STATUS
] != old_status
) {
1821 e1000e_set_interrupt_cause(core
, E1000_ICR_LSC
);
1826 e1000e_set_ctrl(E1000ECore
*core
, int index
, uint32_t val
)
1828 trace_e1000e_core_ctrl_write(index
, val
);
1830 /* RST is self clearing */
1831 core
->mac
[CTRL
] = val
& ~E1000_CTRL_RST
;
1832 core
->mac
[CTRL_DUP
] = core
->mac
[CTRL
];
1834 trace_e1000e_link_set_params(
1835 !!(val
& E1000_CTRL_ASDE
),
1836 (val
& E1000_CTRL_SPD_SEL
) >> E1000_CTRL_SPD_SHIFT
,
1837 !!(val
& E1000_CTRL_FRCSPD
),
1838 !!(val
& E1000_CTRL_FRCDPX
),
1839 !!(val
& E1000_CTRL_RFCE
),
1840 !!(val
& E1000_CTRL_TFCE
));
1842 if (val
& E1000_CTRL_RST
) {
1843 trace_e1000e_core_ctrl_sw_reset();
1844 e1000x_reset_mac_addr(core
->owner_nic
, core
->mac
, core
->permanent_mac
);
1847 if (val
& E1000_CTRL_PHY_RST
) {
1848 trace_e1000e_core_ctrl_phy_reset();
1849 core
->mac
[STATUS
] |= E1000_STATUS_PHYRA
;
1854 e1000e_set_rfctl(E1000ECore
*core
, int index
, uint32_t val
)
1856 trace_e1000e_rx_set_rfctl(val
);
1858 if (!(val
& E1000_RFCTL_ISCSI_DIS
)) {
1859 trace_e1000e_wrn_iscsi_filtering_not_supported();
1862 if (!(val
& E1000_RFCTL_NFSW_DIS
)) {
1863 trace_e1000e_wrn_nfsw_filtering_not_supported();
1866 if (!(val
& E1000_RFCTL_NFSR_DIS
)) {
1867 trace_e1000e_wrn_nfsr_filtering_not_supported();
1870 core
->mac
[RFCTL
] = val
;
1874 e1000e_calc_per_desc_buf_size(E1000ECore
*core
)
1877 core
->rx_desc_buf_size
= 0;
1879 for (i
= 0; i
< ARRAY_SIZE(core
->rxbuf_sizes
); i
++) {
1880 core
->rx_desc_buf_size
+= core
->rxbuf_sizes
[i
];
1885 e1000e_parse_rxbufsize(E1000ECore
*core
)
1887 uint32_t rctl
= core
->mac
[RCTL
];
1889 memset(core
->rxbuf_sizes
, 0, sizeof(core
->rxbuf_sizes
));
1891 if (rctl
& E1000_RCTL_DTYP_MASK
) {
1894 bsize
= core
->mac
[PSRCTL
] & E1000_PSRCTL_BSIZE0_MASK
;
1895 core
->rxbuf_sizes
[0] = (bsize
>> E1000_PSRCTL_BSIZE0_SHIFT
) * 128;
1897 bsize
= core
->mac
[PSRCTL
] & E1000_PSRCTL_BSIZE1_MASK
;
1898 core
->rxbuf_sizes
[1] = (bsize
>> E1000_PSRCTL_BSIZE1_SHIFT
) * 1024;
1900 bsize
= core
->mac
[PSRCTL
] & E1000_PSRCTL_BSIZE2_MASK
;
1901 core
->rxbuf_sizes
[2] = (bsize
>> E1000_PSRCTL_BSIZE2_SHIFT
) * 1024;
1903 bsize
= core
->mac
[PSRCTL
] & E1000_PSRCTL_BSIZE3_MASK
;
1904 core
->rxbuf_sizes
[3] = (bsize
>> E1000_PSRCTL_BSIZE3_SHIFT
) * 1024;
1905 } else if (rctl
& E1000_RCTL_FLXBUF_MASK
) {
1906 int flxbuf
= rctl
& E1000_RCTL_FLXBUF_MASK
;
1907 core
->rxbuf_sizes
[0] = (flxbuf
>> E1000_RCTL_FLXBUF_SHIFT
) * 1024;
1909 core
->rxbuf_sizes
[0] = e1000x_rxbufsize(rctl
);
1912 trace_e1000e_rx_desc_buff_sizes(core
->rxbuf_sizes
[0], core
->rxbuf_sizes
[1],
1913 core
->rxbuf_sizes
[2], core
->rxbuf_sizes
[3]);
1915 e1000e_calc_per_desc_buf_size(core
);
1919 e1000e_calc_rxdesclen(E1000ECore
*core
)
1921 if (e1000e_rx_use_legacy_descriptor(core
)) {
1922 core
->rx_desc_len
= sizeof(struct e1000_rx_desc
);
1924 if (core
->mac
[RCTL
] & E1000_RCTL_DTYP_PS
) {
1925 core
->rx_desc_len
= sizeof(union e1000_rx_desc_packet_split
);
1927 core
->rx_desc_len
= sizeof(union e1000_rx_desc_extended
);
1930 trace_e1000e_rx_desc_len(core
->rx_desc_len
);
1934 e1000e_set_rx_control(E1000ECore
*core
, int index
, uint32_t val
)
1936 core
->mac
[RCTL
] = val
;
1937 trace_e1000e_rx_set_rctl(core
->mac
[RCTL
]);
1939 if (val
& E1000_RCTL_EN
) {
1940 e1000e_parse_rxbufsize(core
);
1941 e1000e_calc_rxdesclen(core
);
1942 core
->rxbuf_min_shift
= ((val
/ E1000_RCTL_RDMTS_QUAT
) & 3) + 1 +
1943 E1000_RING_DESC_LEN_SHIFT
;
1945 e1000e_start_recv(core
);
1950 void(*e1000e_phyreg_writeops
[E1000E_PHY_PAGES
][E1000E_PHY_PAGE_SIZE
])
1951 (E1000ECore
*, int, uint16_t) = {
1953 [PHY_CTRL
] = e1000e_set_phy_ctrl
,
1954 [PHY_PAGE
] = e1000e_set_phy_page
,
1955 [PHY_OEM_BITS
] = e1000e_set_phy_oem_bits
1960 e1000e_clear_ims_bits(E1000ECore
*core
, uint32_t bits
)
1962 trace_e1000e_irq_clear_ims(bits
, core
->mac
[IMS
], core
->mac
[IMS
] & ~bits
);
1963 core
->mac
[IMS
] &= ~bits
;
1967 e1000e_postpone_interrupt(bool *interrupt_pending
,
1968 E1000IntrDelayTimer
*timer
)
1970 if (timer
->running
) {
1971 trace_e1000e_irq_postponed_by_xitr(timer
->delay_reg
<< 2);
1973 *interrupt_pending
= true;
1977 if (timer
->core
->mac
[timer
->delay_reg
] != 0) {
1978 e1000e_intrmgr_rearm_timer(timer
);
1985 e1000e_itr_should_postpone(E1000ECore
*core
)
1987 return e1000e_postpone_interrupt(&core
->itr_intr_pending
, &core
->itr
);
1991 e1000e_eitr_should_postpone(E1000ECore
*core
, int idx
)
1993 return e1000e_postpone_interrupt(&core
->eitr_intr_pending
[idx
],
1998 e1000e_msix_notify_one(E1000ECore
*core
, uint32_t cause
, uint32_t int_cfg
)
2000 uint32_t effective_eiac
;
2002 if (E1000_IVAR_ENTRY_VALID(int_cfg
)) {
2003 uint32_t vec
= E1000_IVAR_ENTRY_VEC(int_cfg
);
2004 if (vec
< E1000E_MSIX_VEC_NUM
) {
2005 if (!e1000e_eitr_should_postpone(core
, vec
)) {
2006 trace_e1000e_irq_msix_notify_vec(vec
);
2007 msix_notify(core
->owner
, vec
);
2010 trace_e1000e_wrn_msix_vec_wrong(cause
, int_cfg
);
2013 trace_e1000e_wrn_msix_invalid(cause
, int_cfg
);
2016 if (core
->mac
[CTRL_EXT
] & E1000_CTRL_EXT_EIAME
) {
2017 trace_e1000e_irq_iam_clear_eiame(core
->mac
[IAM
], cause
);
2018 core
->mac
[IAM
] &= ~cause
;
2021 trace_e1000e_irq_icr_clear_eiac(core
->mac
[ICR
], core
->mac
[EIAC
]);
2023 effective_eiac
= core
->mac
[EIAC
] & cause
;
2025 if (effective_eiac
== E1000_ICR_OTHER
) {
2026 effective_eiac
|= E1000_ICR_OTHER_CAUSES
;
2029 core
->mac
[ICR
] &= ~effective_eiac
;
2031 if (!(core
->mac
[CTRL_EXT
] & E1000_CTRL_EXT_IAME
)) {
2032 core
->mac
[IMS
] &= ~effective_eiac
;
2037 e1000e_msix_notify(E1000ECore
*core
, uint32_t causes
)
2039 if (causes
& E1000_ICR_RXQ0
) {
2040 e1000e_msix_notify_one(core
, E1000_ICR_RXQ0
,
2041 E1000_IVAR_RXQ0(core
->mac
[IVAR
]));
2044 if (causes
& E1000_ICR_RXQ1
) {
2045 e1000e_msix_notify_one(core
, E1000_ICR_RXQ1
,
2046 E1000_IVAR_RXQ1(core
->mac
[IVAR
]));
2049 if (causes
& E1000_ICR_TXQ0
) {
2050 e1000e_msix_notify_one(core
, E1000_ICR_TXQ0
,
2051 E1000_IVAR_TXQ0(core
->mac
[IVAR
]));
2054 if (causes
& E1000_ICR_TXQ1
) {
2055 e1000e_msix_notify_one(core
, E1000_ICR_TXQ1
,
2056 E1000_IVAR_TXQ1(core
->mac
[IVAR
]));
2059 if (causes
& E1000_ICR_OTHER
) {
2060 e1000e_msix_notify_one(core
, E1000_ICR_OTHER
,
2061 E1000_IVAR_OTHER(core
->mac
[IVAR
]));
2066 e1000e_msix_clear_one(E1000ECore
*core
, uint32_t cause
, uint32_t int_cfg
)
2068 if (E1000_IVAR_ENTRY_VALID(int_cfg
)) {
2069 uint32_t vec
= E1000_IVAR_ENTRY_VEC(int_cfg
);
2070 if (vec
< E1000E_MSIX_VEC_NUM
) {
2071 trace_e1000e_irq_msix_pending_clearing(cause
, int_cfg
, vec
);
2072 msix_clr_pending(core
->owner
, vec
);
2074 trace_e1000e_wrn_msix_vec_wrong(cause
, int_cfg
);
2077 trace_e1000e_wrn_msix_invalid(cause
, int_cfg
);
2082 e1000e_msix_clear(E1000ECore
*core
, uint32_t causes
)
2084 if (causes
& E1000_ICR_RXQ0
) {
2085 e1000e_msix_clear_one(core
, E1000_ICR_RXQ0
,
2086 E1000_IVAR_RXQ0(core
->mac
[IVAR
]));
2089 if (causes
& E1000_ICR_RXQ1
) {
2090 e1000e_msix_clear_one(core
, E1000_ICR_RXQ1
,
2091 E1000_IVAR_RXQ1(core
->mac
[IVAR
]));
2094 if (causes
& E1000_ICR_TXQ0
) {
2095 e1000e_msix_clear_one(core
, E1000_ICR_TXQ0
,
2096 E1000_IVAR_TXQ0(core
->mac
[IVAR
]));
2099 if (causes
& E1000_ICR_TXQ1
) {
2100 e1000e_msix_clear_one(core
, E1000_ICR_TXQ1
,
2101 E1000_IVAR_TXQ1(core
->mac
[IVAR
]));
2104 if (causes
& E1000_ICR_OTHER
) {
2105 e1000e_msix_clear_one(core
, E1000_ICR_OTHER
,
2106 E1000_IVAR_OTHER(core
->mac
[IVAR
]));
2111 e1000e_fix_icr_asserted(E1000ECore
*core
)
2113 core
->mac
[ICR
] &= ~E1000_ICR_ASSERTED
;
2114 if (core
->mac
[ICR
]) {
2115 core
->mac
[ICR
] |= E1000_ICR_ASSERTED
;
2118 trace_e1000e_irq_fix_icr_asserted(core
->mac
[ICR
]);
2122 e1000e_send_msi(E1000ECore
*core
, bool msix
)
2124 uint32_t causes
= core
->mac
[ICR
] & core
->mac
[IMS
] & ~E1000_ICR_ASSERTED
;
2127 e1000e_msix_notify(core
, causes
);
2129 if (!e1000e_itr_should_postpone(core
)) {
2130 trace_e1000e_irq_msi_notify(causes
);
2131 msi_notify(core
->owner
, 0);
2137 e1000e_update_interrupt_state(E1000ECore
*core
)
2139 bool interrupts_pending
;
2140 bool is_msix
= msix_enabled(core
->owner
);
2142 /* Set ICR[OTHER] for MSI-X */
2144 if (core
->mac
[ICR
] & E1000_ICR_OTHER_CAUSES
) {
2145 core
->mac
[ICR
] |= E1000_ICR_OTHER
;
2146 trace_e1000e_irq_add_msi_other(core
->mac
[ICR
]);
2150 e1000e_fix_icr_asserted(core
);
2153 * Make sure ICR and ICS registers have the same value.
2154 * The spec says that the ICS register is write-only. However in practice,
2155 * on real hardware ICS is readable, and for reads it has the same value as
2156 * ICR (except that ICS does not have the clear on read behaviour of ICR).
2158 * The VxWorks PRO/1000 driver uses this behaviour.
2160 core
->mac
[ICS
] = core
->mac
[ICR
];
2162 interrupts_pending
= (core
->mac
[IMS
] & core
->mac
[ICR
]) ? true : false;
2164 trace_e1000e_irq_pending_interrupts(core
->mac
[ICR
] & core
->mac
[IMS
],
2165 core
->mac
[ICR
], core
->mac
[IMS
]);
2167 if (is_msix
|| msi_enabled(core
->owner
)) {
2168 if (interrupts_pending
) {
2169 e1000e_send_msi(core
, is_msix
);
2172 if (interrupts_pending
) {
2173 if (!e1000e_itr_should_postpone(core
)) {
2174 e1000e_raise_legacy_irq(core
);
2177 e1000e_lower_legacy_irq(core
);
2183 e1000e_set_interrupt_cause(E1000ECore
*core
, uint32_t val
)
2185 trace_e1000e_irq_set_cause_entry(val
, core
->mac
[ICR
]);
2187 val
|= e1000e_intmgr_collect_delayed_causes(core
);
2188 core
->mac
[ICR
] |= val
;
2190 trace_e1000e_irq_set_cause_exit(val
, core
->mac
[ICR
]);
2192 e1000e_update_interrupt_state(core
);
2196 e1000e_autoneg_timer(void *opaque
)
2198 E1000ECore
*core
= opaque
;
2199 if (!qemu_get_queue(core
->owner_nic
)->link_down
) {
2200 e1000x_update_regs_on_autoneg_done(core
->mac
, core
->phy
[0]);
2201 e1000e_start_recv(core
);
2203 e1000e_update_flowctl_status(core
);
2204 /* signal link status change to the guest */
2205 e1000e_set_interrupt_cause(core
, E1000_ICR_LSC
);
2209 static inline uint16_t
2210 e1000e_get_reg_index_with_offset(const uint16_t *mac_reg_access
, hwaddr addr
)
2212 uint16_t index
= (addr
& 0x1ffff) >> 2;
2213 return index
+ (mac_reg_access
[index
] & 0xfffe);
2216 static const char e1000e_phy_regcap
[E1000E_PHY_PAGES
][0x20] = {
2218 [PHY_CTRL
] = PHY_ANYPAGE
| PHY_RW
,
2219 [PHY_STATUS
] = PHY_ANYPAGE
| PHY_R
,
2220 [PHY_ID1
] = PHY_ANYPAGE
| PHY_R
,
2221 [PHY_ID2
] = PHY_ANYPAGE
| PHY_R
,
2222 [PHY_AUTONEG_ADV
] = PHY_ANYPAGE
| PHY_RW
,
2223 [PHY_LP_ABILITY
] = PHY_ANYPAGE
| PHY_R
,
2224 [PHY_AUTONEG_EXP
] = PHY_ANYPAGE
| PHY_R
,
2225 [PHY_NEXT_PAGE_TX
] = PHY_ANYPAGE
| PHY_RW
,
2226 [PHY_LP_NEXT_PAGE
] = PHY_ANYPAGE
| PHY_R
,
2227 [PHY_1000T_CTRL
] = PHY_ANYPAGE
| PHY_RW
,
2228 [PHY_1000T_STATUS
] = PHY_ANYPAGE
| PHY_R
,
2229 [PHY_EXT_STATUS
] = PHY_ANYPAGE
| PHY_R
,
2230 [PHY_PAGE
] = PHY_ANYPAGE
| PHY_RW
,
2232 [PHY_COPPER_CTRL1
] = PHY_RW
,
2233 [PHY_COPPER_STAT1
] = PHY_R
,
2234 [PHY_COPPER_CTRL3
] = PHY_RW
,
2235 [PHY_RX_ERR_CNTR
] = PHY_R
,
2236 [PHY_OEM_BITS
] = PHY_RW
,
2237 [PHY_BIAS_1
] = PHY_RW
,
2238 [PHY_BIAS_2
] = PHY_RW
,
2239 [PHY_COPPER_INT_ENABLE
] = PHY_RW
,
2240 [PHY_COPPER_STAT2
] = PHY_R
,
2241 [PHY_COPPER_CTRL2
] = PHY_RW
2244 [PHY_MAC_CTRL1
] = PHY_RW
,
2245 [PHY_MAC_INT_ENABLE
] = PHY_RW
,
2246 [PHY_MAC_STAT
] = PHY_R
,
2247 [PHY_MAC_CTRL2
] = PHY_RW
2250 [PHY_LED_03_FUNC_CTRL1
] = PHY_RW
,
2251 [PHY_LED_03_POL_CTRL
] = PHY_RW
,
2252 [PHY_LED_TIMER_CTRL
] = PHY_RW
,
2253 [PHY_LED_45_CTRL
] = PHY_RW
2256 [PHY_1000T_SKEW
] = PHY_R
,
2257 [PHY_1000T_SWAP
] = PHY_R
2260 [PHY_CRC_COUNTERS
] = PHY_R
2265 e1000e_phy_reg_check_cap(E1000ECore
*core
, uint32_t addr
,
2266 char cap
, uint8_t *page
)
2269 (e1000e_phy_regcap
[0][addr
] & PHY_ANYPAGE
) ? 0
2270 : core
->phy
[0][PHY_PAGE
];
2272 if (*page
>= E1000E_PHY_PAGES
) {
2276 return e1000e_phy_regcap
[*page
][addr
] & cap
;
2280 e1000e_phy_reg_write(E1000ECore
*core
, uint8_t page
,
2281 uint32_t addr
, uint16_t data
)
2283 assert(page
< E1000E_PHY_PAGES
);
2284 assert(addr
< E1000E_PHY_PAGE_SIZE
);
2286 if (e1000e_phyreg_writeops
[page
][addr
]) {
2287 e1000e_phyreg_writeops
[page
][addr
](core
, addr
, data
);
2289 core
->phy
[page
][addr
] = data
;
2294 e1000e_set_mdic(E1000ECore
*core
, int index
, uint32_t val
)
2296 uint32_t data
= val
& E1000_MDIC_DATA_MASK
;
2297 uint32_t addr
= ((val
& E1000_MDIC_REG_MASK
) >> E1000_MDIC_REG_SHIFT
);
2300 if ((val
& E1000_MDIC_PHY_MASK
) >> E1000_MDIC_PHY_SHIFT
!= 1) { /* phy # */
2301 val
= core
->mac
[MDIC
] | E1000_MDIC_ERROR
;
2302 } else if (val
& E1000_MDIC_OP_READ
) {
2303 if (!e1000e_phy_reg_check_cap(core
, addr
, PHY_R
, &page
)) {
2304 trace_e1000e_core_mdic_read_unhandled(page
, addr
);
2305 val
|= E1000_MDIC_ERROR
;
2307 val
= (val
^ data
) | core
->phy
[page
][addr
];
2308 trace_e1000e_core_mdic_read(page
, addr
, val
);
2310 } else if (val
& E1000_MDIC_OP_WRITE
) {
2311 if (!e1000e_phy_reg_check_cap(core
, addr
, PHY_W
, &page
)) {
2312 trace_e1000e_core_mdic_write_unhandled(page
, addr
);
2313 val
|= E1000_MDIC_ERROR
;
2315 trace_e1000e_core_mdic_write(page
, addr
, data
);
2316 e1000e_phy_reg_write(core
, page
, addr
, data
);
2319 core
->mac
[MDIC
] = val
| E1000_MDIC_READY
;
2321 if (val
& E1000_MDIC_INT_EN
) {
2322 e1000e_set_interrupt_cause(core
, E1000_ICR_MDAC
);
2327 e1000e_set_rdt(E1000ECore
*core
, int index
, uint32_t val
)
2329 core
->mac
[index
] = val
& 0xffff;
2330 trace_e1000e_rx_set_rdt(e1000e_mq_queue_idx(RDT0
, index
), val
);
2331 e1000e_start_recv(core
);
2335 e1000e_set_status(E1000ECore
*core
, int index
, uint32_t val
)
2337 if ((val
& E1000_STATUS_PHYRA
) == 0) {
2338 core
->mac
[index
] &= ~E1000_STATUS_PHYRA
;
2343 e1000e_set_ctrlext(E1000ECore
*core
, int index
, uint32_t val
)
2345 trace_e1000e_link_set_ext_params(!!(val
& E1000_CTRL_EXT_ASDCHK
),
2346 !!(val
& E1000_CTRL_EXT_SPD_BYPS
));
2348 /* Zero self-clearing bits */
2349 val
&= ~(E1000_CTRL_EXT_ASDCHK
| E1000_CTRL_EXT_EE_RST
);
2350 core
->mac
[CTRL_EXT
] = val
;
2354 e1000e_set_pbaclr(E1000ECore
*core
, int index
, uint32_t val
)
2358 core
->mac
[PBACLR
] = val
& E1000_PBACLR_VALID_MASK
;
2360 if (!msix_enabled(core
->owner
)) {
2364 for (i
= 0; i
< E1000E_MSIX_VEC_NUM
; i
++) {
2365 if (core
->mac
[PBACLR
] & BIT(i
)) {
2366 msix_clr_pending(core
->owner
, i
);
2372 e1000e_set_fcrth(E1000ECore
*core
, int index
, uint32_t val
)
2374 core
->mac
[FCRTH
] = val
& 0xFFF8;
2378 e1000e_set_fcrtl(E1000ECore
*core
, int index
, uint32_t val
)
2380 core
->mac
[FCRTL
] = val
& 0x8000FFF8;
2384 e1000e_set_16bit(E1000ECore
*core
, int index
, uint32_t val
)
2386 core
->mac
[index
] = val
& 0xffff;
2390 e1000e_set_12bit(E1000ECore
*core
, int index
, uint32_t val
)
2392 core
->mac
[index
] = val
& 0xfff;
2396 e1000e_set_vet(E1000ECore
*core
, int index
, uint32_t val
)
2398 core
->mac
[VET
] = val
& 0xffff;
2399 core
->vet
= le16_to_cpu(core
->mac
[VET
]);
2400 trace_e1000e_vlan_vet(core
->vet
);
2404 e1000e_set_dlen(E1000ECore
*core
, int index
, uint32_t val
)
2406 core
->mac
[index
] = val
& E1000_XDLEN_MASK
;
2410 e1000e_set_dbal(E1000ECore
*core
, int index
, uint32_t val
)
2412 core
->mac
[index
] = val
& E1000_XDBAL_MASK
;
2416 e1000e_set_tctl(E1000ECore
*core
, int index
, uint32_t val
)
2419 core
->mac
[index
] = val
;
2421 if (core
->mac
[TARC0
] & E1000_TARC_ENABLE
) {
2422 e1000e_tx_ring_init(core
, &txr
, 0);
2423 e1000e_start_xmit(core
, &txr
);
2426 if (core
->mac
[TARC1
] & E1000_TARC_ENABLE
) {
2427 e1000e_tx_ring_init(core
, &txr
, 1);
2428 e1000e_start_xmit(core
, &txr
);
2433 e1000e_set_tdt(E1000ECore
*core
, int index
, uint32_t val
)
2436 int qidx
= e1000e_mq_queue_idx(TDT
, index
);
2437 uint32_t tarc_reg
= (qidx
== 0) ? TARC0
: TARC1
;
2439 core
->mac
[index
] = val
& 0xffff;
2441 if (core
->mac
[tarc_reg
] & E1000_TARC_ENABLE
) {
2442 e1000e_tx_ring_init(core
, &txr
, qidx
);
2443 e1000e_start_xmit(core
, &txr
);
2448 e1000e_set_ics(E1000ECore
*core
, int index
, uint32_t val
)
2450 trace_e1000e_irq_write_ics(val
);
2451 e1000e_set_interrupt_cause(core
, val
);
2455 e1000e_set_icr(E1000ECore
*core
, int index
, uint32_t val
)
2458 if ((core
->mac
[ICR
] & E1000_ICR_ASSERTED
) &&
2459 (core
->mac
[CTRL_EXT
] & E1000_CTRL_EXT_IAME
)) {
2460 trace_e1000e_irq_icr_process_iame();
2461 e1000e_clear_ims_bits(core
, core
->mac
[IAM
]);
2464 icr
= core
->mac
[ICR
] & ~val
;
2465 /* Windows driver expects that the "receive overrun" bit and other
2466 * ones to be cleared when the "Other" bit (#24) is cleared.
2468 icr
= (val
& E1000_ICR_OTHER
) ? (icr
& ~E1000_ICR_OTHER_CAUSES
) : icr
;
2469 trace_e1000e_irq_icr_write(val
, core
->mac
[ICR
], icr
);
2470 core
->mac
[ICR
] = icr
;
2471 e1000e_update_interrupt_state(core
);
2475 e1000e_set_imc(E1000ECore
*core
, int index
, uint32_t val
)
2477 trace_e1000e_irq_ims_clear_set_imc(val
);
2478 e1000e_clear_ims_bits(core
, val
);
2479 e1000e_update_interrupt_state(core
);
2483 e1000e_set_ims(E1000ECore
*core
, int index
, uint32_t val
)
2485 static const uint32_t ims_ext_mask
=
2486 E1000_IMS_RXQ0
| E1000_IMS_RXQ1
|
2487 E1000_IMS_TXQ0
| E1000_IMS_TXQ1
|
2490 static const uint32_t ims_valid_mask
=
2491 E1000_IMS_TXDW
| E1000_IMS_TXQE
| E1000_IMS_LSC
|
2492 E1000_IMS_RXDMT0
| E1000_IMS_RXO
| E1000_IMS_RXT0
|
2493 E1000_IMS_MDAC
| E1000_IMS_TXD_LOW
| E1000_IMS_SRPD
|
2494 E1000_IMS_ACK
| E1000_IMS_MNG
| E1000_IMS_RXQ0
|
2495 E1000_IMS_RXQ1
| E1000_IMS_TXQ0
| E1000_IMS_TXQ1
|
2498 uint32_t valid_val
= val
& ims_valid_mask
;
2500 trace_e1000e_irq_set_ims(val
, core
->mac
[IMS
], core
->mac
[IMS
] | valid_val
);
2501 core
->mac
[IMS
] |= valid_val
;
2503 if ((valid_val
& ims_ext_mask
) &&
2504 (core
->mac
[CTRL_EXT
] & E1000_CTRL_EXT_PBA_CLR
) &&
2505 msix_enabled(core
->owner
)) {
2506 e1000e_msix_clear(core
, valid_val
);
2509 if ((valid_val
== ims_valid_mask
) &&
2510 (core
->mac
[CTRL_EXT
] & E1000_CTRL_EXT_INT_TIMERS_CLEAR_ENA
)) {
2511 trace_e1000e_irq_fire_all_timers(val
);
2512 e1000e_intrmgr_fire_all_timers(core
);
2515 e1000e_update_interrupt_state(core
);
2519 e1000e_set_rdtr(E1000ECore
*core
, int index
, uint32_t val
)
2521 e1000e_set_16bit(core
, index
, val
);
2523 if ((val
& E1000_RDTR_FPD
) && (core
->rdtr
.running
)) {
2524 trace_e1000e_irq_rdtr_fpd_running();
2525 e1000e_intrmgr_fire_delayed_interrupts(core
);
2527 trace_e1000e_irq_rdtr_fpd_not_running();
2532 e1000e_set_tidv(E1000ECore
*core
, int index
, uint32_t val
)
2534 e1000e_set_16bit(core
, index
, val
);
2536 if ((val
& E1000_TIDV_FPD
) && (core
->tidv
.running
)) {
2537 trace_e1000e_irq_tidv_fpd_running();
2538 e1000e_intrmgr_fire_delayed_interrupts(core
);
2540 trace_e1000e_irq_tidv_fpd_not_running();
2545 e1000e_mac_readreg(E1000ECore
*core
, int index
)
2547 return core
->mac
[index
];
2551 e1000e_mac_ics_read(E1000ECore
*core
, int index
)
2553 trace_e1000e_irq_read_ics(core
->mac
[ICS
]);
2554 return core
->mac
[ICS
];
2558 e1000e_mac_ims_read(E1000ECore
*core
, int index
)
2560 trace_e1000e_irq_read_ims(core
->mac
[IMS
]);
2561 return core
->mac
[IMS
];
2564 #define E1000E_LOW_BITS_READ_FUNC(num) \
2566 e1000e_mac_low##num##_read(E1000ECore *core, int index) \
2568 return core->mac[index] & (BIT(num) - 1); \
2571 #define E1000E_LOW_BITS_READ(num) \
2572 e1000e_mac_low##num##_read
2574 E1000E_LOW_BITS_READ_FUNC(4);
2575 E1000E_LOW_BITS_READ_FUNC(6);
2576 E1000E_LOW_BITS_READ_FUNC(11);
2577 E1000E_LOW_BITS_READ_FUNC(13);
2578 E1000E_LOW_BITS_READ_FUNC(16);
2581 e1000e_mac_swsm_read(E1000ECore
*core
, int index
)
2583 uint32_t val
= core
->mac
[SWSM
];
2584 core
->mac
[SWSM
] = val
| 1;
2589 e1000e_mac_itr_read(E1000ECore
*core
, int index
)
2591 return core
->itr_guest_value
;
2595 e1000e_mac_eitr_read(E1000ECore
*core
, int index
)
2597 return core
->eitr_guest_value
[index
- EITR
];
2601 e1000e_mac_icr_read(E1000ECore
*core
, int index
)
2603 uint32_t ret
= core
->mac
[ICR
];
2604 trace_e1000e_irq_icr_read_entry(ret
);
2606 if (core
->mac
[IMS
] == 0) {
2607 trace_e1000e_irq_icr_clear_zero_ims();
2611 if ((core
->mac
[ICR
] & E1000_ICR_ASSERTED
) &&
2612 (core
->mac
[CTRL_EXT
] & E1000_CTRL_EXT_IAME
)) {
2613 trace_e1000e_irq_icr_clear_iame();
2615 trace_e1000e_irq_icr_process_iame();
2616 e1000e_clear_ims_bits(core
, core
->mac
[IAM
]);
2619 trace_e1000e_irq_icr_read_exit(core
->mac
[ICR
]);
2620 e1000e_update_interrupt_state(core
);
2625 e1000e_mac_read_clr4(E1000ECore
*core
, int index
)
2627 uint32_t ret
= core
->mac
[index
];
2629 core
->mac
[index
] = 0;
2634 e1000e_mac_read_clr8(E1000ECore
*core
, int index
)
2636 uint32_t ret
= core
->mac
[index
];
2638 core
->mac
[index
] = 0;
2639 core
->mac
[index
- 1] = 0;
2644 e1000e_get_ctrl(E1000ECore
*core
, int index
)
2646 uint32_t val
= core
->mac
[CTRL
];
2648 trace_e1000e_link_read_params(
2649 !!(val
& E1000_CTRL_ASDE
),
2650 (val
& E1000_CTRL_SPD_SEL
) >> E1000_CTRL_SPD_SHIFT
,
2651 !!(val
& E1000_CTRL_FRCSPD
),
2652 !!(val
& E1000_CTRL_FRCDPX
),
2653 !!(val
& E1000_CTRL_RFCE
),
2654 !!(val
& E1000_CTRL_TFCE
));
2660 e1000e_get_status(E1000ECore
*core
, int index
)
2662 uint32_t res
= core
->mac
[STATUS
];
2664 if (!(core
->mac
[CTRL
] & E1000_CTRL_GIO_MASTER_DISABLE
)) {
2665 res
|= E1000_STATUS_GIO_MASTER_ENABLE
;
2668 if (core
->mac
[CTRL
] & E1000_CTRL_FRCDPX
) {
2669 res
|= (core
->mac
[CTRL
] & E1000_CTRL_FD
) ? E1000_STATUS_FD
: 0;
2671 res
|= E1000_STATUS_FD
;
2674 if ((core
->mac
[CTRL
] & E1000_CTRL_FRCSPD
) ||
2675 (core
->mac
[CTRL_EXT
] & E1000_CTRL_EXT_SPD_BYPS
)) {
2676 switch (core
->mac
[CTRL
] & E1000_CTRL_SPD_SEL
) {
2677 case E1000_CTRL_SPD_10
:
2678 res
|= E1000_STATUS_SPEED_10
;
2680 case E1000_CTRL_SPD_100
:
2681 res
|= E1000_STATUS_SPEED_100
;
2683 case E1000_CTRL_SPD_1000
:
2685 res
|= E1000_STATUS_SPEED_1000
;
2689 res
|= E1000_STATUS_SPEED_1000
;
2692 trace_e1000e_link_status(
2693 !!(res
& E1000_STATUS_LU
),
2694 !!(res
& E1000_STATUS_FD
),
2695 (res
& E1000_STATUS_SPEED_MASK
) >> E1000_STATUS_SPEED_SHIFT
,
2696 (res
& E1000_STATUS_ASDV
) >> E1000_STATUS_ASDV_SHIFT
);
2702 e1000e_get_tarc(E1000ECore
*core
, int index
)
2704 return core
->mac
[index
] & ((BIT(11) - 1) |
2712 e1000e_mac_writereg(E1000ECore
*core
, int index
, uint32_t val
)
2714 core
->mac
[index
] = val
;
2718 e1000e_mac_setmacaddr(E1000ECore
*core
, int index
, uint32_t val
)
2720 uint32_t macaddr
[2];
2722 core
->mac
[index
] = val
;
2724 macaddr
[0] = cpu_to_le32(core
->mac
[RA
]);
2725 macaddr
[1] = cpu_to_le32(core
->mac
[RA
+ 1]);
2726 qemu_format_nic_info_str(qemu_get_queue(core
->owner_nic
),
2727 (uint8_t *) macaddr
);
2729 trace_e1000e_mac_set_sw(MAC_ARG(macaddr
));
2733 e1000e_set_eecd(E1000ECore
*core
, int index
, uint32_t val
)
2735 static const uint32_t ro_bits
= E1000_EECD_PRES
|
2736 E1000_EECD_AUTO_RD
|
2737 E1000_EECD_SIZE_EX_MASK
;
2739 core
->mac
[EECD
] = (core
->mac
[EECD
] & ro_bits
) | (val
& ~ro_bits
);
2743 e1000e_set_eerd(E1000ECore
*core
, int index
, uint32_t val
)
2745 uint32_t addr
= (val
>> E1000_EERW_ADDR_SHIFT
) & E1000_EERW_ADDR_MASK
;
2749 if ((addr
< E1000E_EEPROM_SIZE
) && (val
& E1000_EERW_START
)) {
2750 data
= core
->eeprom
[addr
];
2751 flags
= E1000_EERW_DONE
;
2754 core
->mac
[EERD
] = flags
|
2755 (addr
<< E1000_EERW_ADDR_SHIFT
) |
2756 (data
<< E1000_EERW_DATA_SHIFT
);
2760 e1000e_set_eewr(E1000ECore
*core
, int index
, uint32_t val
)
2762 uint32_t addr
= (val
>> E1000_EERW_ADDR_SHIFT
) & E1000_EERW_ADDR_MASK
;
2763 uint32_t data
= (val
>> E1000_EERW_DATA_SHIFT
) & E1000_EERW_DATA_MASK
;
2766 if ((addr
< E1000E_EEPROM_SIZE
) && (val
& E1000_EERW_START
)) {
2767 core
->eeprom
[addr
] = data
;
2768 flags
= E1000_EERW_DONE
;
2771 core
->mac
[EERD
] = flags
|
2772 (addr
<< E1000_EERW_ADDR_SHIFT
) |
2773 (data
<< E1000_EERW_DATA_SHIFT
);
2777 e1000e_set_rxdctl(E1000ECore
*core
, int index
, uint32_t val
)
2779 core
->mac
[RXDCTL
] = core
->mac
[RXDCTL1
] = val
;
2783 e1000e_set_itr(E1000ECore
*core
, int index
, uint32_t val
)
2785 uint32_t interval
= val
& 0xffff;
2787 trace_e1000e_irq_itr_set(val
);
2789 core
->itr_guest_value
= interval
;
2790 core
->mac
[index
] = MAX(interval
, E1000E_MIN_XITR
);
2794 e1000e_set_eitr(E1000ECore
*core
, int index
, uint32_t val
)
2796 uint32_t interval
= val
& 0xffff;
2797 uint32_t eitr_num
= index
- EITR
;
2799 trace_e1000e_irq_eitr_set(eitr_num
, val
);
2801 core
->eitr_guest_value
[eitr_num
] = interval
;
2802 core
->mac
[index
] = MAX(interval
, E1000E_MIN_XITR
);
2806 e1000e_set_psrctl(E1000ECore
*core
, int index
, uint32_t val
)
2808 if ((val
& E1000_PSRCTL_BSIZE0_MASK
) == 0) {
2809 hw_error("e1000e: PSRCTL.BSIZE0 cannot be zero");
2812 if ((val
& E1000_PSRCTL_BSIZE1_MASK
) == 0) {
2813 hw_error("e1000e: PSRCTL.BSIZE1 cannot be zero");
2816 core
->mac
[PSRCTL
] = val
;
2820 e1000e_update_rx_offloads(E1000ECore
*core
)
2822 int cso_state
= e1000e_rx_l4_cso_enabled(core
);
2824 trace_e1000e_rx_set_cso(cso_state
);
2826 if (core
->has_vnet
) {
2827 qemu_set_offload(qemu_get_queue(core
->owner_nic
)->peer
,
2828 cso_state
, 0, 0, 0, 0);
2833 e1000e_set_rxcsum(E1000ECore
*core
, int index
, uint32_t val
)
2835 core
->mac
[RXCSUM
] = val
;
2836 e1000e_update_rx_offloads(core
);
2840 e1000e_set_gcr(E1000ECore
*core
, int index
, uint32_t val
)
2842 uint32_t ro_bits
= core
->mac
[GCR
] & E1000_GCR_RO_BITS
;
2843 core
->mac
[GCR
] = (val
& ~E1000_GCR_RO_BITS
) | ro_bits
;
2846 #define e1000e_getreg(x) [x] = e1000e_mac_readreg
2847 static uint32_t (*e1000e_macreg_readops
[])(E1000ECore
*, int) = {
2849 e1000e_getreg(WUFC
),
2850 e1000e_getreg(MANC
),
2851 e1000e_getreg(TOTL
),
2852 e1000e_getreg(RDT0
),
2853 e1000e_getreg(RDBAH0
),
2854 e1000e_getreg(TDBAL1
),
2855 e1000e_getreg(RDLEN0
),
2856 e1000e_getreg(RDH1
),
2857 e1000e_getreg(LATECOL
),
2858 e1000e_getreg(SEQEC
),
2859 e1000e_getreg(XONTXC
),
2861 e1000e_getreg(GORCL
),
2862 e1000e_getreg(MGTPRC
),
2863 e1000e_getreg(EERD
),
2864 e1000e_getreg(EIAC
),
2865 e1000e_getreg(PSRCTL
),
2866 e1000e_getreg(MANC2H
),
2867 e1000e_getreg(RXCSUM
),
2868 e1000e_getreg(GSCL_3
),
2869 e1000e_getreg(GSCN_2
),
2870 e1000e_getreg(RSRPD
),
2871 e1000e_getreg(RDBAL1
),
2872 e1000e_getreg(FCAH
),
2873 e1000e_getreg(FCRTH
),
2874 e1000e_getreg(FLOP
),
2875 e1000e_getreg(FLASHT
),
2876 e1000e_getreg(RXSTMPH
),
2877 e1000e_getreg(TXSTMPL
),
2878 e1000e_getreg(TIMADJL
),
2879 e1000e_getreg(TXDCTL
),
2880 e1000e_getreg(RDH0
),
2881 e1000e_getreg(TDT1
),
2882 e1000e_getreg(TNCRS
),
2885 e1000e_getreg(GSCL_2
),
2886 e1000e_getreg(RDBAH1
),
2887 e1000e_getreg(FLSWDATA
),
2888 e1000e_getreg(RXSATRH
),
2889 e1000e_getreg(TIPG
),
2890 e1000e_getreg(FLMNGCTL
),
2891 e1000e_getreg(FLMNGCNT
),
2892 e1000e_getreg(TSYNCTXCTL
),
2893 e1000e_getreg(EXTCNF_SIZE
),
2894 e1000e_getreg(EXTCNF_CTRL
),
2895 e1000e_getreg(EEMNGDATA
),
2896 e1000e_getreg(CTRL_EXT
),
2897 e1000e_getreg(SYSTIMH
),
2898 e1000e_getreg(EEMNGCTL
),
2899 e1000e_getreg(FLMNGDATA
),
2900 e1000e_getreg(TSYNCRXCTL
),
2902 e1000e_getreg(LEDCTL
),
2903 e1000e_getreg(STATUS
),
2904 e1000e_getreg(TCTL
),
2905 e1000e_getreg(TDBAL
),
2906 e1000e_getreg(TDLEN
),
2907 e1000e_getreg(TDH1
),
2908 e1000e_getreg(RADV
),
2909 e1000e_getreg(ECOL
),
2911 e1000e_getreg(RLEC
),
2912 e1000e_getreg(XOFFTXC
),
2914 e1000e_getreg(RNBC
),
2915 e1000e_getreg(MGTPTC
),
2916 e1000e_getreg(TIMINCA
),
2917 e1000e_getreg(RXCFGL
),
2918 e1000e_getreg(MFUTP01
),
2919 e1000e_getreg(FACTPS
),
2920 e1000e_getreg(GSCL_1
),
2921 e1000e_getreg(GSCN_0
),
2922 e1000e_getreg(GCR2
),
2923 e1000e_getreg(RDT1
),
2924 e1000e_getreg(PBACLR
),
2925 e1000e_getreg(FCTTV
),
2926 e1000e_getreg(EEWR
),
2927 e1000e_getreg(FLSWCTL
),
2928 e1000e_getreg(RXDCTL1
),
2929 e1000e_getreg(RXSATRL
),
2930 e1000e_getreg(SYSTIML
),
2931 e1000e_getreg(RXUDP
),
2932 e1000e_getreg(TORL
),
2933 e1000e_getreg(TDLEN1
),
2936 e1000e_getreg(EECD
),
2937 e1000e_getreg(MFUTP23
),
2938 e1000e_getreg(RAID
),
2939 e1000e_getreg(FCRTV
),
2940 e1000e_getreg(TXDCTL1
),
2941 e1000e_getreg(RCTL
),
2943 e1000e_getreg(MDIC
),
2944 e1000e_getreg(FCRUC
),
2946 e1000e_getreg(RDBAL0
),
2947 e1000e_getreg(TDBAH1
),
2948 e1000e_getreg(RDTR
),
2950 e1000e_getreg(COLC
),
2951 e1000e_getreg(CEXTERR
),
2952 e1000e_getreg(XOFFRXC
),
2953 e1000e_getreg(IPAV
),
2954 e1000e_getreg(GOTCL
),
2955 e1000e_getreg(MGTPDC
),
2957 e1000e_getreg(IVAR
),
2958 e1000e_getreg(POEMB
),
2959 e1000e_getreg(MFVAL
),
2960 e1000e_getreg(FUNCTAG
),
2961 e1000e_getreg(GSCL_4
),
2962 e1000e_getreg(GSCN_3
),
2963 e1000e_getreg(MRQC
),
2964 e1000e_getreg(RDLEN1
),
2967 e1000e_getreg(FLOL
),
2968 e1000e_getreg(RXDCTL
),
2969 e1000e_getreg(RXSTMPL
),
2970 e1000e_getreg(TXSTMPH
),
2971 e1000e_getreg(TIMADJH
),
2972 e1000e_getreg(FCRTL
),
2973 e1000e_getreg(TDBAH
),
2974 e1000e_getreg(TADV
),
2975 e1000e_getreg(XONRXC
),
2976 e1000e_getreg(TSCTFC
),
2977 e1000e_getreg(RFCTL
),
2978 e1000e_getreg(GSCN_1
),
2979 e1000e_getreg(FCAL
),
2980 e1000e_getreg(FLSWCNT
),
2982 [TOTH
] = e1000e_mac_read_clr8
,
2983 [GOTCH
] = e1000e_mac_read_clr8
,
2984 [PRC64
] = e1000e_mac_read_clr4
,
2985 [PRC255
] = e1000e_mac_read_clr4
,
2986 [PRC1023
] = e1000e_mac_read_clr4
,
2987 [PTC64
] = e1000e_mac_read_clr4
,
2988 [PTC255
] = e1000e_mac_read_clr4
,
2989 [PTC1023
] = e1000e_mac_read_clr4
,
2990 [GPRC
] = e1000e_mac_read_clr4
,
2991 [TPT
] = e1000e_mac_read_clr4
,
2992 [RUC
] = e1000e_mac_read_clr4
,
2993 [BPRC
] = e1000e_mac_read_clr4
,
2994 [MPTC
] = e1000e_mac_read_clr4
,
2995 [IAC
] = e1000e_mac_read_clr4
,
2996 [ICR
] = e1000e_mac_icr_read
,
2997 [RDFH
] = E1000E_LOW_BITS_READ(13),
2998 [RDFHS
] = E1000E_LOW_BITS_READ(13),
2999 [RDFPC
] = E1000E_LOW_BITS_READ(13),
3000 [TDFH
] = E1000E_LOW_BITS_READ(13),
3001 [TDFHS
] = E1000E_LOW_BITS_READ(13),
3002 [STATUS
] = e1000e_get_status
,
3003 [TARC0
] = e1000e_get_tarc
,
3004 [PBS
] = E1000E_LOW_BITS_READ(6),
3005 [ICS
] = e1000e_mac_ics_read
,
3006 [AIT
] = E1000E_LOW_BITS_READ(16),
3007 [TORH
] = e1000e_mac_read_clr8
,
3008 [GORCH
] = e1000e_mac_read_clr8
,
3009 [PRC127
] = e1000e_mac_read_clr4
,
3010 [PRC511
] = e1000e_mac_read_clr4
,
3011 [PRC1522
] = e1000e_mac_read_clr4
,
3012 [PTC127
] = e1000e_mac_read_clr4
,
3013 [PTC511
] = e1000e_mac_read_clr4
,
3014 [PTC1522
] = e1000e_mac_read_clr4
,
3015 [GPTC
] = e1000e_mac_read_clr4
,
3016 [TPR
] = e1000e_mac_read_clr4
,
3017 [ROC
] = e1000e_mac_read_clr4
,
3018 [MPRC
] = e1000e_mac_read_clr4
,
3019 [BPTC
] = e1000e_mac_read_clr4
,
3020 [TSCTC
] = e1000e_mac_read_clr4
,
3021 [ITR
] = e1000e_mac_itr_read
,
3022 [RDFT
] = E1000E_LOW_BITS_READ(13),
3023 [RDFTS
] = E1000E_LOW_BITS_READ(13),
3024 [TDFPC
] = E1000E_LOW_BITS_READ(13),
3025 [TDFT
] = E1000E_LOW_BITS_READ(13),
3026 [TDFTS
] = E1000E_LOW_BITS_READ(13),
3027 [CTRL
] = e1000e_get_ctrl
,
3028 [TARC1
] = e1000e_get_tarc
,
3029 [SWSM
] = e1000e_mac_swsm_read
,
3030 [IMS
] = e1000e_mac_ims_read
,
3032 [CRCERRS
... MPC
] = e1000e_mac_readreg
,
3033 [IP6AT
... IP6AT
+ 3] = e1000e_mac_readreg
,
3034 [IP4AT
... IP4AT
+ 6] = e1000e_mac_readreg
,
3035 [RA
... RA
+ 31] = e1000e_mac_readreg
,
3036 [WUPM
... WUPM
+ 31] = e1000e_mac_readreg
,
3037 [MTA
... MTA
+ 127] = e1000e_mac_readreg
,
3038 [VFTA
... VFTA
+ 127] = e1000e_mac_readreg
,
3039 [FFMT
... FFMT
+ 254] = E1000E_LOW_BITS_READ(4),
3040 [FFVT
... FFVT
+ 254] = e1000e_mac_readreg
,
3041 [MDEF
... MDEF
+ 7] = e1000e_mac_readreg
,
3042 [FFLT
... FFLT
+ 10] = E1000E_LOW_BITS_READ(11),
3043 [FTFT
... FTFT
+ 254] = e1000e_mac_readreg
,
3044 [PBM
... PBM
+ 10239] = e1000e_mac_readreg
,
3045 [RETA
... RETA
+ 31] = e1000e_mac_readreg
,
3046 [RSSRK
... RSSRK
+ 31] = e1000e_mac_readreg
,
3047 [MAVTV0
... MAVTV3
] = e1000e_mac_readreg
,
3048 [EITR
...EITR
+ E1000E_MSIX_VEC_NUM
- 1] = e1000e_mac_eitr_read
3050 enum { E1000E_NREADOPS
= ARRAY_SIZE(e1000e_macreg_readops
) };
3052 #define e1000e_putreg(x) [x] = e1000e_mac_writereg
3053 static void (*e1000e_macreg_writeops
[])(E1000ECore
*, int, uint32_t) = {
3055 e1000e_putreg(SWSM
),
3056 e1000e_putreg(WUFC
),
3057 e1000e_putreg(RDBAH1
),
3058 e1000e_putreg(TDBAH
),
3059 e1000e_putreg(TXDCTL
),
3060 e1000e_putreg(RDBAH0
),
3061 e1000e_putreg(LEDCTL
),
3062 e1000e_putreg(FCAL
),
3063 e1000e_putreg(FCRUC
),
3065 e1000e_putreg(TDFH
),
3066 e1000e_putreg(TDFT
),
3067 e1000e_putreg(TDFHS
),
3068 e1000e_putreg(TDFTS
),
3069 e1000e_putreg(TDFPC
),
3072 e1000e_putreg(RDFH
),
3073 e1000e_putreg(RDFT
),
3074 e1000e_putreg(RDFHS
),
3075 e1000e_putreg(RDFTS
),
3076 e1000e_putreg(RDFPC
),
3077 e1000e_putreg(IPAV
),
3078 e1000e_putreg(TDBAH1
),
3079 e1000e_putreg(TIMINCA
),
3081 e1000e_putreg(EIAC
),
3082 e1000e_putreg(IVAR
),
3083 e1000e_putreg(TARC0
),
3084 e1000e_putreg(TARC1
),
3085 e1000e_putreg(FLSWDATA
),
3086 e1000e_putreg(POEMB
),
3088 e1000e_putreg(MFUTP01
),
3089 e1000e_putreg(MFUTP23
),
3090 e1000e_putreg(MANC
),
3091 e1000e_putreg(MANC2H
),
3092 e1000e_putreg(MFVAL
),
3093 e1000e_putreg(EXTCNF_CTRL
),
3094 e1000e_putreg(FACTPS
),
3095 e1000e_putreg(FUNCTAG
),
3096 e1000e_putreg(GSCL_1
),
3097 e1000e_putreg(GSCL_2
),
3098 e1000e_putreg(GSCL_3
),
3099 e1000e_putreg(GSCL_4
),
3100 e1000e_putreg(GSCN_0
),
3101 e1000e_putreg(GSCN_1
),
3102 e1000e_putreg(GSCN_2
),
3103 e1000e_putreg(GSCN_3
),
3104 e1000e_putreg(GCR2
),
3105 e1000e_putreg(MRQC
),
3106 e1000e_putreg(FLOP
),
3107 e1000e_putreg(FLOL
),
3108 e1000e_putreg(FLSWCTL
),
3109 e1000e_putreg(FLSWCNT
),
3111 e1000e_putreg(RXDCTL1
),
3112 e1000e_putreg(TXDCTL1
),
3113 e1000e_putreg(TIPG
),
3114 e1000e_putreg(RXSTMPH
),
3115 e1000e_putreg(RXSTMPL
),
3116 e1000e_putreg(RXSATRL
),
3117 e1000e_putreg(RXSATRH
),
3118 e1000e_putreg(TXSTMPL
),
3119 e1000e_putreg(TXSTMPH
),
3120 e1000e_putreg(SYSTIML
),
3121 e1000e_putreg(SYSTIMH
),
3122 e1000e_putreg(TIMADJL
),
3123 e1000e_putreg(TIMADJH
),
3124 e1000e_putreg(RXUDP
),
3125 e1000e_putreg(RXCFGL
),
3126 e1000e_putreg(TSYNCRXCTL
),
3127 e1000e_putreg(TSYNCTXCTL
),
3128 e1000e_putreg(FLSWDATA
),
3129 e1000e_putreg(EXTCNF_SIZE
),
3130 e1000e_putreg(EEMNGCTL
),
3133 [TDH1
] = e1000e_set_16bit
,
3134 [TDT1
] = e1000e_set_tdt
,
3135 [TCTL
] = e1000e_set_tctl
,
3136 [TDT
] = e1000e_set_tdt
,
3137 [MDIC
] = e1000e_set_mdic
,
3138 [ICS
] = e1000e_set_ics
,
3139 [TDH
] = e1000e_set_16bit
,
3140 [RDH0
] = e1000e_set_16bit
,
3141 [RDT0
] = e1000e_set_rdt
,
3142 [IMC
] = e1000e_set_imc
,
3143 [IMS
] = e1000e_set_ims
,
3144 [ICR
] = e1000e_set_icr
,
3145 [EECD
] = e1000e_set_eecd
,
3146 [RCTL
] = e1000e_set_rx_control
,
3147 [CTRL
] = e1000e_set_ctrl
,
3148 [RDTR
] = e1000e_set_rdtr
,
3149 [RADV
] = e1000e_set_16bit
,
3150 [TADV
] = e1000e_set_16bit
,
3151 [ITR
] = e1000e_set_itr
,
3152 [EERD
] = e1000e_set_eerd
,
3153 [GCR
] = e1000e_set_gcr
,
3154 [PSRCTL
] = e1000e_set_psrctl
,
3155 [RXCSUM
] = e1000e_set_rxcsum
,
3156 [RAID
] = e1000e_set_16bit
,
3157 [RSRPD
] = e1000e_set_12bit
,
3158 [TIDV
] = e1000e_set_tidv
,
3159 [TDLEN1
] = e1000e_set_dlen
,
3160 [TDLEN
] = e1000e_set_dlen
,
3161 [RDLEN0
] = e1000e_set_dlen
,
3162 [RDLEN1
] = e1000e_set_dlen
,
3163 [TDBAL
] = e1000e_set_dbal
,
3164 [TDBAL1
] = e1000e_set_dbal
,
3165 [RDBAL0
] = e1000e_set_dbal
,
3166 [RDBAL1
] = e1000e_set_dbal
,
3167 [RDH1
] = e1000e_set_16bit
,
3168 [RDT1
] = e1000e_set_rdt
,
3169 [STATUS
] = e1000e_set_status
,
3170 [PBACLR
] = e1000e_set_pbaclr
,
3171 [CTRL_EXT
] = e1000e_set_ctrlext
,
3172 [FCAH
] = e1000e_set_16bit
,
3173 [FCT
] = e1000e_set_16bit
,
3174 [FCTTV
] = e1000e_set_16bit
,
3175 [FCRTV
] = e1000e_set_16bit
,
3176 [FCRTH
] = e1000e_set_fcrth
,
3177 [FCRTL
] = e1000e_set_fcrtl
,
3178 [VET
] = e1000e_set_vet
,
3179 [RXDCTL
] = e1000e_set_rxdctl
,
3180 [FLASHT
] = e1000e_set_16bit
,
3181 [EEWR
] = e1000e_set_eewr
,
3182 [CTRL_DUP
] = e1000e_set_ctrl
,
3183 [RFCTL
] = e1000e_set_rfctl
,
3184 [RA
+ 1] = e1000e_mac_setmacaddr
,
3186 [IP6AT
... IP6AT
+ 3] = e1000e_mac_writereg
,
3187 [IP4AT
... IP4AT
+ 6] = e1000e_mac_writereg
,
3188 [RA
+ 2 ... RA
+ 31] = e1000e_mac_writereg
,
3189 [WUPM
... WUPM
+ 31] = e1000e_mac_writereg
,
3190 [MTA
... MTA
+ 127] = e1000e_mac_writereg
,
3191 [VFTA
... VFTA
+ 127] = e1000e_mac_writereg
,
3192 [FFMT
... FFMT
+ 254] = e1000e_mac_writereg
,
3193 [FFVT
... FFVT
+ 254] = e1000e_mac_writereg
,
3194 [PBM
... PBM
+ 10239] = e1000e_mac_writereg
,
3195 [MDEF
... MDEF
+ 7] = e1000e_mac_writereg
,
3196 [FFLT
... FFLT
+ 10] = e1000e_mac_writereg
,
3197 [FTFT
... FTFT
+ 254] = e1000e_mac_writereg
,
3198 [RETA
... RETA
+ 31] = e1000e_mac_writereg
,
3199 [RSSRK
... RSSRK
+ 31] = e1000e_mac_writereg
,
3200 [MAVTV0
... MAVTV3
] = e1000e_mac_writereg
,
3201 [EITR
...EITR
+ E1000E_MSIX_VEC_NUM
- 1] = e1000e_set_eitr
3203 enum { E1000E_NWRITEOPS
= ARRAY_SIZE(e1000e_macreg_writeops
) };
3205 enum { MAC_ACCESS_PARTIAL
= 1 };
3207 /* The array below combines alias offsets of the index values for the
3208 * MAC registers that have aliases, with the indication of not fully
3209 * implemented registers (lowest bit). This combination is possible
3210 * because all of the offsets are even. */
3211 static const uint16_t mac_reg_access
[E1000E_MAC_SIZE
] = {
3212 /* Alias index offsets */
3213 [FCRTL_A
] = 0x07fe, [FCRTH_A
] = 0x0802,
3214 [RDH0_A
] = 0x09bc, [RDT0_A
] = 0x09bc, [RDTR_A
] = 0x09c6,
3215 [RDFH_A
] = 0xe904, [RDFT_A
] = 0xe904,
3216 [TDH_A
] = 0x0cf8, [TDT_A
] = 0x0cf8, [TIDV_A
] = 0x0cf8,
3217 [TDFH_A
] = 0xed00, [TDFT_A
] = 0xed00,
3218 [RA_A
... RA_A
+ 31] = 0x14f0,
3219 [VFTA_A
... VFTA_A
+ 127] = 0x1400,
3220 [RDBAL0_A
... RDLEN0_A
] = 0x09bc,
3221 [TDBAL_A
... TDLEN_A
] = 0x0cf8,
3222 /* Access options */
3223 [RDFH
] = MAC_ACCESS_PARTIAL
, [RDFT
] = MAC_ACCESS_PARTIAL
,
3224 [RDFHS
] = MAC_ACCESS_PARTIAL
, [RDFTS
] = MAC_ACCESS_PARTIAL
,
3225 [RDFPC
] = MAC_ACCESS_PARTIAL
,
3226 [TDFH
] = MAC_ACCESS_PARTIAL
, [TDFT
] = MAC_ACCESS_PARTIAL
,
3227 [TDFHS
] = MAC_ACCESS_PARTIAL
, [TDFTS
] = MAC_ACCESS_PARTIAL
,
3228 [TDFPC
] = MAC_ACCESS_PARTIAL
, [EECD
] = MAC_ACCESS_PARTIAL
,
3229 [PBM
] = MAC_ACCESS_PARTIAL
, [FLA
] = MAC_ACCESS_PARTIAL
,
3230 [FCAL
] = MAC_ACCESS_PARTIAL
, [FCAH
] = MAC_ACCESS_PARTIAL
,
3231 [FCT
] = MAC_ACCESS_PARTIAL
, [FCTTV
] = MAC_ACCESS_PARTIAL
,
3232 [FCRTV
] = MAC_ACCESS_PARTIAL
, [FCRTL
] = MAC_ACCESS_PARTIAL
,
3233 [FCRTH
] = MAC_ACCESS_PARTIAL
, [TXDCTL
] = MAC_ACCESS_PARTIAL
,
3234 [TXDCTL1
] = MAC_ACCESS_PARTIAL
,
3235 [MAVTV0
... MAVTV3
] = MAC_ACCESS_PARTIAL
3239 e1000e_core_write(E1000ECore
*core
, hwaddr addr
, uint64_t val
, unsigned size
)
3241 uint16_t index
= e1000e_get_reg_index_with_offset(mac_reg_access
, addr
);
3243 if (index
< E1000E_NWRITEOPS
&& e1000e_macreg_writeops
[index
]) {
3244 if (mac_reg_access
[index
] & MAC_ACCESS_PARTIAL
) {
3245 trace_e1000e_wrn_regs_write_trivial(index
<< 2);
3247 trace_e1000e_core_write(index
<< 2, size
, val
);
3248 e1000e_macreg_writeops
[index
](core
, index
, val
);
3249 } else if (index
< E1000E_NREADOPS
&& e1000e_macreg_readops
[index
]) {
3250 trace_e1000e_wrn_regs_write_ro(index
<< 2, size
, val
);
3252 trace_e1000e_wrn_regs_write_unknown(index
<< 2, size
, val
);
3257 e1000e_core_read(E1000ECore
*core
, hwaddr addr
, unsigned size
)
3260 uint16_t index
= e1000e_get_reg_index_with_offset(mac_reg_access
, addr
);
3262 if (index
< E1000E_NREADOPS
&& e1000e_macreg_readops
[index
]) {
3263 if (mac_reg_access
[index
] & MAC_ACCESS_PARTIAL
) {
3264 trace_e1000e_wrn_regs_read_trivial(index
<< 2);
3266 val
= e1000e_macreg_readops
[index
](core
, index
);
3267 trace_e1000e_core_read(index
<< 2, size
, val
);
3270 trace_e1000e_wrn_regs_read_unknown(index
<< 2, size
);
3276 e1000e_autoneg_pause(E1000ECore
*core
)
3278 timer_del(core
->autoneg_timer
);
3282 e1000e_autoneg_resume(E1000ECore
*core
)
3284 if (e1000e_have_autoneg(core
) &&
3285 !(core
->phy
[0][PHY_STATUS
] & MII_SR_AUTONEG_COMPLETE
)) {
3286 qemu_get_queue(core
->owner_nic
)->link_down
= false;
3287 timer_mod(core
->autoneg_timer
,
3288 qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL
) + 500);
3293 e1000e_vm_state_change(void *opaque
, int running
, RunState state
)
3295 E1000ECore
*core
= opaque
;
3298 trace_e1000e_vm_state_running();
3299 e1000e_intrmgr_resume(core
);
3300 e1000e_autoneg_resume(core
);
3302 trace_e1000e_vm_state_stopped();
3303 e1000e_autoneg_pause(core
);
3304 e1000e_intrmgr_pause(core
);
3309 e1000e_core_pci_realize(E1000ECore
*core
,
3310 const uint16_t *eeprom_templ
,
3311 uint32_t eeprom_size
,
3312 const uint8_t *macaddr
)
3316 core
->autoneg_timer
= timer_new_ms(QEMU_CLOCK_VIRTUAL
,
3317 e1000e_autoneg_timer
, core
);
3318 e1000e_intrmgr_pci_realize(core
);
3321 qemu_add_vm_change_state_handler(e1000e_vm_state_change
, core
);
3323 for (i
= 0; i
< E1000E_NUM_QUEUES
; i
++) {
3324 net_tx_pkt_init(&core
->tx
[i
].tx_pkt
, core
->owner
,
3325 E1000E_MAX_TX_FRAGS
, core
->has_vnet
);
3328 net_rx_pkt_init(&core
->rx_pkt
, core
->has_vnet
);
3330 e1000x_core_prepare_eeprom(core
->eeprom
,
3333 PCI_DEVICE_GET_CLASS(core
->owner
)->device_id
,
3335 e1000e_update_rx_offloads(core
);
3339 e1000e_core_pci_uninit(E1000ECore
*core
)
3343 timer_del(core
->autoneg_timer
);
3344 timer_free(core
->autoneg_timer
);
3346 e1000e_intrmgr_pci_unint(core
);
3348 qemu_del_vm_change_state_handler(core
->vmstate
);
3350 for (i
= 0; i
< E1000E_NUM_QUEUES
; i
++) {
3351 net_tx_pkt_reset(core
->tx
[i
].tx_pkt
);
3352 net_tx_pkt_uninit(core
->tx
[i
].tx_pkt
);
3355 net_rx_pkt_uninit(core
->rx_pkt
);
3358 static const uint16_t
3359 e1000e_phy_reg_init
[E1000E_PHY_PAGES
][E1000E_PHY_PAGE_SIZE
] = {
3361 [PHY_CTRL
] = MII_CR_SPEED_SELECT_MSB
|
3362 MII_CR_FULL_DUPLEX
|
3365 [PHY_STATUS
] = MII_SR_EXTENDED_CAPS
|
3366 MII_SR_LINK_STATUS
|
3367 MII_SR_AUTONEG_CAPS
|
3368 MII_SR_PREAMBLE_SUPPRESS
|
3369 MII_SR_EXTENDED_STATUS
|
3370 MII_SR_10T_HD_CAPS
|
3371 MII_SR_10T_FD_CAPS
|
3372 MII_SR_100X_HD_CAPS
|
3373 MII_SR_100X_FD_CAPS
,
3376 [PHY_ID2
] = E1000_PHY_ID2_82574x
,
3377 [PHY_AUTONEG_ADV
] = 0xde1,
3378 [PHY_LP_ABILITY
] = 0x7e0,
3379 [PHY_AUTONEG_EXP
] = BIT(2),
3380 [PHY_NEXT_PAGE_TX
] = BIT(0) | BIT(13),
3381 [PHY_1000T_CTRL
] = BIT(8) | BIT(9) | BIT(10) | BIT(11),
3382 [PHY_1000T_STATUS
] = 0x3c00,
3383 [PHY_EXT_STATUS
] = BIT(12) | BIT(13),
3385 [PHY_COPPER_CTRL1
] = BIT(5) | BIT(6) | BIT(8) | BIT(9) |
3387 [PHY_COPPER_STAT1
] = BIT(3) | BIT(10) | BIT(11) | BIT(13) | BIT(15)
3390 [PHY_MAC_CTRL1
] = BIT(3) | BIT(7),
3391 [PHY_MAC_CTRL2
] = BIT(1) | BIT(2) | BIT(6) | BIT(12)
3394 [PHY_LED_TIMER_CTRL
] = BIT(0) | BIT(2) | BIT(14)
3398 static const uint32_t e1000e_mac_reg_init
[] = {
3400 [LEDCTL
] = BIT(1) | BIT(8) | BIT(9) | BIT(15) | BIT(17) | BIT(18),
3401 [EXTCNF_CTRL
] = BIT(3),
3402 [EEMNGCTL
] = BIT(31),
3404 [FLSWCTL
] = BIT(30) | BIT(31),
3407 [RXDCTL1
] = BIT(16),
3408 [TIPG
] = 0x8 | (0x8 << 10) | (0x6 << 20),
3411 [CTRL
] = E1000_CTRL_FD
| E1000_CTRL_SWDPIN2
| E1000_CTRL_SWDPIN0
|
3412 E1000_CTRL_SPD_1000
| E1000_CTRL_SLU
|
3413 E1000_CTRL_ADVD3WUC
,
3414 [STATUS
] = E1000_STATUS_ASDV_1000
| E1000_STATUS_LU
,
3415 [PSRCTL
] = (2 << E1000_PSRCTL_BSIZE0_SHIFT
) |
3416 (4 << E1000_PSRCTL_BSIZE1_SHIFT
) |
3417 (4 << E1000_PSRCTL_BSIZE2_SHIFT
),
3418 [TARC0
] = 0x3 | E1000_TARC_ENABLE
,
3419 [TARC1
] = 0x3 | E1000_TARC_ENABLE
,
3420 [EECD
] = E1000_EECD_AUTO_RD
| E1000_EECD_PRES
,
3421 [EERD
] = E1000_EERW_DONE
,
3422 [EEWR
] = E1000_EERW_DONE
,
3423 [GCR
] = E1000_L0S_ADJUST
|
3424 E1000_L1_ENTRY_LATENCY_MSB
|
3425 E1000_L1_ENTRY_LATENCY_LSB
,
3432 [MANC
] = E1000_MANC_DIS_IP_CHK_ARP
,
3433 [FACTPS
] = E1000_FACTPS_LAN0_ON
| 0x20000000,
3435 [RXCSUM
] = E1000_RXCSUM_IPOFLD
| E1000_RXCSUM_TUOFLD
,
3436 [ITR
] = E1000E_MIN_XITR
,
3437 [EITR
...EITR
+ E1000E_MSIX_VEC_NUM
- 1] = E1000E_MIN_XITR
,
3441 e1000e_core_reset(E1000ECore
*core
)
3445 timer_del(core
->autoneg_timer
);
3447 e1000e_intrmgr_reset(core
);
3449 memset(core
->phy
, 0, sizeof core
->phy
);
3450 memmove(core
->phy
, e1000e_phy_reg_init
, sizeof e1000e_phy_reg_init
);
3451 memset(core
->mac
, 0, sizeof core
->mac
);
3452 memmove(core
->mac
, e1000e_mac_reg_init
, sizeof e1000e_mac_reg_init
);
3454 core
->rxbuf_min_shift
= 1 + E1000_RING_DESC_LEN_SHIFT
;
3456 if (qemu_get_queue(core
->owner_nic
)->link_down
) {
3457 e1000e_link_down(core
);
3460 e1000x_reset_mac_addr(core
->owner_nic
, core
->mac
, core
->permanent_mac
);
3462 for (i
= 0; i
< ARRAY_SIZE(core
->tx
); i
++) {
3463 net_tx_pkt_reset(core
->tx
[i
].tx_pkt
);
3464 memset(&core
->tx
[i
].props
, 0, sizeof(core
->tx
[i
].props
));
3465 core
->tx
[i
].skip_cp
= false;
3469 void e1000e_core_pre_save(E1000ECore
*core
)
3472 NetClientState
*nc
= qemu_get_queue(core
->owner_nic
);
3475 * If link is down and auto-negotiation is supported and ongoing,
3476 * complete auto-negotiation immediately. This allows us to look
3477 * at MII_SR_AUTONEG_COMPLETE to infer link status on load.
3479 if (nc
->link_down
&& e1000e_have_autoneg(core
)) {
3480 core
->phy
[0][PHY_STATUS
] |= MII_SR_AUTONEG_COMPLETE
;
3481 e1000e_update_flowctl_status(core
);
3484 for (i
= 0; i
< ARRAY_SIZE(core
->tx
); i
++) {
3485 if (net_tx_pkt_has_fragments(core
->tx
[i
].tx_pkt
)) {
3486 core
->tx
[i
].skip_cp
= true;
3492 e1000e_core_post_load(E1000ECore
*core
)
3494 NetClientState
*nc
= qemu_get_queue(core
->owner_nic
);
3496 /* nc.link_down can't be migrated, so infer link_down according
3497 * to link status bit in core.mac[STATUS].
3499 nc
->link_down
= (core
->mac
[STATUS
] & E1000_STATUS_LU
) == 0;