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

remove unneeded includes; ok miod@


Revision tags: OPENBSD_7_5_BASE
# 1.39 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.38 11-Mar-2022 mpi

Constify struct cfattach.


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

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

ok dlg@ tobhe@


# 1.36 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_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.35 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.34 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.33 13-Apr-2016 mpi

G/C IFQ_SET_READY().


# 1.32 15-Mar-2016 naddy

Ethernet drivers no longer need to include if_vlan_var.h for the VLAN
definitions; ok mpi@


Revision tags: OPENBSD_5_9_BASE
# 1.31 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.30 09-Nov-2015 dlg

rework the start routines to avoid IF_PREPEND.

IF_PREPEND assumes the underlying send queue is priq, while hfsc may be
enabled on it.

the previous code pattern to DEQUEUE, try and encap the mbuf on the
ring, and if that failed cos there was no space it would PREPEND
it.

now it checks for space on the ring before it attempts to DEQUEUE.
failure to encap means the mbuf is now unconditionally dropped.


# 1.29 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.28 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.27 30-Apr-2015 mpi

Convert moar drivers to if_input().

ok dlg@


# 1.26 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.25 22-Dec-2014 tedu

unifdef INET


# 1.24 18-Nov-2014 tedu

move arc4random prototype to systm.h. more appropriate for most code
to include that than rdnvar.h. ok deraadt dlg


# 1.23 19-Aug-2014 miod

Three independent typos for `independent' or `independently'.


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

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.21 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_3_BASE OPENBSD_5_4_BASE
# 1.20 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@


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.19 19-Oct-2011 kevlo

Add some missing bus_dmamap_sync()'s and sync the others with
the FreeBSD code.

age(4) tested by Thomas Pfaff; alc(4) tested by Gabriel Linder;
ale(4) tested by Johan Torin.

From Brad


# 1.18 21-Sep-2011 kevlo

Some minor clean up to the _start funtions to make the code read a little
better. No functional change.

From Brad


# 1.17 15-Sep-2011 kevlo

Fix up age_encap() / age_start()..

- Remove unnecessary nsegs variable from age_encap() and
use map->dm_nsegs. Also remove unnecessary FreeBSD check
for 0 DMA segments check.
- Remove printfs in age_encap() failure paths that shouldn't
be there.
- Add missing IF_PREPEND() from failure path coming off of
age_encap() within age_start().
- Fix error handling within age_encap(). Previously age_encap()
was attempting to unload a DMA map upon failure from
bus_dmamap_load_mbuf() even though one wasn't loaded at that
point and then always forcing mbufs through the EFBIG path.

Tested by Thomas Pfaff.

From Brad.


# 1.16 26-Aug-2011 kevlo

Prevent watchdog timeouts; tested by Thomas Pfaff

From Brad


Revision tags: OPENBSD_5_0_BASE
# 1.15 17-Jun-2011 kevlo

Enable MSI support; tested by Thomas Pfaff

From Brad


# 1.14 28-May-2011 kevlo

age_newbuf is called from the interrupt context so it can't sleep.

From Brad. Tested by Thomas Pfaff


# 1.13 05-Apr-2011 henning

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


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

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


Revision tags: OPENBSD_4_8_BASE
# 1.11 19-May-2010 oga

BUS_DMA_ZERO love.

ok kevlo@, krw@


# 1.10 08-Apr-2010 tedu

these files don't need to include proc.h anymore. ok oga for agp


Revision tags: OPENBSD_4_7_BASE
# 1.9 27-Feb-2010 kevlo

Fix multicast handling. All Atheros controllers use big-endian form
when computing multicast hash.

From Brad via FreeBSD


# 1.8 07-Jan-2010 sthen

Rename _rxfilter functions to _iff for consistency. From Brad, ok kevlo@


# 1.7 13-Sep-2009 krw

M_DUP_PKTHDR() define -> m_dup_pkthdr() function to properly deal
with m_tag_copy_chain() failures.

