Commit Graph

73 Commits

Author SHA1 Message Date
thorpej
7a9a30c5e7 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.
2020-03-15 23:04:50 +00:00
christos
aa3d6ec155 revert the 0x% -> %# change for fixed width formats pointed out by uwe. 2020-03-14 02:35:33 +00:00
christos
d3dde16c1a PR/55068: sc.dying: Fix printf formats:
- no %s/%p for kernel log
- 0x% -> %#
- always %j for kernel log
2020-03-13 18:17:40 +00:00
thorpej
72f872d2b2 Adopt <net/if_stats.h>. 2020-01-29 06:17:07 +00:00
skrll
bf343540f8 Use a define instead of a magic constant. NFCI. 2020-01-15 08:02:53 +00:00
maxv
f76a68287e Localify, constify. 2020-01-07 06:42:26 +00:00
mrg
8352fa6550 s/UBSNET_MII_DECL_DEFAULT/USBNET_MII_DECL_DEFAULT/. from sc.dying. 2019-08-23 04:32:57 +00:00
mrg
65dae9683e 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.
2019-08-20 06:37:06 +00:00
mrg
43e0dcd183 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().
2019-08-19 07:33:37 +00:00
mrg
f2c22b6b6e - 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.)
2019-08-15 05:52:23 +00:00
mrg
f1e87e99ec 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)
2019-08-14 03:44:58 +00:00
skrll
a4d5367342 Appease module build 2019-08-11 08:56:53 +00:00
mrg
32428abeb6 copy a pattern from if_udav.c, which already had "too much" check.
even though overflow or underflow is really unlikely here, reorder
various expressions to reduce the likelyhood even further.
2019-08-11 02:37:03 +00:00
mrg
97f70a3c6e in tx_prepare callback make sure to reject any mbuf that is larger
than can fit in the buffer.  done at the driver and not usbnet
layer because the driver knows how much beyond the mbuf data needs
to be sent (headers and trailers.)

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

XXX: only tested on these drivers, needs to be copied to udav, smsc
and urndis after testing as well as the not commited conversions.
2019-08-11 01:04:33 +00:00
mrg
dbbc1953bd 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.
2019-08-10 02:17:36 +00:00
mrg
e4ce9137e1 use new un_flags member of usbnet:
- axen(4) and cdce(4) are now able to use struct usbnet directly
  as softc, udav also done but untested
2019-08-09 02:52:59 +00:00
mrg
d066f229b9 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.
2019-08-09 01:17:33 +00:00
mrg
599c0927d8 for ethernet usb network devices, print the mac addr in usbnet. 2019-08-06 01:42:22 +00:00
mrg
76b0c5e318 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!
2019-08-06 00:19:57 +00:00
skrll
61aabaa0fe Typo in error message 2019-08-05 07:03:55 +00:00
mrg
fa8dd7eff9 - 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!
2019-08-04 08:59:13 +00:00
mrg
699d292a9e 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.
2019-07-31 23:47:16 +00:00
mrg
773ec77d3f 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.
2019-07-31 09:13:16 +00:00
mrg
5c5367623b minor white space adjustments. 2019-07-15 03:14:22 +00:00
mrg
05bd368781 more smp cleanup for ure(4)/axen(4)/cdce(4):
- convert IFF_ALLMULTI to ETHER_F_ALLMULTI, using ETHER_LOCK()
- remove IFF_OACTIVE use, and simply check the ring count in start
- assert/take more locks
- XXX: IFF_RUNNING is not properly protected (all driver problem)
- fix axen_timer setting so it actually runs
- document a locking issue in stop callback:
  stop is called with the softc lock held, but the lock order
  in all other places is ifnet -> softc -> rx -> tx, so taking
  ifnet lock when softc lock is held would be problematic
- in rxeof check for stopping/dying more often.  i managed to
  trigger a pagefault in cdce_rxeof() when yanking an active
  device as it attempted to usbd_setup_xfer() on closed pipes.
- add missing USBD_MPSAFE and cdce_stopping resetting for cdce(4)

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

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

i'm not sure why axen drops a little with in+out.  cdce is
helped quite a lot, and ure a little.  it is disappointing that
ure does not outperform cdce -- it's the same actual hardware,
and the device-specific (ure) should outperform the generic
cdce driver...
2019-06-28 01:57:43 +00:00
mrg
e914d846e5 wrap axen_iff() with axen_iff_locked().
add a missing lock exit in error path.
2019-06-22 10:58:39 +00:00
mrg
7c1f464615 mark this driver MPSAFE for usb tasks and pipes, if(4), and callouts.
remove remaining redundant spl calls.
2019-06-22 09:53:56 +00:00
mrg
ed56fb496f re-apply rev 1.44 with a minor bug fix in axen_tick_task().
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-22 08:09:08 +00:00
mrg
d1e6396a98 revert the previous.
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.
2019-06-22 07:17:13 +00:00
mrg
c2c0fad7d4 fix issues seen with transfers being reused before they are finished
being used.

