Home | History | Annotate | Download | only in usb
History log of /src/sys/dev/usb/if_ure.c
RevisionDateAuthorComments
 1.60  12-May-2024  christos PR/58250: RVP: Add TP-Link UE300 USB LAN adapter
 1.59  09-Oct-2023  riastradh ure(4): Set all bits, not no bits, in multicast filter for promisc.

This was lost in revision 1.40.

PR kern/57648

XXX pullup-10
 1.58  16-Sep-2022  msaitoh branches: 1.58.4;
Use unsigned to avoid undefined behavior in ure_uno_mcast(). Found by kUBSan.
 1.57  20-Aug-2022  riastradh usbnet(9): New usbnet_ispromisc(un).

Replaces ifp->if_flags & IFF_PROMISC in multicast filter updates.
 1.56  03-Mar-2022  riastradh usbnet: Omit needless detachcv name parameter to usbnet_attach.
 1.55  03-Mar-2022  riastradh usbnet: Factor usbnet_init_rx_tx out into usbnet_if_init.

Make it private; no need for drivers to call it any more.
 1.54  03-Mar-2022  riastradh usbnet drivers: Prune dead IFF_RUNNING branches in *_uno_init.

usbnet(9) guarantees !IFF_RUNNING now before calling it.
 1.53  03-Mar-2022  riastradh usbnet drivers: Omit needless isdying tests in *_uno_init.

usbnet(9) already checks this immediately before calling *_uno_init.
 1.52  03-Mar-2022  riastradh usbnet drivers: Omit needless usbnet core lock and assertions.

During attach, the caller has exclusive access to the usbnet until
usbnet_attach_ifp. At other times, register access is serialized
either by the usbnet multicast lock or by IFNET_LOCK.
 1.51  03-Mar-2022  riastradh usbnet drivers: Avoid undefined behaviour if read reg fails.

Some callers don't check the error code, e.g. ~all the mii phy
drivers using PHY_READ. Just return zero if the device is gone or
the xfer fails for any other reason.
 1.50  03-Mar-2022  riastradh usbnet drivers: Omit redundant multicast filter update on init.
 1.49  03-Mar-2022  riastradh usbnet: Apply hardware multicast filter updates synchronously again.

To make this work:

1. Do it only under a new lock, unp_mcastlock. This lock lives at
IPL_SOFTCLOCK so it can be taken from network stack callouts. It
is forbidden to acquire the usbnet core lock under unp_mcastlock.

2. Do it only after usbnet_init_rx_tx and before usbnet_stop; if
issued at any other time, drop the update on the floor.

3. Make usbnet_init_rx_tx apply any pending multicast filter updates
under the lock before setting the flag that allows SIOCADDMULTI or
SIOCDELMULTI to apply the updates.

4. Remove core lock asserts from various drivers' register access
routines. This is necessary because the multicast filter updates
are done with register reads/writes, but _cannot_ take the core
lock when the caller holds softnet_lock.

This now programs the hardware multicast filter redundantly in many
drivers which already explicitly call *_uno_mcast from the *_uno_init
routines. This is probably harmless, but it will likely be better to
remove the explicit calls.
 1.48  03-Mar-2022  riastradh usbnet drivers: Omit needless uno_mcast locked subroutines.

uno_mcast is now called with the core lock already held so there is
no need for a separate locked subroutine.
 1.47  03-Mar-2022  riastradh usbnet: Take the core lock around uno_mcast.

Every driver does this already. This will enable us to change the
lock that serializes access to the registers so we can go back to
doing this synchronously in SIOCADDMULTI/SIOCDELMULTI.
 1.46  03-Mar-2022  riastradh usbnet drivers: Omit needless uno_init locked subroutines.

uno_init is now called with the core lock already held so there is no
need for a separate locked subroutine.
 1.45  03-Mar-2022  riastradh usbnet drivers: No need for usbnet_busy in uno_mcast.

