History log of /openbsd-current/sys/dev/pci/if_vge.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.78 24-May-2024 jsg

remove unneeded includes; ok miod@


Revision tags: OPENBSD_7_5_BASE
# 1.77 10-Nov-2023 bluhm

Make ifq and ifiq interface MP safe.

Rename ifq_set_maxlen() to ifq_init_maxlen(). This function neither
uses WRITE_ONCE() nor a mutex and is called before the ifq mutex
is initialized. The new name expresses that it should be used only
during interface attach when there is no concurrency.

Protect ifq_len(), ifq_empty(), ifiq_len(), and ifiq_empty() with
READ_ONCE(). They can be used without lock as they only read a
single integer.

OK dlg@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.76 11-Mar-2022 mpi

Constify struct cfattach.


# 1.75 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.74 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.73 10-Jul-2020 patrick

Change users of IFQ_DEQUEUE(), IFQ_ENQUEUE() and IFQ_LEN() to use the
"new" API.

ok dlg@ tobhe@


Revision tags: OPENBSD_6_7_BASE
# 1.72 05-Jan-2020 jsg

consistently uppercase pci product defines

ok mpi@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.70 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.69 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.68 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.67 16-Nov-2015 dlg

rework vge_start to avoid IFQ_POLL

firstly, this checks for space in the tx ring before looking at the
send queue. if there's no space, then IFF_OACTIVE is set and break.

if there's space use IFQ_DEQUEUE to pull a packet off. if we fail
to encapsulate it, it gets dropped.

encap has been changed so the dmamaps the mbufs are loaded into are
created with 7 segments instead of 32. this means we detect when
the packet would overflow the tx descriptor at dmamap load time,
rather than after we've looped over the segments writing them into
the descriptor. we now use m_defrag to defrag the mbuf instead of
allocating a new one and using m_copydata.

now if we have any encap error on the first mbuf, we no longer set
IFF_OACTIVE and wait for an interrupt that never comes to clear it.

testing and (excellent) code review by richard proctor


# 1.66 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.65 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.64 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


Revision tags: OPENBSD_5_8_BASE
# 1.63 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.62 13-Apr-2015 mpi

Now that if_input() set the receiving interface pointer on mbufs for us
there's no need to do it in m_devget(9).

Stop passing an ``ifp'' will help for upcoming interface pointer -> index
conversion.

While here remove unused ``ifp'' argument from m_clget(9) and kill two
birds^W layer violations in one commit.

ok henning@


# 1.61 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


# 1.60 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.59 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.58 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.57 21-Aug-2013 dlg

get rid of the copy argument in m_devget that let you provide an
alternative to bcopy since noone uses it.

while there use memcpy instead of bcopy because we know the memory cannot
overlap.

ok henning@ matthew@ mikeb@ deraadt@


# 1.56 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.55 15-Mar-2013 brad

Rewrite receive filter handling and ioctl bits.

ok sthen@


# 1.54 14-Mar-2013 brad

Add some missing bits for flow control support and enable it.

Tested with PCI and PCIe vge(4).

ok sthen@


Revision tags: OPENBSD_5_3_BASE
# 1.53 29-Nov-2012 brad

Remove setting an initial assumed baudrate upon driver attach which is not
necessarily correct, there might not even be a link when attaching.

ok mikeb@ reyk@


# 1.52 23-Nov-2012 gsoares

set ifp->if_baudrate with IF_Gbps() / IF_Mbps().

OK reyk@ sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.51 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.50 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


# 1.49 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.48 27-Aug-2010 jsg

remove the unused if_init callback in struct ifnet
ok deraadt@ henning@ claudio@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.47 24-Feb-2010 kettenis

Don't print "EEPROM reload timed out" message. Devices that don't have an
EEPROM exist (RouterBOARD RB600A) and reloading default values from the
EEPROM will fail on those decives.

ok deraadt@


# 1.46 23-Nov-2009 kettenis

Make vge(4) detachable.

ok jsg@, deraadt@


# 1.45 04-Sep-2009 kettenis

Make sure the MAC address is correct on big-endian platforms if it isn't read
from the EEPROM.

ok miod@


# 1.44 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.43 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.42 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.41 22-Oct-2008 brad

Re-add support TX VLAN tag insertion and RX VLAN tag stripping.

Tested by Dawe <dawedawe at gmx dot de>


# 1.40 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.39 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.38 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.37 22-May-2008 mk

More timeout(9) usage cleaned up.

ok claudio


# 1.36 13-May-2008 brad

Since Ethernet links can only be full duplex or half duplex the link
state reporting code in the MII layer / em(4) and vge(4) will never
fall back to the point of only reporting the link as being UP without
the duplex setting being reported, so simplify the code a bit here.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.35 11-Dec-2007 brad

- Remove disabled and unusable HW VLAN tagging code.
- Remove setup of the HW VLAN stripping.

Issue reported by and fix tested by henric@

ok dlg@


# 1.34 10-Oct-2007 kettenis

Fix some obviously bogus code in vge_newbuf(). Should fix PR 5582.

ok claudio@


Revision tags: OPENBSD_4_2_BASE
# 1.33 01-May-2007 canacar

Missing braces in vge_tick(). Fixes link state announcements.
ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.32 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.31 23-Nov-2006 brad

OpenBSD-ify the HW VLAN tag insertion code.


# 1.30 14-Nov-2006 damien

don't always leave the mbuf on the if_snd queue if vge_encap() fails.
if the mbuf is coalesced in vge_encap(), the mbuf reference is no
longer valid. drop the mbuf in this case.

bug introduced in r1.28
tested by Frank Denis
fixes kernel/5291

"go for it" deraadt@


# 1.29 19-Oct-2006 tom

s/Mhz/MHz/ in comments and printf() strings

ok jsg@


# 1.28 03-Oct-2006 damien

don't use IF_PREPEND() on altq's.
use IFQ_POLL()/IFQ_DEQUEUE() logic instead as described in altq(4).

tested by jolan@ on macppc
"diffs look ok" brad@


Revision tags: OPENBSD_4_0_BASE
# 1.27 28-Jul-2006 kettenis

do not bother playing tag with the PCI_COMMAND_STATUS_REG

tested by jolan@, ok brad@


# 1.26 17-Jun-2006 brad

add sys/timeout.h


# 1.25 13-Jun-2006 brad

rev 1.13 fixed the MTU ioctl handler to allow adjusting the MTU
but it seems Jumbo support is broken, so disable Jumbos for now.

issue reported by jolan@


# 1.24 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.23 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.22 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.21 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.20 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.19 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.18 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.17 08-Oct-2005 brad

Some fixes for vge(4)'s multicast handling, including..

- Fix IFF_ALLMULTI handling
- Stop endless loop in multicast hash table filter mode

From christos NetBSD

ok pvalchev@


Revision tags: OPENBSD_3_8_BASE
# 1.16 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.15 03-Jul-2005 brad

enable use of the hardware 64 entry CAM table for perfect multicast
filtering otherwise fallback on the multicast hash table if trying to
filter on more than 64 addresses or if we're trying to flip on ALLMULTI.


# 1.14 03-May-2005 brad

enable HW transmit checksum offload

ok pvalchev@


# 1.13 30-Apr-2005 brad

- Add missing break for SIOCSIFADDR
- Allow setting the MTU

ok pvalchev@


# 1.12 30-Apr-2005 brad

