History log of /openbsd-current/sys/dev/usb/if_url.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.90 23-May-2024 jsg

remove unneeded includes; ok mpi@


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.89 09-Aug-2021 jmatthew

Fix up flags passed to usbd_open_pipe_intr() - interrupt pipes are always
opened exclusively, and the flags argument is passed to usbd_setup_xfer().
USBD_EXCLUSIVE_USE has the same value as USBD_NO_COPY, which means that
data transferred would not be copied to the buffer where the driver expects
it.

None of these drivers actually used the interrupt data for anything, and
in some the interrupt pipe code was #if 0'd out, so this doesn't change
anything, but fixing this up prevents unwary developers like me from
copying code that doesn't work.

ok mglocker@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.88 31-Jul-2020 mglocker

Nuke all occurrences of usbd_abort_pipe() if it gets called right
before usbd_close_pipe(), since usbd_close_pipe() already takes care
about aborting non-empty pipes.

As investigated by gerhard@ usbdi.c rev. 1.57 did add usbd_abort_pipe()
to usbd_close_pipe(), but the drivers didn't get cleaned up afterwards.

ok gerhard@


# 1.87 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_7_BASE
# 1.86 22-Feb-2020 jasper

use the UE_GET_XFERTYPE macro where applicable

ok mpi@


# 1.85 05-Jan-2020 jsg

remove duplicate device ids


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.84 02-Oct-2018 stsp

Make some USB ioctls return ENXIO, instead of EIO, if usbd_is_dying().
Brings us one step closer towards making this condition's error code
consistent across all USB drivers.
Patch by Moritz Buhl
ok mpi@ bluhm@


# 1.83 03-Jul-2018 kevlo

Use LIST_FOREACH construct instead of homebrew loop.

ok bluhm@, mpi@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 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@


# 1.81 06-Nov-2016 mpi

Avoid calling usbd_set_config_no() in *_attach() and let the stack do
it instead.

If anything bad happen due to a malformed descriptor it makes no sense
to try to attach a driver, and bail before probing.

This is similar to the change to avoid calling usbd_set_config_index().


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

G/C IFQ_SET_READY().


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

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


# 1.77 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.76 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.75 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.74 27-Mar-2015 uaa

simply do if_input() between splnet() and splx(), like other drivers
(such as if_udav.c).

ok by mpi@


# 1.73 14-Mar-2015 jsg

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

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.72 12-Feb-2015 mpi

Convert to if_input().

ok dlg@


# 1.71 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.70 13-Jul-2014 mpi

No need for <netinet/in_systm.h> here.


# 1.69 12-Jul-2014 mpi

Kill a bunch of DVACT_DEACTIVATE handlers whose only purpose were to
set the 'dying' flag of a device. Such handlers are useless now that
usbd_detach() already set this flag.

Even if the purpose of this flag is questionnable on OpenBSD because
DVACT_DEACTIVATE acts as a pre-detach event, this is just a first small
step towards the simplification of the autoconf(9) device states.

This cleaning is now possible thanks to the work of pirofti@ to convert
all the USB drivers to properly use usbd_is_dying().

Discussed many times with deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.68 15-Nov-2013 pirofti

Clean-up usbd_abort_pipe() usage.


This function never fails. So change it's return type to void and
adjust the copy-pasted callers that were checking the return.

"If it compiles, ok" mpi@


# 1.67 07-Aug-2013 bluhm

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


Revision tags: OPENBSD_5_4_BASE
# 1.66 15-Apr-2013 mglocker

Get rid of various 'typedef struct' definitions and use plain structure
definitions instead. We don't change usb.h for now to stay compatible
with userland.

Tested by mpi@ on macppc and myself on i386.

ok mpi@


# 1.65 28-Mar-2013 tedu

proc.h is way too much header for usb to handle.


Revision tags: OPENBSD_5_3_BASE
# 1.64 29-Jan-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.63 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.62 23-Jun-2011 deraadt

a bit more ansi; ok tedu


Revision tags: OPENBSD_4_9_BASE
# 1.61 25-Jan-2011 jakemsr

garbage collect "usb events". without /dev/usb there is no way to access
them from userland, and nothing in the kernel uses them.

ok krw@, miod@


# 1.60 06-Dec-2010 jakemsr

* replace per-driver dying and/or other state variables with use of
usbd_deactivete() and usbd_is_dying()
* use usbd_deactivate() in activate()/DEACTIVATE
* convert a few more direct checks of the associated bus' dying flag
with usbd_is_dying()


# 1.59 27-Oct-2010 jakemsr

don't free network related resources if they were not allocated


# 1.58 23-Oct-2010 jakemsr

check that a timeout(9) has been initialized before deleting it

ok phessler


# 1.57 23-Oct-2010 jakemsr

create another kthread to run xfer abort tasks. xfer abort tasks cannot
be run from the generic task kthread, because xfers that need to be
aborted block newly queued tasks from running (i.e. the xfer to be aborted
blocks the abort of that task). as there are now three types of usb
tasks, add an argument to usb_init_task() and another member to struct
usb_task to specify the task type.

fixes boot hangs that are showing up because we now use usb tasks to
attach/detach usb devices.


# 1.56 27-Aug-2010 deraadt

Delete comments about these drivers needing powerhook support; they don't.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.55 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.54 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.53 06-Nov-2008 brad

Set the IFCAP_VLAN_MTU capabilities flag so these interfaces are allowed
to transmit full sized VLAN tagged frames.


# 1.52 03-Oct-2008 brad

Use ether_ioctl().


# 1.51 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_3_BASE OPENBSD_4_4_BASE
# 1.50 23-Nov-2007 mbalmer

Sanitize the use of timeouts:

Instead of calling timeout_set(..., NULL, NULL) in attach routines and
later
timeout_del(...)
timeout_set(..., func, arg)
timeout_add(..., time)
set the function and argument in the initial timeout_set() call and only
use timeout_add(..., time) later.

ok dlg, fgsch, krw, winiger


# 1.49 11-Oct-2007 deraadt

treat usb vendor/product names as a locator, and have usbd_print handle it,
so that it shows up before the :. as a result, all the usb devices do not
need to have name printing code anymore. all this now works and prints
nicely because usbd_probe_and_attach() is serialized. ok kettenis


Revision tags: OPENBSD_4_2_BASE
# 1.48 14-Jun-2007 mbalmer

Remove the definition and usage of the USB_DECLARE_DRIVER_CLASS and
USB_DECLARE_DRIVER macros.

No binary change.

ok dlg.


# 1.47 13-Jun-2007 mbalmer

Remove the definition and usage of the IF_INPUT macro which was defined
as ether_input_mbuf which is itself a macro for ether_input.

No binary change.

ok dlg.


# 1.46 12-Jun-2007 mbalmer

Remove the definition and use of the device_ptr_t which was a struct device *.

No binary change.

ok mk.


# 1.45 11-Jun-2007 mbalmer

Remove the definition and usage of the USBGETSOFTC macro, which was really
only a cast to (void *).

ok jsg.


# 1.44 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEVNAME macro.

(This might look easy, but it was a big diff. Thanks to dlg and especially jsg
for looking over it; we found at least four mistakes in the initial diff.)

ok jsg.


# 1.43 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEV macro. It only created confusion
and the address of it's argument: USBDEV(sc->sc_dev) yields &sc->sc_dev.

No binary changes.

ok jsg.


# 1.42 10-Jun-2007 mbalmer

Remove definitions and usage of usb_callout and related macros. These macros
were used as a layer of confusion^Wabstraction around the timeout(9) API.

No binary change.

ok jsg.


# 1.41 09-Jun-2007 mbalmer

Remove the definition and use of if_deactivate(). It was defined empty and
thus produced no code at all.

No binary change.

ok jsg.


# 1.40 05-Jun-2007 mbalmer

Remove the "Static" declaration of many functions. It was defined to be empty
and it was not consistently used. It was confusing as it suggested these
functions were static, which they were not.

discussed with dlg and jsg, ok jsg.


# 1.39 04-Jun-2007 mbalmer

Last part of FreeBSD/NetBSD sepcific code removal.

ok jsg@


# 1.38 27-May-2007 jsg

Farewell USB_{ATTACH,MATCH,DETACH}* you will not be missed.
ok deraadt@ krw@ mbalmer@


# 1.37 21-May-2007 jsg

Remove logprintf macro


# 1.36 21-May-2007 jsg

Remove Ether_ifattach macro


# 1.35 06-May-2007 krw

More lockmgr -> rwlock low hanging fruit.

ok dlg@


Revision tags: OPENBSD_4_1_BASE
# 1.34 11-Feb-2007 miod

Remove _KERNEL_OPT leftovers.


Revision tags: OPENBSD_4_0_BASE
# 1.33 14-Jul-2006 brad

add ZyXEL USB id, remove useless comments and reorder USB devices.


# 1.32 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.31 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.30 07-Mar-2006 krw

Remove last NRND NetBSDisms from tree.

ok deraadt@ brad@


Revision tags: OPENBSD_3_9_BASE
# 1.29 06-Feb-2006 jmc

typos from alexey dobriyan;


# 1.28 29-Jan-2006 brad

Use usbd_clear_endpoint_stall_async() when clearing endpoint stalls in
an interrupt context.

From NetBSD

ok dlg@


# 1.27 23-Sep-2005 grunk

{TrendNet,Trendware} -> TRENDnet, ok jsg@


Revision tags: OPENBSD_3_8_BASE
# 1.26 01-Aug-2005 brad

Don't keep the devinfo string on the stack, instead use malloc/free.
This should cure some rare stack overflows.

From augustss NetBSD

ok dlg@ pascoe@


# 1.25 19-Jul-2005 jsg

Update for GREENHOUSE2 -> REALTEK USB vid change.


# 1.24 02-Jul-2005 brad

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


# 1.23 02-Jul-2005 brad

don't call mii_pollstat() right after mii_tick() in foo_tick_task()


# 1.22 08-Jun-2005 henning

remove netns crud.
some drivers actually had hooks for SIOCSIFADDR, most just useless includes
"looks good" deraadt miod brad


Revision tags: OPENBSD_3_7_BASE
# 1.21 03-Mar-2005 itojun

ethernet on OQO model 01 device cable. dlg ok


# 1.20 03-Jan-2005 brad

- make sure int is in running state before touching the multicast filters
- call foo_setmulti only instead of init'ing the chip
- don't overwrite potential error return with success when calling
ether_addmulti/ether_delmulti

ok dlg@


# 1.19 17-Nov-2004 deraadt

Three mode devices found in the wild, I think


# 1.18 10-Nov-2004 grange

strncpy->strlcpy
ok henning@


# 1.17 16-Oct-2004 jsg

Add Longshine LCS-8138TX and Micronet SP128AR found in linux driver
ok dlg@


# 1.16 29-Sep-2004 dlg

from netbsd: if_url.c 1.8, if_urlreg.h 1.2, urlphy.c 1.9 and urlphyreg.h 1.2
via Jonathan Gray
log message:

Remove advertising clauses from code written by Shingo WATANABE.
He has kindly consented it.


# 1.15 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.14 08-Jul-2004 deraadt

put "do { } while (0)" wrappers on all the debug maroc functions


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.13 23-Dec-2003 deraadt

init ether address correctly, since our Ether_ifattach macro does not do
that job; 3612, rspmn@arcor.de


# 1.12 15-Dec-2003 cedric

Set devclass to DV_IFNET for all USB network drivers.
ok deraadt@ nate@


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.11 07-May-2003 deraadt

string cleanup; nate ok


Revision tags: OPENBSD_3_3_BASE
# 1.10 27-Jan-2003 jason

branches: 1.10.4;
pad minimum frames with 0's; based on netbsd


# 1.9 11-Nov-2002 nate

sync with NetBSD


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.8 29-Sep-2002 jason

Plug memory leak; nyar-junk@int0rnet.net


# 1.7 25-Jul-2002 nate

get rid of trailing whitespace


# 1.6 10-Jul-2002 deraadt

shorten address printout


# 1.5 26-Jun-2002 espie

Kill __FUNCTION__.


# 1.4 09-May-2002 nate

branches: 1.4.2;
Fix ioctl handling
Add default MTU
fix typo

errors noted by Jason Ackley <jason@ackley.net>


# 1.3 07-May-2002 nate

Add a driver for Realtek RTL8150L based ethernet devices
From NetBSD


# 1.2 07-May-2002 nate

Meant to commit only ulpt and committed everything. Most things weren't ready


# 1.1 07-May-2002 nate

Sync ulpt driver with NetBSD


# 1.89 09-Aug-2021 jmatthew

Fix up flags passed to usbd_open_pipe_intr() - interrupt pipes are always
opened exclusively, and the flags argument is passed to usbd_setup_xfer().
USBD_EXCLUSIVE_USE has the same value as USBD_NO_COPY, which means that
data transferred would not be copied to the buffer where the driver expects
it.

None of these drivers actually used the interrupt data for anything, and
in some the interrupt pipe code was #if 0'd out, so this doesn't change
anything, but fixing this up prevents unwary developers like me from
copying code that doesn't work.

