The NetBSD Project

CVS log for src/sys/dev/usb/usbnet.c

[BACK] Up to [cvs.NetBSD.org] / src / sys / dev / usb

Request diff between arbitrary revisions


Default branch: MAIN


Revision 1.113 / (download) - annotate - [select for diffs], Thu Sep 22 07:02:21 2022 UTC (4 months, 1 week ago) by riastradh
Branch: MAIN
CVS Tags: netbsd-10-base, netbsd-10, bouyer-sunxi-drm-base, bouyer-sunxi-drm, HEAD
Changes since 1.112: +3 -7 lines
Diff to previous 1.112 (colored)

usbnet(9): Omit needless miilock around uno_stop.

This time for real!

Revision 1.112 / (download) - annotate - [select for diffs], Tue Sep 20 07:15:46 2022 UTC (4 months, 1 week ago) by mrg
Branch: MAIN
Changes since 1.111: +6 -10 lines
Diff to previous 1.111 (colored)

revert rev 1.111 (which was 1.106 again, without the 1.107 changes).

fixes an assert reported by msaitoh@.  also fix another missing miilock
assert in usbnet_stop() that triggered for me.

Revision 1.111 / (download) - annotate - [select for diffs], Tue Sep 13 09:38:19 2022 UTC (4 months, 2 weeks ago) by riastradh
Branch: MAIN
Changes since 1.110: +9 -2 lines
Diff to previous 1.110 (colored)

usbnet(9): Call mii_down once we've finished with mii_tick.

Revision 1.110 / (download) - annotate - [select for diffs], Tue Aug 23 01:08:04 2022 UTC (5 months, 1 week ago) by riastradh
Branch: MAIN
Changes since 1.109: +6 -5 lines
Diff to previous 1.109 (colored)

usbnet(9): Don't touch ifp->if_flags in usbnet_start_locked.

Instead, consult unp->unp_txstopped -- but the caller already
guarantees it is not stopped, so turn the conditional into an
assertion anyway.

Revision 1.109 / (download) - annotate - [select for diffs], Sat Aug 20 14:08:59 2022 UTC (5 months, 1 week ago) by riastradh
Branch: MAIN
Changes since 1.108: +29 -3 lines
Diff to previous 1.108 (colored)

usbnet(9): New usbnet_ispromisc(un).

Replaces ifp->if_flags & IFF_PROMISC in multicast filter updates.

Revision 1.108 / (download) - annotate - [select for diffs], Sat Aug 20 14:08:47 2022 UTC (5 months, 1 week ago) by riastradh
Branch: MAIN
Changes since 1.107: +35 -35 lines
Diff to previous 1.107 (colored)

usbnet(9): Rename core lock -> mii lock.

No functional change intended.

Revision 1.107 / (download) - annotate - [select for diffs], Sat Aug 20 14:08:38 2022 UTC (5 months, 1 week ago) by riastradh
Branch: MAIN
Changes since 1.106: +26 -29 lines
Diff to previous 1.106 (colored)

usbnet(9): Limit scope of core lock to mii and tick scheduling.

Bringing the interface up or down is serialized by IFNET_LOCK, and we
prevent further mii callbacks with mii_down, so there's no need for
another lock to serialize uno_init, uno_stop, and the mii callbacks.

Revision 1.106 / (download) - annotate - [select for diffs], Sat Aug 20 14:08:27 2022 UTC (5 months, 1 week ago) by riastradh
Branch: MAIN
Changes since 1.105: +10 -2 lines
Diff to previous 1.105 (colored)

usbnet(9): Call mii_down once we've finished with mii_tick.

Revision 1.105 / (download) - annotate - [select for diffs], Sat Aug 20 14:08:17 2022 UTC (5 months, 1 week ago) by riastradh
Branch: MAIN
Changes since 1.104: +3 -5 lines
Diff to previous 1.104 (colored)

usbnet(9): Simplify core lock use in usbnet_tick_task.

Revision 1.104 / (download) - annotate - [select for diffs], Sat Aug 20 14:08:05 2022 UTC (5 months, 1 week ago) by riastradh
Branch: MAIN
Changes since 1.103: +5 -5 lines
Diff to previous 1.103 (colored)

usbnet(9): Call uno_tick before mii stuff.

The one driver that uses it, cue(4), uses it just for statistics
gathering; hard to imagine that order could be important here.  But
this will allow for some simplification of the surrounding code.

Revision 1.103 / (download) - annotate - [select for diffs], Sat Aug 20 14:07:53 2022 UTC (5 months, 1 week ago) by riastradh
Branch: MAIN
Changes since 1.102: +3 -2 lines
Diff to previous 1.102 (colored)

usbnet(9): Assert core lock is held on usbnet_set_link.

This is only allowed to be called via the uno_statchg callback, which
in turn is called only with the core lock held.  (usbnet_set_link is
also called internally in usbnet(9) with the core lock held.)

Revision 1.102 / (download) - annotate - [select for diffs], Sat Aug 20 14:06:20 2022 UTC (5 months, 1 week ago) by riastradh
Branch: MAIN
Changes since 1.101: +42 -19 lines
Diff to previous 1.101 (colored)

usbnet(9): Split unp_stopping into stopped/txstopped/rxstopped.

In practical terms this could be done with one variable and an atomic
store, but serializing all access with a lock makes reasoning easier,
and the locks have to be taken by the logic that queries the
variables anyway, and the variables are set only under heavy-weight
configuration changes anyway.

What this accomplishes is disentangling lock order between rxlock and
txlock: they are never taken at the same time, so no order is needed.

I renamed unp_stopping to unp_stopped for a compiler-assisted audit
to make sure I reviewed every case of it.

Revision 1.101 / (download) - annotate - [select for diffs], Sat Aug 20 14:06:09 2022 UTC (5 months, 1 week ago) by riastradh
Branch: MAIN
Changes since 1.100: +5 -5 lines
Diff to previous 1.100 (colored)

usbnet(9): Don't touch unp_stopping in usbnet_pipe_intr.

This access was unprotected by a lock, but it's not necessary anyway:
usbnet_stop aborts the pipes, and the xfer doesn't call usbd_transfer
to reschedule itself -- it's an intr pipe, so it's rescheduled
internally by usbdi(9) in a way that usbd_abort_pipe atomically
prevents.

Revision 1.100 / (download) - annotate - [select for diffs], Sat Aug 20 14:05:58 2022 UTC (5 months, 1 week ago) by riastradh
Branch: MAIN
Changes since 1.99: +4 -4 lines
Diff to previous 1.99 (colored)

usbnet(9): Omit needless un->un_intr test in usbnet_pipe_intr.