- Correct the if_link_state_change() logic.
- Reading the EEPROM to learn the station address doesn't seem to work
on boards with VIA gigE controllers that are embedded in VIA chipsets.
Presumably, they don't have an external EEPROM and store the MAC
address somewhere else. To get around this, read the station
address from the RX filter registers instead. This has been tested
to work on both embedded and standalone controllers.

From FreeBSD

ok pvalchev@


# 1.11 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.10 08-Apr-2005 brad

fix parenthesis


# 1.9 08-Apr-2005 brad

- enable reception of VLAN sized frames
- enable HW receive checksum offload

ok pvlachev@


# 1.8 02-Apr-2005 brad

make use of if_link_state_change().

From FreeBSD

ok pvalchev@


Revision tags: OPENBSD_3_7_BASE
# 1.7 15-Mar-2005 pvalchev

use IFQ_ rather than IF_ macro here too, maybe helps altq; ok henning


# 1.6 15-Jan-2005 brad

make sure interface is in RUNNING state before touching the multicast filters

From NetBSD

NetBSD PR 27678 for details

ok mcbride@


# 1.5 27-Dec-2004 pvalchev

remove useless debugging leftover


# 1.4 26-Dec-2004 pvalchev

Bounce the mbuf to the BPF listener before committing it to the wire
in the TX case, fixes rare problems associated with accessing already
free'd memory if the encap routine bails out (panic in PROMISC mode).
ok deraadt


# 1.3 26-Dec-2004 pvalchev

htole32 and friends to get this working on big endian (macppc)


# 1.2 12-Dec-2004 pvalchev

a hack to read MAC address correctly on big endian; ok drahn
however a correct clean way to do this should be found


# 1.1 01-Dec-2004 pvalchev

VIA VT612x PCI Gigabit Ethernet adapter support, ok deraadt
from FreeBSD


# 1.77 10-Nov-2023 bluhm

Make ifq and ifiq interface MP safe.

Rename ifq_set_maxlen() to ifq_init_maxlen(). This function neither
uses WRITE_ONCE() nor a mutex and is called before the ifq mutex
is initialized. The new name expresses that it should be used only
during interface attach when there is no concurrency.

Protect ifq_len(), ifq_empty(), ifiq_len(), and ifiq_empty() with
READ_ONCE(). They can be used without lock as they only read a
single integer.

OK dlg@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.76 11-Mar-2022 mpi

Constify struct cfattach.


# 1.75 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.74 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.73 10-Jul-2020 patrick

Change users of IFQ_DEQUEUE(), IFQ_ENQUEUE() and IFQ_LEN() to use the
"new" API.

ok dlg@ tobhe@


Revision tags: OPENBSD_6_7_BASE
# 1.72 05-Jan-2020 jsg

consistently uppercase pci product defines

ok mpi@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.70 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.69 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.68 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.67 16-Nov-2015 dlg

rework vge_start to avoid IFQ_POLL

firstly, this checks for space in the tx ring before looking at the
send queue. if there's no space, then IFF_OACTIVE is set and break.

if there's space use IFQ_DEQUEUE to pull a packet off. if we fail
to encapsulate it, it gets dropped.

encap has been changed so the dmamaps the mbufs are loaded into are
created with 7 segments instead of 32. this means we detect when
the packet would overflow the tx descriptor at dmamap load time,
rather than after we've looped over the segments writing them into
the descriptor. we now use m_defrag to defrag the mbuf instead of
allocating a new one and using m_copydata.

now if we have any encap error on the first mbuf, we no longer set
IFF_OACTIVE and wait for an interrupt that never comes to clear it.

testing and (excellent) code review by richard proctor


# 1.66 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.65 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.64 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


Revision tags: OPENBSD_5_8_BASE
# 1.63 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.62 13-Apr-2015 mpi

Now that if_input() set the receiving interface pointer on mbufs for us
there's no need to do it in m_devget(9).

Stop passing an ``ifp'' will help for upcoming interface pointer -> index
conversion.

While here remove unused ``ifp'' argument from m_clget(9) and kill two
birds^W layer violations in one commit.

ok henning@


# 1.61 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


# 1.60 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.59 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.58 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.57 21-Aug-2013 dlg

get rid of the copy argument in m_devget that let you provide an
alternative to bcopy since noone uses it.

while there use memcpy instead of bcopy because we know the memory cannot
overlap.

ok henning@ matthew@ mikeb@ deraadt@


# 1.56 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.55 15-Mar-2013 brad

Rewrite receive filter handling and ioctl bits.

ok sthen@


# 1.54 14-Mar-2013 brad

Add some missing bits for flow control support and enable it.

Tested with PCI and PCIe vge(4).

ok sthen@


Revision tags: OPENBSD_5_3_BASE
# 1.53 29-Nov-2012 brad

Remove setting an initial assumed baudrate upon driver attach which is not
necessarily correct, there might not even be a link when attaching.

ok mikeb@ reyk@


# 1.52 23-Nov-2012 gsoares

set ifp->if_baudrate with IF_Gbps() / IF_Mbps().

OK reyk@ sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.51 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.50 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


# 1.49 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.48 27-Aug-2010 jsg

remove the unused if_init callback in struct ifnet
ok deraadt@ henning@ claudio@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.47 24-Feb-2010 kettenis

Don't print "EEPROM reload timed out" message. Devices that don't have an
EEPROM exist (RouterBOARD RB600A) and reloading default values from the
EEPROM will fail on those decives.

ok deraadt@


# 1.46 23-Nov-2009 kettenis

Make vge(4) detachable.

ok jsg@, deraadt@


# 1.45 04-Sep-2009 kettenis

Make sure the MAC address is correct on big-endian platforms if it isn't read
from the EEPROM.

ok miod@


# 1.44 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.43 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.42 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.41 22-Oct-2008 brad

Re-add support TX VLAN tag insertion and RX VLAN tag stripping.

Tested by Dawe <dawedawe at gmx dot de>


# 1.40 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.39 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.38 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.37 22-May-2008 mk

More timeout(9) usage cleaned up.

ok claudio


# 1.36 13-May-2008 brad

Since Ethernet links can only be full duplex or half duplex the link
state reporting code in the MII layer / em(4) and vge(4) will never
fall back to the point of only reporting the link as being UP without
the duplex setting being reported, so simplify the code a bit here.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.35 11-Dec-2007 brad

- Remove disabled and unusable HW VLAN tagging code.
- Remove setup of the HW VLAN stripping.

Issue reported by and fix tested by henric@

ok dlg@


# 1.34 10-Oct-2007 kettenis

Fix some obviously bogus code in vge_newbuf(). Should fix PR 5582.

ok claudio@


Revision tags: OPENBSD_4_2_BASE
# 1.33 01-May-2007 canacar

Missing braces in vge_tick(). Fixes link state announcements.
ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.32 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.31 23-Nov-2006 brad

OpenBSD-ify the HW VLAN tag insertion code.


# 1.30 14-Nov-2006 damien

don't always leave the mbuf on the if_snd queue if vge_encap() fails.
if the mbuf is coalesced in vge_encap(), the mbuf reference is no
longer valid. drop the mbuf in this case.

bug introduced in r1.28
tested by Frank Denis
fixes kernel/5291

"go for it" deraadt@


# 1.29 19-Oct-2006 tom

s/Mhz/MHz/ in comments and printf() strings

ok jsg@


# 1.28 03-Oct-2006 damien

don't use IF_PREPEND() on altq's.
use IFQ_POLL()/IFQ_DEQUEUE() logic instead as described in altq(4).