ok mglocker@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.88 31-Jul-2020 mglocker

Nuke all occurrences of usbd_abort_pipe() if it gets called right
before usbd_close_pipe(), since usbd_close_pipe() already takes care
about aborting non-empty pipes.

As investigated by gerhard@ usbdi.c rev. 1.57 did add usbd_abort_pipe()
to usbd_close_pipe(), but the drivers didn't get cleaned up afterwards.

ok gerhard@


# 1.87 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_7_BASE
# 1.86 22-Feb-2020 jasper

use the UE_GET_XFERTYPE macro where applicable

ok mpi@


# 1.85 05-Jan-2020 jsg

remove duplicate device ids


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.84 02-Oct-2018 stsp

Make some USB ioctls return ENXIO, instead of EIO, if usbd_is_dying().
Brings us one step closer towards making this condition's error code
consistent across all USB drivers.
Patch by Moritz Buhl
ok mpi@ bluhm@


# 1.83 03-Jul-2018 kevlo

Use LIST_FOREACH construct instead of homebrew loop.

ok bluhm@, mpi@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 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@


# 1.81 06-Nov-2016 mpi

Avoid calling usbd_set_config_no() in *_attach() and let the stack do
it instead.

If anything bad happen due to a malformed descriptor it makes no sense
to try to attach a driver, and bail before probing.

This is similar to the change to avoid calling usbd_set_config_index().


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

G/C IFQ_SET_READY().


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

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


# 1.77 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.76 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.75 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.74 27-Mar-2015 uaa

simply do if_input() between splnet() and splx(), like other drivers
(such as if_udav.c).

ok by mpi@


# 1.73 14-Mar-2015 jsg

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

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.72 12-Feb-2015 mpi

Convert to if_input().

ok dlg@


# 1.71 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.70 13-Jul-2014 mpi

No need for <netinet/in_systm.h> here.


# 1.69 12-Jul-2014 mpi

Kill a bunch of DVACT_DEACTIVATE handlers whose only purpose were to
set the 'dying' flag of a device. Such handlers are useless now that
usbd_detach() already set this flag.

Even if the purpose of this flag is questionnable on OpenBSD because
DVACT_DEACTIVATE acts as a pre-detach event, this is just a first small
step towards the simplification of the autoconf(9) device states.

This cleaning is now possible thanks to the work of pirofti@ to convert
all the USB drivers to properly use usbd_is_dying().

Discussed many times with deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.68 15-Nov-2013 pirofti

Clean-up usbd_abort_pipe() usage.


This function never fails. So change it's return type to void and
adjust the copy-pasted callers that were checking the return.

"If it compiles, ok" mpi@


# 1.67 07-Aug-2013 bluhm

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


Revision tags: OPENBSD_5_4_BASE
# 1.66 15-Apr-2013 mglocker

Get rid of various 'typedef struct' definitions and use plain structure
definitions instead. We don't change usb.h for now to stay compatible
with userland.

Tested by mpi@ on macppc and myself on i386.

ok mpi@


# 1.65 28-Mar-2013 tedu

proc.h is way too much header for usb to handle.


Revision tags: OPENBSD_5_3_BASE
# 1.64 29-Jan-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.63 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.62 23-Jun-2011 deraadt

a bit more ansi; ok tedu


Revision tags: OPENBSD_4_9_BASE
# 1.61 25-Jan-2011 jakemsr

garbage collect "usb events". without /dev/usb there is no way to access
them from userland, and nothing in the kernel uses them.

ok krw@, miod@


# 1.60 06-Dec-2010 jakemsr

* replace per-driver dying and/or other state variables with use of
usbd_deactivete() and usbd_is_dying()
* use usbd_deactivate() in activate()/DEACTIVATE
* convert a few more direct checks of the associated bus' dying flag
with usbd_is_dying()


# 1.59 27-Oct-2010 jakemsr

don't free network related resources if they were not allocated


# 1.58 23-Oct-2010 jakemsr

check that a timeout(9) has been initialized before deleting it

ok phessler


# 1.57 23-Oct-2010 jakemsr

create another kthread to run xfer abort tasks. xfer abort tasks cannot
be run from the generic task kthread, because xfers that need to be
aborted block newly queued tasks from running (i.e. the xfer to be aborted
blocks the abort of that task). as there are now three types of usb
tasks, add an argument to usb_init_task() and another member to struct
usb_task to specify the task type.

fixes boot hangs that are showing up because we now use usb tasks to
attach/detach usb devices.


# 1.56 27-Aug-2010 deraadt

Delete comments about these drivers needing powerhook support; they don't.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.55 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.54 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.53 06-Nov-2008 brad

Set the IFCAP_VLAN_MTU capabilities flag so these interfaces are allowed
to transmit full sized VLAN tagged frames.


# 1.52 03-Oct-2008 brad

Use ether_ioctl().


# 1.51 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_3_BASE OPENBSD_4_4_BASE
# 1.50 23-Nov-2007 mbalmer

Sanitize the use of timeouts:

Instead of calling timeout_set(..., NULL, NULL) in attach routines and
later
timeout_del(...)
timeout_set(..., func, arg)
timeout_add(..., time)
set the function and argument in the initial timeout_set() call and only
use timeout_add(..., time) later.

ok dlg, fgsch, krw, winiger


# 1.49 11-Oct-2007 deraadt

treat usb vendor/product names as a locator, and have usbd_print handle it,
so that it shows up before the :. as a result, all the usb devices do not
need to have name printing code anymore. all this now works and prints
nicely because usbd_probe_and_attach() is serialized. ok kettenis


Revision tags: OPENBSD_4_2_BASE
# 1.48 14-Jun-2007 mbalmer

Remove the definition and usage of the USB_DECLARE_DRIVER_CLASS and
USB_DECLARE_DRIVER macros.

No binary change.

ok dlg.


# 1.47 13-Jun-2007 mbalmer

Remove the definition and usage of the IF_INPUT macro which was defined
as ether_input_mbuf which is itself a macro for ether_input.

No binary change.

ok dlg.


# 1.46 12-Jun-2007 mbalmer

Remove the definition and use of the device_ptr_t which was a struct device *.

No binary change.

ok mk.


# 1.45 11-Jun-2007 mbalmer

Remove the definition and usage of the USBGETSOFTC macro, which was really
only a cast to (void *).

ok jsg.


# 1.44 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEVNAME macro.

(This might look easy, but it was a big diff. Thanks to dlg and especially jsg
for looking over it; we found at least four mistakes in the initial diff.)

ok jsg.


# 1.43 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEV macro. It only created confusion
and the address of it's argument: USBDEV(sc->sc_dev) yields &sc->sc_dev.

No binary changes.

ok jsg.


# 1.42 10-Jun-2007 mbalmer

Remove definitions and usage of usb_callout and related macros. These macros
were used as a layer of confusion^Wabstraction around the timeout(9) API.

No binary change.

ok jsg.


# 1.41 09-Jun-2007 mbalmer

Remove the definition and use of if_deactivate(). It was defined empty and
thus produced no code at all.

No binary change.

ok jsg.


# 1.40 05-Jun-2007 mbalmer

Remove the "Static" declaration of many functions. It was defined to be empty
and it was not consistently used. It was confusing as it suggested these
functions were static, which they were not.

discussed with dlg and jsg, ok jsg.


# 1.39 04-Jun-2007 mbalmer

Last part of FreeBSD/NetBSD sepcific code removal.

ok jsg@


# 1.38 27-May-2007 jsg

Farewell USB_{ATTACH,MATCH,DETACH}* you will not be missed.
ok deraadt@ krw@ mbalmer@


# 1.37 21-May-2007 jsg

Remove logprintf macro


# 1.36 21-May-2007 jsg

Remove Ether_ifattach macro


# 1.35 06-May-2007 krw

More lockmgr -> rwlock low hanging fruit.

ok dlg@


Revision tags: OPENBSD_4_1_BASE
# 1.34 11-Feb-2007 miod

Remove _KERNEL_OPT leftovers.


Revision tags: OPENBSD_4_0_BASE
# 1.33 14-Jul-2006 brad

add ZyXEL USB id, remove useless comments and reorder USB devices.


# 1.32 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.31 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.30 07-Mar-2006 krw

Remove last NRND NetBSDisms from tree.

ok deraadt@ brad@


Revision tags: OPENBSD_3_9_BASE
# 1.29 06-Feb-2006 jmc

typos from alexey dobriyan;


# 1.28 29-Jan-2006 brad

Use usbd_clear_endpoint_stall_async() when clearing endpoint stalls in
an interrupt context.

From NetBSD

ok dlg@


# 1.27 23-Sep-2005 grunk

{TrendNet,Trendware} -> TRENDnet, ok jsg@


Revision tags: OPENBSD_3_8_BASE
# 1.26 01-Aug-2005 brad

Don't keep the devinfo string on the stack, instead use malloc/free.
This should cure some rare stack overflows.

From augustss NetBSD

ok dlg@ pascoe@


# 1.25 19-Jul-2005 jsg

Update for GREENHOUSE2 -> REALTEK USB vid change.


# 1.24 02-Jul-2005 brad

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


# 1.23 02-Jul-2005 brad

don't call mii_pollstat() right after mii_tick() in foo_tick_task()


# 1.22 08-Jun-2005 henning

remove netns crud.
some drivers actually had hooks for SIOCSIFADDR, most just useless includes
"looks good" deraadt miod brad


Revision tags: OPENBSD_3_7_BASE
# 1.21 03-Mar-2005 itojun

ethernet on OQO model 01 device cable. dlg ok


# 1.20 03-Jan-2005 brad

- make sure int is in running state before touching the multicast filters
- call foo_setmulti only instead of init'ing the chip
- don't overwrite potential error return with success when calling
ether_addmulti/ether_delmulti

ok dlg@


# 1.19 17-Nov-2004 deraadt

Three mode devices found in the wild, I think


# 1.18 10-Nov-2004 grange

strncpy->strlcpy
ok henning@


# 1.17 16-Oct-2004 jsg

Add Longshine LCS-8138TX and Micronet SP128AR found in linux driver
ok dlg@


# 1.16 29-Sep-2004 dlg

from netbsd: if_url.c 1.8, if_urlreg.h 1.2, urlphy.c 1.9 and urlphyreg.h 1.2
via Jonathan Gray
log message:

Remove advertising clauses from code written by Shingo WATANABE.
He has kindly consented it.


# 1.15 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.14 08-Jul-2004 deraadt

put "do { } while (0)" wrappers on all the debug maroc functions


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.13 23-Dec-2003 deraadt

init ether address correctly, since our Ether_ifattach macro does not do
that job; 3612, rspmn@arcor.de


# 1.12 15-Dec-2003 cedric

Set devclass to DV_IFNET for all USB network drivers.
ok deraadt@ nate@


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.11 07-May-2003 deraadt

string cleanup; nate ok


Revision tags: OPENBSD_3_3_BASE
# 1.10 27-Jan-2003 jason

branches: 1.10.4;
pad minimum frames with 0's; based on netbsd


# 1.9 11-Nov-2002 nate

sync with NetBSD


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.8 29-Sep-2002 jason

Plug memory leak; nyar-junk@int0rnet.net


# 1.7 25-Jul-2002 nate

get rid of trailing whitespace


# 1.6 10-Jul-2002 deraadt

shorten address printout


# 1.5 26-Jun-2002 espie

Kill __FUNCTION__.


# 1.4 09-May-2002 nate

branches: 1.4.2;
Fix ioctl handling
Add default MTU
fix typo

errors noted by Jason Ackley <jason@ackley.net>


# 1.3 07-May-2002 nate

Add a driver for Realtek RTL8150L based ethernet devices
From NetBSD


# 1.2 07-May-2002 nate

Meant to commit only ulpt and committed everything. Most things weren't ready


# 1.1 07-May-2002 nate

Sync ulpt driver with NetBSD


# 1.88 31-Jul-2020 mglocker

Nuke all occurrences of usbd_abort_pipe() if it gets called right
before usbd_close_pipe(), since usbd_close_pipe() already takes care
about aborting non-empty pipes.

As investigated by gerhard@ usbdi.c rev. 1.57 did add usbd_abort_pipe()
to usbd_close_pipe(), but the drivers didn't get cleaned up afterwards.

ok gerhard@


# 1.87 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_7_BASE
# 1.86 22-Feb-2020 jasper

use the UE_GET_XFERTYPE macro where applicable

ok mpi@


# 1.85 05-Jan-2020 jsg

remove duplicate device ids


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.84 02-Oct-2018 stsp

Make some USB ioctls return ENXIO, instead of EIO, if usbd_is_dying().
Brings us one step closer towards making this condition's error code
consistent across all USB drivers.
Patch by Moritz Buhl
ok mpi@ bluhm@


# 1.83 03-Jul-2018 kevlo

Use LIST_FOREACH construct instead of homebrew loop.

ok bluhm@, mpi@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 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@