Use m_defrag() to eliminate hand rolled defragging of mbufs and
some uses of M_DUP_PKTHDR().

Original diff from thib@, claudio@'s feedback integrated by me.

Tests kevlo@ claudio@, "reads ok" blambert@

ok thib@ claudio@, "m_defrag() bits ok" kettenis@


# 1.6 28-Jul-2009 kevlo

- Don't access VPD even if hardware advertised the capability.
It seems that some revisions of the controllers hang while accessing
the VPD. Because VPD access routine is now unused, nuke it.
- Let TWSI reload EEPROM if VPD capability is detected. Reloading
the EEPROM will also set the Ethernet address, so age(4) now reads
AGE_PAR0 and AGE_PAR1 register to get the Ethernet address. This removes
removes a lot of hacks and enhance readability a lot.
- Double PHY reset timeout as it takes more time to take the PHY out of
power-saving state.
- Explicitly check power-saving state by checking undocumented PHY
registers. If link is not up, poke undocumented registers to take
PHY out of power-saving state. This is the same thing done by the
Linux driver.
- Don't rely on auto-clearing feature of master reset bit, just wait
1ms and check idle status of MAC.

From FreeBSD via Brad.


# 1.5 28-Jul-2009 kevlo

Add flow control support

From Brad


Revision tags: OPENBSD_4_6_BASE
# 1.4 29-Mar-2009 sthen

make various strings ("can't map mem space" and similar) more consistent
between instances, saving space in the kernel. feedback from many (some
incorporated, some left for future work).

ok deraadt, kettenis, "why not" miod.


Revision tags: OPENBSD_4_5_BASE
# 1.3 23-Feb-2009 kevlo

- fix test for IPv4 checksum
- change age_get_macaddr() prototype(no functional change) and
set smb pointers to NULL for consistency
- clean up and fix the multicast code; from Brad
- When the attach routine failed, release all resources including
interrupts, interrupt handler, and DMA memory

Tested by couderc@ and giovanni <qgiovanni at gmail dot com>

ok deraadt@


# 1.2 14-Feb-2009 deraadt

this was not even test compiled without VLAN support


# 1.1 16-Jan-2009 kevlo

Add Attansic L1 gigabit Ethernet driver.

Written by Pyun YongHyeon for FreeBSD, ported to DragonFlyBSD
by Sepherosa Ziehau and then ported to OpenBSD by me.

ok dlg@


# 1.39 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.38 11-Mar-2022 mpi

Constify struct cfattach.


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

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

ok dlg@ tobhe@


# 1.36 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_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.35 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.34 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.33 13-Apr-2016 mpi

G/C IFQ_SET_READY().


# 1.32 15-Mar-2016 naddy

Ethernet drivers no longer need to include if_vlan_var.h for the VLAN
definitions; ok mpi@


Revision tags: OPENBSD_5_9_BASE
# 1.31 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.30 09-Nov-2015 dlg

rework the start routines to avoid IF_PREPEND.

IF_PREPEND assumes the underlying send queue is priq, while hfsc may be
enabled on it.

the previous code pattern to DEQUEUE, try and encap the mbuf on the
ring, and if that failed cos there was no space it would PREPEND
it.

now it checks for space on the ring before it attempts to DEQUEUE.
failure to encap means the mbuf is now unconditionally dropped.


# 1.29 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.28 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.27 30-Apr-2015 mpi

Convert moar drivers to if_input().

ok dlg@


# 1.26 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.25 22-Dec-2014 tedu

unifdef INET


# 1.24 18-Nov-2014 tedu

move arc4random prototype to systm.h. more appropriate for most code
to include that than rdnvar.h. ok deraadt dlg


# 1.23 19-Aug-2014 miod

Three independent typos for `independent' or `independently'.


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

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.21 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_3_BASE OPENBSD_5_4_BASE
# 1.20 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@


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.19 19-Oct-2011 kevlo