tested by jolan@ on macppc
"diffs look ok" brad@


Revision tags: OPENBSD_4_0_BASE
# 1.27 28-Jul-2006 kettenis

do not bother playing tag with the PCI_COMMAND_STATUS_REG

tested by jolan@, ok brad@


# 1.26 17-Jun-2006 brad

add sys/timeout.h


# 1.25 13-Jun-2006 brad

rev 1.13 fixed the MTU ioctl handler to allow adjusting the MTU
but it seems Jumbo support is broken, so disable Jumbos for now.

issue reported by jolan@


# 1.24 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.23 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.22 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.21 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.20 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.19 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.18 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.17 08-Oct-2005 brad

Some fixes for vge(4)'s multicast handling, including..

- Fix IFF_ALLMULTI handling
- Stop endless loop in multicast hash table filter mode

From christos NetBSD

ok pvalchev@


Revision tags: OPENBSD_3_8_BASE
# 1.16 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.15 03-Jul-2005 brad

enable use of the hardware 64 entry CAM table for perfect multicast
filtering otherwise fallback on the multicast hash table if trying to
filter on more than 64 addresses or if we're trying to flip on ALLMULTI.


# 1.14 03-May-2005 brad

enable HW transmit checksum offload

ok pvalchev@


# 1.13 30-Apr-2005 brad

- Add missing break for SIOCSIFADDR
- Allow setting the MTU

ok pvalchev@


# 1.12 30-Apr-2005 brad

- Correct the if_link_state_change() logic.
- Reading the EEPROM to learn the station address doesn't seem to work
on boards with VIA gigE controllers that are embedded in VIA chipsets.
Presumably, they don't have an external EEPROM and store the MAC
address somewhere else. To get around this, read the station
address from the RX filter registers instead. This has been tested
to work on both embedded and standalone controllers.

From FreeBSD

ok pvalchev@


# 1.11 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.10 08-Apr-2005 brad

fix parenthesis


# 1.9 08-Apr-2005 brad

- enable reception of VLAN sized frames
- enable HW receive checksum offload

ok pvlachev@


# 1.8 02-Apr-2005 brad

make use of if_link_state_change().

From FreeBSD

ok pvalchev@


Revision tags: OPENBSD_3_7_BASE
# 1.7 15-Mar-2005 pvalchev

use IFQ_ rather than IF_ macro here too, maybe helps altq; ok henning


# 1.6 15-Jan-2005 brad

make sure interface is in RUNNING state before touching the multicast filters

From NetBSD

NetBSD PR 27678 for details

ok mcbride@


# 1.5 27-Dec-2004 pvalchev

remove useless debugging leftover


# 1.4 26-Dec-2004 pvalchev

Bounce the mbuf to the BPF listener before committing it to the wire
in the TX case, fixes rare problems associated with accessing already
free'd memory if the encap routine bails out (panic in PROMISC mode).
ok deraadt


# 1.3 26-Dec-2004 pvalchev

htole32 and friends to get this working on big endian (macppc)


# 1.2 12-Dec-2004 pvalchev

a hack to read MAC address correctly on big endian; ok drahn
however a correct clean way to do this should be found


# 1.1 01-Dec-2004 pvalchev

VIA VT612x PCI Gigabit Ethernet adapter support, ok deraadt
from FreeBSD


# 1.76 11-Mar-2022 mpi

Constify struct cfattach.


# 1.75 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.74 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.73 10-Jul-2020 patrick

Change users of IFQ_DEQUEUE(), IFQ_ENQUEUE() and IFQ_LEN() to use the
"new" API.

ok dlg@ tobhe@


Revision tags: OPENBSD_6_7_BASE
# 1.72 05-Jan-2020 jsg

consistently uppercase pci product defines

ok mpi@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.70 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.69 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.68 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.67 16-Nov-2015 dlg

rework vge_start to avoid IFQ_POLL

firstly, this checks for space in the tx ring before looking at the
send queue. if there's no space, then IFF_OACTIVE is set and break.

if there's space use IFQ_DEQUEUE to pull a packet off. if we fail
to encapsulate it, it gets dropped.

encap has been changed so the dmamaps the mbufs are loaded into are
created with 7 segments instead of 32. this means we detect when
the packet would overflow the tx descriptor at dmamap load time,
rather than after we've looped over the segments writing them into
the descriptor. we now use m_defrag to defrag the mbuf instead of
allocating a new one and using m_copydata.

now if we have any encap error on the first mbuf, we no longer set
IFF_OACTIVE and wait for an interrupt that never comes to clear it.

testing and (excellent) code review by richard proctor


# 1.66 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.65 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.64 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


Revision tags: OPENBSD_5_8_BASE
# 1.63 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.62 13-Apr-2015 mpi

Now that if_input() set the receiving interface pointer on mbufs for us
there's no need to do it in m_devget(9).

Stop passing an ``ifp'' will help for upcoming interface pointer -> index
conversion.

While here remove unused ``ifp'' argument from m_clget(9) and kill two
birds^W layer violations in one commit.

ok henning@


# 1.61 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


# 1.60 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.59 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.58 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.57 21-Aug-2013 dlg

get rid of the copy argument in m_devget that let you provide an
alternative to bcopy since noone uses it.

while there use memcpy instead of bcopy because we know the memory cannot
overlap.

ok henning@ matthew@ mikeb@ deraadt@


# 1.56 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.55 15-Mar-2013 brad

Rewrite receive filter handling and ioctl bits.

ok sthen@


# 1.54 14-Mar-2013 brad

Add some missing bits for flow control support and enable it.

Tested with PCI and PCIe vge(4).

ok sthen@


Revision tags: OPENBSD_5_3_BASE
# 1.53 29-Nov-2012 brad

Remove setting an initial assumed baudrate upon driver attach which is not
necessarily correct, there might not even be a link when attaching.

ok mikeb@ reyk@


# 1.52 23-Nov-2012 gsoares

set ifp->if_baudrate with IF_Gbps() / IF_Mbps().

OK reyk@ sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.51 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.50 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


# 1.49 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.48 27-Aug-2010 jsg

remove the unused if_init callback in struct ifnet
ok deraadt@ henning@ claudio@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.47 24-Feb-2010 kettenis

Don't print "EEPROM reload timed out" message. Devices that don't have an
EEPROM exist (RouterBOARD RB600A) and reloading default values from the
EEPROM will fail on those decives.

ok deraadt@


# 1.46 23-Nov-2009 kettenis

Make vge(4) detachable.

ok jsg@, deraadt@


# 1.45 04-Sep-2009 kettenis

Make sure the MAC address is correct on big-endian platforms if it isn't read
from the EEPROM.

ok miod@


# 1.44 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.43 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.42 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.41 22-Oct-2008 brad

Re-add support TX VLAN tag insertion and RX VLAN tag stripping.

Tested by Dawe <dawedawe at gmx dot de>


# 1.40 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.39 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.38 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.37 22-May-2008 mk

More timeout(9) usage cleaned up.

ok claudio


# 1.36 13-May-2008 brad

Since Ethernet links can only be full duplex or half duplex the link
state reporting code in the MII layer / em(4) and vge(4) will never
fall back to the point of only reporting the link as being UP without
the duplex setting being reported, so simplify the code a bit here.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.35 11-Dec-2007 brad

- Remove disabled and unusable HW VLAN tagging code.
- Remove setup of the HW VLAN stripping.

Issue reported by and fix tested by henric@

ok dlg@