# 1.81 06-Nov-2016 mpi

Avoid calling usbd_set_config_no() in *_attach() and let the stack do
it instead.

If anything bad happen due to a malformed descriptor it makes no sense
to try to attach a driver, and bail before probing.

This is similar to the change to avoid calling usbd_set_config_index().


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

G/C IFQ_SET_READY().


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

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


# 1.77 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.76 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.75 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.74 27-Mar-2015 uaa

simply do if_input() between splnet() and splx(), like other drivers
(such as if_udav.c).

ok by mpi@


# 1.73 14-Mar-2015 jsg

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

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.72 12-Feb-2015 mpi

Convert to if_input().

ok dlg@


# 1.71 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.70 13-Jul-2014 mpi

No need for <netinet/in_systm.h> here.


# 1.69 12-Jul-2014 mpi

Kill a bunch of DVACT_DEACTIVATE handlers whose only purpose were to
set the 'dying' flag of a device. Such handlers are useless now that
usbd_detach() already set this flag.

Even if the purpose of this flag is questionnable on OpenBSD because
DVACT_DEACTIVATE acts as a pre-detach event, this is just a first small
step towards the simplification of the autoconf(9) device states.

This cleaning is now possible thanks to the work of pirofti@ to convert
all the USB drivers to properly use usbd_is_dying().

Discussed many times with deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.68 15-Nov-2013 pirofti

Clean-up usbd_abort_pipe() usage.


This function never fails. So change it's return type to void and
adjust the copy-pasted callers that were checking the return.

"If it compiles, ok" mpi@


# 1.67 07-Aug-2013 bluhm

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


Revision tags: OPENBSD_5_4_BASE
# 1.66 15-Apr-2013 mglocker

Get rid of various 'typedef struct' definitions and use plain structure
definitions instead. We don't change usb.h for now to stay compatible
with userland.

Tested by mpi@ on macppc and myself on i386.

ok mpi@


# 1.65 28-Mar-2013 tedu

proc.h is way too much header for usb to handle.


Revision tags: OPENBSD_5_3_BASE
# 1.64 29-Jan-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.63 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.62 23-Jun-2011 deraadt

a bit more ansi; ok tedu


Revision tags: OPENBSD_4_9_BASE
# 1.61 25-Jan-2011 jakemsr

garbage collect "usb events". without /dev/usb there is no way to access
them from userland, and nothing in the kernel uses them.

ok krw@, miod@


# 1.60 06-Dec-2010 jakemsr

* replace per-driver dying and/or other state variables with use of
usbd_deactivete() and usbd_is_dying()
* use usbd_deactivate() in activate()/DEACTIVATE
* convert a few more direct checks of the associated bus' dying flag
with usbd_is_dying()


# 1.59 27-Oct-2010 jakemsr

don't free network related resources if they were not allocated


# 1.58 23-Oct-2010 jakemsr

check that a timeout(9) has been initialized before deleting it

ok phessler


# 1.57 23-Oct-2010 jakemsr

create another kthread to run xfer abort tasks. xfer abort tasks cannot
be run from the generic task kthread, because xfers that need to be
aborted block newly queued tasks from running (i.e. the xfer to be aborted
blocks the abort of that task). as there are now three types of usb
tasks, add an argument to usb_init_task() and another member to struct
usb_task to specify the task type.

fixes boot hangs that are showing up because we now use usb tasks to
attach/detach usb devices.


# 1.56 27-Aug-2010 deraadt

Delete comments about these drivers needing powerhook support; they don't.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.55 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.54 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.53 06-Nov-2008 brad

Set the IFCAP_VLAN_MTU capabilities flag so these interfaces are allowed
to transmit full sized VLAN tagged frames.


# 1.52 03-Oct-2008 brad

Use ether_ioctl().


# 1.51 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_3_BASE OPENBSD_4_4_BASE
# 1.50 23-Nov-2007 mbalmer

Sanitize the use of timeouts:

Instead of calling timeout_set(..., NULL, NULL) in attach routines and
later
timeout_del(...)
timeout_set(..., func, arg)
timeout_add(..., time)
set the function and argument in the initial timeout_set() call and only
use timeout_add(..., time) later.

ok dlg, fgsch, krw, winiger


# 1.49 11-Oct-2007 deraadt

treat usb vendor/product names as a locator, and have usbd_print handle it,
so that it shows up before the :. as a result, all the usb devices do not
need to have name printing code anymore. all this now works and prints
nicely because usbd_probe_and_attach() is serialized. ok kettenis


Revision tags: OPENBSD_4_2_BASE
# 1.48 14-Jun-2007 mbalmer

Remove the definition and usage of the USB_DECLARE_DRIVER_CLASS and
USB_DECLARE_DRIVER macros.

No binary change.

ok dlg.


# 1.47 13-Jun-2007 mbalmer

Remove the definition and usage of the IF_INPUT macro which was defined
as ether_input_mbuf which is itself a macro for ether_input.

No binary change.

ok dlg.


# 1.46 12-Jun-2007 mbalmer

Remove the definition and use of the device_ptr_t which was a struct device *.

No binary change.

ok mk.


# 1.45 11-Jun-2007 mbalmer

Remove the definition and usage of the USBGETSOFTC macro, which was really
only a cast to (void *).

ok jsg.


# 1.44 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEVNAME macro.

(This might look easy, but it was a big diff. Thanks to dlg and especially jsg
for looking over it; we found at least four mistakes in the initial diff.)

ok jsg.


# 1.43 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEV macro. It only created confusion
and the address of it's argument: USBDEV(sc->sc_dev) yields &sc->sc_dev.

No binary changes.

ok jsg.


# 1.42 10-Jun-2007 mbalmer

Remove definitions and usage of usb_callout and related macros. These macros
were used as a layer of confusion^Wabstraction around the timeout(9) API.

No binary change.

ok jsg.


# 1.41 09-Jun-2007 mbalmer

Remove the definition and use of if_deactivate(). It was defined empty and
thus produced no code at all.

No binary change.

ok jsg.


# 1.40 05-Jun-2007 mbalmer

Remove the "Static" declaration of many functions. It was defined to be empty
and it was not consistently used. It was confusing as it suggested these
functions were static, which they were not.

discussed with dlg and jsg, ok jsg.


# 1.39 04-Jun-2007 mbalmer

Last part of FreeBSD/NetBSD sepcific code removal.

ok jsg@


# 1.38 27-May-2007 jsg

Farewell USB_{ATTACH,MATCH,DETACH}* you will not be missed.
ok deraadt@ krw@ mbalmer@


# 1.37 21-May-2007 jsg

Remove logprintf macro


# 1.36 21-May-2007 jsg

Remove Ether_ifattach macro


# 1.35 06-May-2007 krw

More lockmgr -> rwlock low hanging fruit.

ok dlg@


Revision tags: OPENBSD_4_1_BASE
# 1.34 11-Feb-2007 miod

Remove _KERNEL_OPT leftovers.


Revision tags: OPENBSD_4_0_BASE
# 1.33 14-Jul-2006 brad

add ZyXEL USB id, remove useless comments and reorder USB devices.


# 1.32 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.31 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.30 07-Mar-2006 krw

Remove last NRND NetBSDisms from tree.

ok deraadt@ brad@


Revision tags: OPENBSD_3_9_BASE
# 1.29 06-Feb-2006 jmc

typos from alexey dobriyan;


# 1.28 29-Jan-2006 brad

Use usbd_clear_endpoint_stall_async() when clearing endpoint stalls in
an interrupt context.

From NetBSD

ok dlg@


# 1.27 23-Sep-2005 grunk

{TrendNet,Trendware} -> TRENDnet, ok jsg@


Revision tags: OPENBSD_3_8_BASE
# 1.26 01-Aug-2005 brad

Don't keep the devinfo string on the stack, instead use malloc/free.
This should cure some rare stack overflows.

From augustss NetBSD

ok dlg@ pascoe@


# 1.25 19-Jul-2005 jsg

Update for GREENHOUSE2 -> REALTEK USB vid change.


# 1.24 02-Jul-2005 brad

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


# 1.23 02-Jul-2005 brad

don't call mii_pollstat() right after mii_tick() in foo_tick_task()


# 1.22 08-Jun-2005 henning

remove netns crud.
some drivers actually had hooks for SIOCSIFADDR, most just useless includes
"looks good" deraadt miod brad


Revision tags: OPENBSD_3_7_BASE
# 1.21 03-Mar-2005 itojun

ethernet on OQO model 01 device cable. dlg ok


# 1.20 03-Jan-2005 brad

- make sure int is in running state before touching the multicast filters
- call foo_setmulti only instead of init'ing the chip
- don't overwrite potential error return with success when calling
ether_addmulti/ether_delmulti

ok dlg@


# 1.19 17-Nov-2004 deraadt

Three mode devices found in the wild, I think


# 1.18 10-Nov-2004 grange

strncpy->strlcpy
ok henning@


# 1.17 16-Oct-2004 jsg

Add Longshine LCS-8138TX and Micronet SP128AR found in linux driver
ok dlg@


# 1.16 29-Sep-2004 dlg

from netbsd: if_url.c 1.8, if_urlreg.h 1.2, urlphy.c 1.9 and urlphyreg.h 1.2
via Jonathan Gray
log message:

Remove advertising clauses from code written by Shingo WATANABE.
He has kindly consented it.


# 1.15 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.14 08-Jul-2004 deraadt

put "do { } while (0)" wrappers on all the debug maroc functions


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.13 23-Dec-2003 deraadt

init ether address correctly, since our Ether_ifattach macro does not do
that job; 3612, rspmn@arcor.de


# 1.12 15-Dec-2003 cedric

Set devclass to DV_IFNET for all USB network drivers.
ok deraadt@ nate@


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.11 07-May-2003 deraadt

string cleanup; nate ok


Revision tags: OPENBSD_3_3_BASE
# 1.10 27-Jan-2003 jason

branches: 1.10.4;
pad minimum frames with 0's; based on netbsd


# 1.9 11-Nov-2002 nate

sync with NetBSD


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.8 29-Sep-2002 jason

Plug memory leak; nyar-junk@int0rnet.net


# 1.7 25-Jul-2002 nate

get rid of trailing whitespace


# 1.6 10-Jul-2002 deraadt

shorten address printout


# 1.5 26-Jun-2002 espie

Kill __FUNCTION__.


# 1.4 09-May-2002 nate

branches: 1.4.2;
Fix ioctl handling
Add default MTU
fix typo

errors noted by Jason Ackley <jason@ackley.net>


# 1.3 07-May-2002 nate

Add a driver for Realtek RTL8150L based ethernet devices
From NetBSD


# 1.2 07-May-2002 nate

Meant to commit only ulpt and committed everything. Most things weren't ready


# 1.1 07-May-2002 nate

Sync ulpt driver with NetBSD


# 1.87 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_7_BASE
# 1.86 22-Feb-2020 jasper

use the UE_GET_XFERTYPE macro where applicable

ok mpi@


# 1.85 05-Jan-2020 jsg

remove duplicate device ids


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.84 02-Oct-2018 stsp

Make some USB ioctls return ENXIO, instead of EIO, if usbd_is_dying().
Brings us one step closer towards making this condition's error code
consistent across all USB drivers.
Patch by Moritz Buhl
ok mpi@ bluhm@


# 1.83 03-Jul-2018 kevlo

Use LIST_FOREACH construct instead of homebrew loop.

ok bluhm@, mpi@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 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@


# 1.81 06-Nov-2016 mpi

Avoid calling usbd_set_config_no() in *_attach() and let the stack do
it instead.

If anything bad happen due to a malformed descriptor it makes no sense
to try to attach a driver, and bail before probing.

This is similar to the change to avoid calling usbd_set_config_index().


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

G/C IFQ_SET_READY().


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

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


# 1.77 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.76 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.75 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.74 27-Mar-2015 uaa

simply do if_input() between splnet() and splx(), like other drivers
(such as if_udav.c).

ok by mpi@


# 1.73 14-Mar-2015 jsg

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

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.72 12-Feb-2015 mpi

Convert to if_input().

ok dlg@


# 1.71 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.70 13-Jul-2014 mpi

No need for <netinet/in_systm.h> here.


# 1.69 12-Jul-2014 mpi

Kill a bunch of DVACT_DEACTIVATE handlers whose only purpose were to
set the 'dying' flag of a device. Such handlers are useless now that
usbd_detach() already set this flag.

Even if the purpose of this flag is questionnable on OpenBSD because
DVACT_DEACTIVATE acts as a pre-detach event, this is just a first small
step towards the simplification of the autoconf(9) device states.

This cleaning is now possible thanks to the work of pirofti@ to convert
all the USB drivers to properly use usbd_is_dying().

Discussed many times with deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.68 15-Nov-2013 pirofti

Clean-up usbd_abort_pipe() usage.


This function never fails. So change it's return type to void and
adjust the copy-pasted callers that were checking the return.

"If it compiles, ok" mpi@


# 1.67 07-Aug-2013 bluhm

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