This callback always runs with IFNET_LOCK held, and during a task
that usbnet_detach prevents scheduling anew and waits for finishing
before completing the detach, so there is no need to hang onto a
reference count here.
 1.44  03-Mar-2022  riastradh usbnet drivers: No need for usbnet_busy in uno_init.

This callback always runs with the IFNET_LOCK held, and the interface
cannot be detached until the IFNET_LOCK is released, so there is no
need to hang onto a reference count here. (None of the usbnet
drivers touch the IFNET_LOCK except to verify it is held sometimes.)
 1.43  03-Mar-2022  riastradh usbnet: Split multicast filter reprogramming into separate operation.
 1.42  03-Mar-2022  riastradh usbnet drivers: Stop timeout loops early if device is detaching.
 1.41  03-Mar-2022  riastradh usbnet: Enter uno_init with the core lock held.

This reduces code in all drivers except urndis(4) and aue(4).

However, it's still safe for urndis to drop the core lock because the
ifnet is locked, and the ifnet lock covers the DOWN->UP (uno_init)
and UP->DOWN (uno_stop) transitions.
 1.40  27-Mar-2020  nisimura - change to use rcvfilt_locked() name to clarify the intent.
- stylise receive filter manipulation logic.
- use ETHER_F_ALLMULTI flag.
 1.39  21-Mar-2020  skrll KNF
 1.38  15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.37  13-Mar-2020  martin Fix printf format
 1.36  13-Mar-2020  christos PR/55068: sc.dying: Fix printf formats:
- no %s/%p for kernel log
- 0x% -> %#
- always %j for kernel log
 1.35  29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.34  07-Jan-2020  maxv branches: 1.34.2;
Localify, constify.
 1.33  16-Oct-2019  bad allocate a random mac address if on-chip mac is all zeroes.

helps ure(4) on NanoPi R1.

partly from ganbold@freebsd r346052.

XXX pullup-9
 1.32  16-Oct-2019  bad read mac address of ure version 4c10 from URE_PLA_IDR, save as 4c00.

from ganbold@freebsd r346052.

XXX pullup-9
 1.31  23-Aug-2019  mrg s/UBSNET_MII_DECL_DEFAULT/USBNET_MII_DECL_DEFAULT/. from sc.dying.
 1.30  20-Aug-2019  mrg couple more changes to usbnet(9):

- MII read/write reg return int instead of usbd_status (requested by skrll)
- usbnet_attach_ifp(9) changes arg, two mii-specific flags are placed by a
pointer to new struct usbnet_mii. if not NULL, then attach an MII to this
interface like previous have_mii parameter. use this to allow ure(4) to
properly pass PHY location to mii_attach().

welcome netbsd 9.99.10.
 1.29  19-Aug-2019  mrg move the check against un_phyno from usbnet back into the drivers
that do this (axe, axen, mue, smsc, ure.) it made mii scanning
only work for phy 0, and aue needs it for at least one device.

fix smsc to return usbd_status not -1 on failure. XXX smsc was
writing to '*val' even in error cases, it does not now.

remove a double call to IFQ_SET_READY() (noticed by chuq).

avoid unlock+instant relock by using usbnet_lock_mii_un_locked().
 1.28  16-Aug-2019  mrg make the default debug level zero.
 1.27  15-Aug-2019  mrg - usbnet_rx_loop_cb's usbd_xfer parameter is never used and available
in the usbnet_chain if needed. remove it
- usbnet media status change already set link to false, don't repeat
this in every driver
- don't clear link in stop, nothing was re-enabling it for non-MII
- add optional uno_tick_cb(struct usbnet *un) that is called from the
usbnet tick timer
- remove wrong debug sysctl prototype

rx_loop and timer are kernel versions changes, but hopefully this is
the last one for usbnet. working with 3 more drivers now (cue, mue
and url), leaving only aue, kue, upl and umb undone (aue may work
with previously supported devices, mine doesn't work with our driver,
kue and upl have patches for testing and umb is undone.)
 1.26  14-Aug-2019  mrg introduce usbnet_set_dying(). will be used by url(4) conversion.