# 1.34 10-Oct-2007 kettenis

Fix some obviously bogus code in vge_newbuf(). Should fix PR 5582.

ok claudio@


Revision tags: OPENBSD_4_2_BASE
# 1.33 01-May-2007 canacar

Missing braces in vge_tick(). Fixes link state announcements.
ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.32 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.31 23-Nov-2006 brad

OpenBSD-ify the HW VLAN tag insertion code.


# 1.30 14-Nov-2006 damien

don't always leave the mbuf on the if_snd queue if vge_encap() fails.
if the mbuf is coalesced in vge_encap(), the mbuf reference is no
longer valid. drop the mbuf in this case.

bug introduced in r1.28
tested by Frank Denis
fixes kernel/5291

"go for it" deraadt@


# 1.29 19-Oct-2006 tom

s/Mhz/MHz/ in comments and printf() strings

ok jsg@


# 1.28 03-Oct-2006 damien

don't use IF_PREPEND() on altq's.
use IFQ_POLL()/IFQ_DEQUEUE() logic instead as described in altq(4).

tested by jolan@ on macppc
"diffs look ok" brad@


Revision tags: OPENBSD_4_0_BASE
# 1.27 28-Jul-2006 kettenis

do not bother playing tag with the PCI_COMMAND_STATUS_REG

tested by jolan@, ok brad@


# 1.26 17-Jun-2006 brad

add sys/timeout.h


# 1.25 13-Jun-2006 brad

rev 1.13 fixed the MTU ioctl handler to allow adjusting the MTU
but it seems Jumbo support is broken, so disable Jumbos for now.

issue reported by jolan@


# 1.24 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.23 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.22 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.21 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.20 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.19 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.18 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.17 08-Oct-2005 brad

Some fixes for vge(4)'s multicast handling, including..

- Fix IFF_ALLMULTI handling
- Stop endless loop in multicast hash table filter mode

From christos NetBSD

ok pvalchev@


Revision tags: OPENBSD_3_8_BASE
# 1.16 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.15 03-Jul-2005 brad

enable use of the hardware 64 entry CAM table for perfect multicast
filtering otherwise fallback on the multicast hash table if trying to
filter on more than 64 addresses or if we're trying to flip on ALLMULTI.


# 1.14 03-May-2005 brad

enable HW transmit checksum offload

ok pvalchev@


# 1.13 30-Apr-2005 brad

- Add missing break for SIOCSIFADDR
- Allow setting the MTU

ok pvalchev@


# 1.12 30-Apr-2005 brad

- Correct the if_link_state_change() logic.
- Reading the EEPROM to learn the station address doesn't seem to work
on boards with VIA gigE controllers that are embedded in VIA chipsets.
Presumably, they don't have an external EEPROM and store the MAC
address somewhere else. To get around this, read the station
address from the RX filter registers instead. This has been tested
to work on both embedded and standalone controllers.

From FreeBSD

ok pvalchev@


# 1.11 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.10 08-Apr-2005 brad

fix parenthesis


# 1.9 08-Apr-2005 brad

- enable reception of VLAN sized frames
- enable HW receive checksum offload

ok pvlachev@


# 1.8 02-Apr-2005 brad

make use of if_link_state_change().

From FreeBSD

ok pvalchev@


Revision tags: OPENBSD_3_7_BASE
# 1.7 15-Mar-2005 pvalchev

use IFQ_ rather than IF_ macro here too, maybe helps altq; ok henning


# 1.6 15-Jan-2005 brad

make sure interface is in RUNNING state before touching the multicast filters

From NetBSD

NetBSD PR 27678 for details

ok mcbride@


# 1.5 27-Dec-2004 pvalchev

remove useless debugging leftover


# 1.4 26-Dec-2004 pvalchev

Bounce the mbuf to the BPF listener before committing it to the wire
in the TX case, fixes rare problems associated with accessing already
free'd memory if the encap routine bails out (panic in PROMISC mode).
ok deraadt


# 1.3 26-Dec-2004 pvalchev

htole32 and friends to get this working on big endian (macppc)


# 1.2 12-Dec-2004 pvalchev

a hack to read MAC address correctly on big endian; ok drahn
however a correct clean way to do this should be found


# 1.1 01-Dec-2004 pvalchev

VIA VT612x PCI Gigabit Ethernet adapter support, ok deraadt
from FreeBSD


# 1.75 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.74 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.73 10-Jul-2020 patrick

Change users of IFQ_DEQUEUE(), IFQ_ENQUEUE() and IFQ_LEN() to use the
"new" API.

ok dlg@ tobhe@


Revision tags: OPENBSD_6_7_BASE
# 1.72 05-Jan-2020 jsg

consistently uppercase pci product defines

ok mpi@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.70 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.69 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.68 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.67 16-Nov-2015 dlg

rework vge_start to avoid IFQ_POLL

firstly, this checks for space in the tx ring before looking at the
send queue. if there's no space, then IFF_OACTIVE is set and break.

if there's space use IFQ_DEQUEUE to pull a packet off. if we fail
to encapsulate it, it gets dropped.

encap has been changed so the dmamaps the mbufs are loaded into are
created with 7 segments instead of 32. this means we detect when
the packet would overflow the tx descriptor at dmamap load time,
rather than after we've looped over the segments writing them into
the descriptor. we now use m_defrag to defrag the mbuf instead of
allocating a new one and using m_copydata.

now if we have any encap error on the first mbuf, we no longer set
IFF_OACTIVE and wait for an interrupt that never comes to clear it.

testing and (excellent) code review by richard proctor


# 1.66 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.65 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.64 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


Revision tags: OPENBSD_5_8_BASE
# 1.63 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.62 13-Apr-2015 mpi

Now that if_input() set the receiving interface pointer on mbufs for us
there's no need to do it in m_devget(9).

Stop passing an ``ifp'' will help for upcoming interface pointer -> index
conversion.

While here remove unused ``ifp'' argument from m_clget(9) and kill two
birds^W layer violations in one commit.

ok henning@


# 1.61 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


# 1.60 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.59 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.58 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.57 21-Aug-2013 dlg

get rid of the copy argument in m_devget that let you provide an
alternative to bcopy since noone uses it.

while there use memcpy instead of bcopy because we know the memory cannot
overlap.

ok henning@ matthew@ mikeb@ deraadt@


# 1.56 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.55 15-Mar-2013 brad

Rewrite receive filter handling and ioctl bits.

ok sthen@


# 1.54 14-Mar-2013 brad

Add some missing bits for flow control support and enable it.

Tested with PCI and PCIe vge(4).

ok sthen@


Revision tags: OPENBSD_5_3_BASE
# 1.53 29-Nov-2012 brad

Remove setting an initial assumed baudrate upon driver attach which is not
necessarily correct, there might not even be a link when attaching.

ok mikeb@ reyk@


# 1.52 23-Nov-2012 gsoares

set ifp->if_baudrate with IF_Gbps() / IF_Mbps().

OK reyk@ sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.51 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.50 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


# 1.49 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.48 27-Aug-2010 jsg

remove the unused if_init callback in struct ifnet
ok deraadt@ henning@ claudio@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.47 24-Feb-2010 kettenis

Don't print "EEPROM reload timed out" message. Devices that don't have an
EEPROM exist (RouterBOARD RB600A) and reloading default values from the
EEPROM will fail on those decives.

ok deraadt@


# 1.46 23-Nov-2009 kettenis

Make vge(4) detachable.

ok jsg@, deraadt@