Revision tags: OPENBSD_5_4_BASE
# 1.66 15-Apr-2013 mglocker

Get rid of various 'typedef struct' definitions and use plain structure
definitions instead. We don't change usb.h for now to stay compatible
with userland.

Tested by mpi@ on macppc and myself on i386.

ok mpi@


# 1.65 28-Mar-2013 tedu

proc.h is way too much header for usb to handle.


Revision tags: OPENBSD_5_3_BASE
# 1.64 29-Jan-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.63 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.62 23-Jun-2011 deraadt

a bit more ansi; ok tedu


Revision tags: OPENBSD_4_9_BASE
# 1.61 25-Jan-2011 jakemsr

garbage collect "usb events". without /dev/usb there is no way to access
them from userland, and nothing in the kernel uses them.

ok krw@, miod@


# 1.60 06-Dec-2010 jakemsr

* replace per-driver dying and/or other state variables with use of
usbd_deactivete() and usbd_is_dying()
* use usbd_deactivate() in activate()/DEACTIVATE
* convert a few more direct checks of the associated bus' dying flag
with usbd_is_dying()


# 1.59 27-Oct-2010 jakemsr

don't free network related resources if they were not allocated


# 1.58 23-Oct-2010 jakemsr

check that a timeout(9) has been initialized before deleting it

ok phessler


# 1.57 23-Oct-2010 jakemsr

create another kthread to run xfer abort tasks. xfer abort tasks cannot
be run from the generic task kthread, because xfers that need to be
aborted block newly queued tasks from running (i.e. the xfer to be aborted
blocks the abort of that task). as there are now three types of usb
tasks, add an argument to usb_init_task() and another member to struct
usb_task to specify the task type.

fixes boot hangs that are showing up because we now use usb tasks to
attach/detach usb devices.


# 1.56 27-Aug-2010 deraadt

Delete comments about these drivers needing powerhook support; they don't.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.55 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.54 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.53 06-Nov-2008 brad

Set the IFCAP_VLAN_MTU capabilities flag so these interfaces are allowed
to transmit full sized VLAN tagged frames.


# 1.52 03-Oct-2008 brad

Use ether_ioctl().


# 1.51 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_3_BASE OPENBSD_4_4_BASE
# 1.50 23-Nov-2007 mbalmer

Sanitize the use of timeouts:

Instead of calling timeout_set(..., NULL, NULL) in attach routines and
later
timeout_del(...)
timeout_set(..., func, arg)
timeout_add(..., time)
set the function and argument in the initial timeout_set() call and only
use timeout_add(..., time) later.

ok dlg, fgsch, krw, winiger


# 1.49 11-Oct-2007 deraadt

treat usb vendor/product names as a locator, and have usbd_print handle it,
so that it shows up before the :. as a result, all the usb devices do not
need to have name printing code anymore. all this now works and prints
nicely because usbd_probe_and_attach() is serialized. ok kettenis


Revision tags: OPENBSD_4_2_BASE
# 1.48 14-Jun-2007 mbalmer

Remove the definition and usage of the USB_DECLARE_DRIVER_CLASS and
USB_DECLARE_DRIVER macros.

No binary change.

ok dlg.


# 1.47 13-Jun-2007 mbalmer

Remove the definition and usage of the IF_INPUT macro which was defined
as ether_input_mbuf which is itself a macro for ether_input.

No binary change.

ok dlg.


# 1.46 12-Jun-2007 mbalmer

Remove the definition and use of the device_ptr_t which was a struct device *.

No binary change.

ok mk.


# 1.45 11-Jun-2007 mbalmer

Remove the definition and usage of the USBGETSOFTC macro, which was really
only a cast to (void *).

ok jsg.


# 1.44 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEVNAME macro.

(This might look easy, but it was a big diff. Thanks to dlg and especially jsg
for looking over it; we found at least four mistakes in the initial diff.)

ok jsg.


# 1.43 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEV macro. It only created confusion
and the address of it's argument: USBDEV(sc->sc_dev) yields &sc->sc_dev.

No binary changes.

ok jsg.


# 1.42 10-Jun-2007 mbalmer

Remove definitions and usage of usb_callout and related macros. These macros
were used as a layer of confusion^Wabstraction around the timeout(9) API.

No binary change.

ok jsg.


# 1.41 09-Jun-2007 mbalmer

Remove the definition and use of if_deactivate(). It was defined empty and
thus produced no code at all.

No binary change.

ok jsg.


# 1.40 05-Jun-2007 mbalmer

Remove the "Static" declaration of many functions. It was defined to be empty
and it was not consistently used. It was confusing as it suggested these
functions were static, which they were not.

discussed with dlg and jsg, ok jsg.


# 1.39 04-Jun-2007 mbalmer

Last part of FreeBSD/NetBSD sepcific code removal.

ok jsg@


# 1.38 27-May-2007 jsg

Farewell USB_{ATTACH,MATCH,DETACH}* you will not be missed.
ok deraadt@ krw@ mbalmer@


# 1.37 21-May-2007 jsg

Remove logprintf macro


# 1.36 21-May-2007 jsg

Remove Ether_ifattach macro


# 1.35 06-May-2007 krw

More lockmgr -> rwlock low hanging fruit.

ok dlg@


Revision tags: OPENBSD_4_1_BASE
# 1.34 11-Feb-2007 miod

Remove _KERNEL_OPT leftovers.


Revision tags: OPENBSD_4_0_BASE
# 1.33 14-Jul-2006 brad

add ZyXEL USB id, remove useless comments and reorder USB devices.


# 1.32 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.31 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.30 07-Mar-2006 krw

Remove last NRND NetBSDisms from tree.

ok deraadt@ brad@


Revision tags: OPENBSD_3_9_BASE
# 1.29 06-Feb-2006 jmc

typos from alexey dobriyan;


# 1.28 29-Jan-2006 brad

Use usbd_clear_endpoint_stall_async() when clearing endpoint stalls in
an interrupt context.

From NetBSD

ok dlg@


# 1.27 23-Sep-2005 grunk

{TrendNet,Trendware} -> TRENDnet, ok jsg@


Revision tags: OPENBSD_3_8_BASE
# 1.26 01-Aug-2005 brad

Don't keep the devinfo string on the stack, instead use malloc/free.
This should cure some rare stack overflows.

From augustss NetBSD

ok dlg@ pascoe@


# 1.25 19-Jul-2005 jsg

Update for GREENHOUSE2 -> REALTEK USB vid change.


# 1.24 02-Jul-2005 brad

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


# 1.23 02-Jul-2005 brad

don't call mii_pollstat() right after mii_tick() in foo_tick_task()


# 1.22 08-Jun-2005 henning

remove netns crud.
some drivers actually had hooks for SIOCSIFADDR, most just useless includes
"looks good" deraadt miod brad


Revision tags: OPENBSD_3_7_BASE
# 1.21 03-Mar-2005 itojun

ethernet on OQO model 01 device cable. dlg ok


# 1.20 03-Jan-2005 brad

- make sure int is in running state before touching the multicast filters
- call foo_setmulti only instead of init'ing the chip
- don't overwrite potential error return with success when calling
ether_addmulti/ether_delmulti

ok dlg@


# 1.19 17-Nov-2004 deraadt

Three mode devices found in the wild, I think


# 1.18 10-Nov-2004 grange

strncpy->strlcpy
ok henning@


# 1.17 16-Oct-2004 jsg

Add Longshine LCS-8138TX and Micronet SP128AR found in linux driver
ok dlg@


# 1.16 29-Sep-2004 dlg

from netbsd: if_url.c 1.8, if_urlreg.h 1.2, urlphy.c 1.9 and urlphyreg.h 1.2
via Jonathan Gray
log message:

Remove advertising clauses from code written by Shingo WATANABE.
He has kindly consented it.


# 1.15 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.14 08-Jul-2004 deraadt

put "do { } while (0)" wrappers on all the debug maroc functions


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.13 23-Dec-2003 deraadt

init ether address correctly, since our Ether_ifattach macro does not do
that job; 3612, rspmn@arcor.de


# 1.12 15-Dec-2003 cedric

Set devclass to DV_IFNET for all USB network drivers.
ok deraadt@ nate@


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.11 07-May-2003 deraadt

string cleanup; nate ok


Revision tags: OPENBSD_3_3_BASE
# 1.10 27-Jan-2003 jason

branches: 1.10.4;
pad minimum frames with 0's; based on netbsd


# 1.9 11-Nov-2002 nate

sync with NetBSD


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.8 29-Sep-2002 jason

Plug memory leak; nyar-junk@int0rnet.net


# 1.7 25-Jul-2002 nate

get rid of trailing whitespace


# 1.6 10-Jul-2002 deraadt

shorten address printout


# 1.5 26-Jun-2002 espie

Kill __FUNCTION__.


# 1.4 09-May-2002 nate

branches: 1.4.2;
Fix ioctl handling
Add default MTU
fix typo

errors noted by Jason Ackley <jason@ackley.net>


# 1.3 07-May-2002 nate

Add a driver for Realtek RTL8150L based ethernet devices
From NetBSD


# 1.2 07-May-2002 nate

Meant to commit only ulpt and committed everything. Most things weren't ready


# 1.1 07-May-2002 nate

Sync ulpt driver with NetBSD


# 1.86 22-Feb-2020 jasper

use the UE_GET_XFERTYPE macro where applicable

ok mpi@


# 1.85 05-Jan-2020 jsg

remove duplicate device ids


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.84 02-Oct-2018 stsp

Make some USB ioctls return ENXIO, instead of EIO, if usbd_is_dying().
Brings us one step closer towards making this condition's error code
consistent across all USB drivers.
Patch by Moritz Buhl
ok mpi@ bluhm@


# 1.83 03-Jul-2018 kevlo

Use LIST_FOREACH construct instead of homebrew loop.

ok bluhm@, mpi@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 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@


# 1.81 06-Nov-2016 mpi

Avoid calling usbd_set_config_no() in *_attach() and let the stack do
it instead.

If anything bad happen due to a malformed descriptor it makes no sense
to try to attach a driver, and bail before probing.

This is similar to the change to avoid calling usbd_set_config_index().


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

G/C IFQ_SET_READY().


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

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


# 1.77 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.76 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.75 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.74 27-Mar-2015 uaa

simply do if_input() between splnet() and splx(), like other drivers
(such as if_udav.c).

ok by mpi@


# 1.73 14-Mar-2015 jsg

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

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.72 12-Feb-2015 mpi

Convert to if_input().

ok dlg@


# 1.71 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.70 13-Jul-2014 mpi

No need for <netinet/in_systm.h> here.


# 1.69 12-Jul-2014 mpi

Kill a bunch of DVACT_DEACTIVATE handlers whose only purpose were to
set the 'dying' flag of a device. Such handlers are useless now that
usbd_detach() already set this flag.

Even if the purpose of this flag is questionnable on OpenBSD because
DVACT_DEACTIVATE acts as a pre-detach event, this is just a first small
step towards the simplification of the autoconf(9) device states.

This cleaning is now possible thanks to the work of pirofti@ to convert
all the USB drivers to properly use usbd_is_dying().

Discussed many times with deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.68 15-Nov-2013 pirofti

Clean-up usbd_abort_pipe() usage.


This function never fails. So change it's return type to void and
adjust the copy-pasted callers that were checking the return.

"If it compiles, ok" mpi@


# 1.67 07-Aug-2013 bluhm

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


Revision tags: OPENBSD_5_4_BASE
# 1.66 15-Apr-2013 mglocker

Get rid of various 'typedef struct' definitions and use plain structure
definitions instead. We don't change usb.h for now to stay compatible
with userland.

Tested by mpi@ on macppc and myself on i386.

ok mpi@


# 1.65 28-Mar-2013 tedu

proc.h is way too much header for usb to handle.


Revision tags: OPENBSD_5_3_BASE
# 1.64 29-Jan-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.63 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.62 23-Jun-2011 deraadt

a bit more ansi; ok tedu


Revision tags: OPENBSD_4_9_BASE
# 1.61 25-Jan-2011 jakemsr

garbage collect "usb events". without /dev/usb there is no way to access
them from userland, and nothing in the kernel uses them.

ok krw@, miod@


# 1.60 06-Dec-2010 jakemsr

* replace per-driver dying and/or other state variables with use of
usbd_deactivete() and usbd_is_dying()
* use usbd_deactivate() in activate()/DEACTIVATE
* convert a few more direct checks of the associated bus' dying flag
with usbd_is_dying()


# 1.59 27-Oct-2010 jakemsr

don't free network related resources if they were not allocated


# 1.58 23-Oct-2010 jakemsr

check that a timeout(9) has been initialized before deleting it

ok phessler


# 1.57 23-Oct-2010 jakemsr

create another kthread to run xfer abort tasks. xfer abort tasks cannot
be run from the generic task kthread, because xfers that need to be
aborted block newly queued tasks from running (i.e. the xfer to be aborted
blocks the abort of that task). as there are now three types of usb
tasks, add an argument to usb_init_task() and another member to struct
usb_task to specify the task type.