un->un_intr can't change after attach, and we don't open the pipe if
it's null.  So no need to test it.

Revision 1.99 / (download) - annotate - [select for diffs], Sat Aug 20 12:30:00 2022 UTC (5 months, 1 week ago) by riastradh
Branch: MAIN
Changes since 1.98: +2 -4 lines
Diff to previous 1.98 (colored)

usbnet(9): Revert previous -- usbnet_media_upd does have IFNET_LOCK.

Not sure why I thought otherwise.

Revision 1.98 / (download) - annotate - [select for diffs], Sat Aug 20 12:28:25 2022 UTC (5 months, 1 week ago) by riastradh
Branch: MAIN
Changes since 1.97: +4 -2 lines
Diff to previous 1.97 (colored)

usbnet(9): Avoid ether_mediachange if stopped.

We are called without IFNET_LOCK held here, so touching ifp->if_flags
is forbidden, but that's the first thing ether_mediachange does.

XXX not right either, need to eliminate the check from
ether_mediachange

Revision 1.97 / (download) - annotate - [select for diffs], Tue Aug 16 00:44:20 2022 UTC (5 months, 2 weeks ago) by riastradh
Branch: MAIN
Changes since 1.96: +6 -12 lines
Diff to previous 1.96 (colored)

usbnet(9): Omit needless usbnet_core_mutex function.

While here, use inline, not __inline__, since this is not a header
file where inline might be redefined by the user.

Revision 1.96 / (download) - annotate - [select for diffs], Fri Aug 12 11:25:45 2022 UTC (5 months, 2 weeks ago) by riastradh
Branch: MAIN
Changes since 1.95: +4 -4 lines
Diff to previous 1.95 (colored)

usbnet(9): Fix mbuf alignment and narrow bounds check.

In usbnet.c rev. 1.16, usbnet_newbuf was first passed a buffer length
to verify it fits within MCLBYTES.  It also changed m_adj to go
before, not after, setting m_len and m_pkthdr.len -- which had the
effect of making the m_adj a no-op, because after MGETHDR the mbuf
has zero length and m_adj stops at the length of the mbuf, so nothing
was aligned as intended.

To make this aligned as intended, we require the buffer length to be
_below_ MCLBYTES, by ETHER_ALIGN, so there's room for the ethernet
header in a maximum-length payload.  Once we do that, it is safe to
initialize m_len = m_pkthdr.len = ETHER_ALIGN + buflen, which is
below the actual size of the mbuf (MHLEN or MCLBYTES, depending), and
_then_ do m_adj to align the pointer.

Revision 1.95 / (download) - annotate - [select for diffs], Sun Aug 7 23:49:30 2022 UTC (5 months, 3 weeks ago) by riastradh
Branch: MAIN
Changes since 1.94: +7 -13 lines
Diff to previous 1.94 (colored)

usbnet(9): Simplify assertions now that urndis(4) is less sketchy.

Revision 1.94 / (download) - annotate - [select for diffs], Sat Mar 5 06:55:49 2022 UTC (10 months, 3 weeks ago) by riastradh
Branch: MAIN
Changes since 1.93: +2 -3 lines
Diff to previous 1.93 (colored)

usbnet(9): uno_init is now optional.

Update assertion and man page accordingly.

Revision 1.93 / (download) - annotate - [select for diffs], Thu Mar 3 06:06:52 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.92: +3 -6 lines
Diff to previous 1.92 (colored)

usb: usbd_close_pipe never fails.  Make it return void.

Prune dead branches as a result of this change.

Revision 1.92 / (download) - annotate - [select for diffs], Thu Mar 3 06:05:38 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.91: +5 -14 lines
Diff to previous 1.91 (colored)

usb: usbd_abort_pipe never fails.  Make it return void.

Prune dead branches as a result of this change.

Revision 1.91 / (download) - annotate - [select for diffs], Thu Mar 3 05:56:44 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.90: +5 -5 lines
Diff to previous 1.90 (colored)

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.

Revision 1.90 / (download) - annotate - [select for diffs], Thu Mar 3 05:56:28 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.89: +3 -4 lines
Diff to previous 1.89 (colored)

usbnet: Omit needless detachcv name parameter to usbnet_attach.

Revision 1.89 / (download) - annotate - [select for diffs], Thu Mar 3 05:56:18 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.88: +3 -3 lines
Diff to previous 1.88 (colored)

usbnet: Omit empty uno_init functions.

Revision 1.88 / (download) - annotate - [select for diffs], Thu Mar 3 05:56:09 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.87: +9 -4 lines
Diff to previous 1.87 (colored)

usbnet: Factor usbnet_init_rx_tx out into usbnet_if_init.

Make it private; no need for drivers to call it any more.

Revision 1.87 / (download) - annotate - [select for diffs], Thu Mar 3 05:55:52 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.86: +9 -2 lines
Diff to previous 1.86 (colored)

usbnet: Handle usbnet_set_link for drivers with no media detect.

Revision 1.86 / (download) - annotate - [select for diffs], Thu Mar 3 05:55:29 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.85: +3 -5 lines
Diff to previous 1.85 (colored)

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.

Revision 1.85 / (download) - annotate - [select for diffs], Thu Mar 3 05:55:10 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.84: +22 -2 lines
Diff to previous 1.84 (colored)

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_.

Revision 1.84 / (download) - annotate - [select for diffs], Thu Mar 3 05:54:52 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.83: +14 -20 lines
Diff to previous 1.83 (colored)

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.

Revision 1.83 / (download) - annotate - [select for diffs], Thu Mar 3 05:54:28 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.82: +5 -5 lines
Diff to previous 1.82 (colored)

usbnet: Make usbnet_mii_readreg/writereg/statchg private to usbnet.c.

No drivers need to use these.

Revision 1.82 / (download) - annotate - [select for diffs], Thu Mar 3 05:53:23 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.81: +45 -83 lines
Diff to previous 1.81 (colored)

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.

Revision 1.81 / (download) - annotate - [select for diffs], Thu Mar 3 05:52:46 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.80: +6 -3 lines
Diff to previous 1.80 (colored)

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.

Revision 1.80 / (download) - annotate - [select for diffs], Thu Mar 3 05:52:27 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.79: +2 -6 lines
Diff to previous 1.79 (colored)

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!

Revision 1.79 / (download) - annotate - [select for diffs], Thu Mar 3 05:52:20 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.78: +12 -33 lines
Diff to previous 1.78 (colored)

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.

Revision 1.78 / (download) - annotate - [select for diffs], Thu Mar 3 05:52:11 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.77: +2 -40 lines
Diff to previous 1.77 (colored)