bump version.

introduce USBNET_MODULE() that encompasses almost all the module
specific code for usbnet modules. they still need to include
the relevant ioconf.c, but everything else is now just, eg,

USBNET_MODULE(axen)
 1.25  11-Aug-2019  mrg don't set dv_private. it's a bad pattern and only didn't
trip kmem_free() lossage because struct usbnet is at the
start of the softc.

for now, enforce this as part of the ABI.

catch up urndis with tx_prepare checking buffer length,
and also add an assert to usbnet_start_locked() to match.
 1.24  11-Aug-2019  skrll Appease module build
 1.23  11-Aug-2019  mrg copy a pattern from if_udav.c, which already had "too much" check.

even though overflow or underflow is really unlikely here, reorder
various expressions to reduce the likelyhood even further.
 1.22  11-Aug-2019  mrg in tx_prepare callback make sure to reject any mbuf that is larger
than can fit in the buffer. done at the driver and not usbnet
layer because the driver knows how much beyond the mbuf data needs
to be sent (headers and trailers.)

axen(4) had a KASSERT() for this condition, but there's no
invariant here we can check so it's best as an error return.

XXX: only tested on these drivers, needs to be copied to udav, smsc
and urndis after testing as well as the not commited conversions.
 1.21  10-Aug-2019  mrg reduce the scope of struct usbnet:
- move a large number of members internal to usbnet.c's new
"struct usbnet_private".
- provide accessors for a few of these
- move struct usbnet_cdata into usbnet.c as well, but move
bufsz, list count, and xfer flags back out into struct usbnet,
and have them set as part of the setup efore usbnet_attach()
- split the intr pipe parts into their own structure
- move all the main usbnet*lock* code into usbnet.c too

usbnet_attach() goes down to 2 args, and the inputs needed are
now the full contents of 'struct usbnet' besides the driver
owned 'un_flags' and usbnet owned 'un_pri'.

welcome netbsd 9.99.6.
 1.20  09-Aug-2019  mrg use new un_flags member of usbnet:
- axen(4) and cdce(4) are now able to use struct usbnet directly
as softc, udav also done but untested
 1.19  09-Aug-2019  mrg update usbnet some:
- move rx/tx xfer flags into usbnet_cdata
- move the callbacks into usbnet_ops structure
- move rx/tx xfer flags arguments from usbnet_init_rx_tx()
and move them all into usbnet_attach() arguments
- s/miibus/mii/ in some places for consistency

other clean up:
- create wrapper functions for callbacks, move knowledge about
special handling (OK to be missing, error eating) there.
- use cdata pointer if already available
- provide some more macros (will be real functions later) for
accessing usbnet members, use existing ones more

bump kernel version.
 1.18  06-Aug-2019  mrg for ethernet usb network devices, print the mac addr in usbnet.
 1.17  06-Aug-2019  mrg extend usbnet to cope with if_upl, if_smsc, and if_umb needs:

- usbnet_enqueue() can set mbuf flags and csum_data
- usbnet_input() for non-ethernet based devices (upl, umb)
- allow a complete override for ioctl()
- remove converted list -- we have compiling and/or working patches for
all the devices except for umb(4), will be merged as testing happens

hopefully this is the last ABI change, though it may end up being
extended for additional smsc(4) support.


hello for real netbsd 9.99.3!
 1.16  04-Aug-2019  mrg move / re-add some headers to fix INET6 builds.
 1.15  04-Aug-2019  mrg convert axe(4) and ure(4) to usbnet.

axe loses 838 lines (37%) and ure loses 716 lines (36%).
 1.14  19-Jul-2019  mrg branches: 1.14.2;
call ure_stop_locked(), not ure_stop(), from ure_init_locked() to
avoid locking botch. fixes assert reported by sc.dying.
 1.13  28-Jun-2019  mrg more smp cleanup for ure(4)/axen(4)/cdce(4):