fixes boot hangs that are showing up because we now use usb tasks to
attach/detach usb devices.


# 1.56 27-Aug-2010 deraadt

Delete comments about these drivers needing powerhook support; they don't.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.55 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.54 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.53 06-Nov-2008 brad

Set the IFCAP_VLAN_MTU capabilities flag so these interfaces are allowed
to transmit full sized VLAN tagged frames.


# 1.52 03-Oct-2008 brad

Use ether_ioctl().


# 1.51 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_3_BASE OPENBSD_4_4_BASE
# 1.50 23-Nov-2007 mbalmer

Sanitize the use of timeouts:

Instead of calling timeout_set(..., NULL, NULL) in attach routines and
later
timeout_del(...)
timeout_set(..., func, arg)
timeout_add(..., time)
set the function and argument in the initial timeout_set() call and only
use timeout_add(..., time) later.

ok dlg, fgsch, krw, winiger


# 1.49 11-Oct-2007 deraadt

treat usb vendor/product names as a locator, and have usbd_print handle it,
so that it shows up before the :. as a result, all the usb devices do not
need to have name printing code anymore. all this now works and prints
nicely because usbd_probe_and_attach() is serialized. ok kettenis


Revision tags: OPENBSD_4_2_BASE
# 1.48 14-Jun-2007 mbalmer

Remove the definition and usage of the USB_DECLARE_DRIVER_CLASS and
USB_DECLARE_DRIVER macros.

No binary change.

ok dlg.


# 1.47 13-Jun-2007 mbalmer

Remove the definition and usage of the IF_INPUT macro which was defined
as ether_input_mbuf which is itself a macro for ether_input.

No binary change.

ok dlg.


# 1.46 12-Jun-2007 mbalmer

Remove the definition and use of the device_ptr_t which was a struct device *.

No binary change.

ok mk.


# 1.45 11-Jun-2007 mbalmer

Remove the definition and usage of the USBGETSOFTC macro, which was really
only a cast to (void *).

ok jsg.


# 1.44 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEVNAME macro.

(This might look easy, but it was a big diff. Thanks to dlg and especially jsg
for looking over it; we found at least four mistakes in the initial diff.)

ok jsg.


# 1.43 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEV macro. It only created confusion
and the address of it's argument: USBDEV(sc->sc_dev) yields &sc->sc_dev.

No binary changes.

ok jsg.


# 1.42 10-Jun-2007 mbalmer

Remove definitions and usage of usb_callout and related macros. These macros
were used as a layer of confusion^Wabstraction around the timeout(9) API.

No binary change.

ok jsg.


# 1.41 09-Jun-2007 mbalmer

Remove the definition and use of if_deactivate(). It was defined empty and
thus produced no code at all.

No binary change.

ok jsg.


# 1.40 05-Jun-2007 mbalmer

Remove the "Static" declaration of many functions. It was defined to be empty
and it was not consistently used. It was confusing as it suggested these
functions were static, which they were not.

discussed with dlg and jsg, ok jsg.


# 1.39 04-Jun-2007 mbalmer

Last part of FreeBSD/NetBSD sepcific code removal.

ok jsg@


# 1.38 27-May-2007 jsg

Farewell USB_{ATTACH,MATCH,DETACH}* you will not be missed.
ok deraadt@ krw@ mbalmer@


# 1.37 21-May-2007 jsg

Remove logprintf macro


# 1.36 21-May-2007 jsg

Remove Ether_ifattach macro


# 1.35 06-May-2007 krw

More lockmgr -> rwlock low hanging fruit.

ok dlg@


Revision tags: OPENBSD_4_1_BASE
# 1.34 11-Feb-2007 miod

Remove _KERNEL_OPT leftovers.


Revision tags: OPENBSD_4_0_BASE
# 1.33 14-Jul-2006 brad

add ZyXEL USB id, remove useless comments and reorder USB devices.


# 1.32 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.31 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.30 07-Mar-2006 krw

Remove last NRND NetBSDisms from tree.

ok deraadt@ brad@


Revision tags: OPENBSD_3_9_BASE
# 1.29 06-Feb-2006 jmc

typos from alexey dobriyan;


# 1.28 29-Jan-2006 brad

Use usbd_clear_endpoint_stall_async() when clearing endpoint stalls in
an interrupt context.

From NetBSD

ok dlg@


# 1.27 23-Sep-2005 grunk

{TrendNet,Trendware} -> TRENDnet, ok jsg@


Revision tags: OPENBSD_3_8_BASE
# 1.26 01-Aug-2005 brad

Don't keep the devinfo string on the stack, instead use malloc/free.
This should cure some rare stack overflows.

From augustss NetBSD

ok dlg@ pascoe@


# 1.25 19-Jul-2005 jsg

Update for GREENHOUSE2 -> REALTEK USB vid change.


# 1.24 02-Jul-2005 brad

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


# 1.23 02-Jul-2005 brad

don't call mii_pollstat() right after mii_tick() in foo_tick_task()


# 1.22 08-Jun-2005 henning

remove netns crud.
some drivers actually had hooks for SIOCSIFADDR, most just useless includes
"looks good" deraadt miod brad


Revision tags: OPENBSD_3_7_BASE
# 1.21 03-Mar-2005 itojun

ethernet on OQO model 01 device cable. dlg ok


# 1.20 03-Jan-2005 brad

- make sure int is in running state before touching the multicast filters
- call foo_setmulti only instead of init'ing the chip
- don't overwrite potential error return with success when calling
ether_addmulti/ether_delmulti

ok dlg@


# 1.19 17-Nov-2004 deraadt

Three mode devices found in the wild, I think


# 1.18 10-Nov-2004 grange

strncpy->strlcpy
ok henning@


# 1.17 16-Oct-2004 jsg

Add Longshine LCS-8138TX and Micronet SP128AR found in linux driver
ok dlg@


# 1.16 29-Sep-2004 dlg

from netbsd: if_url.c 1.8, if_urlreg.h 1.2, urlphy.c 1.9 and urlphyreg.h 1.2
via Jonathan Gray
log message:

Remove advertising clauses from code written by Shingo WATANABE.
He has kindly consented it.


# 1.15 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.14 08-Jul-2004 deraadt

put "do { } while (0)" wrappers on all the debug maroc functions


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.13 23-Dec-2003 deraadt

init ether address correctly, since our Ether_ifattach macro does not do
that job; 3612, rspmn@arcor.de


# 1.12 15-Dec-2003 cedric

Set devclass to DV_IFNET for all USB network drivers.
ok deraadt@ nate@


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.11 07-May-2003 deraadt

string cleanup; nate ok


Revision tags: OPENBSD_3_3_BASE
# 1.10 27-Jan-2003 jason

branches: 1.10.4;
pad minimum frames with 0's; based on netbsd


# 1.9 11-Nov-2002 nate

sync with NetBSD


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.8 29-Sep-2002 jason

Plug memory leak; nyar-junk@int0rnet.net


# 1.7 25-Jul-2002 nate

get rid of trailing whitespace


# 1.6 10-Jul-2002 deraadt

shorten address printout


# 1.5 26-Jun-2002 espie

Kill __FUNCTION__.


# 1.4 09-May-2002 nate

branches: 1.4.2;
Fix ioctl handling
Add default MTU
fix typo

errors noted by Jason Ackley <jason@ackley.net>


# 1.3 07-May-2002 nate

Add a driver for Realtek RTL8150L based ethernet devices
From NetBSD


# 1.2 07-May-2002 nate

Meant to commit only ulpt and committed everything. Most things weren't ready


# 1.1 07-May-2002 nate

Sync ulpt driver with NetBSD


# 1.85 05-Jan-2020 jsg

remove duplicate device ids


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.84 02-Oct-2018 stsp

Make some USB ioctls return ENXIO, instead of EIO, if usbd_is_dying().
Brings us one step closer towards making this condition's error code
consistent across all USB drivers.
Patch by Moritz Buhl
ok mpi@ bluhm@


# 1.83 03-Jul-2018 kevlo

Use LIST_FOREACH construct instead of homebrew loop.

ok bluhm@, mpi@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 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@


# 1.81 06-Nov-2016 mpi

Avoid calling usbd_set_config_no() in *_attach() and let the stack do
it instead.

If anything bad happen due to a malformed descriptor it makes no sense
to try to attach a driver, and bail before probing.

This is similar to the change to avoid calling usbd_set_config_index().


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

G/C IFQ_SET_READY().


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

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


# 1.77 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.76 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.75 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.74 27-Mar-2015 uaa

simply do if_input() between splnet() and splx(), like other drivers
(such as if_udav.c).

ok by mpi@


# 1.73 14-Mar-2015 jsg

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

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.72 12-Feb-2015 mpi

Convert to if_input().

ok dlg@


# 1.71 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.70 13-Jul-2014 mpi

No need for <netinet/in_systm.h> here.


# 1.69 12-Jul-2014 mpi

Kill a bunch of DVACT_DEACTIVATE handlers whose only purpose were to
set the 'dying' flag of a device. Such handlers are useless now that
usbd_detach() already set this flag.

Even if the purpose of this flag is questionnable on OpenBSD because
DVACT_DEACTIVATE acts as a pre-detach event, this is just a first small
step towards the simplification of the autoconf(9) device states.

This cleaning is now possible thanks to the work of pirofti@ to convert
all the USB drivers to properly use usbd_is_dying().

Discussed many times with deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.68 15-Nov-2013 pirofti

Clean-up usbd_abort_pipe() usage.


This function never fails. So change it's return type to void and
adjust the copy-pasted callers that were checking the return.

"If it compiles, ok" mpi@


# 1.67 07-Aug-2013 bluhm

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


Revision tags: OPENBSD_5_4_BASE
# 1.66 15-Apr-2013 mglocker

Get rid of various 'typedef struct' definitions and use plain structure
definitions instead. We don't change usb.h for now to stay compatible
with userland.

Tested by mpi@ on macppc and myself on i386.

ok mpi@


# 1.65 28-Mar-2013 tedu

proc.h is way too much header for usb to handle.


Revision tags: OPENBSD_5_3_BASE
# 1.64 29-Jan-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.63 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.62 23-Jun-2011 deraadt

a bit more ansi; ok tedu


Revision tags: OPENBSD_4_9_BASE
# 1.61 25-Jan-2011 jakemsr

garbage collect "usb events". without /dev/usb there is no way to access
them from userland, and nothing in the kernel uses them.

ok krw@, miod@


# 1.60 06-Dec-2010 jakemsr

* replace per-driver dying and/or other state variables with use of
usbd_deactivete() and usbd_is_dying()
* use usbd_deactivate() in activate()/DEACTIVATE
* convert a few more direct checks of the associated bus' dying flag
with usbd_is_dying()


# 1.59 27-Oct-2010 jakemsr

don't free network related resources if they were not allocated


# 1.58 23-Oct-2010 jakemsr

check that a timeout(9) has been initialized before deleting it

ok phessler


# 1.57 23-Oct-2010 jakemsr

create another kthread to run xfer abort tasks. xfer abort tasks cannot
be run from the generic task kthread, because xfers that need to be
aborted block newly queued tasks from running (i.e. the xfer to be aborted
blocks the abort of that task). as there are now three types of usb
tasks, add an argument to usb_init_task() and another member to struct
usb_task to specify the task type.

fixes boot hangs that are showing up because we now use usb tasks to
attach/detach usb devices.


# 1.56 27-Aug-2010 deraadt

Delete comments about these drivers needing powerhook support; they don't.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.55 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.54 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.53 06-Nov-2008 brad

Set the IFCAP_VLAN_MTU capabilities flag so these interfaces are allowed
to transmit full sized VLAN tagged frames.


# 1.52 03-Oct-2008 brad

Use ether_ioctl().


# 1.51 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_3_BASE OPENBSD_4_4_BASE
# 1.50 23-Nov-2007 mbalmer

Sanitize the use of timeouts:

Instead of calling timeout_set(..., NULL, NULL) in attach routines and
later
timeout_del(...)
timeout_set(..., func, arg)
timeout_add(..., time)
set the function and argument in the initial timeout_set() call and only
use timeout_add(..., time) later.

ok dlg, fgsch, krw, winiger


# 1.49 11-Oct-2007 deraadt

treat usb vendor/product names as a locator, and have usbd_print handle it,
so that it shows up before the :. as a result, all the usb devices do not
need to have name printing code anymore. all this now works and prints
nicely because usbd_probe_and_attach() is serialized. ok kettenis


Revision tags: OPENBSD_4_2_BASE
# 1.48 14-Jun-2007 mbalmer

Remove the definition and usage of the USB_DECLARE_DRIVER_CLASS and
USB_DECLARE_DRIVER macros.

No binary change.

ok dlg.


# 1.47 13-Jun-2007 mbalmer

Remove the definition and usage of the IF_INPUT macro which was defined
as ether_input_mbuf which is itself a macro for ether_input.

No binary change.

ok dlg.


# 1.46 12-Jun-2007 mbalmer