Add some missing bus_dmamap_sync()'s and sync the others with
the FreeBSD code.

age(4) tested by Thomas Pfaff; alc(4) tested by Gabriel Linder;
ale(4) tested by Johan Torin.

From Brad


# 1.18 21-Sep-2011 kevlo

Some minor clean up to the _start funtions to make the code read a little
better. No functional change.

From Brad


# 1.17 15-Sep-2011 kevlo

Fix up age_encap() / age_start()..

- Remove unnecessary nsegs variable from age_encap() and
use map->dm_nsegs. Also remove unnecessary FreeBSD check
for 0 DMA segments check.
- Remove printfs in age_encap() failure paths that shouldn't
be there.
- Add missing IF_PREPEND() from failure path coming off of
age_encap() within age_start().
- Fix error handling within age_encap(). Previously age_encap()
was attempting to unload a DMA map upon failure from
bus_dmamap_load_mbuf() even though one wasn't loaded at that
point and then always forcing mbufs through the EFBIG path.

Tested by Thomas Pfaff.

From Brad.


# 1.16 26-Aug-2011 kevlo

Prevent watchdog timeouts; tested by Thomas Pfaff

From Brad


Revision tags: OPENBSD_5_0_BASE
# 1.15 17-Jun-2011 kevlo

Enable MSI support; tested by Thomas Pfaff

From Brad


# 1.14 28-May-2011 kevlo

age_newbuf is called from the interrupt context so it can't sleep.

From Brad. Tested by Thomas Pfaff


# 1.13 05-Apr-2011 henning

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


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

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


Revision tags: OPENBSD_4_8_BASE
# 1.11 19-May-2010 oga

BUS_DMA_ZERO love.

ok kevlo@, krw@


# 1.10 08-Apr-2010 tedu

these files don't need to include proc.h anymore. ok oga for agp


Revision tags: OPENBSD_4_7_BASE
# 1.9 27-Feb-2010 kevlo

Fix multicast handling. All Atheros controllers use big-endian form
when computing multicast hash.

From Brad via FreeBSD


# 1.8 07-Jan-2010 sthen

Rename _rxfilter functions to _iff for consistency. From Brad, ok kevlo@


# 1.7 13-Sep-2009 krw

M_DUP_PKTHDR() define -> m_dup_pkthdr() function to properly deal
with m_tag_copy_chain() failures.

Use m_defrag() to eliminate hand rolled defragging of mbufs and
some uses of M_DUP_PKTHDR().

Original diff from thib@, claudio@'s feedback integrated by me.

Tests kevlo@ claudio@, "reads ok" blambert@

ok thib@ claudio@, "m_defrag() bits ok" kettenis@


# 1.6 28-Jul-2009 kevlo

- Don't access VPD even if hardware advertised the capability.
It seems that some revisions of the controllers hang while accessing
the VPD. Because VPD access routine is now unused, nuke it.
- Let TWSI reload EEPROM if VPD capability is detected. Reloading
the EEPROM will also set the Ethernet address, so age(4) now reads
AGE_PAR0 and AGE_PAR1 register to get the Ethernet address. This removes
removes a lot of hacks and enhance readability a lot.
- Double PHY reset timeout as it takes more time to take the PHY out of
power-saving state.
- Explicitly check power-saving state by checking undocumented PHY
registers. If link is not up, poke undocumented registers to take
PHY out of power-saving state. This is the same thing done by the
Linux driver.
- Don't rely on auto-clearing feature of master reset bit, just wait
1ms and check idle status of MAC.

From FreeBSD via Brad.


# 1.5 28-Jul-2009 kevlo

Add flow control support

From Brad


Revision tags: OPENBSD_4_6_BASE
# 1.4 29-Mar-2009 sthen

make various strings ("can't map mem space" and similar) more consistent
between instances, saving space in the kernel. feedback from many (some
incorporated, some left for future work).