- convert IFF_ALLMULTI to ETHER_F_ALLMULTI, using ETHER_LOCK()
- remove IFF_OACTIVE use, and simply check the ring count in start
- assert/take more locks
- XXX: IFF_RUNNING is not properly protected (all driver problem)
- fix axen_timer setting so it actually runs
- document a locking issue in stop callback:
stop is called with the softc lock held, but the lock order
in all other places is ifnet -> softc -> rx -> tx, so taking
ifnet lock when softc lock is held would be problematic
- in rxeof check for stopping/dying more often. i managed to
trigger a pagefault in cdce_rxeof() when yanking an active
device as it attempted to usbd_setup_xfer() on closed pipes.
- add missing USBD_MPSAFE and cdce_stopping resetting for cdce(4)

between this and other recent clean ups increase performance of
these drivers mostly. some numbers (in mbit/sec):

old: new:
driver in out in+out in out in+out
---- -- --- ------ -- --- ------
cdce 39 32 44 38 33 54
axen 44 34 45 48 37 42
ure 36 34 35 36 38 38

i'm not sure why axen drops a little with in+out. cdce is
helped quite a lot, and ure a little. it is disappointing that
ure does not outperform cdce -- it's the same actual hardware,
and the device-specific (ure) should outperform the generic
cdce driver...
 1.12  24-Jun-2019  mrg actually set ure_stopping, and don't follow it in init.

pointed out by sc.dying on source-changes-d. thanks.
 1.11  23-Jun-2019  mrg make cdce(4) and ure(4) usb and mpsafe:

- introduce locking ala smsc(4)/axen(4) style
- convert to mpsafe interfaces
- add tick task to cdce(4) to deal with missing watchdog, and
actually make the watchdog do something
- convert DELAY() to usbd_delay_ms() in cdce(4) and don't increase
the time in a potentially unbounded way
- remove spl calls

tested with network cable and usb adapter pullouts, reboots and
many many GBs of data transferred in either direction under load.
 1.10  16-Jun-2019  christos Always increment, not just if we are queueing.
 1.9  16-Jun-2019  christos PR/54297: sc dying: opacket of ure(4) is always 0
 1.8  09-Jun-2019  mrg branches: 1.8.2;
rearrange some parts of attach/detach to avoid partial-attach
leading to detach crash.
 1.7  28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.6  23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.5  23-May-2019  msaitoh -No functional change:
- KNF
- u_int*_t -> uint*_t.
 1.4  07-Mar-2019  msaitoh Use pmf(9).
 1.3  09-Feb-2019  rin Print chip ID when attached.
 1.2  06-Feb-2019  rin Fix sign compare differently; instead of casting from int to unsigned,
casting from sizeof (and friends) to int.

Suggested by joerg@.
 1.1  06-Feb-2019  rin Add ure(4): RealTek RTL8152/RTL8153 10/100/Gigabit USB Ethernet device.