Remove the definition and use of the device_ptr_t which was a struct device *.

No binary change.

ok mk.


# 1.45 11-Jun-2007 mbalmer

Remove the definition and usage of the USBGETSOFTC macro, which was really
only a cast to (void *).

ok jsg.


# 1.44 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEVNAME macro.

(This might look easy, but it was a big diff. Thanks to dlg and especially jsg
for looking over it; we found at least four mistakes in the initial diff.)

ok jsg.


# 1.43 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEV macro. It only created confusion
and the address of it's argument: USBDEV(sc->sc_dev) yields &sc->sc_dev.

No binary changes.

ok jsg.


# 1.42 10-Jun-2007 mbalmer

Remove definitions and usage of usb_callout and related macros. These macros
were used as a layer of confusion^Wabstraction around the timeout(9) API.

No binary change.

ok jsg.


# 1.41 09-Jun-2007 mbalmer

Remove the definition and use of if_deactivate(). It was defined empty and
thus produced no code at all.

No binary change.

ok jsg.


# 1.40 05-Jun-2007 mbalmer

Remove the "Static" declaration of many functions. It was defined to be empty
and it was not consistently used. It was confusing as it suggested these
functions were static, which they were not.

discussed with dlg and jsg, ok jsg.


# 1.39 04-Jun-2007 mbalmer

Last part of FreeBSD/NetBSD sepcific code removal.

ok jsg@


# 1.38 27-May-2007 jsg

Farewell USB_{ATTACH,MATCH,DETACH}* you will not be missed.
ok deraadt@ krw@ mbalmer@


# 1.37 21-May-2007 jsg

Remove logprintf macro


# 1.36 21-May-2007 jsg

Remove Ether_ifattach macro


# 1.35 06-May-2007 krw

More lockmgr -> rwlock low hanging fruit.

ok dlg@


Revision tags: OPENBSD_4_1_BASE
# 1.34 11-Feb-2007 miod

Remove _KERNEL_OPT leftovers.


Revision tags: OPENBSD_4_0_BASE
# 1.33 14-Jul-2006 brad

add ZyXEL USB id, remove useless comments and reorder USB devices.


# 1.32 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.31 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.30 07-Mar-2006 krw

Remove last NRND NetBSDisms from tree.

ok deraadt@ brad@


Revision tags: OPENBSD_3_9_BASE
# 1.29 06-Feb-2006 jmc

typos from alexey dobriyan;


# 1.28 29-Jan-2006 brad

Use usbd_clear_endpoint_stall_async() when clearing endpoint stalls in
an interrupt context.

From NetBSD

ok dlg@


# 1.27 23-Sep-2005 grunk

{TrendNet,Trendware} -> TRENDnet, ok jsg@


Revision tags: OPENBSD_3_8_BASE
# 1.26 01-Aug-2005 brad

Don't keep the devinfo string on the stack, instead use malloc/free.
This should cure some rare stack overflows.

From augustss NetBSD

ok dlg@ pascoe@


# 1.25 19-Jul-2005 jsg

Update for GREENHOUSE2 -> REALTEK USB vid change.


# 1.24 02-Jul-2005 brad

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


# 1.23 02-Jul-2005 brad

don't call mii_pollstat() right after mii_tick() in foo_tick_task()


# 1.22 08-Jun-2005 henning

remove netns crud.
some drivers actually had hooks for SIOCSIFADDR, most just useless includes
"looks good" deraadt miod brad


Revision tags: OPENBSD_3_7_BASE
# 1.21 03-Mar-2005 itojun

ethernet on OQO model 01 device cable. dlg ok


# 1.20 03-Jan-2005 brad

- make sure int is in running state before touching the multicast filters
- call foo_setmulti only instead of init'ing the chip
- don't overwrite potential error return with success when calling
ether_addmulti/ether_delmulti

ok dlg@


# 1.19 17-Nov-2004 deraadt

Three mode devices found in the wild, I think


# 1.18 10-Nov-2004 grange

strncpy->strlcpy
ok henning@


# 1.17 16-Oct-2004 jsg

Add Longshine LCS-8138TX and Micronet SP128AR found in linux driver
ok dlg@


# 1.16 29-Sep-2004 dlg

from netbsd: if_url.c 1.8, if_urlreg.h 1.2, urlphy.c 1.9 and urlphyreg.h 1.2
via Jonathan Gray
log message:

Remove advertising clauses from code written by Shingo WATANABE.
He has kindly consented it.


# 1.15 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.14 08-Jul-2004 deraadt

put "do { } while (0)" wrappers on all the debug maroc functions


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.13 23-Dec-2003 deraadt

init ether address correctly, since our Ether_ifattach macro does not do
that job; 3612, rspmn@arcor.de


# 1.12 15-Dec-2003 cedric

Set devclass to DV_IFNET for all USB network drivers.
ok deraadt@ nate@


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.11 07-May-2003 deraadt

string cleanup; nate ok


Revision tags: OPENBSD_3_3_BASE
# 1.10 27-Jan-2003 jason

branches: 1.10.4;
pad minimum frames with 0's; based on netbsd


# 1.9 11-Nov-2002 nate

sync with NetBSD


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.8 29-Sep-2002 jason

Plug memory leak; nyar-junk@int0rnet.net


# 1.7 25-Jul-2002 nate

get rid of trailing whitespace


# 1.6 10-Jul-2002 deraadt

shorten address printout


# 1.5 26-Jun-2002 espie

Kill __FUNCTION__.


# 1.4 09-May-2002 nate

branches: 1.4.2;
Fix ioctl handling
Add default MTU
fix typo

errors noted by Jason Ackley <jason@ackley.net>


# 1.3 07-May-2002 nate

Add a driver for Realtek RTL8150L based ethernet devices
From NetBSD


# 1.2 07-May-2002 nate

Meant to commit only ulpt and committed everything. Most things weren't ready


# 1.1 07-May-2002 nate

Sync ulpt driver with NetBSD


# 1.84 02-Oct-2018 stsp

Make some USB ioctls return ENXIO, instead of EIO, if usbd_is_dying().
Brings us one step closer towards making this condition's error code
consistent across all USB drivers.
Patch by Moritz Buhl
ok mpi@ bluhm@


# 1.83 03-Jul-2018 kevlo

Use LIST_FOREACH construct instead of homebrew loop.

ok bluhm@, mpi@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 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@


# 1.81 06-Nov-2016 mpi

Avoid calling usbd_set_config_no() in *_attach() and let the stack do
it instead.

If anything bad happen due to a malformed descriptor it makes no sense
to try to attach a driver, and bail before probing.

This is similar to the change to avoid calling usbd_set_config_index().


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

G/C IFQ_SET_READY().


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

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


# 1.77 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.76 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.75 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.74 27-Mar-2015 uaa

simply do if_input() between splnet() and splx(), like other drivers
(such as if_udav.c).

ok by mpi@


# 1.73 14-Mar-2015 jsg

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

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.72 12-Feb-2015 mpi

Convert to if_input().

ok dlg@


# 1.71 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.70 13-Jul-2014 mpi

No need for <netinet/in_systm.h> here.


# 1.69 12-Jul-2014 mpi

Kill a bunch of DVACT_DEACTIVATE handlers whose only purpose were to
set the 'dying' flag of a device. Such handlers are useless now that
usbd_detach() already set this flag.

Even if the purpose of this flag is questionnable on OpenBSD because
DVACT_DEACTIVATE acts as a pre-detach event, this is just a first small
step towards the simplification of the autoconf(9) device states.

This cleaning is now possible thanks to the work of pirofti@ to convert
all the USB drivers to properly use usbd_is_dying().

Discussed many times with deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.68 15-Nov-2013 pirofti

Clean-up usbd_abort_pipe() usage.


This function never fails. So change it's return type to void and
adjust the copy-pasted callers that were checking the return.

"If it compiles, ok" mpi@


# 1.67 07-Aug-2013 bluhm

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


Revision tags: OPENBSD_5_4_BASE
# 1.66 15-Apr-2013 mglocker

Get rid of various 'typedef struct' definitions and use plain structure
definitions instead. We don't change usb.h for now to stay compatible
with userland.

Tested by mpi@ on macppc and myself on i386.

ok mpi@


# 1.65 28-Mar-2013 tedu

proc.h is way too much header for usb to handle.


Revision tags: OPENBSD_5_3_BASE
# 1.64 29-Jan-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.63 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.62 23-Jun-2011 deraadt

a bit more ansi; ok tedu


Revision tags: OPENBSD_4_9_BASE
# 1.61 25-Jan-2011 jakemsr

garbage collect "usb events". without /dev/usb there is no way to access
them from userland, and nothing in the kernel uses them.

ok krw@, miod@


# 1.60 06-Dec-2010 jakemsr

* replace per-driver dying and/or other state variables with use of
usbd_deactivete() and usbd_is_dying()
* use usbd_deactivate() in activate()/DEACTIVATE
* convert a few more direct checks of the associated bus' dying flag
with usbd_is_dying()


# 1.59 27-Oct-2010 jakemsr

don't free network related resources if they were not allocated


# 1.58 23-Oct-2010 jakemsr

check that a timeout(9) has been initialized before deleting it

ok phessler


# 1.57 23-Oct-2010 jakemsr

create another kthread to run xfer abort tasks. xfer abort tasks cannot
be run from the generic task kthread, because xfers that need to be
aborted block newly queued tasks from running (i.e. the xfer to be aborted
blocks the abort of that task). as there are now three types of usb
tasks, add an argument to usb_init_task() and another member to struct
usb_task to specify the task type.

fixes boot hangs that are showing up because we now use usb tasks to
attach/detach usb devices.


# 1.56 27-Aug-2010 deraadt

Delete comments about these drivers needing powerhook support; they don't.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.55 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.54 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.53 06-Nov-2008 brad

Set the IFCAP_VLAN_MTU capabilities flag so these interfaces are allowed
to transmit full sized VLAN tagged frames.


# 1.52 03-Oct-2008 brad

Use ether_ioctl().


# 1.51 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_3_BASE OPENBSD_4_4_BASE
# 1.50 23-Nov-2007 mbalmer

Sanitize the use of timeouts:

Instead of calling timeout_set(..., NULL, NULL) in attach routines and
later
timeout_del(...)
timeout_set(..., func, arg)
timeout_add(..., time)
set the function and argument in the initial timeout_set() call and only
use timeout_add(..., time) later.

ok dlg, fgsch, krw, winiger


# 1.49 11-Oct-2007 deraadt

treat usb vendor/product names as a locator, and have usbd_print handle it,
so that it shows up before the :. as a result, all the usb devices do not
need to have name printing code anymore. all this now works and prints
nicely because usbd_probe_and_attach() is serialized. ok kettenis


Revision tags: OPENBSD_4_2_BASE
# 1.48 14-Jun-2007 mbalmer

Remove the definition and usage of the USB_DECLARE_DRIVER_CLASS and
USB_DECLARE_DRIVER macros.

No binary change.

ok dlg.


# 1.47 13-Jun-2007 mbalmer

Remove the definition and usage of the IF_INPUT macro which was defined
as ether_input_mbuf which is itself a macro for ether_input.

No binary change.

ok dlg.


# 1.46 12-Jun-2007 mbalmer

Remove the definition and use of the device_ptr_t which was a struct device *.

No binary change.

ok mk.


# 1.45 11-Jun-2007 mbalmer

Remove the definition and usage of the USBGETSOFTC macro, which was really
only a cast to (void *).

ok jsg.


# 1.44 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEVNAME macro.

(This might look easy, but it was a big diff. Thanks to dlg and especially jsg
for looking over it; we found at least four mistakes in the initial diff.)

ok jsg.


# 1.43 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEV macro. It only created confusion
and the address of it's argument: USBDEV(sc->sc_dev) yields &sc->sc_dev.

No binary changes.

ok jsg.


# 1.42 10-Jun-2007 mbalmer

Remove definitions and usage of usb_callout and related macros. These macros
were used as a layer of confusion^Wabstraction around the timeout(9) API.

No binary change.

ok jsg.


# 1.41 09-Jun-2007 mbalmer

Remove the definition and use of if_deactivate(). It was defined empty and
thus produced no code at all.

No binary change.

ok jsg.


# 1.40 05-Jun-2007 mbalmer

Remove the "Static" declaration of many functions. It was defined to be empty
and it was not consistently used. It was confusing as it suggested these
functions were static, which they were not.

discussed with dlg and jsg, ok jsg.


# 1.39 04-Jun-2007 mbalmer

Last part of FreeBSD/NetBSD sepcific code removal.

ok jsg@


# 1.38 27-May-2007 jsg

Farewell USB_{ATTACH,MATCH,DETACH}* you will not be missed.
ok deraadt@ krw@ mbalmer@


# 1.37 21-May-2007 jsg

Remove logprintf macro


# 1.36 21-May-2007 jsg

Remove Ether_ifattach macro


# 1.35 06-May-2007 krw

More lockmgr -> rwlock low hanging fruit.

ok dlg@