ok deraadt, kettenis, "why not" miod.


Revision tags: OPENBSD_4_5_BASE
# 1.3 23-Feb-2009 kevlo

- fix test for IPv4 checksum
- change age_get_macaddr() prototype(no functional change) and
set smb pointers to NULL for consistency
- clean up and fix the multicast code; from Brad
- When the attach routine failed, release all resources including
interrupts, interrupt handler, and DMA memory

Tested by couderc@ and giovanni <qgiovanni at gmail dot com>

ok deraadt@


# 1.2 14-Feb-2009 deraadt

this was not even test compiled without VLAN support


# 1.1 16-Jan-2009 kevlo

Add Attansic L1 gigabit Ethernet driver.

Written by Pyun YongHyeon for FreeBSD, ported to DragonFlyBSD
by Sepherosa Ziehau and then ported to OpenBSD by me.

ok dlg@


# 1.38 11-Mar-2022 mpi

Constify struct cfattach.


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

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

ok dlg@ tobhe@


# 1.36 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_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.35 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.34 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.33 13-Apr-2016 mpi

G/C IFQ_SET_READY().


# 1.32 15-Mar-2016 naddy

Ethernet drivers no longer need to include if_vlan_var.h for the VLAN
definitions; ok mpi@


Revision tags: OPENBSD_5_9_BASE
# 1.31 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.30 09-Nov-2015 dlg

rework the start routines to avoid IF_PREPEND.

IF_PREPEND assumes the underlying send queue is priq, while hfsc may be
enabled on it.

the previous code pattern to DEQUEUE, try and encap the mbuf on the
ring, and if that failed cos there was no space it would PREPEND
it.

now it checks for space on the ring before it attempts to DEQUEUE.
failure to encap means the mbuf is now unconditionally dropped.


# 1.29 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.28 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.27 30-Apr-2015 mpi

Convert moar drivers to if_input().

ok dlg@


# 1.26 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.25 22-Dec-2014 tedu

unifdef INET


# 1.24 18-Nov-2014 tedu

move arc4random prototype to systm.h. more appropriate for most code
to include that than rdnvar.h. ok deraadt dlg


# 1.23 19-Aug-2014 miod

Three independent typos for `independent' or `independently'.


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

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.21 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_3_BASE OPENBSD_5_4_BASE
# 1.20 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@


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.19 19-Oct-2011 kevlo

Add some missing bus_dmamap_sync()'s and sync the others with
the FreeBSD code.

age(4) tested by Thomas Pfaff; alc(4) tested by Gabriel Linder;
ale(4) tested by Johan Torin.

From Brad


# 1.18 21-Sep-2011 kevlo

Some minor clean up to the _start funtions to make the code read a little
better. No functional change.

From Brad


# 1.17 15-Sep-2011 kevlo

Fix up age_encap() / age_start()..

- Remove unnecessary nsegs variable from age_encap() and
use map->dm_nsegs. Also remove unnecessary FreeBSD check
for 0 DMA segments check.
- Remove printfs in age_encap() failure paths that shouldn't
be there.
- Add missing IF_PREPEND() from failure path coming off of
age_encap() within age_start().
- Fix error handling within age_encap(). Previously age_encap()
was attempting to unload a DMA map upon failure from
bus_dmamap_load_mbuf() even though one wasn't loaded at that
point and then always forcing mbufs through the EFBIG path.

Tested by Thomas Pfaff.

From Brad.


# 1.16 26-Aug-2011 kevlo

Prevent watchdog timeouts; tested by Thomas Pfaff

From Brad


Revision tags: OPENBSD_5_0_BASE
# 1.15 17-Jun-2011 kevlo

Enable MSI support; tested by Thomas Pfaff

From Brad


# 1.14 28-May-2011 kevlo

age_newbuf is called from the interrupt context so it can't sleep.

From Brad. Tested by Thomas Pfaff