# 1.45 04-Sep-2009 kettenis

Make sure the MAC address is correct on big-endian platforms if it isn't read
from the EEPROM.

ok miod@


# 1.44 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.43 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.42 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.41 22-Oct-2008 brad

Re-add support TX VLAN tag insertion and RX VLAN tag stripping.

Tested by Dawe <dawedawe at gmx dot de>


# 1.40 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.39 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.38 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.37 22-May-2008 mk

More timeout(9) usage cleaned up.

ok claudio


# 1.36 13-May-2008 brad

Since Ethernet links can only be full duplex or half duplex the link
state reporting code in the MII layer / em(4) and vge(4) will never
fall back to the point of only reporting the link as being UP without
the duplex setting being reported, so simplify the code a bit here.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.35 11-Dec-2007 brad

- Remove disabled and unusable HW VLAN tagging code.
- Remove setup of the HW VLAN stripping.

Issue reported by and fix tested by henric@

ok dlg@


# 1.34 10-Oct-2007 kettenis

Fix some obviously bogus code in vge_newbuf(). Should fix PR 5582.

ok claudio@


Revision tags: OPENBSD_4_2_BASE
# 1.33 01-May-2007 canacar

Missing braces in vge_tick(). Fixes link state announcements.
ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.32 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.31 23-Nov-2006 brad

OpenBSD-ify the HW VLAN tag insertion code.


# 1.30 14-Nov-2006 damien

don't always leave the mbuf on the if_snd queue if vge_encap() fails.
if the mbuf is coalesced in vge_encap(), the mbuf reference is no
longer valid. drop the mbuf in this case.

bug introduced in r1.28
tested by Frank Denis
fixes kernel/5291

"go for it" deraadt@


# 1.29 19-Oct-2006 tom

s/Mhz/MHz/ in comments and printf() strings

ok jsg@


# 1.28 03-Oct-2006 damien

don't use IF_PREPEND() on altq's.
use IFQ_POLL()/IFQ_DEQUEUE() logic instead as described in altq(4).

tested by jolan@ on macppc
"diffs look ok" brad@


Revision tags: OPENBSD_4_0_BASE
# 1.27 28-Jul-2006 kettenis

do not bother playing tag with the PCI_COMMAND_STATUS_REG

tested by jolan@, ok brad@


# 1.26 17-Jun-2006 brad

add sys/timeout.h


# 1.25 13-Jun-2006 brad

rev 1.13 fixed the MTU ioctl handler to allow adjusting the MTU
but it seems Jumbo support is broken, so disable Jumbos for now.

issue reported by jolan@


# 1.24 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.23 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.22 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.21 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.20 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.19 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.18 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.17 08-Oct-2005 brad

Some fixes for vge(4)'s multicast handling, including..

- Fix IFF_ALLMULTI handling
- Stop endless loop in multicast hash table filter mode

From christos NetBSD

ok pvalchev@


Revision tags: OPENBSD_3_8_BASE
# 1.16 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.15 03-Jul-2005 brad

enable use of the hardware 64 entry CAM table for perfect multicast
filtering otherwise fallback on the multicast hash table if trying to
filter on more than 64 addresses or if we're trying to flip on ALLMULTI.


# 1.14 03-May-2005 brad

enable HW transmit checksum offload

ok pvalchev@


# 1.13 30-Apr-2005 brad

- Add missing break for SIOCSIFADDR
- Allow setting the MTU

ok pvalchev@


# 1.12 30-Apr-2005 brad

- Correct the if_link_state_change() logic.
- Reading the EEPROM to learn the station address doesn't seem to work
on boards with VIA gigE controllers that are embedded in VIA chipsets.
Presumably, they don't have an external EEPROM and store the MAC
address somewhere else. To get around this, read the station
address from the RX filter registers instead. This has been tested
to work on both embedded and standalone controllers.

From FreeBSD

ok pvalchev@


# 1.11 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.10 08-Apr-2005 brad

fix parenthesis


# 1.9 08-Apr-2005 brad

- enable reception of VLAN sized frames
- enable HW receive checksum offload

ok pvlachev@


# 1.8 02-Apr-2005 brad

make use of if_link_state_change().

From FreeBSD

ok pvalchev@


Revision tags: OPENBSD_3_7_BASE
# 1.7 15-Mar-2005 pvalchev

use IFQ_ rather than IF_ macro here too, maybe helps altq; ok henning


# 1.6 15-Jan-2005 brad

make sure interface is in RUNNING state before touching the multicast filters

From NetBSD

NetBSD PR 27678 for details

ok mcbride@


# 1.5 27-Dec-2004 pvalchev

remove useless debugging leftover


# 1.4 26-Dec-2004 pvalchev

Bounce the mbuf to the BPF listener before committing it to the wire
in the TX case, fixes rare problems associated with accessing already
free'd memory if the encap routine bails out (panic in PROMISC mode).
ok deraadt


# 1.3 26-Dec-2004 pvalchev

htole32 and friends to get this working on big endian (macppc)


# 1.2 12-Dec-2004 pvalchev

a hack to read MAC address correctly on big endian; ok drahn
however a correct clean way to do this should be found


# 1.1 01-Dec-2004 pvalchev

VIA VT612x PCI Gigabit Ethernet adapter support, ok deraadt
from FreeBSD


# 1.74 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.73 10-Jul-2020 patrick

Change users of IFQ_DEQUEUE(), IFQ_ENQUEUE() and IFQ_LEN() to use the
"new" API.

ok dlg@ tobhe@


Revision tags: OPENBSD_6_7_BASE
# 1.72 05-Jan-2020 jsg

consistently uppercase pci product defines

ok mpi@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.70 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.69 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.68 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.67 16-Nov-2015 dlg

rework vge_start to avoid IFQ_POLL

firstly, this checks for space in the tx ring before looking at the
send queue. if there's no space, then IFF_OACTIVE is set and break.

if there's space use IFQ_DEQUEUE to pull a packet off. if we fail
to encapsulate it, it gets dropped.

encap has been changed so the dmamaps the mbufs are loaded into are
created with 7 segments instead of 32. this means we detect when
the packet would overflow the tx descriptor at dmamap load time,
rather than after we've looped over the segments writing them into
the descriptor. we now use m_defrag to defrag the mbuf instead of
allocating a new one and using m_copydata.

now if we have any encap error on the first mbuf, we no longer set
IFF_OACTIVE and wait for an interrupt that never comes to clear it.

testing and (excellent) code review by richard proctor


# 1.66 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.65 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.64 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


Revision tags: OPENBSD_5_8_BASE
# 1.63 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.62 13-Apr-2015 mpi

Now that if_input() set the receiving interface pointer on mbufs for us
there's no need to do it in m_devget(9).

Stop passing an ``ifp'' will help for upcoming interface pointer -> index
conversion.

While here remove unused ``ifp'' argument from m_clget(9) and kill two
birds^W layer violations in one commit.

ok henning@


# 1.61 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


# 1.60 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.59 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.58 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.57 21-Aug-2013 dlg

get rid of the copy argument in m_devget that let you provide an
alternative to bcopy since noone uses it.

while there use memcpy instead of bcopy because we know the memory cannot
overlap.

ok henning@ matthew@ mikeb@ deraadt@


# 1.56 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.55 15-Mar-2013 brad

Rewrite receive filter handling and ioctl bits.

ok sthen@


# 1.54 14-Mar-2013 brad

Add some missing bits for flow control support and enable it.

Tested with PCI and PCIe vge(4).

