summaryrefslogtreecommitdiff
path: root/sys/dev/usb/if_axen.c
AgeCommit message (Collapse)Author
2022-08-20usbnet(9): New usbnet_ispromisc(un).riastradh
Replaces ifp->if_flags & IFF_PROMISC in multicast filter updates.
2022-03-03usbnet: Omit needless detachcv name parameter to usbnet_attach.riastradh
2022-03-03usbnet: Factor usbnet_init_rx_tx out into usbnet_if_init.riastradh
Make it private; no need for drivers to call it any more.
2022-03-03usbnet drivers: From *_uno_init, call *_uno_stop, not usbnet_stop.riastradh
Make usbnet_stop private now that no drivers use it. None of the driver-independent logic in usbnet_stop has any effect at this point because we are guaranteed not to be running, so only the driver-dependent logic in *_uno_stop (at most) is needed. For drivers with no *_uno_stop, just omit the call to usbnet_stop altogether. Some of this logic is obviously redundant with the subsequent call to *_reset -- to be addressed in a subsequent commit.
2022-03-03usbnet drivers: Omit needless isdying tests in *_uno_init.riastradh
usbnet(9) already checks this immediately before calling *_uno_init.
2022-03-03usbnet drivers: Omit needless usbnet core lock and assertions.riastradh
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.
2022-03-03usbnet drivers: Avoid undefined behaviour if read reg fails.riastradh
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.
2022-03-03axen(4): Use axen mii read/write reg routines, not usbnet ones.riastradh
The usbnet wrappers don't add anything important. We already test usbnet_isdying in axen_cmd, and that's already a best-effort thing (which should probably be done better by having usbd_do_request fail promptly if detaching anyway).
2022-03-03usbnet drivers: Assert IFNET_LOCKED in if ioctl routines.riastradh
These only happen either during the transition up or down (init or stop), or while that transition is excluded (ioctl). This may be called from ioctl or from init, which both hold the ifnet lock. XXX smsc_setoe_locked should maybe trigger reinit because the rx loop behaves differently depending on whether checksumming is enabled. XXX mue_sethwcsum_locked needs to exclude mcast updates.
2022-03-03usbnet drivers: Omit redundant multicast filter update on init.riastradh
2022-03-03usbnet: Apply hardware multicast filter updates synchronously again.riastradh
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.
2022-03-03usbnet drivers: Omit needless uno_mcast locked subroutines.riastradh
uno_mcast is now called with the core lock already held so there is no need for a separate locked subroutine.
2022-03-03usbnet: Take the core lock around uno_mcast.riastradh
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.
2022-03-03usbnet drivers: Omit needless uno_init locked subroutines.riastradh
uno_init is now called with the core lock already held so there is no need for a separate locked subroutine.
2022-03-03usbnet drivers: No need for usbnet_busy during attach.riastradh
usbnet_detach cannot run until the attach routine has finished (unless a driver goes out of its way to tie its shoelaces together and explicitly call it during the attach routine, which none of them do), so there is no need to hang onto a reference count that we release before attach returns.
2022-03-03usbnet drivers: No need for usbnet_busy in uno_ioctl.riastradh
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 subnet drivers touch the IFNET_LOCK except to verify it is held sometimes.)
2022-03-03usbnet drivers: No need for usbnet_busy in uno_mcast.riastradh
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.
2022-03-03usbnet drivers: No need for usbnet_busy in uno_init.riastradh
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.)
2022-03-03usbnet: Split multicast filter reprogramming into separate operation.riastradh
2022-03-03usbnet: Enter uno_init with the core lock held.riastradh
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.
2022-03-03axen(4), mue(4), smsc(4): Omit irrelevant cases in ioctl.riastradh
SIOCSIFFLAGS and SIOCSETHERCAP always end up in ether_ioctl_reinit, which triggers the same logic to reprogram the multicast filters anyway.
2020-03-15Define and implement a locking protocol for the ifmedia / mii layers:thorpej
- 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.
2020-03-14revert the 0x% -> %# change for fixed width formats pointed out by uwe.christos
2020-03-13PR/55068: sc.dying: Fix printf formats:christos
- no %s/%p for kernel log - 0x% -> %# - always %j for kernel log
2020-01-29Adopt <net/if_stats.h>.thorpej
2020-01-15Use a define instead of a magic constant. NFCI.skrll
2020-01-07Localify, constify.maxv
2019-08-23s/UBSNET_MII_DECL_DEFAULT/USBNET_MII_DECL_DEFAULT/. from sc.dying.mrg
2019-08-20couple more changes to usbnet(9):mrg
- 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.
2019-08-19move the check against un_phyno from usbnet back into the driversmrg
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().
2019-08-15- usbnet_rx_loop_cb's usbd_xfer parameter is never used and availablemrg
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.)
2019-08-14introduce usbnet_set_dying(). will be used by url(4) conversion.mrg
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)
2019-08-11Appease module buildskrll
2019-08-11copy a pattern from if_udav.c, which already had "too much" check.mrg
even though overflow or underflow is really unlikely here, reorder various expressions to reduce the likelyhood even further.
2019-08-11in tx_prepare callback make sure to reject any mbuf that is largermrg
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.
2019-08-10reduce the scope of struct usbnet:mrg
- 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.
2019-08-09use new un_flags member of usbnet:mrg
- axen(4) and cdce(4) are now able to use struct usbnet directly as softc, udav also done but untested
2019-08-09update usbnet some:mrg
- 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.
2019-08-06for ethernet usb network devices, print the mac addr in usbnet.mrg
2019-08-06extend usbnet to cope with if_upl, if_smsc, and if_umb needs:mrg
- 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!
2019-08-05Typo in error messageskrll
2019-08-04- adjust usbnet interface to allow usbd_open_pipe_intr(), from themrg
new comment: * if un_intr_buf is not NULL, use usbd_open_pipe_intr() not * usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer, * size, and interval. the standard handling is in usbnet.c, with a callback to deal with the interrupt it self. not fully tested, designed for if_aue.c and a few others not yet converted. - make usbhist for usbnet.c work, thanks paulg - usbnet_init_rx_tx() clears out all allocations upon failure now - add usbnet_ec() to get a pointer to the struct ethercom - add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks and *owned*() for asserting welcome 9.99.3!
2019-07-31couple of minor API updates:mrg
- change the read/write register callbacks to have the same phy/reg order as the MII code. - add "mii_flags" param to usbnet_attach_ifp(). axe(4) wants it. also: - add usbnet debug code, sysctl node support - remove commented DPRINTF()s accidentally left in place - add usbnet_softc() - reorder some attach code to be consistent - re-add USBD_FORCE_SHORT_XFER for axen rx chain ride 9.99.2 bump.
2019-07-31introduce a library of common code / backends to share code betweenmrg
USB ethernet drivers. usbnet.h introduces a new set of APIs to provide common solutions for these driver features: - USB endpoint pipe handling - rx and tx chain handling - generic handlers or support for several struct ifnet callbacks - MII bus locking - interrupt handling - partial autoconf handling: much of attach, and detach/activate can use common versions directly. currently, only axen(4) and cdce(4) are converted. the reductions in these drivers are quite significant: if_cdce.c is reduced from 1000 lines to 320 lines, and if_axen is reduced from 1902 lines to 1021 lines. add a "usbnet" module and make the if_axen module depend upon it.
2019-07-15minor white space adjustments.mrg
2019-06-28more smp cleanup for ure(4)/axen(4)/cdce(4):mrg
- 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...
2019-06-22wrap axen_iff() with axen_iff_locked().mrg
add a missing lock exit in error path.
2019-06-22mark this driver MPSAFE for usb tasks and pipes, if(4), and callouts.mrg
remove remaining redundant spl calls.
2019-06-22re-apply rev 1.44 with a minor bug fix in axen_tick_task().mrg
it introduced a problem when there wasn't a reasonaly constant stream of incoming packets, and i had a 'nttcp' running against my test machine constantly, avoiding the bug.
2019-06-22revert the previous.mrg
i'm fairly postive i tested it, as i tested enabing mpsafe version on top of this successfully. however, something happened mid-ssh with a kernel with mpsafe and my session hung, and since then i've been unable to boot kernels with the previous revision applied.