Ported from OpenBSD. Support for RX/TX checksum offload added by myself.
 1.8.2.3  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.8.2.2  10-Jun-2019  christos Sync with HEAD
 1.8.2.1  09-Jun-2019  christos file if_ure.c was added on branch phil-wifi on 2019-06-10 22:07:34 +0000
 1.14.2.3  18-Sep-2022  martin Pull up following revision(s) (requested by msaitoh in ticket #1528):

sys/dev/usb/if_ure.c: revision 1.58 (via patch)

Use unsigned to avoid undefined behavior in ure_uno_mcast(). Found by kUBSan.
 1.14.2.2  17-Oct-2019  martin Pull up following revision(s) (requested by bad in ticket #343):

sys/dev/usb/if_ure.c: revision 1.32
sys/dev/usb/if_ure.c: revision 1.33

read mac address of ure version 4c10 from URE_PLA_IDR, save as 4c00.
from ganbold@freebsd r346052.
XXX pullup-9

-

allocate a random mac address if on-chip mac is all zeroes.
helps ure(4) on NanoPi R1.
partly from ganbold@freebsd r346052.
XXX pullup-9
 1.14.2.1  01-Sep-2019  martin Pull up following revision(s) (requested by mrg in ticket #135):

distrib/sets/lists/comp/mi 1.2279
distrib/sets/lists/modules/mi 1.123
share/man/man9/Makefile 1.438
share/man/man9/usbnet.9 1.1-1.9
sys/dev/ic/rndisreg.h 1.3
sys/dev/usb/TODO 1.47-1.52
sys/dev/usb/TODO.usbmp 1.15,1.16
sys/dev/usb/files.usb 1.157-1.167
sys/dev/usb/if_aue.c 1.155-1.161
sys/dev/usb/if_auereg.h 1.30-1.32
sys/dev/usb/if_axe.c 1.103-1.119
sys/dev/usb/if_axen.c 1.51-1.53,1.55-1.67
sys/dev/usb/if_axenreg.h 1.15
sys/dev/usb/if_cdce.c 1.54-1.67
sys/dev/usb/if_cue.c 1.85,1.86
sys/dev/usb/if_cuereg.h 1.23
sys/dev/usb/if_kue.c 1.97-1.100
sys/dev/usb/if_kuereg.h 1.23,1.24
sys/dev/usb/if_mue.c 1.51-1.55
sys/dev/usb/if_muereg.h 1.6
sys/dev/usb/if_muevar.h 1.9
sys/dev/usb/if_smsc.c 1.46-1.61
sys/dev/usb/if_smscreg.h 1.6
sys/dev/usb/if_smscvar.h delete
sys/dev/usb/if_udav.c 1.60-1.71
sys/dev/usb/if_udavreg.h 1.14,1.15
sys/dev/usb/if_upl.c 1.65,1.66
sys/dev/usb/if_ure.c 1.15-1.31
sys/dev/usb/if_urevar.h 1.4,1.5
sys/dev/usb/if_url.c 1.67-1.70
sys/dev/usb/if_urlreg.h 1.14
sys/dev/usb/if_urndis.c 1.22-1.33
sys/dev/usb/if_urtwn.c 1.72
sys/dev/usb/ohci.c 1.290
sys/dev/usb/uhub.c 1.143
sys/dev/usb/usb.c 1.180
sys/dev/usb/usb.h 1.118
sys/dev/usb/usb_mem.c 1.71
sys/dev/usb/usb_subr.c 1.238,1.239
sys/dev/usb/usbdevs 1.772
sys/dev/usb/usbdi.c 1.183,1.186
sys/dev/usb/usbdi.h 1.97
sys/dev/usb/usbdi_util.c 1.75
sys/dev/usb/usbhist.h 1.5,1.6
sys/dev/usb/usbnet.c 1.1-1.24
sys/dev/usb/usbnet.h 1.1-1.14
sys/dev/usb/usbroothub.c 1.9
sys/dev/usb/xhci.c 1.109,1.110
sys/modules/Makefile 1.223
sys/modules/usbnet/Makefile 1.1

usbnet(9): Add common framework for USB network devices.
This bring various safety fixes to all updated drivers,
and includes locking clean up, detach safety when being
used or not, separate rx/tx locks to improve performance,
porting to NET_MPSAFE, many edge/error case bugs in
drivers fixed, as well as resovling PRs 54303 and 54308.
These drivers are converted: axe(4), axen(4), aue(4),
cdce(4), cue(4), kue(4), mue(4), smsc(4), udav(4),
upl(4), ure(4), url(4), and urndis(4).
 1.34.2.1  29-Feb-2020  ad Sync with head.
 1.58.4.2  13-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #967):

sys/dev/usb/usbdevs: revision 1.816
sys/dev/usb/if_ure.c: revision 1.60

PR/58250: RVP: Add TP-Link UE300 USB LAN adapter
 1.58.4.1  14-Oct-2023  martin Pull up following revision(s) (requested by riastradh in ticket #413):

sys/dev/usb/if_ure.c: revision 1.59

ure(4): Set all bits, not no bits, in multicast filter for promisc.
This was lost in revision 1.40.
PR kern/57648

RSS XML Feed