usbnet: usbnet_busy is no longer referenced; release it!

Revision 1.77 / (download) - annotate - [select for diffs], Thu Mar 3 05:52:03 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.76: +2 -10 lines
Diff to previous 1.76 (colored)

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.

Revision 1.76 / (download) - annotate - [select for diffs], Thu Mar 3 05:51:56 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.75: +2 -9 lines
Diff to previous 1.75 (colored)

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.

Revision 1.75 / (download) - annotate - [select for diffs], Thu Mar 3 05:51:06 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.74: +11 -17 lines
Diff to previous 1.74 (colored)

usbnet: Split multicast filter reprogramming into separate operation.

Revision 1.74 / (download) - annotate - [select for diffs], Thu Mar 3 05:50:47 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.73: +6 -18 lines
Diff to previous 1.73 (colored)

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.

Revision 1.73 / (download) - annotate - [select for diffs], Thu Mar 3 05:50:39 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.72: +22 -24 lines
Diff to previous 1.72 (colored)

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).

Revision 1.72 / (download) - annotate - [select for diffs], Thu Mar 3 05:50:31 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.71: +6 -2 lines
Diff to previous 1.71 (colored)

usbnet: Print diagnostic about refcnt stragglers.

I don't think there can be any, but this message, if printed, would
falsify my hypothesis!

Revision 1.71 / (download) - annotate - [select for diffs], Thu Mar 3 05:50:22 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.70: +8 -3 lines
Diff to previous 1.70 (colored)

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.

Revision 1.70 / (download) - annotate - [select for diffs], Thu Mar 3 05:50:12 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.69: +20 -8 lines
Diff to previous 1.69 (colored)

usbnet: Assert ioctl locking.

Revision 1.69 / (download) - annotate - [select for diffs], Thu Mar 3 05:50:05 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.68: +3 -3 lines
Diff to previous 1.68 (colored)

usbnet: Impart blame on whose ifnet is unlocked in uno_init.

Revision 1.68 / (download) - annotate - [select for diffs], Thu Mar 3 05:49:58 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.67: +8 -3 lines
Diff to previous 1.67 (colored)

usbnet: Don't waste time calling uno_stop if device is detaching.

The hardware is most likely gone, so trying to write to its registers
(and, in some cases, wait until a timeout for a device to reset) is a
waste of time.  Even if it was detached only in software with drvctl,
reattaching it will reset the device anyway.

Revision 1.67 / (download) - annotate - [select for diffs], Thu Mar 3 05:49:44 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.66: +11 -6 lines
Diff to previous 1.66 (colored)

usbnet: Avoid IFNET_LOCK on detach if we never attached the ifp.

Revision 1.66 / (download) - annotate - [select for diffs], Thu Mar 3 05:49:37 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.65: +7 -7 lines
Diff to previous 1.65 (colored)

usbnet: Clear watchdog timer before stopping hardware.

No need to take the lock again -- which might not be necessary
because the callout and task have completed, but let's obviate the
need to think about that.

Revision 1.65 / (download) - annotate - [select for diffs], Thu Mar 3 05:49:29 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.64: +3 -16 lines
Diff to previous 1.64 (colored)

usbnet: Omit needless locking/busying/testing in usbnet_tick_task.

usbnet_stop waits for the task to complete before resetting the
hardware, and usbnet_detach waits for usbnet_stop to complete before
destroying anything, so there's no need for any of this.

Revision 1.64 / (download) - annotate - [select for diffs], Thu Mar 3 05:49:22 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.63: +4 -6 lines
Diff to previous 1.63 (colored)

usbnet: Omit needless tests in usbnet_tick.

It's harmless for us to schedule the tick task even if unp_dying or
unp_stopping is set by now, because usbnet_stop will just wait for it
to finish anyway, and the callout can't be scheduled again until the
interface is done stopping and is brought back up again.

No need for unp == NULL test -- un->un_pri is initialized well before
this callout can be scheduled, and is nulled out only at the end of
usbnet_detach, at which point we have already halted this callout.

Revision 1.63 / (download) - annotate - [select for diffs], Thu Mar 3 05:49:14 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.62: +5 -6 lines
Diff to previous 1.62 (colored)

usbnet: Uncomment and fix assertion for ifp->if_flags |= IFF_RUNNING.

We always hold IFNET_LOCK for ioctls that end up here -- the ones
that don't hold it are only SIOCADDMULTI/SIOCDELMULTI, which don't
end up here.  However, urndis(4) throws a spanner in the works by
doing weird device initialization.

Revision 1.62 / (download) - annotate - [select for diffs], Thu Mar 3 05:49:07 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.61: +10 -3 lines
Diff to previous 1.61 (colored)

usbnet: Don't issue a detach event if we never issued an attach one.

Revision 1.61 / (download) - annotate - [select for diffs], Thu Mar 3 05:49:00 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.60: +4 -3 lines
Diff to previous 1.60 (colored)

usbnet: Make detach order reverse attach order, for unp_stat_ch.

No functional change intended.

Revision 1.60 / (download) - annotate - [select for diffs], Thu Mar 3 05:48:52 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.59: +16 -16 lines
Diff to previous 1.59 (colored)

usbnet: Detach interface and mii before waiting for refcnt to drain.

All outstanding software activity under usbnet's control -- which is
all that participates in the refcnting -- should be quiesced by
stopping and detaching everything.

Revision 1.59 / (download) - annotate - [select for diffs], Thu Mar 3 05:48:45 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.58: +9 -5 lines
Diff to previous 1.58 (colored)

usbnet: Omit needless callout_halt and usb_rem_task_wait.

The callout and tasks cannot be pending at this point -- it is a bug
if usbnet_if_stop failed to quiesce everything, so turn these into
KASSERTs.

Revision 1.58 / (download) - annotate - [select for diffs], Thu Mar 3 05:48:37 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.57: +21 -2 lines
Diff to previous 1.57 (colored)

usbnet: Refuse to bring interfaces back up once dying.

Make this happen uniformly across all usbnet drivers, not on a
per-driver basis.

This ensures new activity on the interface can't happen by the time
we have stopped existing activity and waited for it to complete.

Revision 1.57 / (download) - annotate - [select for diffs], Thu Mar 3 05:48:30 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.56: +5 -2 lines
Diff to previous 1.56 (colored)

usbnet: Assert IFNET_LOCKED in usbnet_media_upd.

This ensures, if the device is being initialized or stopped,
usbnet_media_upd will not run until it's done, so the reset sequence
has exclusive access to the device registers used by mii.

Revision 1.56 / (download) - annotate - [select for diffs], Thu Mar 3 05:48:22 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.55: +19 -6 lines
Diff to previous 1.55 (colored)

