Commit Graph

294731 Commits

Author SHA1 Message Date
riastradh 065aa2e999 usb: usbd_abort_pipe never fails. Make it return void.
Prune dead branches as a result of this change.
2022-03-03 06:05:38 +00:00
riastradh 80ad5cc0fd usb: Factor usb_insert_transfer out of upm_transfer and make private.
Almost every upm_transfer function starts with:

	mutex_enter(&sc->sc_lock);
	err = usb_insert_transfer(xfer);
	mutex_exit(&sc->sc_lock);
	if (err)
		return err;

Some of them have debug messages sprinkled in here too, or assert
that err == USBD_NORMAL_COMPLETION (alternative is USBD_IN_PROGRESS,
only for pipes with up_running or up_serialise, presumably not
applicable for these types of pipes).  Some of them also assert
xfer->ux_status == USBD_NOT_STARTED, which is guaranteed on entry and
preserved by usb_insert_transer.

Exceptions:

- arch/mips/adm5120/dev/ahci.c ahci_device_isoc_transfer just returns
  USBD_NORMAL_COMPLETION, but I'm pretty sure this is and always has
  been broken anyway, so won't make anything worse (if anything, might
  make it better...)

- external/bsd/dwc2/dwc2.c dwc2_device_bulk_transfer and
  dwc2_device_isoc_transfer _also_ issue dwc2_device_start(xfer)
  under the lock.  This is probably a better way to do it, but let's
  do it uniformly across all HCIs at once.

- rump/dev/lib/libugenhc/ugenhc.c rumpusb_device_bulk_transfer
  sometimes returns USBD_IN_PROGRESS _without_ queueing the transfer,
  in the !rump_threads case.  Not really sure how this is supposed to
  work...  If it actually breaks anything, we can figure it out.
2022-03-03 06:04:31 +00:00
riastradh 3165ccf84f usbnet(9): Update man page. 2022-03-03 05:57:05 +00:00
riastradh 6ef03c52fd urndis(4): Simplify circuitous initialization logic. 2022-03-03 05:56:58 +00:00
riastradh 6115a65fb4 usbnet: Update some comments. 2022-03-03 05:56:51 +00:00
riastradh 847d2eafd6 usbnet: On if_stop, abort xfers before resetting hardware.
uno_stop is supposed to have exclusive access to the hardware; this
ensures that any concurrent uno_rx_loop has completed before we enter
uno_stop.
2022-03-03 05:56:44 +00:00
riastradh 94ebbffa78 usbnet: Fix type of struct usbnet::un_ed according to plan. 2022-03-03 05:56:36 +00:00
riastradh 0b4ab8ce17 usbnet: Omit needless detachcv name parameter to usbnet_attach. 2022-03-03 05:56:28 +00:00
riastradh 05a3622e31 usbnet: Omit empty uno_init functions. 2022-03-03 05:56:18 +00:00
riastradh 93ec4d7309 usbnet: Factor usbnet_init_rx_tx out into usbnet_if_init.
Make it private; no need for drivers to call it any more.
2022-03-03 05:56:09 +00:00
riastradh 330f8add01 usbnet drivers: Simplify return of usbnet_init_rx_tx. 2022-03-03 05:56:00 +00:00
riastradh 4169cb4d08 usbnet: Handle usbnet_set_link for drivers with no media detect. 2022-03-03 05:55:52 +00:00
riastradh 339846cf48 url(4): Inline call to url_uno_stop -- alias for url_reset. 2022-03-03 05:55:45 +00:00
riastradh 13026c8aaf usbnet drivers: Omit redundant device reset via *_uno_stop on init.
Only those drivers where *_uno_stop is just *_reset, and *_uno_init
immediately calls *_reset afterward, are affected.
2022-03-03 05:55:38 +00:00
riastradh 48639f8993 usbnet drivers: From *_uno_init, call *_uno_stop, not usbnet_stop.
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-03 05:55:29 +00:00
riastradh cd2c73ebff usbnet drivers: Prune dead IFF_RUNNING branches in *_uno_init.
usbnet(9) guarantees !IFF_RUNNING now before calling it.
2022-03-03 05:55:19 +00:00
riastradh 8d74eae916 usbnet: Do nothing on if_init/stop if already in the target state.
The network stack _shouldn't_ ever call us if so, but I'm not yet
sure it _won't_.
2022-03-03 05:55:10 +00:00
riastradh cad9acd850 usbnet drivers: Omit needless isdying tests in *_uno_init.
usbnet(9) already checks this immediately before calling *_uno_init.
2022-03-03 05:55:01 +00:00
riastradh 7714090b62 usbnet: Delete the core lock from the API.
Init/stop and ioctl happen under IFNET_LOCK.  Multicast updates only
happen after init and before stop.  Core lock is no longer a relevant
part of the API.  Internally, it serves essentially just to lock out
asynchronous mii activity during init/stop.
2022-03-03 05:54:52 +00:00
riastradh f0a28505a7 urndis(4): Delete some crazy logic that I think is unnecessary.
XXX definitely need to test this one
2022-03-03 05:54:45 +00:00
riastradh 5c509362df 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.
2022-03-03 05:54:37 +00:00
riastradh 47bf81df8f usbnet: Make usbnet_mii_readreg/writereg/statchg private to usbnet.c.
No drivers need to use these.
2022-03-03 05:54:28 +00:00
riastradh 9e1fa980c8 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.
2022-03-03 05:54:21 +00:00
riastradh 8cf9a9747f axen(4): Use axen mii read/write reg routines, not usbnet ones.
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-03 05:54:11 +00:00
riastradh bb5afa0974 usbnet drivers: Assert IFNET_LOCKED in if ioctl routines.
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-03 05:54:03 +00:00
riastradh 4295ae1b78 udav(4): Stop asserting !usbnet_isdying.
This can change at any moment; no software lock can prevent the
device from being detached.  Any test of it is necessarily
best-effort just to avoid wasting time later on waiting for requests
to fail or time out.
2022-03-03 05:53:56 +00:00
riastradh c9221c8403 aue(4): Simplify. No functional change. 2022-03-03 05:53:48 +00:00
riastradh 0e793ef4b9 aue(4): Enable rx/tx registers on init before usbnet_init_rx_tx.
This way, we still have exclusive access to the registers before
calls to aue_uno_mcast can start happening without the usbnet core
lock.
2022-03-03 05:53:41 +00:00
riastradh 2d75ebfa29 usbnet drivers: Omit redundant multicast filter update on init. 2022-03-03 05:53:33 +00:00
riastradh f59d8c9753 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.
2022-03-03 05:53:23 +00:00
riastradh 4f98063591 usbnet drivers: Stop abusing ifp->if_flags & IFF_ALLMULTI.
This legacy flag is a figment of userland's imagination.  The actual
kernel state is ec->ec_flags & ETHER_F_ALLMULTI, protected by the
ETHER_LOCK, so that multicast filter updates -- which run without
IFNET_LOCK -- need not attempt to write racily to ifp->if_flags.
2022-03-03 05:53:14 +00:00
riastradh 2a987a0a95 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.
2022-03-03 05:53:04 +00:00
riastradh cb0d28a94d aue(4): Reduce aue_uno_mcast from aue_uno_init to aue_setiff_locked.
This operation only needs to update the hardware to reflect
SIOCADDMULTI/SIOCDELMULTI.  Not clear that everything in aue(4) needs
to be reset -- in fact I'm pretty sure that's undesirable!

