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

remove unneeded includes; ok miod@


Revision tags: OPENBSD_7_5_BASE
# 1.80 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_3_BASE OPENBSD_7_4_BASE
# 1.79 09-Oct-2022 kevlo

Fix typo in debug messages.

ok deraadt@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.78 11-Mar-2022 mpi

Constify struct cfattach.


# 1.77 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.75 10-Jul-2020 patrick

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

ok dlg@ tobhe@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.74 25-Sep-2019 kevlo

Argument order fix for MCLGETI.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.73 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.72 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.71 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.70 24-Nov-2015 mpi

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


# 1.69 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.68 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.67 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.66 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.65 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


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

unifdef INET


# 1.63 20-Aug-2014 dlg

replace the custom jumbo allocator with MCLGETI.

putting this in the tree to make it easier for people to test.


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

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.61 26-Nov-2013 mpi

Instead of comparing the lower and higher addresses of all the multicast
entries to decide if the IFF_ALLMULTI flag should be set, check if there
is at least one real range between them.

This should not change the behavior of any driver but if you encounter
any problem, feel free to revert the offending chunk and ping me about
it.

ok naddy@, dlg@


# 1.60 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


# 1.59 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.58 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.57 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.56 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


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

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


# 1.54 03-Apr-2011 jasper

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

ok claudio@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.53 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.52 13-Aug-2009 jasper

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

ok dlg@


# 1.51 10-Aug-2009 deraadt

delete xxshutdown handlers that are never even hooked up


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.50 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.49 22-Oct-2008 brad

Fix a typo.


# 1.48 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.47 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.46 26-Nov-2007 martynas