usbnet: Fix ordering of actions in usbnet_stop.

Make sure all software activity is quiescent (callouts and tasks,
including ifmedia and mii callbacks -- anything that might trigger
register access) before asking the driver to stop the hardware.  This
way, the driver uno_stop routine is guaranteed exclusive access to
the registers.

This will also enable us to simplify the callouts and tasks so they
don't have to check the software state -- to be done in a separate
commit.

Revision 1.55 / (download) - annotate - [select for diffs], Thu Mar 3 05:48:14 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.54: +2 -8 lines
Diff to previous 1.54 (colored)

usbnet: Remove usbnet_set_dying.

Not necessary for the one caller that did it (url(4)): usbnet_detach
handles failed attach just fine without it.

Revision 1.54 / (download) - annotate - [select for diffs], Thu Mar 3 05:47:58 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.53: +2 -5 lines
Diff to previous 1.53 (colored)

usbnet: Omit needless unp == NULL test in usbnet_tick_task.

The task is never scheduled until after un->un_pri is initialized,
and un->un_pri isn't nulled until after the callout and task are
quiescent.

Revision 1.53 / (download) - annotate - [select for diffs], Thu Mar 3 05:47:50 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.52: +3 -4 lines
Diff to previous 1.52 (colored)

usbnet: Don't check if_flags for IFF_RUNNING in usbnet_pipe_intr.

The one user of this interface in tree, aue(4), doesn't care --
if_statinc is safe whether IFF_RUNNING or not.

Revision 1.52 / (download) - annotate - [select for diffs], Thu Mar 3 05:47:43 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.51: +3 -4 lines
Diff to previous 1.51 (colored)

usbnet: Don't check if_flags for IFF_RUNNING in usbnet_rxeof.

This can only run after we start the pipes in usbnet_init_rx_tx, and
before we abort the pipes in usbnet_stop, during which time if_flags
& IFF_RUNNING is stably set.

Revision 1.51 / (download) - annotate - [select for diffs], Thu Mar 3 05:47:36 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.50: +12 -9 lines
Diff to previous 1.50 (colored)

usbnet: Assert IFNET_LOCKED in usbnet_init_rx_tx, usbnet_stop.

Exception: urndis(4) abuses this API to start this logic before the
ifp is actually initialized.  So for the sake of urndis(4), until
sense can be beaten into it, allow the !unp_ifp_attached case to run
without IFNET_LOCK.

Revision 1.50 / (download) - annotate - [select for diffs], Thu Mar 3 05:47:28 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.49: +8 -2 lines
Diff to previous 1.49 (colored)

usbnet: Assert IFNET_LOCKED on if_flags change callbacks.

- if_init
- if_stop
- ethersubr(9) ifflags_cb

Revision 1.49 / (download) - annotate - [select for diffs], Thu Mar 3 05:47:21 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.48: +8 -3 lines
Diff to previous 1.48 (colored)

usbnet: Ensure access to unp_timer is protected by unp_txlock.

Revision 1.48 / (download) - annotate - [select for diffs], Thu Mar 3 05:47:14 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.47: +7 -4 lines
Diff to previous 1.47 (colored)

usbnet: Ensure ifp->if_softc is initialized _before_ publishing ifp.

Otherwise other parts of the system might start using ifp the moment
we if_register it, and trip over null if_softc.

Revision 1.47 / (download) - annotate - [select for diffs], Thu Mar 3 05:47:06 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.46: +4 -4 lines
Diff to previous 1.46 (colored)

usbnet: Take IFNET_LOCK around access to if_flags in usbnet_detach.

This is not stable without IFNET_LOCK.  Extraneous calls to
usbnet_stop arising from this race might be harmless, but let's
render it unnecessary to even think about that.

Revision 1.46 / (download) - annotate - [select for diffs], Thu Mar 3 05:46:58 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.45: +14 -13 lines
Diff to previous 1.45 (colored)

usbnet: Set and clear IFF_RUNNING slightly earlier and later.

- Set IFF_RUNNING before any calls to usbnet_rxeof are possible.
- Don't clear IFF_RUNNING until all transfers have been aborted.

Revision 1.45 / (download) - annotate - [select for diffs], Thu Mar 3 05:46:50 2022 UTC (10 months, 4 weeks ago) by riastradh
Branch: MAIN
Changes since 1.44: +3 -3 lines
Diff to previous 1.44 (colored)

usbnet: Simplify usbnet_isdying.

usbnet_detach (or its caller) stops all users before it returns.

If un->un_pri is null at this point, there's a bug -- something
didn't wait for everything to finish before calling usbnet_detach.

Revision 1.25.2.6 / (download) - annotate - [select for diffs], Mon Jan 31 17:30:21 2022 UTC (11 months, 4 weeks ago) by martin
Branch: netbsd-9
CVS Tags: netbsd-9-3-RELEASE
Changes since 1.25.2.5: +95 -4 lines
Diff to previous 1.25.2.5 (colored) next main 1.26 (colored)

Pull up following revision(s) (requested by riastradh in ticket #1415):

	sys/dev/usb/usbnet.c: revision 1.44 (via patch)

usbnet: Defer hardware multicast filter updates to USB task.

Breaks deadlock:
- usbnet_detach holds usbnet lock, awaits kpause in ure_reset
- callout holds softclock `lock' (sequential softints, blocks kpause
  wakeup), awaits softnet_lock in tcp_timer_keep, frag6_fasttimo, &c.
- soclose holds softnet_lock, awaits usbnet lock in SIOCDELMULTI

This change breaks the deadlock by not passing the SIOCADDMULTI or
SIOCDELMULTI ioctl synchronously to the driver, which typically takes
the usbnet lock.

With this change, the ethernet layer still maintains the list of
multicast addresses synchronously, but we defer the driver logic that
updates the hardware multicast filter to an asynchronous USB task
without softnet_lock held.

This doesn't cause exactly the same ioctl to be sent to the driver --
usbnet just sends SIOCDELMULTI with an all-zero struct ifreq, and
might drop some ioctls if issued in quick succession.  This is OK
because none of the drivers actually distinguish between SIOCADDMULTI
and SIOCDELMULTI, or examine the argument; the drivers just commit
whatever multicast addresses are listed in the ethercom.

Other than the different ioctl submitted, there is no change to the
ABI or locking scheme of usbnet, so this is safe to pull up to
netbsd-9.  This means we unfortunately can't guarantee that if a
process issues SIOCADDMULTI and then sendto, the multicast filter
update will be done by the time of the sendto -- and, more
importantly, the packets received in reply to it.  But failing to
guarantee that is better than deadlocking!  Later changes on HEAD
will restore the synchronous multicast filter updates with much more
extensive ABI changes and API simplifications in usbnet(9).
Proposed on tech-net:

https://mail-index.netbsd.org/tech-net/2021/12/30/msg008164.html

XXX pullup-9

Revision 1.44 / (download) - annotate - [select for diffs], Sat Jan 29 21:37:07 2022 UTC (12 months ago) by riastradh
Branch: MAIN
Changes since 1.43: +97 -5 lines
Diff to previous 1.43 (colored)

usbnet: Defer hardware multicast filter updates to USB task.

Breaks deadlock:

- usbnet_detach holds usbnet lock, awaits kpause in ure_reset
- callout holds softclock `lock' (sequential softints, blocks kpause
  wakeup), awaits softnet_lock in tcp_timer_keep, frag6_fasttimo, &c.