ok sthen@


Revision tags: OPENBSD_5_3_BASE
# 1.53 29-Nov-2012 brad

Remove setting an initial assumed baudrate upon driver attach which is not
necessarily correct, there might not even be a link when attaching.

ok mikeb@ reyk@


# 1.52 23-Nov-2012 gsoares

set ifp->if_baudrate with IF_Gbps() / IF_Mbps().

OK reyk@ sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.51 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.50 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


# 1.49 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.48 27-Aug-2010 jsg

remove the unused if_init callback in struct ifnet
ok deraadt@ henning@ claudio@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.47 24-Feb-2010 kettenis

Don't print "EEPROM reload timed out" message. Devices that don't have an
EEPROM exist (RouterBOARD RB600A) and reloading default values from the
EEPROM will fail on those decives.

ok deraadt@


# 1.46 23-Nov-2009 kettenis

Make vge(4) detachable.

ok jsg@, deraadt@


# 1.45 04-Sep-2009 kettenis

Make sure the MAC address is correct on big-endian platforms if it isn't read
from the EEPROM.

ok miod@


# 1.44 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.43 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.42 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.41 22-Oct-2008 brad

Re-add support TX VLAN tag insertion and RX VLAN tag stripping.

Tested by Dawe <dawedawe at gmx dot de>


# 1.40 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.39 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.38 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.37 22-May-2008 mk

More timeout(9) usage cleaned up.

ok claudio


# 1.36 13-May-2008 brad

Since Ethernet links can only be full duplex or half duplex the link
state reporting code in the MII layer / em(4) and vge(4) will never
fall back to the point of only reporting the link as being UP without
the duplex setting being reported, so simplify the code a bit here.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.35 11-Dec-2007 brad

- Remove disabled and unusable HW VLAN tagging code.
- Remove setup of the HW VLAN stripping.

Issue reported by and fix tested by henric@

ok dlg@


# 1.34 10-Oct-2007 kettenis

Fix some obviously bogus code in vge_newbuf(). Should fix PR 5582.

ok claudio@


Revision tags: OPENBSD_4_2_BASE
# 1.33 01-May-2007 canacar

Missing braces in vge_tick(). Fixes link state announcements.
ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.32 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.31 23-Nov-2006 brad

OpenBSD-ify the HW VLAN tag insertion code.


# 1.30 14-Nov-2006 damien

don't always leave the mbuf on the if_snd queue if vge_encap() fails.
if the mbuf is coalesced in vge_encap(), the mbuf reference is no
longer valid. drop the mbuf in this case.

bug introduced in r1.28
tested by Frank Denis
fixes kernel/5291

"go for it" deraadt@


# 1.29 19-Oct-2006 tom

s/Mhz/MHz/ in comments and printf() strings

ok jsg@


# 1.28 03-Oct-2006 damien

don't use IF_PREPEND() on altq's.
use IFQ_POLL()/IFQ_DEQUEUE() logic instead as described in altq(4).

tested by jolan@ on macppc
"diffs look ok" brad@


Revision tags: OPENBSD_4_0_BASE
# 1.27 28-Jul-2006 kettenis

do not bother playing tag with the PCI_COMMAND_STATUS_REG

tested by jolan@, ok brad@


# 1.26 17-Jun-2006 brad

add sys/timeout.h


# 1.25 13-Jun-2006 brad

rev 1.13 fixed the MTU ioctl handler to allow adjusting the MTU
but it seems Jumbo support is broken, so disable Jumbos for now.

issue reported by jolan@


# 1.24 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.23 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.22 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.21 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.20 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.19 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.18 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.17 08-Oct-2005 brad

Some fixes for vge(4)'s multicast handling, including..

- Fix IFF_ALLMULTI handling
- Stop endless loop in multicast hash table filter mode

From christos NetBSD

ok pvalchev@


Revision tags: OPENBSD_3_8_BASE
# 1.16 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.15 03-Jul-2005 brad

enable use of the hardware 64 entry CAM table for perfect multicast
filtering otherwise fallback on the multicast hash table if trying to
filter on more than 64 addresses or if we're trying to flip on ALLMULTI.


# 1.14 03-May-2005 brad

enable HW transmit checksum offload

ok pvalchev@


# 1.13 30-Apr-2005 brad

- Add missing break for SIOCSIFADDR
- Allow setting the MTU

ok pvalchev@


# 1.12 30-Apr-2005 brad

- Correct the if_link_state_change() logic.
- Reading the EEPROM to learn the station address doesn't seem to work
on boards with VIA gigE controllers that are embedded in VIA chipsets.
Presumably, they don't have an external EEPROM and store the MAC
address somewhere else. To get around this, read the station
address from the RX filter registers instead. This has been tested
to work on both embedded and standalone controllers.

From FreeBSD

ok pvalchev@


# 1.11 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.10 08-Apr-2005 brad

fix parenthesis


# 1.9 08-Apr-2005 brad

- enable reception of VLAN sized frames
- enable HW receive checksum offload

ok pvlachev@


# 1.8 02-Apr-2005 brad

make use of if_link_state_change().

From FreeBSD

ok pvalchev@


Revision tags: OPENBSD_3_7_BASE
# 1.7 15-Mar-2005 pvalchev

use IFQ_ rather than IF_ macro here too, maybe helps altq; ok henning


# 1.6 15-Jan-2005 brad

make sure interface is in RUNNING state before touching the multicast filters

From NetBSD

NetBSD PR 27678 for details

ok mcbride@


# 1.5 27-Dec-2004 pvalchev

remove useless debugging leftover


# 1.4 26-Dec-2004 pvalchev

Bounce the mbuf to the BPF listener before committing it to the wire
in the TX case, fixes rare problems associated with accessing already
free'd memory if the encap routine bails out (panic in PROMISC mode).
ok deraadt


# 1.3 26-Dec-2004 pvalchev

htole32 and friends to get this working on big endian (macppc)


# 1.2 12-Dec-2004 pvalchev

a hack to read MAC address correctly on big endian; ok drahn
however a correct clean way to do this should be found


# 1.1 01-Dec-2004 pvalchev

VIA VT612x PCI Gigabit Ethernet adapter support, ok deraadt
from FreeBSD


# 1.72 05-Jan-2020 jsg

consistently uppercase pci product defines

ok mpi@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.70 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.69 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.68 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.67 16-Nov-2015 dlg

rework vge_start to avoid IFQ_POLL

firstly, this checks for space in the tx ring before looking at the
send queue. if there's no space, then IFF_OACTIVE is set and break.

if there's space use IFQ_DEQUEUE to pull a packet off. if we fail
to encapsulate it, it gets dropped.

encap has been changed so the dmamaps the mbufs are loaded into are
created with 7 segments instead of 32. this means we detect when
the packet would overflow the tx descriptor at dmamap load time,
rather than after we've looped over the segments writing them into
the descriptor. we now use m_defrag to defrag the mbuf instead of
allocating a new one and using m_copydata.

now if we have any encap error on the first mbuf, we no longer set
IFF_OACTIVE and wait for an interrupt that never comes to clear it.

testing and (excellent) code review by richard proctor


# 1.66 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.65 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.64 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


Revision tags: OPENBSD_5_8_BASE
# 1.63 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.62 13-Apr-2015 mpi

Now that if_input() set the receiving interface pointer on mbufs for us
there's no need to do it in m_devget(9).

Stop passing an ``ifp'' will help for upcoming interface pointer -> index
conversion.