# 1.13 05-Apr-2011 henning

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


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

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


Revision tags: OPENBSD_4_8_BASE
# 1.11 19-May-2010 oga

BUS_DMA_ZERO love.

ok kevlo@, krw@


# 1.10 08-Apr-2010 tedu

these files don't need to include proc.h anymore. ok oga for agp


Revision tags: OPENBSD_4_7_BASE
# 1.9 27-Feb-2010 kevlo

Fix multicast handling. All Atheros controllers use big-endian form
when computing multicast hash.

From Brad via FreeBSD


# 1.8 07-Jan-2010 sthen

Rename _rxfilter functions to _iff for consistency. From Brad, ok kevlo@


# 1.7 13-Sep-2009 krw

M_DUP_PKTHDR() define -> m_dup_pkthdr() function to properly deal
with m_tag_copy_chain() failures.

Use m_defrag() to eliminate hand rolled defragging of mbufs and
some uses of M_DUP_PKTHDR().

Original diff from thib@, claudio@'s feedback integrated by me.

Tests kevlo@ claudio@, "reads ok" blambert@

ok thib@ claudio@, "m_defrag() bits ok" kettenis@


# 1.6 28-Jul-2009 kevlo

- Don't access VPD even if hardware advertised the capability.
It seems that some revisions of the controllers hang while accessing
the VPD. Because VPD access routine is now unused, nuke it.
- Let TWSI reload EEPROM if VPD capability is detected. Reloading
the EEPROM will also set the Ethernet address, so age(4) now reads
AGE_PAR0 and AGE_PAR1 register to get the Ethernet address. This removes
removes a lot of hacks and enhance readability a lot.
- Double PHY reset timeout as it takes more time to take the PHY out of
power-saving state.
- Explicitly check power-saving state by checking undocumented PHY
registers. If link is not up, poke undocumented registers to take
PHY out of power-saving state. This is the same thing done by the
Linux driver.
- Don't rely on auto-clearing feature of master reset bit, just wait
1ms and check idle status of MAC.

From FreeBSD via Brad.


# 1.5 28-Jul-2009 kevlo

Add flow control support

From Brad


Revision tags: OPENBSD_4_6_BASE
# 1.4 29-Mar-2009 sthen

make various strings ("can't map mem space" and similar) more consistent
between instances, saving space in the kernel. feedback from many (some
incorporated, some left for future work).

ok deraadt, kettenis, "why not" miod.


Revision tags: OPENBSD_4_5_BASE
# 1.3 23-Feb-2009 kevlo

- fix test for IPv4 checksum
- change age_get_macaddr() prototype(no functional change) and
set smb pointers to NULL for consistency
- clean up and fix the multicast code; from Brad
- When the attach routine failed, release all resources including
interrupts, interrupt handler, and DMA memory

Tested by couderc@ and giovanni <qgiovanni at gmail dot com>

ok deraadt@


# 1.2 14-Feb-2009 deraadt

this was not even test compiled without VLAN support


# 1.1 16-Jan-2009 kevlo

Add Attansic L1 gigabit Ethernet driver.

Written by Pyun YongHyeon for FreeBSD, ported to DragonFlyBSD
by Sepherosa Ziehau and then ported to OpenBSD by me.

ok dlg@


# 1.37 10-Jul-2020 patrick

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

ok dlg@ tobhe@


# 1.36 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_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.35 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.34 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.33 13-Apr-2016 mpi

G/C IFQ_SET_READY().


# 1.32 15-Mar-2016 naddy

Ethernet drivers no longer need to include if_vlan_var.h for the VLAN
definitions; ok mpi@


Revision tags: OPENBSD_5_9_BASE
# 1.31 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.30 09-Nov-2015 dlg

rework the start routines to avoid IF_PREPEND.

IF_PREPEND assumes the underlying send queue is priq, while hfsc may be
enabled on it.