- soclose holds softnet_lock, awaits usbnet lock in SIOCDELMULTI

This change breaks the deadlock by not passing the SIOCADDMULTI or
SIOCDELMULTI ioctl synchronously to the driver, which typically takes
the usbnet lock.

With this change, the ethernet layer still maintains the list of
multicast addresses synchronously, but we defer the driver logic that
updates the hardware multicast filter to an asynchronous USB task
without softnet_lock held.

This doesn't cause exactly the same ioctl to be sent to the driver --
usbnet just sends SIOCDELMULTI with an all-zero struct ifreq, and
might drop some ioctls if issued in quick succession.  This is OK
because none of the drivers actually distinguish between SIOCADDMULTI
and SIOCDELMULTI, or examine the argument; the drivers just commit
whatever multicast addresses are listed in the ethercom.

Other than the different ioctl submitted, there is no change to the
ABI or locking scheme of usbnet, so this is safe to pull up to
netbsd-9.  This means we unfortunately can't guarantee that if a
process issues SIOCADDMULTI and then sendto, the multicast filter
update will be done by the time of the sendto -- and, more
importantly, the packets received in reply to it.  But failing to
guarantee that is better than deadlocking!  Later changes on HEAD
will restore the synchronous multicast filter updates with much more
extensive ABI changes and API simplifications in usbnet(9).

Proposed on tech-net:
https://mail-index.netbsd.org/tech-net/2021/12/30/msg008164.html

XXX pullup-9

Revision 1.43 / (download) - annotate - [select for diffs], Sat Dec 11 19:24:21 2021 UTC (13 months, 2 weeks ago) by mrg
Branch: MAIN
Changes since 1.42: +2 -4 lines
Diff to previous 1.42 (colored)

remove clause 3 from all my licenses that aren't conflicting with
another copyright claim line.  again.  (i did this in 2008 and then
did not update all of my personal templates.)

Revision 1.41.2.1 / (download) - annotate - [select for diffs], Thu Jun 17 04:46:31 2021 UTC (19 months, 2 weeks ago) by thorpej
Branch: thorpej-i2c-spi-conf
Changes since 1.41: +3 -7 lines
Diff to previous 1.41 (colored) next main 1.42 (colored)

Sync w/ HEAD.

Revision 1.42 / (download) - annotate - [select for diffs], Wed Jun 16 00:21:19 2021 UTC (19 months, 2 weeks ago) by riastradh
Branch: MAIN
CVS Tags: thorpej-i2c-spi-conf2-base, thorpej-i2c-spi-conf2, thorpej-i2c-spi-conf-base, thorpej-futex2-base, thorpej-futex2, thorpej-cfargs2-base, thorpej-cfargs2
Changes since 1.41: +3 -7 lines
Diff to previous 1.41 (colored)

if_attach and if_initialize cannot fail, don't test return value

These were originally made failable back in 2017 when if_initialize
allocated a softint in every interface for link state changes, so
that it could fail gracefully instead of panicking:

https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html

However, this spawned many seldom- or never-tested error branches,
which are risky to have around.  And that softint in every interface
has since been replaced by a single global workqueue, because link
state changes require thread context but not low latency or high
throughput:

https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html

So there is no longer any reason for if_initialize to fail.  (The
subroutine if_stats_init can't fail because percpu_alloc can't fail
either.)

There is a snag: the softint_establish in if_percpuq_create could
fail, potentially leading to bad consequences later on trying to use
the softint.  This change doesn't introduce any new bugs because of
the snag -- if_percpuq_attach was already broken.  However, the snag
can be better addressed without spawning error branches, either by
using a single softint or making softints less scarce.

(Separate commit will change the signatures of if_attach and
if_initialize to return void, scheduled to ride whatever is the next
convenient kernel bump.)

Patch and testing on amd64 and evbmips64-eb by maya@; commit message
soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me.

Revision 1.41 / (download) - annotate - [select for diffs], Sun Apr 25 05:15:20 2021 UTC (21 months, 1 week ago) by rin
Branch: MAIN
CVS Tags: cjep_sun2x-base1, cjep_sun2x-base, cjep_sun2x, cjep_staticlib_x-base1, cjep_staticlib_x-base, cjep_staticlib_x
Branch point for: thorpej-i2c-spi-conf
Changes since 1.40: +8 -3 lines
Diff to previous 1.40 (colored)

Sample # of TX packets as entropy source.

For RX packets, individual drivers need to be modified.

Revision 1.39.2.1 / (download) - annotate - [select for diffs], Sat Apr 3 22:28:51 2021 UTC (21 months, 4 weeks ago) by thorpej
Branch: thorpej-futex
Changes since 1.39: +6 -6 lines
Diff to previous 1.39 (colored) next main 1.40 (colored)

Sync with HEAD.

Revision 1.40 / (download) - annotate - [select for diffs], Mon Mar 1 17:41:44 2021 UTC (23 months ago) by jakllsch
Branch: MAIN
CVS Tags: thorpej-futex-base, thorpej-cfargs-base, thorpej-cfargs
Changes since 1.39: +6 -6 lines
Diff to previous 1.39 (colored)

reduce aprint_error(9) abuse

Revision 1.25.2.5 / (download) - annotate - [select for diffs], Fri Aug 28 19:36:34 2020 UTC (2 years, 5 months ago) by martin
Branch: netbsd-9
CVS Tags: netbsd-9-2-RELEASE, netbsd-9-1-RELEASE
Changes since 1.25.2.4: +5 -2 lines
Diff to previous 1.25.2.4 (colored)