Revision tags: OPENBSD_4_1_BASE
# 1.34 11-Feb-2007 miod

Remove _KERNEL_OPT leftovers.


Revision tags: OPENBSD_4_0_BASE
# 1.33 14-Jul-2006 brad

add ZyXEL USB id, remove useless comments and reorder USB devices.


# 1.32 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.31 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.30 07-Mar-2006 krw

Remove last NRND NetBSDisms from tree.

ok deraadt@ brad@


Revision tags: OPENBSD_3_9_BASE
# 1.29 06-Feb-2006 jmc

typos from alexey dobriyan;


# 1.28 29-Jan-2006 brad

Use usbd_clear_endpoint_stall_async() when clearing endpoint stalls in
an interrupt context.

From NetBSD

ok dlg@


# 1.27 23-Sep-2005 grunk

{TrendNet,Trendware} -> TRENDnet, ok jsg@


Revision tags: OPENBSD_3_8_BASE
# 1.26 01-Aug-2005 brad

Don't keep the devinfo string on the stack, instead use malloc/free.
This should cure some rare stack overflows.

From augustss NetBSD

ok dlg@ pascoe@


# 1.25 19-Jul-2005 jsg

Update for GREENHOUSE2 -> REALTEK USB vid change.


# 1.24 02-Jul-2005 brad

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


# 1.23 02-Jul-2005 brad

don't call mii_pollstat() right after mii_tick() in foo_tick_task()


# 1.22 08-Jun-2005 henning

remove netns crud.
some drivers actually had hooks for SIOCSIFADDR, most just useless includes
"looks good" deraadt miod brad


Revision tags: OPENBSD_3_7_BASE
# 1.21 03-Mar-2005 itojun

ethernet on OQO model 01 device cable. dlg ok


# 1.20 03-Jan-2005 brad

- make sure int is in running state before touching the multicast filters
- call foo_setmulti only instead of init'ing the chip
- don't overwrite potential error return with success when calling
ether_addmulti/ether_delmulti

ok dlg@


# 1.19 17-Nov-2004 deraadt

Three mode devices found in the wild, I think


# 1.18 10-Nov-2004 grange

strncpy->strlcpy
ok henning@


# 1.17 16-Oct-2004 jsg

Add Longshine LCS-8138TX and Micronet SP128AR found in linux driver
ok dlg@


# 1.16 29-Sep-2004 dlg

from netbsd: if_url.c 1.8, if_urlreg.h 1.2, urlphy.c 1.9 and urlphyreg.h 1.2
via Jonathan Gray
log message:

Remove advertising clauses from code written by Shingo WATANABE.
He has kindly consented it.


# 1.15 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.14 08-Jul-2004 deraadt

put "do { } while (0)" wrappers on all the debug maroc functions


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.13 23-Dec-2003 deraadt

init ether address correctly, since our Ether_ifattach macro does not do
that job; 3612, rspmn@arcor.de


# 1.12 15-Dec-2003 cedric

Set devclass to DV_IFNET for all USB network drivers.
ok deraadt@ nate@


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.11 07-May-2003 deraadt

string cleanup; nate ok


Revision tags: OPENBSD_3_3_BASE
# 1.10 27-Jan-2003 jason

branches: 1.10.4;
pad minimum frames with 0's; based on netbsd


# 1.9 11-Nov-2002 nate

sync with NetBSD


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.8 29-Sep-2002 jason

Plug memory leak; nyar-junk@int0rnet.net


# 1.7 25-Jul-2002 nate

get rid of trailing whitespace


# 1.6 10-Jul-2002 deraadt

shorten address printout


# 1.5 26-Jun-2002 espie

Kill __FUNCTION__.


# 1.4 09-May-2002 nate

branches: 1.4.2;
Fix ioctl handling
Add default MTU
fix typo

errors noted by Jason Ackley <jason@ackley.net>


# 1.3 07-May-2002 nate

Add a driver for Realtek RTL8150L based ethernet devices
From NetBSD


# 1.2 07-May-2002 nate

Meant to commit only ulpt and committed everything. Most things weren't ready


# 1.1 07-May-2002 nate

Sync ulpt driver with NetBSD


# 1.83 03-Jul-2018 kevlo

Use LIST_FOREACH construct instead of homebrew loop.

ok bluhm@, mpi@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 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@


# 1.81 06-Nov-2016 mpi

Avoid calling usbd_set_config_no() in *_attach() and let the stack do
it instead.

If anything bad happen due to a malformed descriptor it makes no sense
to try to attach a driver, and bail before probing.

This is similar to the change to avoid calling usbd_set_config_index().


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

G/C IFQ_SET_READY().


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

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


# 1.77 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.76 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.75 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.74 27-Mar-2015 uaa

simply do if_input() between splnet() and splx(), like other drivers
(such as if_udav.c).

ok by mpi@


# 1.73 14-Mar-2015 jsg

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

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.72 12-Feb-2015 mpi

Convert to if_input().

ok dlg@


# 1.71 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.70 13-Jul-2014 mpi

No need for <netinet/in_systm.h> here.


# 1.69 12-Jul-2014 mpi

Kill a bunch of DVACT_DEACTIVATE handlers whose only purpose were to
set the 'dying' flag of a device. Such handlers are useless now that
usbd_detach() already set this flag.

Even if the purpose of this flag is questionnable on OpenBSD because
DVACT_DEACTIVATE acts as a pre-detach event, this is just a first small
step towards the simplification of the autoconf(9) device states.

This cleaning is now possible thanks to the work of pirofti@ to convert
all the USB drivers to properly use usbd_is_dying().

Discussed many times with deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.68 15-Nov-2013 pirofti

Clean-up usbd_abort_pipe() usage.


This function never fails. So change it's return type to void and
adjust the copy-pasted callers that were checking the return.

"If it compiles, ok" mpi@


# 1.67 07-Aug-2013 bluhm

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


Revision tags: OPENBSD_5_4_BASE
# 1.66 15-Apr-2013 mglocker

Get rid of various 'typedef struct' definitions and use plain structure
definitions instead. We don't change usb.h for now to stay compatible
with userland.

Tested by mpi@ on macppc and myself on i386.

ok mpi@


# 1.65 28-Mar-2013 tedu

proc.h is way too much header for usb to handle.


Revision tags: OPENBSD_5_3_BASE
# 1.64 29-Jan-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.63 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.62 23-Jun-2011 deraadt

a bit more ansi; ok tedu


Revision tags: OPENBSD_4_9_BASE
# 1.61 25-Jan-2011 jakemsr

garbage collect "usb events". without /dev/usb there is no way to access
them from userland, and nothing in the kernel uses them.

ok krw@, miod@


# 1.60 06-Dec-2010 jakemsr

* replace per-driver dying and/or other state variables with use of
usbd_deactivete() and usbd_is_dying()
* use usbd_deactivate() in activate()/DEACTIVATE
* convert a few more direct checks of the associated bus' dying flag
with usbd_is_dying()


# 1.59 27-Oct-2010 jakemsr

don't free network related resources if they were not allocated


# 1.58 23-Oct-2010 jakemsr

check that a timeout(9) has been initialized before deleting it

ok phessler


# 1.57 23-Oct-2010 jakemsr

create another kthread to run xfer abort tasks. xfer abort tasks cannot
be run from the generic task kthread, because xfers that need to be
aborted block newly queued tasks from running (i.e. the xfer to be aborted
blocks the abort of that task). as there are now three types of usb
tasks, add an argument to usb_init_task() and another member to struct
usb_task to specify the task type.

fixes boot hangs that are showing up because we now use usb tasks to
attach/detach usb devices.


# 1.56 27-Aug-2010 deraadt

Delete comments about these drivers needing powerhook support; they don't.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.55 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.54 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.53 06-Nov-2008 brad

Set the IFCAP_VLAN_MTU capabilities flag so these interfaces are allowed
to transmit full sized VLAN tagged frames.


# 1.52 03-Oct-2008 brad

Use ether_ioctl().


# 1.51 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_3_BASE OPENBSD_4_4_BASE
# 1.50 23-Nov-2007 mbalmer

Sanitize the use of timeouts:

Instead of calling timeout_set(..., NULL, NULL) in attach routines and
later
timeout_del(...)
timeout_set(..., func, arg)
timeout_add(..., time)
set the function and argument in the initial timeout_set() call and only
use timeout_add(..., time) later.

ok dlg, fgsch, krw, winiger


# 1.49 11-Oct-2007 deraadt

treat usb vendor/product names as a locator, and have usbd_print handle it,
so that it shows up before the :. as a result, all the usb devices do not
need to have name printing code anymore. all this now works and prints
nicely because usbd_probe_and_attach() is serialized. ok kettenis


Revision tags: OPENBSD_4_2_BASE
# 1.48 14-Jun-2007 mbalmer

Remove the definition and usage of the USB_DECLARE_DRIVER_CLASS and
USB_DECLARE_DRIVER macros.

No binary change.

ok dlg.


# 1.47 13-Jun-2007 mbalmer

Remove the definition and usage of the IF_INPUT macro which was defined
as ether_input_mbuf which is itself a macro for ether_input.

No binary change.

ok dlg.


# 1.46 12-Jun-2007 mbalmer

Remove the definition and use of the device_ptr_t which was a struct device *.

No binary change.

ok mk.


# 1.45 11-Jun-2007 mbalmer

Remove the definition and usage of the USBGETSOFTC macro, which was really
only a cast to (void *).

ok jsg.


# 1.44 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEVNAME macro.

(This might look easy, but it was a big diff. Thanks to dlg and especially jsg
for looking over it; we found at least four mistakes in the initial diff.)

ok jsg.


# 1.43 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEV macro. It only created confusion
and the address of it's argument: USBDEV(sc->sc_dev) yields &sc->sc_dev.

No binary changes.

ok jsg.


# 1.42 10-Jun-2007 mbalmer

Remove definitions and usage of usb_callout and related macros. These macros
were used as a layer of confusion^Wabstraction around the timeout(9) API.

No binary change.

ok jsg.


# 1.41 09-Jun-2007 mbalmer

Remove the definition and use of if_deactivate(). It was defined empty and
thus produced no code at all.

No binary change.

ok jsg.


# 1.40 05-Jun-2007 mbalmer

Remove the "Static" declaration of many functions. It was defined to be empty
and it was not consistently used. It was confusing as it suggested these
functions were static, which they were not.

discussed with dlg and jsg, ok jsg.


# 1.39 04-Jun-2007 mbalmer

Last part of FreeBSD/NetBSD sepcific code removal.

ok jsg@


# 1.38 27-May-2007 jsg

Farewell USB_{ATTACH,MATCH,DETACH}* you will not be missed.
ok deraadt@ krw@ mbalmer@


# 1.37 21-May-2007 jsg

Remove logprintf macro


# 1.36 21-May-2007 jsg

Remove Ether_ifattach macro


# 1.35 06-May-2007 krw

More lockmgr -> rwlock low hanging fruit.

ok dlg@


Revision tags: OPENBSD_4_1_BASE
# 1.34 11-Feb-2007 miod

Remove _KERNEL_OPT leftovers.


Revision tags: OPENBSD_4_0_BASE
# 1.33 14-Jul-2006 brad

add ZyXEL USB id, remove useless comments and reorder USB devices.


# 1.32 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.31 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.30 07-Mar-2006 krw

Remove last NRND NetBSDisms from tree.

ok deraadt@ brad@


Revision tags: OPENBSD_3_9_BASE
# 1.29 06-Feb-2006 jmc

typos from alexey dobriyan;


# 1.28 29-Jan-2006 brad

Use usbd_clear_endpoint_stall_async() when clearing endpoint stalls in
an interrupt context.

From NetBSD

ok dlg@


# 1.27 23-Sep-2005 grunk

{TrendNet,Trendware} -> TRENDnet, ok jsg@


Revision tags: OPENBSD_3_8_BASE
# 1.26 01-Aug-2005 brad

Don't keep the devinfo string on the stack, instead use malloc/free.
This should cure some rare stack overflows.

From augustss NetBSD

ok dlg@ pascoe@


# 1.25 19-Jul-2005 jsg

Update for GREENHOUSE2 -> REALTEK USB vid change.


# 1.24 02-Jul-2005 brad

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


# 1.23 02-Jul-2005 brad

don't call mii_pollstat() right after mii_tick() in foo_tick_task()


# 1.22 08-Jun-2005 henning

remove netns crud.
some drivers actually had hooks for SIOCSIFADDR, most just useless includes
"looks good" deraadt miod brad


Revision tags: OPENBSD_3_7_BASE
# 1.21 03-Mar-2005 itojun

ethernet on OQO model 01 device cable. dlg ok


# 1.20 03-Jan-2005 brad

- make sure int is in running state before touching the multicast filters
- call foo_setmulti only instead of init'ing the chip
- don't overwrite potential error return with success when calling
ether_addmulti/ether_delmulti

ok dlg@


# 1.19 17-Nov-2004 deraadt

Three mode devices found in the wild, I think