While here remove unused ``ifp'' argument from m_clget(9) and kill two
birds^W layer violations in one commit.

ok henning@


# 1.61 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


# 1.60 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.59 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.58 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.57 21-Aug-2013 dlg

get rid of the copy argument in m_devget that let you provide an
alternative to bcopy since noone uses it.

while there use memcpy instead of bcopy because we know the memory cannot
overlap.

ok henning@ matthew@ mikeb@ deraadt@


# 1.56 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.55 15-Mar-2013 brad

Rewrite receive filter handling and ioctl bits.

ok sthen@


# 1.54 14-Mar-2013 brad

Add some missing bits for flow control support and enable it.

Tested with PCI and PCIe vge(4).

ok sthen@


Revision tags: OPENBSD_5_3_BASE
# 1.53 29-Nov-2012 brad

Remove setting an initial assumed baudrate upon driver attach which is not
necessarily correct, there might not even be a link when attaching.

ok mikeb@ reyk@


# 1.52 23-Nov-2012 gsoares

set ifp->if_baudrate with IF_Gbps() / IF_Mbps().

OK reyk@ sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.51 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.50 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


# 1.49 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.48 27-Aug-2010 jsg

remove the unused if_init callback in struct ifnet
ok deraadt@ henning@ claudio@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.47 24-Feb-2010 kettenis

Don't print "EEPROM reload timed out" message. Devices that don't have an
EEPROM exist (RouterBOARD RB600A) and reloading default values from the
EEPROM will fail on those decives.

ok deraadt@


# 1.46 23-Nov-2009 kettenis

Make vge(4) detachable.

ok jsg@, deraadt@


# 1.45 04-Sep-2009 kettenis

Make sure the MAC address is correct on big-endian platforms if it isn't read
from the EEPROM.

ok miod@


# 1.44 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.43 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.42 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.41 22-Oct-2008 brad

Re-add support TX VLAN tag insertion and RX VLAN tag stripping.

Tested by Dawe <dawedawe at gmx dot de>


# 1.40 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.39 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.38 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.37 22-May-2008 mk

More timeout(9) usage cleaned up.

ok claudio


# 1.36 13-May-2008 brad

Since Ethernet links can only be full duplex or half duplex the link
state reporting code in the MII layer / em(4) and vge(4) will never
fall back to the point of only reporting the link as being UP without
the duplex setting being reported, so simplify the code a bit here.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.35 11-Dec-2007 brad

- Remove disabled and unusable HW VLAN tagging code.
- Remove setup of the HW VLAN stripping.

Issue reported by and fix tested by henric@

ok dlg@


# 1.34 10-Oct-2007 kettenis

Fix some obviously bogus code in vge_newbuf(). Should fix PR 5582.

ok claudio@


Revision tags: OPENBSD_4_2_BASE
# 1.33 01-May-2007 canacar

Missing braces in vge_tick(). Fixes link state announcements.
ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.32 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.31 23-Nov-2006 brad

OpenBSD-ify the HW VLAN tag insertion code.


# 1.30 14-Nov-2006 damien

don't always leave the mbuf on the if_snd queue if vge_encap() fails.
if the mbuf is coalesced in vge_encap(), the mbuf reference is no
longer valid. drop the mbuf in this case.

bug introduced in r1.28
tested by Frank Denis
fixes kernel/5291

"go for it" deraadt@


# 1.29 19-Oct-2006 tom

s/Mhz/MHz/ in comments and printf() strings

ok jsg@


# 1.28 03-Oct-2006 damien

don't use IF_PREPEND() on altq's.
use IFQ_POLL()/IFQ_DEQUEUE() logic instead as described in altq(4).

tested by jolan@ on macppc
"diffs look ok" brad@


Revision tags: OPENBSD_4_0_BASE
# 1.27 28-Jul-2006 kettenis

do not bother playing tag with the PCI_COMMAND_STATUS_REG

tested by jolan@, ok brad@


# 1.26 17-Jun-2006 brad

add sys/timeout.h


# 1.25 13-Jun-2006 brad

rev 1.13 fixed the MTU ioctl handler to allow adjusting the MTU
but it seems Jumbo support is broken, so disable Jumbos for now.

issue reported by jolan@


# 1.24 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.23 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.22 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.21 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.20 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.19 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.18 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.17 08-Oct-2005 brad

Some fixes for vge(4)'s multicast handling, including..

- Fix IFF_ALLMULTI handling
- Stop endless loop in multicast hash table filter mode

From christos NetBSD

ok pvalchev@


Revision tags: OPENBSD_3_8_BASE
# 1.16 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.15 03-Jul-2005 brad

enable use of the hardware 64 entry CAM table for perfect multicast
filtering otherwise fallback on the multicast hash table if trying to
filter on more than 64 addresses or if we're trying to flip on ALLMULTI.


# 1.14 03-May-2005 brad

enable HW transmit checksum offload

ok pvalchev@


# 1.13 30-Apr-2005 brad

- Add missing break for SIOCSIFADDR
- Allow setting the MTU

ok pvalchev@


# 1.12 30-Apr-2005 brad

- Correct the if_link_state_change() logic.
- Reading the EEPROM to learn the station address doesn't seem to work
on boards with VIA gigE controllers that are embedded in VIA chipsets.
Presumably, they don't have an external EEPROM and store the MAC
address somewhere else. To get around this, read the station
address from the RX filter registers instead. This has been tested
to work on both embedded and standalone controllers.

From FreeBSD

ok pvalchev@


# 1.11 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.10 08-Apr-2005 brad

fix parenthesis


# 1.9 08-Apr-2005 brad

- enable reception of VLAN sized frames
- enable HW receive checksum offload

ok pvlachev@


# 1.8 02-Apr-2005 brad

make use of if_link_state_change().

From FreeBSD

ok pvalchev@


Revision tags: OPENBSD_3_7_BASE
# 1.7 15-Mar-2005 pvalchev

use IFQ_ rather than IF_ macro here too, maybe helps altq; ok henning


# 1.6 15-Jan-2005 brad

make sure interface is in RUNNING state before touching the multicast filters

From NetBSD

NetBSD PR 27678 for details

ok mcbride@


# 1.5 27-Dec-2004 pvalchev

remove useless debugging leftover


# 1.4 26-Dec-2004 pvalchev

Bounce the mbuf to the BPF listener before committing it to the wire
in the TX case, fixes rare problems associated with accessing already
free'd memory if the encap routine bails out (panic in PROMISC mode).
ok deraadt


# 1.3 26-Dec-2004 pvalchev

htole32 and friends to get this working on big endian (macppc)


# 1.2 12-Dec-2004 pvalchev

a hack to read MAC address correctly on big endian; ok drahn
however a correct clean way to do this should be found


# 1.1 01-Dec-2004 pvalchev

VIA VT612x PCI Gigabit Ethernet adapter support, ok deraadt
from FreeBSD


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.71 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.70 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.69 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.68 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.67 16-Nov-2015 dlg

rework vge_start to avoid IFQ_POLL

firstly, this checks for space in the tx ring before looking at the
send queue. if there's no space, then IFF_OACTIVE is set and break.

if there's space use IFQ_DEQUEUE to pull a packet off. if we fail
to encapsulate it, it gets dropped.

encap has been changed so the dmamaps the mbufs are loaded into are
created with 7 segments instead of 32. this means we detect when
the packet would overflow the tx descriptor at dmamap load time,
rather than after we've looped over the segments writing them into
the descriptor. we now use m_defrag to defrag the mbuf instead of
allocating a new one and using m_copydata.