the previous code pattern to DEQUEUE, try and encap the mbuf on the
ring, and if that failed cos there was no space it would PREPEND
it.

now it checks for space on the ring before it attempts to DEQUEUE.
failure to encap means the mbuf is now unconditionally dropped.


# 1.29 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.28 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.27 30-Apr-2015 mpi

Convert moar drivers to if_input().

ok dlg@


# 1.26 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.25 22-Dec-2014 tedu

unifdef INET


# 1.24 18-Nov-2014 tedu

move arc4random prototype to systm.h. more appropriate for most code
to include that than rdnvar.h. ok deraadt dlg


# 1.23 19-Aug-2014 miod

Three independent typos for `independent' or `independently'.


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

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.21 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_3_BASE OPENBSD_5_4_BASE
# 1.20 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@


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.19 19-Oct-2011 kevlo

Add some missing bus_dmamap_sync()'s and sync the others with
the FreeBSD code.

age(4) tested by Thomas Pfaff; alc(4) tested by Gabriel Linder;
ale(4) tested by Johan Torin.

From Brad


# 1.18 21-Sep-2011 kevlo

Some minor clean up to the _start funtions to make the code read a little
better. No functional change.

From Brad


# 1.17 15-Sep-2011 kevlo

Fix up age_encap() / age_start()..

- Remove unnecessary nsegs variable from age_encap() and
use map->dm_nsegs. Also remove unnecessary FreeBSD check
for 0 DMA segments check.
- Remove printfs in age_encap() failure paths that shouldn't
be there.
- Add missing IF_PREPEND() from failure path coming off of
age_encap() within age_start().
- Fix error handling within age_encap(). Previously age_encap()
was attempting to unload a DMA map upon failure from
bus_dmamap_load_mbuf() even though one wasn't loaded at that
point and then always forcing mbufs through the EFBIG path.

Tested by Thomas Pfaff.

From Brad.


# 1.16 26-Aug-2011 kevlo

Prevent watchdog timeouts; tested by Thomas Pfaff

From Brad


Revision tags: OPENBSD_5_0_BASE
# 1.15 17-Jun-2011 kevlo

Enable MSI support; tested by Thomas Pfaff

From Brad


# 1.14 28-May-2011 kevlo

age_newbuf is called from the interrupt context so it can't sleep.

From Brad. Tested by Thomas Pfaff


# 1.13 05-Apr-2011 henning

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


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

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


Revision tags: OPENBSD_4_8_BASE
# 1.11 19-May-2010 oga

BUS_DMA_ZERO love.

ok kevlo@, krw@


# 1.10 08-Apr-2010 tedu

these files don't need to include proc.h anymore. ok oga for agp


Revision tags: OPENBSD_4_7_BASE
# 1.9 27-Feb-2010 kevlo

Fix multicast handling. All Atheros controllers use big-endian form
when computing multicast hash.

From Brad via FreeBSD


# 1.8 07-Jan-2010 sthen

Rename _rxfilter functions to _iff for consistency. From Brad, ok kevlo@


# 1.7 13-Sep-2009 krw

M_DUP_PKTHDR() define -> m_dup_pkthdr() function to properly deal
with m_tag_copy_chain() failures.

Use m_defrag() to eliminate hand rolled defragging of mbufs and
some uses of M_DUP_PKTHDR().

Original diff from thib@, claudio@'s feedback integrated by me.

Tests kevlo@ claudio@, "reads ok" blambert@

ok thib@ claudio@, "m_defrag() bits ok" kettenis@


# 1.6 28-Jul-2009 kevlo