# 1.18 10-Nov-2004 grange

strncpy->strlcpy
ok henning@


# 1.17 16-Oct-2004 jsg

Add Longshine LCS-8138TX and Micronet SP128AR found in linux driver
ok dlg@


# 1.16 29-Sep-2004 dlg

from netbsd: if_url.c 1.8, if_urlreg.h 1.2, urlphy.c 1.9 and urlphyreg.h 1.2
via Jonathan Gray
log message:

Remove advertising clauses from code written by Shingo WATANABE.
He has kindly consented it.


# 1.15 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.14 08-Jul-2004 deraadt

put "do { } while (0)" wrappers on all the debug maroc functions


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.13 23-Dec-2003 deraadt

init ether address correctly, since our Ether_ifattach macro does not do
that job; 3612, rspmn@arcor.de


# 1.12 15-Dec-2003 cedric

Set devclass to DV_IFNET for all USB network drivers.
ok deraadt@ nate@


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.11 07-May-2003 deraadt

string cleanup; nate ok


Revision tags: OPENBSD_3_3_BASE
# 1.10 27-Jan-2003 jason

branches: 1.10.4;
pad minimum frames with 0's; based on netbsd


# 1.9 11-Nov-2002 nate

sync with NetBSD


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.8 29-Sep-2002 jason

Plug memory leak; nyar-junk@int0rnet.net


# 1.7 25-Jul-2002 nate

get rid of trailing whitespace


# 1.6 10-Jul-2002 deraadt

shorten address printout


# 1.5 26-Jun-2002 espie

Kill __FUNCTION__.


# 1.4 09-May-2002 nate

branches: 1.4.2;
Fix ioctl handling
Add default MTU
fix typo

errors noted by Jason Ackley <jason@ackley.net>


# 1.3 07-May-2002 nate

Add a driver for Realtek RTL8150L based ethernet devices
From NetBSD


# 1.2 07-May-2002 nate

Meant to commit only ulpt and committed everything. Most things weren't ready


# 1.1 07-May-2002 nate

Sync ulpt driver with NetBSD


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.82 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@


# 1.81 06-Nov-2016 mpi

Avoid calling usbd_set_config_no() in *_attach() and let the stack do
it instead.

If anything bad happen due to a malformed descriptor it makes no sense
to try to attach a driver, and bail before probing.

This is similar to the change to avoid calling usbd_set_config_index().


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

G/C IFQ_SET_READY().


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

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


# 1.77 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.76 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.75 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.74 27-Mar-2015 uaa

simply do if_input() between splnet() and splx(), like other drivers
(such as if_udav.c).

ok by mpi@


# 1.73 14-Mar-2015 jsg

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

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.72 12-Feb-2015 mpi

Convert to if_input().

ok dlg@


# 1.71 22-Dec-2014 tedu

unifdef INET


Revision tags: OPENBSD_5_6_BASE
# 1.70 13-Jul-2014 mpi

No need for <netinet/in_systm.h> here.


# 1.69 12-Jul-2014 mpi

Kill a bunch of DVACT_DEACTIVATE handlers whose only purpose were to
set the 'dying' flag of a device. Such handlers are useless now that
usbd_detach() already set this flag.

Even if the purpose of this flag is questionnable on OpenBSD because
DVACT_DEACTIVATE acts as a pre-detach event, this is just a first small
step towards the simplification of the autoconf(9) device states.

This cleaning is now possible thanks to the work of pirofti@ to convert
all the USB drivers to properly use usbd_is_dying().

Discussed many times with deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.68 15-Nov-2013 pirofti

Clean-up usbd_abort_pipe() usage.


This function never fails. So change it's return type to void and
adjust the copy-pasted callers that were checking the return.

"If it compiles, ok" mpi@


# 1.67 07-Aug-2013 bluhm

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


Revision tags: OPENBSD_5_4_BASE
# 1.66 15-Apr-2013 mglocker

Get rid of various 'typedef struct' definitions and use plain structure
definitions instead. We don't change usb.h for now to stay compatible
with userland.

Tested by mpi@ on macppc and myself on i386.

ok mpi@


# 1.65 28-Mar-2013 tedu

proc.h is way too much header for usb to handle.


Revision tags: OPENBSD_5_3_BASE
# 1.64 29-Jan-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok sthen@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.63 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.62 23-Jun-2011 deraadt

a bit more ansi; ok tedu


Revision tags: OPENBSD_4_9_BASE
# 1.61 25-Jan-2011 jakemsr

garbage collect "usb events". without /dev/usb there is no way to access
them from userland, and nothing in the kernel uses them.

ok krw@, miod@


# 1.60 06-Dec-2010 jakemsr

* replace per-driver dying and/or other state variables with use of
usbd_deactivete() and usbd_is_dying()
* use usbd_deactivate() in activate()/DEACTIVATE
* convert a few more direct checks of the associated bus' dying flag
with usbd_is_dying()


# 1.59 27-Oct-2010 jakemsr

don't free network related resources if they were not allocated


# 1.58 23-Oct-2010 jakemsr

check that a timeout(9) has been initialized before deleting it

ok phessler


# 1.57 23-Oct-2010 jakemsr

create another kthread to run xfer abort tasks. xfer abort tasks cannot
be run from the generic task kthread, because xfers that need to be
aborted block newly queued tasks from running (i.e. the xfer to be aborted
blocks the abort of that task). as there are now three types of usb
tasks, add an argument to usb_init_task() and another member to struct
usb_task to specify the task type.

fixes boot hangs that are showing up because we now use usb tasks to
attach/detach usb devices.


# 1.56 27-Aug-2010 deraadt

Delete comments about these drivers needing powerhook support; they don't.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.55 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.54 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.53 06-Nov-2008 brad

Set the IFCAP_VLAN_MTU capabilities flag so these interfaces are allowed
to transmit full sized VLAN tagged frames.


# 1.52 03-Oct-2008 brad

Use ether_ioctl().


# 1.51 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_3_BASE OPENBSD_4_4_BASE
# 1.50 23-Nov-2007 mbalmer

Sanitize the use of timeouts:

Instead of calling timeout_set(..., NULL, NULL) in attach routines and
later
timeout_del(...)
timeout_set(..., func, arg)
timeout_add(..., time)
set the function and argument in the initial timeout_set() call and only
use timeout_add(..., time) later.

ok dlg, fgsch, krw, winiger


# 1.49 11-Oct-2007 deraadt

treat usb vendor/product names as a locator, and have usbd_print handle it,
so that it shows up before the :. as a result, all the usb devices do not
need to have name printing code anymore. all this now works and prints
nicely because usbd_probe_and_attach() is serialized. ok kettenis


Revision tags: OPENBSD_4_2_BASE
# 1.48 14-Jun-2007 mbalmer

Remove the definition and usage of the USB_DECLARE_DRIVER_CLASS and
USB_DECLARE_DRIVER macros.

No binary change.

ok dlg.


# 1.47 13-Jun-2007 mbalmer

Remove the definition and usage of the IF_INPUT macro which was defined
as ether_input_mbuf which is itself a macro for ether_input.

No binary change.

ok dlg.


# 1.46 12-Jun-2007 mbalmer

Remove the definition and use of the device_ptr_t which was a struct device *.

No binary change.

ok mk.


# 1.45 11-Jun-2007 mbalmer

Remove the definition and usage of the USBGETSOFTC macro, which was really
only a cast to (void *).

ok jsg.


# 1.44 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEVNAME macro.

(This might look easy, but it was a big diff. Thanks to dlg and especially jsg
for looking over it; we found at least four mistakes in the initial diff.)

ok jsg.


# 1.43 10-Jun-2007 mbalmer

Remove the definition and use of the USBDEV macro. It only created confusion
and the address of it's argument: USBDEV(sc->sc_dev) yields &sc->sc_dev.

No binary changes.

ok jsg.


# 1.42 10-Jun-2007 mbalmer

Remove definitions and usage of usb_callout and related macros. These macros
were used as a layer of confusion^Wabstraction around the timeout(9) API.

No binary change.

ok jsg.


# 1.41 09-Jun-2007 mbalmer

Remove the definition and use of if_deactivate(). It was defined empty and
thus produced no code at all.

No binary change.

ok jsg.


# 1.40 05-Jun-2007 mbalmer

Remove the "Static" declaration of many functions. It was defined to be empty
and it was not consistently used. It was confusing as it suggested these
functions were static, which they were not.

discussed with dlg and jsg, ok jsg.


# 1.39 04-Jun-2007 mbalmer

Last part of FreeBSD/NetBSD sepcific code removal.

ok jsg@


# 1.38 27-May-2007 jsg

Farewell USB_{ATTACH,MATCH,DETACH}* you will not be missed.
ok deraadt@ krw@ mbalmer@


# 1.37 21-May-2007 jsg

Remove logprintf macro


# 1.36 21-May-2007 jsg

Remove Ether_ifattach macro


# 1.35 06-May-2007 krw

More lockmgr -> rwlock low hanging fruit.

ok dlg@


Revision tags: OPENBSD_4_1_BASE
# 1.34 11-Feb-2007 miod

Remove _KERNEL_OPT leftovers.


Revision tags: OPENBSD_4_0_BASE
# 1.33 14-Jul-2006 brad

add ZyXEL USB id, remove useless comments and reorder USB devices.


# 1.32 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.31 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.30 07-Mar-2006 krw

Remove last NRND NetBSDisms from tree.

ok deraadt@ brad@


Revision tags: OPENBSD_3_9_BASE
# 1.29 06-Feb-2006 jmc

typos from alexey dobriyan;


# 1.28 29-Jan-2006 brad

Use usbd_clear_endpoint_stall_async() when clearing endpoint stalls in
an interrupt context.

From NetBSD

ok dlg@


# 1.27 23-Sep-2005 grunk

{TrendNet,Trendware} -> TRENDnet, ok jsg@


Revision tags: OPENBSD_3_8_BASE
# 1.26 01-Aug-2005 brad

Don't keep the devinfo string on the stack, instead use malloc/free.
This should cure some rare stack overflows.

From augustss NetBSD

ok dlg@ pascoe@


# 1.25 19-Jul-2005 jsg

Update for GREENHOUSE2 -> REALTEK USB vid change.


# 1.24 02-Jul-2005 brad

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


# 1.23 02-Jul-2005 brad

don't call mii_pollstat() right after mii_tick() in foo_tick_task()


# 1.22 08-Jun-2005 henning

remove netns crud.
some drivers actually had hooks for SIOCSIFADDR, most just useless includes
"looks good" deraadt miod brad


Revision tags: OPENBSD_3_7_BASE
# 1.21 03-Mar-2005 itojun

ethernet on OQO model 01 device cable. dlg ok


# 1.20 03-Jan-2005 brad

- make sure int is in running state before touching the multicast filters
- call foo_setmulti only instead of init'ing the chip
- don't overwrite potential error return with success when calling
ether_addmulti/ether_delmulti

ok dlg@


# 1.19 17-Nov-2004 deraadt

Three mode devices found in the wild, I think


# 1.18 10-Nov-2004 grange

strncpy->strlcpy
ok henning@


# 1.17 16-Oct-2004 jsg

Add Longshine LCS-8138TX and Micronet SP128AR found in linux driver
ok dlg@


# 1.16 29-Sep-2004 dlg

from netbsd: if_url.c 1.8, if_urlreg.h 1.2, urlphy.c 1.9 and urlphyreg.h 1.2
via Jonathan Gray
log message:

Remove advertising clauses from code written by Shingo WATANABE.
He has kindly consented it.


# 1.15 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.14 08-Jul-2004 deraadt

put "do { } while (0)" wrappers on all the debug maroc functions


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.13 23-Dec-2003 deraadt

init ether address correctly, since our Ether_ifattach macro does not do
that job; 3612, rspmn@arcor.de


# 1.12 15-Dec-2003 cedric

Set devclass to DV_IFNET for all USB network drivers.
ok deraadt@ nate@


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.11 07-May-2003 deraadt

string cleanup; nate ok


Revision tags: OPENBSD_3_3_BASE
# 1.10 27-Jan-2003 jason

branches: 1.10.4;
pad minimum frames with 0's; based on netbsd


# 1.9 11-Nov-2002 nate

sync with NetBSD


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.8 29-Sep-2002 jason

Plug memory leak; nyar-junk@int0rnet.net


# 1.7 25-Jul-2002 nate

get rid of trailing whitespace


# 1.6 10-Jul-2002 deraadt

shorten address printout


# 1.5 26-Jun-2002 espie

Kill __FUNCTION__.


# 1.4 09-May-2002 nate

branches: 1.4.2;
Fix ioctl handling
Add default MTU
fix typo

errors noted by Jason Ackley <jason@ackley.net>


# 1.3 07-May-2002 nate

Add a driver for Realtek RTL8150L based ethernet devices
From NetBSD


# 1.2 07-May-2002 nate

Meant to commit only ulpt and committed everything. Most things weren't ready


# 1.1 07-May-2002 nate

Sync ulpt driver with NetBSD