Pull up following revision(s) (requested by riastradh in ticket #1067):

	sys/dev/usb/usbnet.c: revision 1.39
	sys/dev/usb/if_atu.c: revision 1.73

usbnet: Reject buflen>MCLBYTES in usbnet_newbuf.
atu(4): Reject packets larger than MCLBYTES.

Revision 1.39 / (download) - annotate - [select for diffs], Fri Aug 28 17:05:32 2020 UTC (2 years, 5 months ago) by riastradh
Branch: MAIN
Branch point for: thorpej-futex
Changes since 1.38: +5 -2 lines
Diff to previous 1.38 (colored)

usbnet: Reject buflen>MCLBYTES in usbnet_newbuf.

Revision 1.38.4.2 / (download) - annotate - [select for diffs], Mon Apr 13 08:04:51 2020 UTC (2 years, 9 months ago) by martin
Branch: phil-wifi
Changes since 1.38.4.1: +1593 -0 lines
Diff to previous 1.38.4.1 (colored) to branchpoint 1.38 (colored) next main 1.39 (colored)

Mostly merge changes from HEAD upto 20200411

Revision 1.38.4.1, Sun Mar 15 23:04:51 2020 UTC (2 years, 10 months ago) by martin
Branch: phil-wifi
Changes since 1.38: +0 -1593 lines
FILE REMOVED

file usbnet.c was added on branch phil-wifi on 2020-04-13 08:04:51 +0000

Revision 1.38 / (download) - annotate - [select for diffs], Sun Mar 15 23:04:51 2020 UTC (2 years, 10 months ago) by thorpej
Branch: MAIN
CVS Tags: phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, bouyer-xenpvh-base2, bouyer-xenpvh-base1, bouyer-xenpvh-base, bouyer-xenpvh
Branch point for: phil-wifi
Changes since 1.37: +97 -113 lines
Diff to previous 1.37 (colored)

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.

Revision 1.37 / (download) - annotate - [select for diffs], Sat Mar 14 03:01:36 2020 UTC (2 years, 10 months ago) by christos
Branch: MAIN
Changes since 1.36: +7 -7 lines
Diff to previous 1.36 (colored)

fix more broken kernhist formats (now I got them all).

Revision 1.36 / (download) - annotate - [select for diffs], Fri Mar 13 18:17:41 2020 UTC (2 years, 10 months ago) by christos
Branch: MAIN
Changes since 1.35: +21 -19 lines
Diff to previous 1.35 (colored)

PR/55068: sc.dying: Fix printf formats:
- no %s/%p for kernel log
- 0x% -> %#
- always %j for kernel log

Revision 1.33.2.1 / (download) - annotate - [select for diffs], Sat Feb 29 20:19:17 2020 UTC (2 years, 11 months ago) by ad
Branch: ad-namecache
Changes since 1.33: +11 -11 lines
Diff to previous 1.33 (colored) next main 1.34 (colored)

Sync with head.

Revision 1.35 / (download) - annotate - [select for diffs], Tue Feb 4 05:46:32 2020 UTC (2 years, 11 months ago) by thorpej
Branch: MAIN
CVS Tags: is-mlppp-base, is-mlppp, ad-namecache-base3
Changes since 1.34: +3 -3 lines
Diff to previous 1.34 (colored)

Use ifmedia_fini().

Revision 1.34 / (download) - annotate - [select for diffs], Wed Jan 29 06:39:07 2020 UTC (3 years ago) by thorpej
Branch: MAIN
Changes since 1.33: +10 -10 lines
Diff to previous 1.33 (colored)

Adopt <net/if_stats.h>.

Revision 1.25.2.4 / (download) - annotate - [select for diffs], Tue Dec 17 12:55:10 2019 UTC (3 years, 1 month ago) by martin
Branch: netbsd-9
CVS Tags: netbsd-9-0-RELEASE, netbsd-9-0-RC2
Changes since 1.25.2.3: +9 -8 lines
Diff to previous 1.25.2.3 (colored)

Pull up following revision(s) (requested by riastradh in ticket #565):

	sys/dev/usb/usbnet.c: revision 1.31
	sys/dev/usb/usbnet.c: revision 1.32
	sys/dev/usb/usbnet.c: revision 1.33

Fix order of nulling un->un_pri->unp_ec.ec_mii.

Can't null it until after if_detach prevents further use.

While here, fix conditionals in usbnet_tick_task to use the unp_dying
flag, not the nullness of mii (or of ifp, which never null because
it's an embedded member).

Fix inequality for refcnt drain: -1 here means all refs gone.

Don't assume mii is not null here. Some drivers like urndis don't use
mii, so they always have mii == NULL.
ok riastradh. fixes PR kern/54762

Revision 1.33 / (download) - annotate - [select for diffs], Sat Dec 14 15:40:43 2019 UTC (3 years, 1 month ago) by maya
Branch: MAIN
CVS Tags: ad-namecache-base2, ad-namecache-base1, ad-namecache-base
Branch point for: ad-namecache
Changes since 1.32: +7 -6 lines
Diff to previous 1.32 (colored)

Don't assume mii is not null here. Some drivers like urndis don't use
mii, so they always have mii == NULL.

ok riastradh. fixes PR kern/54762

Revision 1.32 / (download) - annotate - [select for diffs], Tue Dec 3 05:01:58 2019 UTC (3 years, 1 month ago) by riastradh
Branch: MAIN
Changes since 1.31: +3 -3 lines
Diff to previous 1.31 (colored)

Fix inequality for refcnt drain: -1 here means all refs gone.

Revision 1.31 / (download) - annotate - [select for diffs], Tue Dec 3 05:01:45 2019 UTC (3 years, 1 month ago) by riastradh
Branch: MAIN
Changes since 1.30: +11 -11 lines
Diff to previous 1.30 (colored)

Fix order of nulling un->un_pri->unp_ec.ec_mii.

Can't null it until after if_detach prevents further use.

While here, fix conditionals in usbnet_tick_task to use the unp_dying
flag, not the nullness of mii (or of ifp, which never null because
it's an embedded member).

Revision 1.30 / (download) - annotate - [select for diffs], Wed Nov 6 07:30:59 2019 UTC (3 years, 2 months ago) by mrg
Branch: MAIN
CVS Tags: phil-wifi-20191119
Changes since 1.29: +4 -2 lines
Diff to previous 1.29 (colored)

add a note about ifnet lock vs usbnet locks.

Revision 1.29 / (download) - annotate - [select for diffs], Fri Sep 13 07:55:07 2019 UTC (3 years, 4 months ago) by msaitoh
Branch: MAIN
Changes since 1.28: +4 -4 lines
Diff to previous 1.28 (colored)

 if_flags is neither int nor short. It's unsigned short.

Revision 1.25.2.3 / (download) - annotate - [select for diffs], Fri Sep 13 06:51:58 2019 UTC (3 years, 4 months ago) by martin
Branch: netbsd-9
CVS Tags: netbsd-9-0-RC1
Changes since 1.25.2.2: +54 -16 lines
Diff to previous 1.25.2.2 (colored)

Pull up following revision(s) (requested by mrg in ticket #197):

	sys/dev/usb/if_url.c: revision 1.71
	sys/dev/usb/usbnet.h: revision 1.15
	sys/dev/usb/usb_mem.c: revision 1.72
	sys/dev/usb/if_urndis.c: revision 1.24
	sys/dev/usb/if_upl.c: revision 1.67
	sys/dev/usb/usbnet.c: revision 1.25
	sys/dev/usb/usbnet.c: revision 1.26
	sys/dev/usb/usbnet.c: revision 1.27
	sys/dev/usb/usbnet.c: revision 1.28

Teach urndis to handle some REMOTE_NDIS_INDICATE_STATUS_MSG. If the status
is reasonable, don't tell userland we got an error. Stops spurious EIO.
From openbsd.

Fix bug, remove {0,0} because we switched to usb_lookup().

s/no free/no freelist entry/ in a debug message.

fix a lock hang reported by sc.dying in PR#54495.

remove locking in usbnet_tick().  assume that all locking
needs are handled inside usbnet_tick_task(), which runs in
the usbtask thread.  ensure that usbnet private is valid
before using it.

also check NULL private pointer in usbnet_isdying().
all the other cases should never happen.

don't try to set dying when we haven't usbnet_attach()d yet.
reported by maxv.

- use CALLARGS vs CALLED for better usbhist
- turn off usbnetdebug default
- log for all entry/exit points of usbnet_pipe_intr()
- in usbnet_start_locked() track whether any packet has been
  transmitted for setting the timer.  avoids spurious
  "watchdog timeouts"
- in usbnet_stop() use callout_halt() vs callout_halt, and
  also stop the usb task.  fixes crash of usbtask after the
  phy has detached.
- add a little more defensive checking in the tick task, and
  add some high-log-level logs.
- in usbnet_detach() move the call to usbnet_stop_ifp() above
  the calls to callout/usbtask stopping.
- set ec_mii and unp_pri to NULL when freeing their data

normalise an error message.

document usbnet_private locking.  minor knf.

Revision 1.28 / (download) - annotate - [select for diffs], Mon Sep 9 07:20:16 2019 UTC (3 years, 4 months ago) by mrg
Branch: MAIN
Changes since 1.27: +7 -2 lines
Diff to previous 1.27 (colored)

document usbnet_private locking.  minor knf.

Revision 1.27 / (download) - annotate - [select for diffs], Sun Sep 8 19:00:33 2019 UTC (3 years, 4 months ago) by mrg
Branch: MAIN
Changes since 1.26: +3 -3 lines
Diff to previous 1.26 (colored)

normalise an error message.

Revision 1.26 / (download) - annotate - [select for diffs], Sun Sep 8 18:59:32 2019 UTC (3 years, 4 months ago) by mrg
Branch: MAIN
Changes since 1.25: +46 -10 lines
Diff to previous 1.25 (colored)

- use CALLARGS vs CALLED for better usbhist
- turn off usbnetdebug default
- log for all entry/exit points of usbnet_pipe_intr()
- in usbnet_start_locked() track whether any packet has been
  transmitted for setting the timer.  avoids spurious
  "watchdog timeouts"
- in usbnet_stop() use callout_halt() vs callout_halt, and
  also stop the usb task.  fixes crash of usbtask after the
  phy has detached.
- add a little more defensive checking in the tick task, and
  add some high-log-level logs.
- in usbnet_detach() move the call to usbnet_stop_ifp() above
  the calls to callout/usbtask stopping.
- set ec_mii and unp_pri to NULL when freeing their data

Revision 1.25.2.2 / (download) - annotate - [select for diffs], Sun Sep 1 13:00:36 2019 UTC (3 years, 5 months ago) by martin
Branch: netbsd-9
Changes since 1.25.2.1: +1566 -0 lines
Diff to previous 1.25.2.1 (colored)

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).

Revision 1.25.2.1, Thu Aug 29 09:17:51 2019 UTC (3 years, 5 months ago) by martin
Branch: netbsd-9
Changes since 1.25: +0 -1563 lines
FILE REMOVED

file usbnet.c was added on branch netbsd-9 on 2019-09-01 13:00:36 +0000

Revision 1.25 / (download) - annotate - [select for diffs], Thu Aug 29 09:17:51 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Branch point for: netbsd-9
Changes since 1.24: +4 -7 lines
Diff to previous 1.24 (colored)

fix a lock hang reported by sc.dying in PR#54495.

remove locking in usbnet_tick().  assume that all locking
needs are handled inside usbnet_tick_task(), which runs in
the usbtask thread.  ensure that usbnet private is valid
before using it.

also check NULL private pointer in usbnet_isdying().
all the other cases should never happen.

Revision 1.24 / (download) - annotate - [select for diffs], Wed Aug 28 06:07:21 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.23: +8 -7 lines
Diff to previous 1.23 (colored)

in usbnet_detach(), check both that the private pointer has
been allocated and that unp_attached is true before trying
to access anything else.

fixes a detach problem noticed by maxv when, eg, the call
to usbd_set_config_no() fails and attach bails early.

Revision 1.23 / (download) - annotate - [select for diffs], Fri Aug 23 04:29:28 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.22: +51 -11 lines
Diff to previous 1.22 (colored)

- remove unused uncd_rx_cnt
- add USBNETHIST_CALLARGSN and use it in many places
- add more history logs
- add a log if watchdog abort leaves uncd_tx_cnt non zero
- add a unique (32-bit) number for a each usbnet device and
  use it for logging
- explicitly check for full tx ring in usbnet_start_locked()
  and return early, which avoids setting the 5 second timer
  and triggering a watchdog
- reset uncd_tx_prod and uncd_tx_cnt to zero in stop

Revision 1.22 / (download) - annotate - [select for diffs], Tue Aug 20 06:37:06 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.21: +12 -13 lines
Diff to previous 1.21 (colored)

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.

Revision 1.21 / (download) - annotate - [select for diffs], Tue Aug 20 06:18:54 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.20: +3 -3 lines
Diff to previous 1.20 (colored)

properly fix the kernhist calls.

one must cast and cast and cast and maybe a fish will be caught...

Revision 1.20 / (download) - annotate - [select for diffs], Mon Aug 19 07:33:37 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.19: +11 -12 lines
Diff to previous 1.19 (colored)

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().

Revision 1.19 / (download) - annotate - [select for diffs], Mon Aug 19 06:35:14 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.18: +10 -5 lines
Diff to previous 1.18 (colored)

add USBHIST_CALLARGS() frontend to KERNHIST_CALLARGS().
add USBNETHIST_CALLARGS() frontend to USBHIST_CALLARGS().

use both in read/write reg, instead of aprint.

use %jx and (uintptr_t) and fix the 32 bit debug build.

Revision 1.18 / (download) - annotate - [select for diffs], Sun Aug 18 09:46:58 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.17: +3 -3 lines
Diff to previous 1.17 (colored)

fix a think-o in the previous: don't return when saving the first error.
from skrll@.

Revision 1.17 / (download) - annotate - [select for diffs], Sun Aug 18 09:29:38 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.16: +28 -17 lines
Diff to previous 1.16 (colored)

update usbnet slight:
- drivers that want to use if_input() will also set _if_input.  for
  now, avoid attaching a per-cpu queue for them.  use if_initialize()
  and if_register().
- when stopping pipes, don't give up after the first failure, but
  keep the first failure error for return and keep going
- if 0 a KASSERT() in usbnet_init_rx_tx().  there's a path via
  if_mcast_op() that can have the ifnet unlocked today..
- in usbnet_watchdog(), abort the pipe instead of faking tx
  completion.  avoids issues with devices with more than one tx
  descriptor, as well as avoiding triggering usb asserts.

with these, upl(4) port to usbnet(9) now works.  (would be a version
bump, but upl(4) and the unported umb(4) are the only consumers that
would care.)

Revision 1.16 / (download) - annotate - [select for diffs], Fri Aug 16 08:38:21 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.15: +16 -16 lines
Diff to previous 1.15 (colored)

internal to usbnet:

add buflen param to usbnet_newbuf().  use this to skip allocating
an mbuf cluster for small packets (ported from kue(4).)

remove usbnet_rx_start_pipes()'s always usbnet_rxeof argument.

Revision 1.15 / (download) - annotate - [select for diffs], Thu Aug 15 05:52:23 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.14: +19 -11 lines
Diff to previous 1.14 (colored)

- 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.)

Revision 1.14 / (download) - annotate - [select for diffs], Wed Aug 14 03:44:58 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.13: +8 -2 lines
Diff to previous 1.13 (colored)

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)

Revision 1.13 / (download) - annotate - [select for diffs], Sun Aug 11 23:55:43 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.12: +7 -3 lines
Diff to previous 1.12 (colored)

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.

Revision 1.12 / (download) - annotate - [select for diffs], Sun Aug 11 01:31:19 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.11: +25 -24 lines
Diff to previous 1.11 (colored)

- use usbnet_isowned*() more
- more const

Revision 1.11 / (download) - annotate - [select for diffs], Sat Aug 10 02:17:36 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.10: +415 -224 lines
Diff to previous 1.10 (colored)

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.

Revision 1.10 / (download) - annotate - [select for diffs], Fri Aug 9 01:17:33 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.9: +131 -52 lines
Diff to previous 1.9 (colored)

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.

Revision 1.9 / (download) - annotate - [select for diffs], Wed Aug 7 10:01:05 2019 UTC (3 years, 5 months ago) by maya
Branch: MAIN
Changes since 1.8: +8 -4 lines
Diff to previous 1.8 (colored)

Don't tell userland about ENETRESET even if a usbnet driver didn't define
un_ioctl_cb.

Revision 1.8 / (download) - annotate - [select for diffs], Wed Aug 7 01:47:18 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.7: +8 -8 lines
Diff to previous 1.7 (colored)

fix two issues, found by maya@ while testing urndis:
- avoid an KASSERT() in usbnet_rx_tx_init() when called early
- move the pmf and usb driver event calls out of the mii specific code,
  now suspend is able to work on them again.

urndis port to usbnet works with additional ipv6 lossage that
may indicate it doesn't work (not commited yet.)

Revision 1.7 / (download) - annotate - [select for diffs], Wed Aug 7 00:38:02 2019 UTC (3 years, 5 months ago) by pgoyette
Branch: MAIN
Changes since 1.6: +2 -12 lines
Diff to previous 1.6 (colored)

Many years ago someone created a new __link_set_sysctl_funcs to hold
the list of routines that need to be called for setting up sysctl
variables.  This worked great for all code included in the kernel
itself, but didn't deal with modules that want to create their own
sysctl data.  So, we ended up with a lot of #ifdef _MODULE blocks
so modules could explicitly call their setup functions when loaded
as non-built-in modules.

So today, we complete the task that was started so many years ago.

When modules are loaded, after we've called xxx_modcmd(INIT...) we
check if the module contains its own __link_set_sysctl_funcs, and
if so we call the functions listed.  We add a struct sysctllog member
to the struct module so we can call sysctl_teardown() when the module
gets unloaded.  (The sequence of events ensures that the sysctl stuff
doesn't get created until the rest of the module's init code does any
required memory allocation.)

So, no more need to explicitly call the sysctl setup routines when
built as a loadable module.

Revision 1.6 / (download) - annotate - [select for diffs], Tue Aug 6 01:42:22 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.5: +4 -2 lines
Diff to previous 1.5 (colored)

for ethernet usb network devices, print the mac addr in usbnet.

Revision 1.5 / (download) - annotate - [select for diffs], Tue Aug 6 00:19:57 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.4: +61 -8 lines
Diff to previous 1.4 (colored)

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!

Revision 1.4 / (download) - annotate - [select for diffs], Sun Aug 4 08:59:13 2019 UTC (3 years, 5 months ago) by mrg
Branch: MAIN
Changes since 1.3: +104 -18 lines
Diff to previous 1.3 (colored)

- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
  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!

Revision 1.3 / (download) - annotate - [select for diffs], Sat Aug 3 15:58:14 2019 UTC (3 years, 5 months ago) by skrll
Branch: MAIN
Changes since 1.2: +4 -4 lines
Diff to previous 1.2 (colored)

Trailing white space

Revision 1.2 / (download) - annotate - [select for diffs], Wed Jul 31 23:47:16 2019 UTC (3 years, 6 months ago) by mrg
Branch: MAIN
Changes since 1.1: +49 -17 lines
Diff to previous 1.1 (colored)

couple of minor API updates:
- 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.

Revision 1.1 / (download) - annotate - [select for diffs], Wed Jul 31 09:13:16 2019 UTC (3 years, 6 months ago) by mrg
Branch: MAIN

introduce a library of common code / backends to share code between
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.

This form allows you to request diff's between any two revisions of a file. You may select a symbolic revision name using the selection box or you may type in a numeric name using the type-in text box.




CVSweb <webmaster@jp.NetBSD.org>