typos; ok jmc@
sys/netinet/in_pcb.c and sys/net/bridgestp.c ok henning@
sys/dev/pci/bktr/* ok jakemsr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.45 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


Revision tags: OPENBSD_4_0_BASE
# 1.44 28-May-2006 brad

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

ok reyk@


# 1.43 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.42 27-May-2006 brad

remove FreeBSD specific code.


# 1.41 27-May-2006 brad

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

ok reyk@


# 1.40 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.39 30-Apr-2006 brad

- check for IFF_RUNNING being set before calling lge_init().
- call lge_setmulti() when enabling/disabling promisc mode or
if the IFF_ALLMULTI flag is set.


# 1.38 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.37 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.36 24-Dec-2005 brad

clear RUNNING here to do a full init.


# 1.35 23-Nov-2005 mickey

assume vtophys(vaddr_t) just what all the other archs expect; no functional change


# 1.34 09-Oct-2005 brad

fix bus_dmamem_alloc() failure case.


# 1.33 09-Oct-2005 brad

use pci_matchbyid().


# 1.32 08-Oct-2005 brad

stop bzero'ing the softc in lge_attach() and tada lge(4) now works
to some extent.


# 1.31 08-Oct-2005 brad

a little better like this.


# 1.30 08-Oct-2005 brad

- remove return at end of void function
- function return value on separate line
- ANSI protos


# 1.29 08-Oct-2005 brad

remove unused VLAN headers.


# 1.28 07-Oct-2005 brad

IFCAP_VLAN_MTU


# 1.27 07-Oct-2005 brad

revert this change.


# 1.26 07-Oct-2005 brad

sync lge_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()


# 1.25 07-Oct-2005 brad

free bus_dma resources for all failures in attach.


# 1.24 07-Oct-2005 brad

some fixes for the lge driver, though still doesn't work..

- use MEXTADD() macro
- remove spl from attach
- use splnet
- disestablish interrupt on failure and some other cleaning


# 1.23 11-Sep-2005 mickey

do not inline pci_mapreg_map() anymore as it is olrite now; brad@ ok


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

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


# 1.21 02-Jul-2005 brad

clear IFF_RUNNING & IFF_OACTIVE in foo_stop() before de-allocating resources.


# 1.20 18-Jun-2005 brad

though this doesn't work yet at least allow it to compile first.


# 1.19 11-May-2005 brad

Do not call mii_pollstat() immediately after mii_tick().

From FreeBSD


# 1.18 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.17 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


Revision tags: OPENBSD_3_6_BASE
# 1.16 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.15 05-Jun-2004 mcbride

- replace handrolled crc32 with ether_crc32_be()
- make multicast ranges work

ok deraadt@


# 1.14 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.13 06-Oct-2003 david

make lge(4) compile, from tedu@
ok jason@ nate@


Revision tags: OPENBSD_3_4_BASE
# 1.12 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.11 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.10 10-Jul-2002 deraadt

shorten address printout


Revision tags: OPENBSD_3_1_BASE
# 1.9 14-Mar-2002 millert

First round of __P removal in sys


# 1.8 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.7 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


Revision tags: UBC_BASE
# 1.6 06-Nov-2001 miod

branches: 1.6.2;
Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


# 1.5 05-Nov-2001 todd

compile fix; fgsch@ ok


# 1.4 05-Nov-2001 fgsch

Use ether_input_mbuf(). As a bonus, tcpdump should show the ethernet
headers now; nate@ ok.


Revision tags: OPENBSD_3_0_BASE
# 1.3 11-Sep-2001 miod

branches: 1.3.4;
Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.2 05-Sep-2001 nate

fix pci_intr_map so that it uses the new interface


# 1.1 04-Sep-2001 nate

Driver for the Level1 LXT1001 Gigabit Ethernet Chip.
From FreeBSD


# 1.80 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_3_BASE OPENBSD_7_4_BASE
# 1.79 09-Oct-2022 kevlo

Fix typo in debug messages.

ok deraadt@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.78 11-Mar-2022 mpi

Constify struct cfattach.


# 1.77 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.75 10-Jul-2020 patrick

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

ok dlg@ tobhe@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.74 25-Sep-2019 kevlo

Argument order fix for MCLGETI.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.73 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.72 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.71 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.70 24-Nov-2015 mpi

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


# 1.69 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.68 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.67 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.66 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.65 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


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

unifdef INET


# 1.63 20-Aug-2014 dlg

replace the custom jumbo allocator with MCLGETI.

putting this in the tree to make it easier for people to test.


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

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.61 26-Nov-2013 mpi

Instead of comparing the lower and higher addresses of all the multicast
entries to decide if the IFF_ALLMULTI flag should be set, check if there
is at least one real range between them.

This should not change the behavior of any driver but if you encounter
any problem, feel free to revert the offending chunk and ping me about
it.

ok naddy@, dlg@


# 1.60 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


# 1.59 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.58 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.57 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.56 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


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

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


# 1.54 03-Apr-2011 jasper

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

ok claudio@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.53 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.52 13-Aug-2009 jasper

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

ok dlg@


# 1.51 10-Aug-2009 deraadt

delete xxshutdown handlers that are never even hooked up


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.50 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.49 22-Oct-2008 brad

Fix a typo.


# 1.48 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.47 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.46 26-Nov-2007 martynas

typos; ok jmc@
sys/netinet/in_pcb.c and sys/net/bridgestp.c ok henning@
sys/dev/pci/bktr/* ok jakemsr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.45 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


Revision tags: OPENBSD_4_0_BASE
# 1.44 28-May-2006 brad

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

ok reyk@


# 1.43 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.42 27-May-2006 brad

remove FreeBSD specific code.


# 1.41 27-May-2006 brad

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

ok reyk@


# 1.40 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.39 30-Apr-2006 brad

- check for IFF_RUNNING being set before calling lge_init().
- call lge_setmulti() when enabling/disabling promisc mode or
if the IFF_ALLMULTI flag is set.


# 1.38 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.37 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.36 24-Dec-2005 brad

clear RUNNING here to do a full init.


# 1.35 23-Nov-2005 mickey

assume vtophys(vaddr_t) just what all the other archs expect; no functional change


# 1.34 09-Oct-2005 brad

fix bus_dmamem_alloc() failure case.


# 1.33 09-Oct-2005 brad

use pci_matchbyid().


# 1.32 08-Oct-2005 brad

stop bzero'ing the softc in lge_attach() and tada lge(4) now works
to some extent.


# 1.31 08-Oct-2005 brad

a little better like this.


# 1.30 08-Oct-2005 brad

- remove return at end of void function
- function return value on separate line
- ANSI protos


# 1.29 08-Oct-2005 brad

remove unused VLAN headers.


# 1.28 07-Oct-2005 brad

IFCAP_VLAN_MTU


# 1.27 07-Oct-2005 brad

revert this change.


# 1.26 07-Oct-2005 brad

sync lge_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()


# 1.25 07-Oct-2005 brad

free bus_dma resources for all failures in attach.


# 1.24 07-Oct-2005 brad

some fixes for the lge driver, though still doesn't work..

- use MEXTADD() macro
- remove spl from attach
- use splnet
- disestablish interrupt on failure and some other cleaning


# 1.23 11-Sep-2005 mickey

do not inline pci_mapreg_map() anymore as it is olrite now; brad@ ok


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

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


# 1.21 02-Jul-2005 brad

clear IFF_RUNNING & IFF_OACTIVE in foo_stop() before de-allocating resources.


# 1.20 18-Jun-2005 brad

though this doesn't work yet at least allow it to compile first.


# 1.19 11-May-2005 brad

Do not call mii_pollstat() immediately after mii_tick().

From FreeBSD


# 1.18 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.17 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


Revision tags: OPENBSD_3_6_BASE
# 1.16 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.15 05-Jun-2004 mcbride

- replace handrolled crc32 with ether_crc32_be()
- make multicast ranges work

ok deraadt@


# 1.14 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.13 06-Oct-2003 david

make lge(4) compile, from tedu@
ok jason@ nate@


Revision tags: OPENBSD_3_4_BASE
# 1.12 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.11 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.10 10-Jul-2002 deraadt

shorten address printout


Revision tags: OPENBSD_3_1_BASE
# 1.9 14-Mar-2002 millert

First round of __P removal in sys


# 1.8 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.7 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


Revision tags: UBC_BASE
# 1.6 06-Nov-2001 miod

branches: 1.6.2;
Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


# 1.5 05-Nov-2001 todd

compile fix; fgsch@ ok


# 1.4 05-Nov-2001 fgsch

Use ether_input_mbuf(). As a bonus, tcpdump should show the ethernet
headers now; nate@ ok.


Revision tags: OPENBSD_3_0_BASE
# 1.3 11-Sep-2001 miod

branches: 1.3.4;
Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.2 05-Sep-2001 nate

fix pci_intr_map so that it uses the new interface


# 1.1 04-Sep-2001 nate

Driver for the Level1 LXT1001 Gigabit Ethernet Chip.
From FreeBSD


# 1.79 09-Oct-2022 kevlo

Fix typo in debug messages.

ok deraadt@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.78 11-Mar-2022 mpi

Constify struct cfattach.


# 1.77 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.75 10-Jul-2020 patrick

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

ok dlg@ tobhe@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.74 25-Sep-2019 kevlo

Argument order fix for MCLGETI.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.73 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.72 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.71 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.70 24-Nov-2015 mpi

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


# 1.69 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.68 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.67 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.66 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.65 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


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

unifdef INET


# 1.63 20-Aug-2014 dlg

replace the custom jumbo allocator with MCLGETI.

putting this in the tree to make it easier for people to test.


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

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.61 26-Nov-2013 mpi

Instead of comparing the lower and higher addresses of all the multicast
entries to decide if the IFF_ALLMULTI flag should be set, check if there
is at least one real range between them.

This should not change the behavior of any driver but if you encounter
any problem, feel free to revert the offending chunk and ping me about
it.

ok naddy@, dlg@


# 1.60 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


# 1.59 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.58 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.57 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.56 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


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

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


# 1.54 03-Apr-2011 jasper

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

ok claudio@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.53 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.52 13-Aug-2009 jasper

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

ok dlg@


# 1.51 10-Aug-2009 deraadt

delete xxshutdown handlers that are never even hooked up


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.50 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.49 22-Oct-2008 brad

Fix a typo.


# 1.48 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.47 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.46 26-Nov-2007 martynas

typos; ok jmc@
sys/netinet/in_pcb.c and sys/net/bridgestp.c ok henning@
sys/dev/pci/bktr/* ok jakemsr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.45 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


Revision tags: OPENBSD_4_0_BASE
# 1.44 28-May-2006 brad

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

ok reyk@


# 1.43 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.42 27-May-2006 brad

remove FreeBSD specific code.


# 1.41 27-May-2006 brad

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

ok reyk@


# 1.40 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.39 30-Apr-2006 brad

- check for IFF_RUNNING being set before calling lge_init().
- call lge_setmulti() when enabling/disabling promisc mode or
if the IFF_ALLMULTI flag is set.


# 1.38 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.37 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.36 24-Dec-2005 brad

clear RUNNING here to do a full init.


# 1.35 23-Nov-2005 mickey

assume vtophys(vaddr_t) just what all the other archs expect; no functional change


# 1.34 09-Oct-2005 brad

fix bus_dmamem_alloc() failure case.


# 1.33 09-Oct-2005 brad

use pci_matchbyid().


# 1.32 08-Oct-2005 brad

stop bzero'ing the softc in lge_attach() and tada lge(4) now works
to some extent.


# 1.31 08-Oct-2005 brad

a little better like this.


# 1.30 08-Oct-2005 brad

- remove return at end of void function
- function return value on separate line
- ANSI protos


# 1.29 08-Oct-2005 brad

remove unused VLAN headers.


# 1.28 07-Oct-2005 brad

IFCAP_VLAN_MTU


# 1.27 07-Oct-2005 brad

revert this change.


# 1.26 07-Oct-2005 brad

sync lge_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()


# 1.25 07-Oct-2005 brad

free bus_dma resources for all failures in attach.


# 1.24 07-Oct-2005 brad

some fixes for the lge driver, though still doesn't work..

- use MEXTADD() macro
- remove spl from attach
- use splnet
- disestablish interrupt on failure and some other cleaning


# 1.23 11-Sep-2005 mickey

do not inline pci_mapreg_map() anymore as it is olrite now; brad@ ok


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

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


# 1.21 02-Jul-2005 brad

clear IFF_RUNNING & IFF_OACTIVE in foo_stop() before de-allocating resources.


# 1.20 18-Jun-2005 brad

though this doesn't work yet at least allow it to compile first.


# 1.19 11-May-2005 brad

Do not call mii_pollstat() immediately after mii_tick().

From FreeBSD


# 1.18 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.17 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


Revision tags: OPENBSD_3_6_BASE
# 1.16 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.15 05-Jun-2004 mcbride

- replace handrolled crc32 with ether_crc32_be()
- make multicast ranges work

ok deraadt@


# 1.14 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.13 06-Oct-2003 david

make lge(4) compile, from tedu@
ok jason@ nate@


Revision tags: OPENBSD_3_4_BASE
# 1.12 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.11 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.10 10-Jul-2002 deraadt

shorten address printout


Revision tags: OPENBSD_3_1_BASE
# 1.9 14-Mar-2002 millert

First round of __P removal in sys


# 1.8 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.7 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


Revision tags: UBC_BASE
# 1.6 06-Nov-2001 miod

branches: 1.6.2;
Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


# 1.5 05-Nov-2001 todd

compile fix; fgsch@ ok


# 1.4 05-Nov-2001 fgsch

Use ether_input_mbuf(). As a bonus, tcpdump should show the ethernet
headers now; nate@ ok.


Revision tags: OPENBSD_3_0_BASE
# 1.3 11-Sep-2001 miod

branches: 1.3.4;
Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.2 05-Sep-2001 nate

fix pci_intr_map so that it uses the new interface


# 1.1 04-Sep-2001 nate

Driver for the Level1 LXT1001 Gigabit Ethernet Chip.
From FreeBSD


# 1.78 11-Mar-2022 mpi

Constify struct cfattach.


# 1.77 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.75 10-Jul-2020 patrick

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

ok dlg@ tobhe@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.74 25-Sep-2019 kevlo

Argument order fix for MCLGETI.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.73 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.72 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.71 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.70 24-Nov-2015 mpi

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


# 1.69 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.68 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.67 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.66 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.65 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


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

unifdef INET


# 1.63 20-Aug-2014 dlg

replace the custom jumbo allocator with MCLGETI.

putting this in the tree to make it easier for people to test.


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

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.61 26-Nov-2013 mpi

Instead of comparing the lower and higher addresses of all the multicast
entries to decide if the IFF_ALLMULTI flag should be set, check if there
is at least one real range between them.

This should not change the behavior of any driver but if you encounter
any problem, feel free to revert the offending chunk and ping me about
it.

ok naddy@, dlg@


# 1.60 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


# 1.59 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.58 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.57 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.56 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


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

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


# 1.54 03-Apr-2011 jasper

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

ok claudio@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.53 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.52 13-Aug-2009 jasper

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

ok dlg@


# 1.51 10-Aug-2009 deraadt

delete xxshutdown handlers that are never even hooked up


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.50 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.49 22-Oct-2008 brad

Fix a typo.


# 1.48 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.47 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.46 26-Nov-2007 martynas

typos; ok jmc@
sys/netinet/in_pcb.c and sys/net/bridgestp.c ok henning@
sys/dev/pci/bktr/* ok jakemsr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.45 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


Revision tags: OPENBSD_4_0_BASE
# 1.44 28-May-2006 brad

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

ok reyk@


# 1.43 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.42 27-May-2006 brad

remove FreeBSD specific code.


# 1.41 27-May-2006 brad

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

ok reyk@


# 1.40 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.39 30-Apr-2006 brad

- check for IFF_RUNNING being set before calling lge_init().
- call lge_setmulti() when enabling/disabling promisc mode or
if the IFF_ALLMULTI flag is set.


# 1.38 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.37 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.36 24-Dec-2005 brad

clear RUNNING here to do a full init.


# 1.35 23-Nov-2005 mickey

assume vtophys(vaddr_t) just what all the other archs expect; no functional change


# 1.34 09-Oct-2005 brad

fix bus_dmamem_alloc() failure case.


# 1.33 09-Oct-2005 brad

use pci_matchbyid().


# 1.32 08-Oct-2005 brad

stop bzero'ing the softc in lge_attach() and tada lge(4) now works
to some extent.


# 1.31 08-Oct-2005 brad

a little better like this.


# 1.30 08-Oct-2005 brad

- remove return at end of void function
- function return value on separate line
- ANSI protos


# 1.29 08-Oct-2005 brad

remove unused VLAN headers.


# 1.28 07-Oct-2005 brad

IFCAP_VLAN_MTU


# 1.27 07-Oct-2005 brad

revert this change.


# 1.26 07-Oct-2005 brad

sync lge_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()


# 1.25 07-Oct-2005 brad

free bus_dma resources for all failures in attach.


# 1.24 07-Oct-2005 brad

some fixes for the lge driver, though still doesn't work..

- use MEXTADD() macro
- remove spl from attach
- use splnet
- disestablish interrupt on failure and some other cleaning


# 1.23 11-Sep-2005 mickey

do not inline pci_mapreg_map() anymore as it is olrite now; brad@ ok


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

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


# 1.21 02-Jul-2005 brad

clear IFF_RUNNING & IFF_OACTIVE in foo_stop() before de-allocating resources.


# 1.20 18-Jun-2005 brad

though this doesn't work yet at least allow it to compile first.


# 1.19 11-May-2005 brad

Do not call mii_pollstat() immediately after mii_tick().

From FreeBSD


# 1.18 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.17 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


Revision tags: OPENBSD_3_6_BASE
# 1.16 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.15 05-Jun-2004 mcbride

- replace handrolled crc32 with ether_crc32_be()
- make multicast ranges work

ok deraadt@


# 1.14 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.13 06-Oct-2003 david

make lge(4) compile, from tedu@
ok jason@ nate@


Revision tags: OPENBSD_3_4_BASE
# 1.12 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.11 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.10 10-Jul-2002 deraadt

shorten address printout


Revision tags: OPENBSD_3_1_BASE
# 1.9 14-Mar-2002 millert

First round of __P removal in sys


# 1.8 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.7 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


Revision tags: UBC_BASE
# 1.6 06-Nov-2001 miod

branches: 1.6.2;
Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


# 1.5 05-Nov-2001 todd

compile fix; fgsch@ ok


# 1.4 05-Nov-2001 fgsch

Use ether_input_mbuf(). As a bonus, tcpdump should show the ethernet
headers now; nate@ ok.


Revision tags: OPENBSD_3_0_BASE
# 1.3 11-Sep-2001 miod

branches: 1.3.4;
Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.2 05-Sep-2001 nate

fix pci_intr_map so that it uses the new interface


# 1.1 04-Sep-2001 nate

Driver for the Level1 LXT1001 Gigabit Ethernet Chip.
From FreeBSD


# 1.77 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.75 10-Jul-2020 patrick

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

ok dlg@ tobhe@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.74 25-Sep-2019 kevlo

Argument order fix for MCLGETI.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.73 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.72 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.71 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.70 24-Nov-2015 mpi

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


# 1.69 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.68 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.67 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.66 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.65 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


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

unifdef INET


# 1.63 20-Aug-2014 dlg

replace the custom jumbo allocator with MCLGETI.

putting this in the tree to make it easier for people to test.


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

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.61 26-Nov-2013 mpi

Instead of comparing the lower and higher addresses of all the multicast
entries to decide if the IFF_ALLMULTI flag should be set, check if there
is at least one real range between them.

This should not change the behavior of any driver but if you encounter
any problem, feel free to revert the offending chunk and ping me about
it.

ok naddy@, dlg@


# 1.60 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


# 1.59 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.58 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.57 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.56 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


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

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


# 1.54 03-Apr-2011 jasper

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

ok claudio@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.53 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.52 13-Aug-2009 jasper

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

ok dlg@


# 1.51 10-Aug-2009 deraadt

delete xxshutdown handlers that are never even hooked up


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.50 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.49 22-Oct-2008 brad

Fix a typo.


# 1.48 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.47 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.46 26-Nov-2007 martynas

typos; ok jmc@
sys/netinet/in_pcb.c and sys/net/bridgestp.c ok henning@
sys/dev/pci/bktr/* ok jakemsr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.45 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


Revision tags: OPENBSD_4_0_BASE
# 1.44 28-May-2006 brad

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

ok reyk@


# 1.43 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.42 27-May-2006 brad

remove FreeBSD specific code.


# 1.41 27-May-2006 brad

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

ok reyk@


# 1.40 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.39 30-Apr-2006 brad

- check for IFF_RUNNING being set before calling lge_init().
- call lge_setmulti() when enabling/disabling promisc mode or
if the IFF_ALLMULTI flag is set.


# 1.38 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.37 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.36 24-Dec-2005 brad

clear RUNNING here to do a full init.


# 1.35 23-Nov-2005 mickey

assume vtophys(vaddr_t) just what all the other archs expect; no functional change


# 1.34 09-Oct-2005 brad

fix bus_dmamem_alloc() failure case.


# 1.33 09-Oct-2005 brad

use pci_matchbyid().


# 1.32 08-Oct-2005 brad

stop bzero'ing the softc in lge_attach() and tada lge(4) now works
to some extent.


# 1.31 08-Oct-2005 brad

a little better like this.


# 1.30 08-Oct-2005 brad

- remove return at end of void function
- function return value on separate line
- ANSI protos


# 1.29 08-Oct-2005 brad

remove unused VLAN headers.


# 1.28 07-Oct-2005 brad

IFCAP_VLAN_MTU


# 1.27 07-Oct-2005 brad

revert this change.


# 1.26 07-Oct-2005 brad

sync lge_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()


# 1.25 07-Oct-2005 brad

free bus_dma resources for all failures in attach.


# 1.24 07-Oct-2005 brad

some fixes for the lge driver, though still doesn't work..

- use MEXTADD() macro
- remove spl from attach
- use splnet
- disestablish interrupt on failure and some other cleaning


# 1.23 11-Sep-2005 mickey

do not inline pci_mapreg_map() anymore as it is olrite now; brad@ ok


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

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


# 1.21 02-Jul-2005 brad

clear IFF_RUNNING & IFF_OACTIVE in foo_stop() before de-allocating resources.


# 1.20 18-Jun-2005 brad

though this doesn't work yet at least allow it to compile first.


# 1.19 11-May-2005 brad

Do not call mii_pollstat() immediately after mii_tick().

From FreeBSD


# 1.18 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.17 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


Revision tags: OPENBSD_3_6_BASE
# 1.16 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.15 05-Jun-2004 mcbride

- replace handrolled crc32 with ether_crc32_be()
- make multicast ranges work

ok deraadt@


# 1.14 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.13 06-Oct-2003 david

make lge(4) compile, from tedu@
ok jason@ nate@


Revision tags: OPENBSD_3_4_BASE
# 1.12 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.11 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.10 10-Jul-2002 deraadt

shorten address printout


Revision tags: OPENBSD_3_1_BASE
# 1.9 14-Mar-2002 millert

First round of __P removal in sys


# 1.8 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.7 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


Revision tags: UBC_BASE
# 1.6 06-Nov-2001 miod

branches: 1.6.2;
Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


# 1.5 05-Nov-2001 todd

compile fix; fgsch@ ok


# 1.4 05-Nov-2001 fgsch

Use ether_input_mbuf(). As a bonus, tcpdump should show the ethernet
headers now; nate@ ok.


Revision tags: OPENBSD_3_0_BASE
# 1.3 11-Sep-2001 miod

branches: 1.3.4;
Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.2 05-Sep-2001 nate

fix pci_intr_map so that it uses the new interface


# 1.1 04-Sep-2001 nate

Driver for the Level1 LXT1001 Gigabit Ethernet Chip.
From FreeBSD


# 1.76 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.75 10-Jul-2020 patrick

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

ok dlg@ tobhe@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.74 25-Sep-2019 kevlo

Argument order fix for MCLGETI.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.73 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.72 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.71 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.70 24-Nov-2015 mpi

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


# 1.69 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.68 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.67 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.66 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.65 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


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

unifdef INET


# 1.63 20-Aug-2014 dlg

replace the custom jumbo allocator with MCLGETI.

putting this in the tree to make it easier for people to test.


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

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.61 26-Nov-2013 mpi

Instead of comparing the lower and higher addresses of all the multicast
entries to decide if the IFF_ALLMULTI flag should be set, check if there
is at least one real range between them.

This should not change the behavior of any driver but if you encounter
any problem, feel free to revert the offending chunk and ping me about
it.

ok naddy@, dlg@


# 1.60 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


# 1.59 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.58 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.57 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.56 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


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

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


# 1.54 03-Apr-2011 jasper

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

ok claudio@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.53 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.52 13-Aug-2009 jasper

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

ok dlg@


# 1.51 10-Aug-2009 deraadt

delete xxshutdown handlers that are never even hooked up


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.50 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.49 22-Oct-2008 brad

Fix a typo.


# 1.48 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.47 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.46 26-Nov-2007 martynas

typos; ok jmc@
sys/netinet/in_pcb.c and sys/net/bridgestp.c ok henning@
sys/dev/pci/bktr/* ok jakemsr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.45 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


Revision tags: OPENBSD_4_0_BASE
# 1.44 28-May-2006 brad

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

ok reyk@


# 1.43 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.42 27-May-2006 brad

remove FreeBSD specific code.


# 1.41 27-May-2006 brad

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

ok reyk@


# 1.40 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.39 30-Apr-2006 brad

- check for IFF_RUNNING being set before calling lge_init().
- call lge_setmulti() when enabling/disabling promisc mode or
if the IFF_ALLMULTI flag is set.


# 1.38 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.37 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.36 24-Dec-2005 brad

clear RUNNING here to do a full init.


# 1.35 23-Nov-2005 mickey

assume vtophys(vaddr_t) just what all the other archs expect; no functional change


# 1.34 09-Oct-2005 brad

fix bus_dmamem_alloc() failure case.


# 1.33 09-Oct-2005 brad

use pci_matchbyid().


# 1.32 08-Oct-2005 brad

stop bzero'ing the softc in lge_attach() and tada lge(4) now works
to some extent.


# 1.31 08-Oct-2005 brad

a little better like this.


# 1.30 08-Oct-2005 brad

- remove return at end of void function
- function return value on separate line
- ANSI protos


# 1.29 08-Oct-2005 brad

remove unused VLAN headers.


# 1.28 07-Oct-2005 brad

IFCAP_VLAN_MTU


# 1.27 07-Oct-2005 brad

revert this change.


# 1.26 07-Oct-2005 brad

sync lge_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()


# 1.25 07-Oct-2005 brad

free bus_dma resources for all failures in attach.


# 1.24 07-Oct-2005 brad

some fixes for the lge driver, though still doesn't work..

- use MEXTADD() macro
- remove spl from attach
- use splnet
- disestablish interrupt on failure and some other cleaning


# 1.23 11-Sep-2005 mickey

do not inline pci_mapreg_map() anymore as it is olrite now; brad@ ok


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

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


# 1.21 02-Jul-2005 brad

clear IFF_RUNNING & IFF_OACTIVE in foo_stop() before de-allocating resources.


# 1.20 18-Jun-2005 brad

though this doesn't work yet at least allow it to compile first.


# 1.19 11-May-2005 brad

Do not call mii_pollstat() immediately after mii_tick().

From FreeBSD


# 1.18 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.17 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


Revision tags: OPENBSD_3_6_BASE
# 1.16 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.15 05-Jun-2004 mcbride

- replace handrolled crc32 with ether_crc32_be()
- make multicast ranges work

ok deraadt@


# 1.14 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.13 06-Oct-2003 david

make lge(4) compile, from tedu@
ok jason@ nate@


Revision tags: OPENBSD_3_4_BASE
# 1.12 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.11 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.10 10-Jul-2002 deraadt

shorten address printout


Revision tags: OPENBSD_3_1_BASE
# 1.9 14-Mar-2002 millert

First round of __P removal in sys


# 1.8 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.7 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


Revision tags: UBC_BASE
# 1.6 06-Nov-2001 miod

branches: 1.6.2;
Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


# 1.5 05-Nov-2001 todd

compile fix; fgsch@ ok


# 1.4 05-Nov-2001 fgsch

Use ether_input_mbuf(). As a bonus, tcpdump should show the ethernet
headers now; nate@ ok.


Revision tags: OPENBSD_3_0_BASE
# 1.3 11-Sep-2001 miod

branches: 1.3.4;
Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.2 05-Sep-2001 nate

fix pci_intr_map so that it uses the new interface


# 1.1 04-Sep-2001 nate

Driver for the Level1 LXT1001 Gigabit Ethernet Chip.
From FreeBSD


# 1.75 10-Jul-2020 patrick

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

ok dlg@ tobhe@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.74 25-Sep-2019 kevlo

Argument order fix for MCLGETI.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.73 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.72 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.71 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.70 24-Nov-2015 mpi

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


# 1.69 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.68 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.67 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.66 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.65 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


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

unifdef INET


# 1.63 20-Aug-2014 dlg

replace the custom jumbo allocator with MCLGETI.

putting this in the tree to make it easier for people to test.


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

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.61 26-Nov-2013 mpi

Instead of comparing the lower and higher addresses of all the multicast
entries to decide if the IFF_ALLMULTI flag should be set, check if there
is at least one real range between them.

This should not change the behavior of any driver but if you encounter
any problem, feel free to revert the offending chunk and ping me about
it.

ok naddy@, dlg@


# 1.60 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


# 1.59 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.58 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.57 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.56 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


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

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


# 1.54 03-Apr-2011 jasper

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

ok claudio@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.53 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.52 13-Aug-2009 jasper

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

ok dlg@


# 1.51 10-Aug-2009 deraadt

delete xxshutdown handlers that are never even hooked up


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.50 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.49 22-Oct-2008 brad

Fix a typo.


# 1.48 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.47 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.46 26-Nov-2007 martynas

typos; ok jmc@
sys/netinet/in_pcb.c and sys/net/bridgestp.c ok henning@
sys/dev/pci/bktr/* ok jakemsr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.45 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


Revision tags: OPENBSD_4_0_BASE
# 1.44 28-May-2006 brad

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

ok reyk@


# 1.43 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.42 27-May-2006 brad

remove FreeBSD specific code.


# 1.41 27-May-2006 brad

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

ok reyk@


# 1.40 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.39 30-Apr-2006 brad

- check for IFF_RUNNING being set before calling lge_init().
- call lge_setmulti() when enabling/disabling promisc mode or
if the IFF_ALLMULTI flag is set.


# 1.38 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.37 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.36 24-Dec-2005 brad

clear RUNNING here to do a full init.


# 1.35 23-Nov-2005 mickey

assume vtophys(vaddr_t) just what all the other archs expect; no functional change


# 1.34 09-Oct-2005 brad

fix bus_dmamem_alloc() failure case.


# 1.33 09-Oct-2005 brad

use pci_matchbyid().


# 1.32 08-Oct-2005 brad

stop bzero'ing the softc in lge_attach() and tada lge(4) now works
to some extent.


# 1.31 08-Oct-2005 brad

a little better like this.


# 1.30 08-Oct-2005 brad

- remove return at end of void function
- function return value on separate line
- ANSI protos


# 1.29 08-Oct-2005 brad

remove unused VLAN headers.


# 1.28 07-Oct-2005 brad

IFCAP_VLAN_MTU


# 1.27 07-Oct-2005 brad

revert this change.


# 1.26 07-Oct-2005 brad

sync lge_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()


# 1.25 07-Oct-2005 brad

free bus_dma resources for all failures in attach.


# 1.24 07-Oct-2005 brad

some fixes for the lge driver, though still doesn't work..

- use MEXTADD() macro
- remove spl from attach
- use splnet
- disestablish interrupt on failure and some other cleaning


# 1.23 11-Sep-2005 mickey

do not inline pci_mapreg_map() anymore as it is olrite now; brad@ ok


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

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


# 1.21 02-Jul-2005 brad

clear IFF_RUNNING & IFF_OACTIVE in foo_stop() before de-allocating resources.


# 1.20 18-Jun-2005 brad

though this doesn't work yet at least allow it to compile first.


# 1.19 11-May-2005 brad

Do not call mii_pollstat() immediately after mii_tick().

From FreeBSD


# 1.18 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.17 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


Revision tags: OPENBSD_3_6_BASE
# 1.16 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.15 05-Jun-2004 mcbride

- replace handrolled crc32 with ether_crc32_be()
- make multicast ranges work

ok deraadt@


# 1.14 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.13 06-Oct-2003 david

make lge(4) compile, from tedu@
ok jason@ nate@


Revision tags: OPENBSD_3_4_BASE
# 1.12 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.11 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.10 10-Jul-2002 deraadt

shorten address printout


Revision tags: OPENBSD_3_1_BASE
# 1.9 14-Mar-2002 millert

First round of __P removal in sys


# 1.8 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.7 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


Revision tags: UBC_BASE
# 1.6 06-Nov-2001 miod

branches: 1.6.2;
Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


# 1.5 05-Nov-2001 todd

compile fix; fgsch@ ok


# 1.4 05-Nov-2001 fgsch

Use ether_input_mbuf(). As a bonus, tcpdump should show the ethernet
headers now; nate@ ok.


Revision tags: OPENBSD_3_0_BASE
# 1.3 11-Sep-2001 miod

branches: 1.3.4;
Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.2 05-Sep-2001 nate

fix pci_intr_map so that it uses the new interface


# 1.1 04-Sep-2001 nate

Driver for the Level1 LXT1001 Gigabit Ethernet Chip.
From FreeBSD


# 1.74 25-Sep-2019 kevlo

Argument order fix for MCLGETI.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.73 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.72 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.71 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.70 24-Nov-2015 mpi

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


# 1.69 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.68 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.67 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.66 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.65 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


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

unifdef INET


# 1.63 20-Aug-2014 dlg

replace the custom jumbo allocator with MCLGETI.

putting this in the tree to make it easier for people to test.


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

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.61 26-Nov-2013 mpi

Instead of comparing the lower and higher addresses of all the multicast
entries to decide if the IFF_ALLMULTI flag should be set, check if there
is at least one real range between them.

This should not change the behavior of any driver but if you encounter
any problem, feel free to revert the offending chunk and ping me about
it.

ok naddy@, dlg@


# 1.60 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


# 1.59 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.58 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.57 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.56 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


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

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


# 1.54 03-Apr-2011 jasper

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

ok claudio@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.53 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.52 13-Aug-2009 jasper

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

ok dlg@


# 1.51 10-Aug-2009 deraadt

delete xxshutdown handlers that are never even hooked up


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.50 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.49 22-Oct-2008 brad

Fix a typo.


# 1.48 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.47 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.46 26-Nov-2007 martynas

typos; ok jmc@
sys/netinet/in_pcb.c and sys/net/bridgestp.c ok henning@
sys/dev/pci/bktr/* ok jakemsr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.45 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


Revision tags: OPENBSD_4_0_BASE
# 1.44 28-May-2006 brad

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

ok reyk@


# 1.43 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.42 27-May-2006 brad

remove FreeBSD specific code.


# 1.41 27-May-2006 brad

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

ok reyk@


# 1.40 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.39 30-Apr-2006 brad

- check for IFF_RUNNING being set before calling lge_init().
- call lge_setmulti() when enabling/disabling promisc mode or
if the IFF_ALLMULTI flag is set.


# 1.38 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.37 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.36 24-Dec-2005 brad

clear RUNNING here to do a full init.


# 1.35 23-Nov-2005 mickey

assume vtophys(vaddr_t) just what all the other archs expect; no functional change


# 1.34 09-Oct-2005 brad

fix bus_dmamem_alloc() failure case.


# 1.33 09-Oct-2005 brad

use pci_matchbyid().


# 1.32 08-Oct-2005 brad

stop bzero'ing the softc in lge_attach() and tada lge(4) now works
to some extent.


# 1.31 08-Oct-2005 brad

a little better like this.


# 1.30 08-Oct-2005 brad

- remove return at end of void function
- function return value on separate line
- ANSI protos


# 1.29 08-Oct-2005 brad

remove unused VLAN headers.


# 1.28 07-Oct-2005 brad

IFCAP_VLAN_MTU


# 1.27 07-Oct-2005 brad

revert this change.


# 1.26 07-Oct-2005 brad

sync lge_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()


# 1.25 07-Oct-2005 brad

free bus_dma resources for all failures in attach.


# 1.24 07-Oct-2005 brad

some fixes for the lge driver, though still doesn't work..

- use MEXTADD() macro
- remove spl from attach
- use splnet
- disestablish interrupt on failure and some other cleaning


# 1.23 11-Sep-2005 mickey

do not inline pci_mapreg_map() anymore as it is olrite now; brad@ ok


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

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


# 1.21 02-Jul-2005 brad

clear IFF_RUNNING & IFF_OACTIVE in foo_stop() before de-allocating resources.


# 1.20 18-Jun-2005 brad

though this doesn't work yet at least allow it to compile first.


# 1.19 11-May-2005 brad

Do not call mii_pollstat() immediately after mii_tick().

From FreeBSD


# 1.18 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.17 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


Revision tags: OPENBSD_3_6_BASE
# 1.16 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.15 05-Jun-2004 mcbride

- replace handrolled crc32 with ether_crc32_be()
- make multicast ranges work

ok deraadt@


# 1.14 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.13 06-Oct-2003 david

make lge(4) compile, from tedu@
ok jason@ nate@


Revision tags: OPENBSD_3_4_BASE
# 1.12 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.11 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.10 10-Jul-2002 deraadt

shorten address printout


Revision tags: OPENBSD_3_1_BASE
# 1.9 14-Mar-2002 millert

First round of __P removal in sys


# 1.8 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.7 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


Revision tags: UBC_BASE
# 1.6 06-Nov-2001 miod

branches: 1.6.2;
Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


# 1.5 05-Nov-2001 todd

compile fix; fgsch@ ok


# 1.4 05-Nov-2001 fgsch

Use ether_input_mbuf(). As a bonus, tcpdump should show the ethernet
headers now; nate@ ok.


Revision tags: OPENBSD_3_0_BASE
# 1.3 11-Sep-2001 miod

branches: 1.3.4;
Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.2 05-Sep-2001 nate

fix pci_intr_map so that it uses the new interface


# 1.1 04-Sep-2001 nate

Driver for the Level1 LXT1001 Gigabit Ethernet Chip.
From FreeBSD


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.73 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.72 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.71 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.70 24-Nov-2015 mpi

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


# 1.69 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.68 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.67 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.66 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.65 08-Apr-2015 mpi

Convert to if_input().

ok dlg@


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

unifdef INET


# 1.63 20-Aug-2014 dlg

replace the custom jumbo allocator with MCLGETI.

putting this in the tree to make it easier for people to test.


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

Fewer <netinet/in_systm.h>


Revision tags: OPENBSD_5_5_BASE
# 1.61 26-Nov-2013 mpi

Instead of comparing the lower and higher addresses of all the multicast
entries to decide if the IFF_ALLMULTI flag should be set, check if there
is at least one real range between them.

This should not change the behavior of any driver but if you encounter
any problem, feel free to revert the offending chunk and ping me about
it.

ok naddy@, dlg@


# 1.60 01-Oct-2013 sf

Use %z* for size_t

while there, fix a few %d into %u


# 1.59 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.58 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.57 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.56 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


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

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


# 1.54 03-Apr-2011 jasper

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

ok claudio@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.53 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.52 13-Aug-2009 jasper

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

ok dlg@


# 1.51 10-Aug-2009 deraadt

delete xxshutdown handlers that are never even hooked up


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.50 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.49 22-Oct-2008 brad

Fix a typo.


# 1.48 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.47 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.46 26-Nov-2007 martynas

typos; ok jmc@
sys/netinet/in_pcb.c and sys/net/bridgestp.c ok henning@
sys/dev/pci/bktr/* ok jakemsr@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.45 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


Revision tags: OPENBSD_4_0_BASE
# 1.44 28-May-2006 brad

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

ok reyk@


# 1.43 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.42 27-May-2006 brad

remove FreeBSD specific code.


# 1.41 27-May-2006 brad

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

ok reyk@


# 1.40 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.39 30-Apr-2006 brad

- check for IFF_RUNNING being set before calling lge_init().
- call lge_setmulti() when enabling/disabling promisc mode or
if the IFF_ALLMULTI flag is set.


# 1.38 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.37 20-Mar-2006 brad

de-register.


Revision tags: OPENBSD_3_9_BASE
# 1.36 24-Dec-2005 brad

clear RUNNING here to do a full init.


# 1.35 23-Nov-2005 mickey

assume vtophys(vaddr_t) just what all the other archs expect; no functional change


# 1.34 09-Oct-2005 brad

fix bus_dmamem_alloc() failure case.


# 1.33 09-Oct-2005 brad

use pci_matchbyid().


# 1.32 08-Oct-2005 brad

stop bzero'ing the softc in lge_attach() and tada lge(4) now works
to some extent.


# 1.31 08-Oct-2005 brad

a little better like this.


# 1.30 08-Oct-2005 brad

- remove return at end of void function
- function return value on separate line
- ANSI protos


# 1.29 08-Oct-2005 brad

remove unused VLAN headers.


# 1.28 07-Oct-2005 brad

IFCAP_VLAN_MTU


# 1.27 07-Oct-2005 brad

revert this change.


# 1.26 07-Oct-2005 brad

sync lge_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()


# 1.25 07-Oct-2005 brad

free bus_dma resources for all failures in attach.


# 1.24 07-Oct-2005 brad

some fixes for the lge driver, though still doesn't work..

- use MEXTADD() macro
- remove spl from attach
- use splnet
- disestablish interrupt on failure and some other cleaning


# 1.23 11-Sep-2005 mickey

do not inline pci_mapreg_map() anymore as it is olrite now; brad@ ok


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

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


# 1.21 02-Jul-2005 brad

clear IFF_RUNNING & IFF_OACTIVE in foo_stop() before de-allocating resources.


# 1.20 18-Jun-2005 brad

though this doesn't work yet at least allow it to compile first.


# 1.19 11-May-2005 brad

Do not call mii_pollstat() immediately after mii_tick().

From FreeBSD


# 1.18 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.17 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


Revision tags: OPENBSD_3_6_BASE
# 1.16 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.15 05-Jun-2004 mcbride

- replace handrolled crc32 with ether_crc32_be()
- make multicast ranges work

ok deraadt@


# 1.14 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.13 06-Oct-2003 david

make lge(4) compile, from tedu@
ok jason@ nate@


Revision tags: OPENBSD_3_4_BASE
# 1.12 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.11 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.10 10-Jul-2002 deraadt

shorten address printout


Revision tags: OPENBSD_3_1_BASE
# 1.9 14-Mar-2002 millert

First round of __P removal in sys


# 1.8 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.7 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


Revision tags: UBC_BASE
# 1.6 06-Nov-2001 miod

branches: 1.6.2;
Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


# 1.5 05-Nov-2001 todd

compile fix; fgsch@ ok


# 1.4 05-Nov-2001 fgsch

Use ether_input_mbuf(). As a bonus, tcpdump should show the ethernet
headers now; nate@ ok.


Revision tags: OPENBSD_3_0_BASE
# 1.3 11-Sep-2001 miod

branches: 1.3.4;
Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.2 05-Sep-2001 nate

fix pci_intr_map so that it uses the new interface


# 1.1 04-Sep-2001 nate

Driver for the Level1 LXT1001 Gigabit Ethernet Chip.
From FreeBSD