- Don't access VPD even if hardware advertised the capability.
It seems that some revisions of the controllers hang while accessing
the VPD. Because VPD access routine is now unused, nuke it.
- Let TWSI reload EEPROM if VPD capability is detected. Reloading
the EEPROM will also set the Ethernet address, so age(4) now reads
AGE_PAR0 and AGE_PAR1 register to get the Ethernet address. This removes
removes a lot of hacks and enhance readability a lot.
- Double PHY reset timeout as it takes more time to take the PHY out of
power-saving state.
- Explicitly check power-saving state by checking undocumented PHY
registers. If link is not up, poke undocumented registers to take
PHY out of power-saving state. This is the same thing done by the
Linux driver.
- Don't rely on auto-clearing feature of master reset bit, just wait
1ms and check idle status of MAC.

From FreeBSD via Brad.


# 1.5 28-Jul-2009 kevlo

Add flow control support

From Brad


Revision tags: OPENBSD_4_6_BASE
# 1.4 29-Mar-2009 sthen

make various strings ("can't map mem space" and similar) more consistent
between instances, saving space in the kernel. feedback from many (some
incorporated, some left for future work).

ok deraadt, kettenis, "why not" miod.


Revision tags: OPENBSD_4_5_BASE
# 1.3 23-Feb-2009 kevlo

- fix test for IPv4 checksum
- change age_get_macaddr() prototype(no functional change) and
set smb pointers to NULL for consistency
- clean up and fix the multicast code; from Brad
- When the attach routine failed, release all resources including
interrupts, interrupt handler, and DMA memory

Tested by couderc@ and giovanni <qgiovanni at gmail dot com>

ok deraadt@


# 1.2 14-Feb-2009 deraadt

this was not even test compiled without VLAN support


# 1.1 16-Jan-2009 kevlo

Add Attansic L1 gigabit Ethernet driver.

Written by Pyun YongHyeon for FreeBSD, ported to DragonFlyBSD
by Sepherosa Ziehau and then ported to OpenBSD by me.

ok dlg@


Revision tags: OPENBSD_6_2_BASE
# 1.35 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.34 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.33 13-Apr-2016 mpi

G/C IFQ_SET_READY().


# 1.32 15-Mar-2016 naddy

Ethernet drivers no longer need to include if_vlan_var.h for the VLAN
definitions; ok mpi@


Revision tags: OPENBSD_5_9_BASE
# 1.31 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.30 09-Nov-2015 dlg

rework the start routines to avoid IF_PREPEND.

IF_PREPEND assumes the underlying send queue is priq, while hfsc may be
enabled on it.

the previous code pattern to DEQUEUE, try and encap the mbuf on the
ring, and if that failed cos there was no space it would PREPEND
it.

now it checks for space on the ring before it attempts to DEQUEUE.
failure to encap means the mbuf is now unconditionally dropped.


# 1.29 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.28 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.27 30-Apr-2015 mpi

Convert moar drivers to if_input().

ok dlg@


# 1.26 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.25 22-Dec-2014 tedu

unifdef INET


# 1.24 18-Nov-2014 tedu

move arc4random prototype to systm.h. more appropriate for most code
to include that than rdnvar.h. ok deraadt dlg


# 1.23 19-Aug-2014 miod

Three independent typos for `independent' or `independently'.


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

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.21 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_3_BASE OPENBSD_5_4_BASE
# 1.20 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@


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.19 19-Oct-2011 kevlo

Add some missing bus_dmamap_sync()'s and sync the others with
the FreeBSD code.

age(4) tested by Thomas Pfaff; alc(4) tested by Gabriel Linder;
ale(4) tested by Johan Torin.

From Brad


# 1.18 21-Sep-2011 kevlo

Some minor clean up to the _start funtions to make the code read a little
better. No functional change.

From Brad


# 1.17 15-Sep-2011 kevlo

Fix up age_encap() / age_start()..

- Remove unnecessary nsegs variable from age_encap() and
use map->dm_nsegs. Also remove unnecessary FreeBSD check
for 0 DMA segments check.
- Remove printfs in age_encap() failure paths that shouldn't
be there.
- Add missing IF_PREPEND() from failure path coming off of
age_encap() within age_start().
- Fix error handling within age_encap(). Previously age_encap()
was attempting to unload a DMA map upon failure from
bus_dmamap_load_mbuf() even though one wasn't loaded at that
point and then always forcing mbufs through the EFBIG path.