WARNING: I have not tested this with a real aue(4) device.
2022-03-03 05:52:55 +00:00
riastradh c499beaef1 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.
2022-03-03 05:52:46 +00:00
riastradh 1da4c1563d 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.
2022-03-03 05:52:35 +00:00
riastradh 751cff0160 usbnet: No need for the core lock in usbnet_ifflags_cb.
The only state this touches is unp_if_flags, and all paths touching
it also hold IFNET_LOCK -- not to mention this is the only path that
touches unp_if_flags in the first place!
2022-03-03 05:52:27 +00:00
riastradh 5c872ef115 usbnet: Make the tx/rx locks private to usbnet.c.
Suffice it for the drivers to know that uno_tx_prepare and
uno_rx_loop have exclusive access to the chain, and, for tx,
exclusive access to the mbuf.
2022-03-03 05:52:20 +00:00
riastradh 62449b2057 usbnet: usbnet_busy is no longer referenced; release it! 2022-03-03 05:52:11 +00:00
riastradh c4fe84699e usbnet: No need for usbnet_busy in mii callbacks.
After mii_detach, these have all completed and no new ones can be
made, and detach doesn't start destroying anything until after
mii_detach has returned, so there is no need to hang onto a reference
count here.
2022-03-03 05:52:03 +00:00
riastradh 8b5b750b9f usbnet: No need for usbnet_busy in usbnet_init_rx_tx or usbnet_stop.
These run with 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.
2022-03-03 05:51:56 +00:00
riastradh 8b61d7e2b9 usbnet drivers: No need for usbnet_busy during attach.
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-03 05:51:44 +00:00
riastradh ea9ce4a6d7 usbnet drivers: No need for usbnet_busy in uno_ioctl.
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-03 05:51:35 +00:00
riastradh 23fe390cac 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.
2022-03-03 05:51:27 +00:00
riastradh 9cfb26a542 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.)
2022-03-03 05:51:17 +00:00
riastradh d9c770e700 usbnet: Split multicast filter reprogramming into separate operation. 2022-03-03 05:51:06 +00:00
riastradh 7f15b7014c usbnet drivers: Stop timeout loops early if device is detaching. 2022-03-03 05:50:57 +00:00
riastradh 839d7b202a usbnet: Omit needless locking around usbnet_isdying.
Now that is tested and set with atomic_load/store, there is no need
to hold the lock -- which means we can set it while the core lock is
held during, e.g., a reset sequence, and use that to interrupt the
sequence so it doesn't get stuck waiting to time out when the device
is physically removed.
2022-03-03 05:50:47 +00:00
riastradh 4c7e9da15d usbnet: Use atomic_load/store_relaxed for unp_dying.
This way we don't need to hold the core lock to avoid upsetting
sanitizers (which probably find the current code upsetting), and we
can use it to exit early from timeout loops that run under the core
lock (which is probably not necessary for them to do anyway, but
let's worry about that later).
2022-03-03 05:50:39 +00:00
riastradh ad98cb4e29 usbnet: Print diagnostic about refcnt stragglers.
I don't think there can be any, but this message, if printed, would
falsify my hypothesis!
2022-03-03 05:50:31 +00:00
riastradh 2cb1302a9a 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.
2022-03-03 05:50:22 +00:00