now if we have any encap error on the first mbuf, we no longer set
IFF_OACTIVE and wait for an interrupt that never comes to clear it.

testing and (excellent) code review by richard proctor


# 1.66 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.65 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.64 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


Revision tags: OPENBSD_5_8_BASE
# 1.63 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.62 13-Apr-2015 mpi

Now that if_input() set the receiving interface pointer on mbufs for us
there's no need to do it in m_devget(9).

Stop passing an ``ifp'' will help for upcoming interface pointer -> index
conversion.

While here remove unused ``ifp'' argument from m_clget(9) and kill two
birds^W layer violations in one commit.

ok henning@


# 1.61 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


# 1.60 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.59 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.58 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.57 21-Aug-2013 dlg

get rid of the copy argument in m_devget that let you provide an
alternative to bcopy since noone uses it.

while there use memcpy instead of bcopy because we know the memory cannot
overlap.

ok henning@ matthew@ mikeb@ deraadt@


# 1.56 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.55 15-Mar-2013 brad

Rewrite receive filter handling and ioctl bits.

ok sthen@


# 1.54 14-Mar-2013 brad

Add some missing bits for flow control support and enable it.

Tested with PCI and PCIe vge(4).

ok sthen@


Revision tags: OPENBSD_5_3_BASE
# 1.53 29-Nov-2012 brad

Remove setting an initial assumed baudrate upon driver attach which is not
necessarily correct, there might not even be a link when attaching.

ok mikeb@ reyk@


# 1.52 23-Nov-2012 gsoares

set ifp->if_baudrate with IF_Gbps() / IF_Mbps().

OK reyk@ sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.51 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.50 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


# 1.49 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.48 27-Aug-2010 jsg

remove the unused if_init callback in struct ifnet
ok deraadt@ henning@ claudio@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.47 24-Feb-2010 kettenis

Don't print "EEPROM reload timed out" message. Devices that don't have an
EEPROM exist (RouterBOARD RB600A) and reloading default values from the
EEPROM will fail on those decives.

ok deraadt@


# 1.46 23-Nov-2009 kettenis

Make vge(4) detachable.

ok jsg@, deraadt@


# 1.45 04-Sep-2009 kettenis

Make sure the MAC address is correct on big-endian platforms if it isn't read
from the EEPROM.

ok miod@


# 1.44 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.43 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.42 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.41 22-Oct-2008 brad

Re-add support TX VLAN tag insertion and RX VLAN tag stripping.

Tested by Dawe <dawedawe at gmx dot de>


# 1.40 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.39 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.38 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.37 22-May-2008 mk

More timeout(9) usage cleaned up.

ok claudio


# 1.36 13-May-2008 brad

Since Ethernet links can only be full duplex or half duplex the link
state reporting code in the MII layer / em(4) and vge(4) will never
fall back to the point of only reporting the link as being UP without
the duplex setting being reported, so simplify the code a bit here.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.35 11-Dec-2007 brad

- Remove disabled and unusable HW VLAN tagging code.
- Remove setup of the HW VLAN stripping.

Issue reported by and fix tested by henric@

ok dlg@


# 1.34 10-Oct-2007 kettenis

Fix some obviously bogus code in vge_newbuf(). Should fix PR 5582.

ok claudio@


Revision tags: OPENBSD_4_2_BASE
# 1.33 01-May-2007 canacar

Missing braces in vge_tick(). Fixes link state announcements.
ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.32 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.31 23-Nov-2006 brad

OpenBSD-ify the HW VLAN tag insertion code.


# 1.30 14-Nov-2006 damien

don't always leave the mbuf on the if_snd queue if vge_encap() fails.
if the mbuf is coalesced in vge_encap(), the mbuf reference is no
longer valid. drop the mbuf in this case.

bug introduced in r1.28
tested by Frank Denis
fixes kernel/5291

"go for it" deraadt@


# 1.29 19-Oct-2006 tom

s/Mhz/MHz/ in comments and printf() strings

ok jsg@


# 1.28 03-Oct-2006 damien

don't use IF_PREPEND() on altq's.
use IFQ_POLL()/IFQ_DEQUEUE() logic instead as described in altq(4).

tested by jolan@ on macppc
"diffs look ok" brad@


Revision tags: OPENBSD_4_0_BASE
# 1.27 28-Jul-2006 kettenis

do not bother playing tag with the PCI_COMMAND_STATUS_REG

tested by jolan@, ok brad@


# 1.26 17-Jun-2006 brad

add sys/timeout.h


# 1.25 13-Jun-2006 brad

rev 1.13 fixed the MTU ioctl handler to allow adjusting the MTU
but it seems Jumbo support is broken, so disable Jumbos for now.

issue reported by jolan@


# 1.24 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.23 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.22 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.21 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.20 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.19 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.18 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.17 08-Oct-2005 brad

Some fixes for vge(4)'s multicast handling, including..

- Fix IFF_ALLMULTI handling
- Stop endless loop in multicast hash table filter mode

From christos NetBSD

ok pvalchev@


Revision tags: OPENBSD_3_8_BASE
# 1.16 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.15 03-Jul-2005 brad

enable use of the hardware 64 entry CAM table for perfect multicast
filtering otherwise fallback on the multicast hash table if trying to
filter on more than 64 addresses or if we're trying to flip on ALLMULTI.


# 1.14 03-May-2005 brad

enable HW transmit checksum offload

ok pvalchev@


# 1.13 30-Apr-2005 brad

- Add missing break for SIOCSIFADDR
- Allow setting the MTU

ok pvalchev@


# 1.12 30-Apr-2005 brad

- Correct the if_link_state_change() logic.
- Reading the EEPROM to learn the station address doesn't seem to work
on boards with VIA gigE controllers that are embedded in VIA chipsets.
Presumably, they don't have an external EEPROM and store the MAC
address somewhere else. To get around this, read the station
address from the RX filter registers instead. This has been tested
to work on both embedded and standalone controllers.

From FreeBSD

ok pvalchev@


# 1.11 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.10 08-Apr-2005 brad

fix parenthesis


# 1.9 08-Apr-2005 brad

- enable reception of VLAN sized frames
- enable HW receive checksum offload

ok pvlachev@


# 1.8 02-Apr-2005 brad

make use of if_link_state_change().

From FreeBSD

ok pvalchev@


Revision tags: OPENBSD_3_7_BASE
# 1.7 15-Mar-2005 pvalchev

use IFQ_ rather than IF_ macro here too, maybe helps altq; ok henning


# 1.6 15-Jan-2005 brad

make sure interface is in RUNNING state before touching the multicast filters

From NetBSD

NetBSD PR 27678 for details

ok mcbride@


# 1.5 27-Dec-2004 pvalchev

remove useless debugging leftover


# 1.4 26-Dec-2004 pvalchev

Bounce the mbuf to the BPF listener before committing it to the wire
in the TX case, fixes rare problems associated with accessing already
free'd memory if the encap routine bails out (panic in PROMISC mode).
ok deraadt


# 1.3 26-Dec-2004 pvalchev

htole32 and friends to get this working on big endian (macppc)


# 1.2 12-Dec-2004 pvalchev

a hack to read MAC address correctly on big endian; ok drahn
however a correct clean way to do this should be found


# 1.1 01-Dec-2004 pvalchev

VIA VT612x PCI Gigabit Ethernet adapter support, ok deraadt
from FreeBSD