adapt locking to the modern world.  some what inspired by if_smsc.c:
- add locks for softc, rx and tx
- add safe detach support
- safe detach vs mii lock requires 2 methods to lock the MII lock,
- check axen_dying and new axen_stopping more often
- consolidate checks to reduce the number of error paths that need
  to release a resource
- move axen_watchdog() out of if_timer into the tick task to
  prepare for MPSAFEification

TODO:
- remove spl usage
- enable mpsafe

special thanks to skrll and mlelstv for clearing up various
confusion and providing examples.
2019-06-21 14:19:46 +00:00
mrg
2fc98dfbe9 minor clean up, almost NFCI:
- use const, __func__, more
- axen_mii_lock is a normal mutex not rwlock, and make sure it's
  properly cleaned up for failed attach
- check axen_dying in axen_miibus_statchg()
- rename axen_ax88179_eeprom() to axen_get_eaddr() and move the code
  here into the support the current method.
- adjust some comments
2019-06-20 10:46:24 +00:00
mrg
14c9b3f922 move struct axen_chain, struct axen_cdata, struct axen_softc,
struct axen_type, sc_if, GET_MII(), and GET_IFP() -- all the
software defined components from if_axenreg.h into if_axen.c.
2019-06-18 09:34:57 +00:00
msaitoh
8375928380 Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*. 2019-05-28 07:41:46 +00:00
msaitoh
5542e458a9 Whitespace fix (mainly tabify). 2019-05-23 13:10:50 +00:00
msaitoh
c34bdbc550 -No functional change:
- KNF
  - u_int*_t -> uint*_t.
2019-05-23 10:57:27 +00:00
msaitoh
430e9a94b1 Fix a bug that the duplex of manual media setting may be wrong
when the IFM_GMASK bit other than IFM_[FH]DX is set.
2019-04-11 08:50:59 +00:00
rin
d9fe5a835c Remove unused. 2019-02-17 09:33:19 +00:00
mlelstv
17b38fa12e Use unsigned variables for buffer length to avoid compiler warnings. 2019-02-07 10:36:20 +00:00
rin
c21c969408 Add ratecheck for TX errors for axen(4) and mue(4). 2019-02-06 08:38:41 +00:00
rin
311f3c5d80 Fix panic when detach or "ifconfig down" for axen(4) and mue(4).
- Mitigate race conditions, that become critical when multiple outstanding
  transfers are enabled.
- Drop link flags earlier in foo_stop() to make sure (paranoia).
2019-02-06 08:16:49 +00:00
rin
77b515e890 Enable multiple outstanding transfers.
XXX Linux driver uses much larger numbers of transfers.
2019-02-06 08:06:59 +00:00
rin
a0ccfc08f4 Add couple of error printf.
XXX We should not to use aprint_xxx() for non-autoconf staffs.
2019-02-06 08:04:08 +00:00
rin
389dd2cc58 Oops, fix previous again. Really support TSOv4. 2019-02-06 08:01:24 +00:00
rin
982d5e623f Fix previous. 2019-02-06 07:59:24 +00:00
rin
6a3228dc48 Support TSOv4 (They call it LSOv1).
The adapter does not support TSOv6 (aka LSOv2).
2019-02-06 07:56:14 +00:00
rin
f32fb6b950 Fix padding for a full length USB packet in TX:
- Update boundary length for SS mode, taken from OpenBSD.
- Make sure everything passed to the adapter is little endian.
- Specify padding bits in a similar manner to Linux.

XXX I wonder whether this is really necessary...
2019-02-06 07:48:33 +00:00
rin
6adf8560d1 Cosmetic changes; no functional changes. 2019-02-06 07:35:46 +00:00
rin
d36d652c39 Drop AXEN_MEDIUM_ALWAYS_ONE (from Linux), which reduces drop erros in RX. 2019-02-06 07:31:38 +00:00
rin
54a55fb09c Remove useless memset. 2019-02-06 07:28:01 +00:00
rin
fc9aba3436 Correct error bits in RX packet header:
- Drop error is bit 31.
- CRC error is bit 29.
- Distinguish the two errors in debug printf.
2019-01-31 15:27:57 +00:00