Tested by Thomas Pfaff.

From Brad.


# 1.16 26-Aug-2011 kevlo

Prevent watchdog timeouts; tested by Thomas Pfaff

From Brad


Revision tags: OPENBSD_5_0_BASE
# 1.15 17-Jun-2011 kevlo

Enable MSI support; tested by Thomas Pfaff

From Brad


# 1.14 28-May-2011 kevlo

age_newbuf is called from the interrupt context so it can't sleep.

From Brad. Tested by Thomas Pfaff


# 1.13 05-Apr-2011 henning

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


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

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


Revision tags: OPENBSD_4_8_BASE
# 1.11 19-May-2010 oga

BUS_DMA_ZERO love.

ok kevlo@, krw@


# 1.10 08-Apr-2010 tedu

these files don't need to include proc.h anymore. ok oga for agp


Revision tags: OPENBSD_4_7_BASE
# 1.9 27-Feb-2010 kevlo

Fix multicast handling. All Atheros controllers use big-endian form
when computing multicast hash.

From Brad via FreeBSD


# 1.8 07-Jan-2010 sthen

Rename _rxfilter functions to _iff for consistency. From Brad, ok kevlo@


# 1.7 13-Sep-2009 krw

M_DUP_PKTHDR() define -> m_dup_pkthdr() function to properly deal
with m_tag_copy_chain() failures.

Use m_defrag() to eliminate hand rolled defragging of mbufs and
some uses of M_DUP_PKTHDR().

Original diff from thib@, claudio@'s feedback integrated by me.

Tests kevlo@ claudio@, "reads ok" blambert@

ok thib@ claudio@, "m_defrag() bits ok" kettenis@


# 1.6 28-Jul-2009 kevlo

- Don't access VPD even if hardware advertised the capability.
It seems that some revisions of the controllers hang while accessing
the VPD. Because VPD access routine is now unused, nuke it.
- Let TWSI reload EEPROM if VPD capability is detected. Reloading
the EEPROM will also set the Ethernet address, so age(4) now reads
AGE_PAR0 and AGE_PAR1 register to get the Ethernet address. This removes
removes a lot of hacks and enhance readability a lot.
- Double PHY reset timeout as it takes more time to take the PHY out of
power-saving state.
- Explicitly check power-saving state by checking undocumented PHY
registers. If link is not up, poke undocumented registers to take
PHY out of power-saving state. This is the same thing done by the
Linux driver.
- Don't rely on auto-clearing feature of master reset bit, just wait
1ms and check idle status of MAC.

From FreeBSD via Brad.


# 1.5 28-Jul-2009 kevlo

Add flow control support

From Brad


Revision tags: OPENBSD_4_6_BASE
# 1.4 29-Mar-2009 sthen

make various strings ("can't map mem space" and similar) more consistent
between instances, saving space in the kernel. feedback from many (some
incorporated, some left for future work).

ok deraadt, kettenis, "why not" miod.


Revision tags: OPENBSD_4_5_BASE
# 1.3 23-Feb-2009 kevlo

- fix test for IPv4 checksum
- change age_get_macaddr() prototype(no functional change) and
set smb pointers to NULL for consistency
- clean up and fix the multicast code; from Brad
- When the attach routine failed, release all resources including
interrupts, interrupt handler, and DMA memory

Tested by couderc@ and giovanni <qgiovanni at gmail dot com>

ok deraadt@


# 1.2 14-Feb-2009 deraadt

this was not even test compiled without VLAN support


# 1.1 16-Jan-2009 kevlo

Add Attansic L1 gigabit Ethernet driver.

Written by Pyun YongHyeon for FreeBSD, ported to DragonFlyBSD
by Sepherosa Ziehau and then ported to OpenBSD by me.

ok dlg@