Commit Graph

55 Commits

Author SHA1 Message Date
drochner d8e1a7b61a Use pci_aprint_devinfo(9) instead of pci_devinfo+aprint_{normal,naive}
where it looks straightforward, and pci_aprint_devinfo_fancy in a few
others where drivers want to supply their own device names instead
of the pcidevs generated one. More complicated cases, where names
are composed at runtime, are left alone for now. It certainly makes
sense to simplify the drivers here rather than inventing a catch-all API.
This should serve as as example for new drivers, and also ensure
consistent output in the AB_QUIET ("boot -q") case. Also, it avoids
excessive stack usage where drivers attach child devices because the
buffer for the device name is not kept on the local stack anymore.
2012-01-30 19:41:18 +00:00
tsutsui 3a5ccb056f Pull the following fix from OpenBSD:
http://www.openbsd.org/cgi-bin/cvsweb/src/sys/dev/pci/if_nfe.c#rev1.97
>> Some nfe(4)/rlphy(4) combos don't work, because the PHY responds to all
>> addresses on the mii bus.  As a countereasure, only attach the first PHY we
>> encounter.  It is very unlikely we're going to ever see nfe(4) with multiple
>> PHYs.  The same is probably true for any modern NIC.

Should suppress bogus ukphy30 noted in PR kern/42950.
No bad side effect on my nfe(4) which didn't get ghosts:
---
nfe0 at pci0 dev 5 function 0: NVIDIA nForce3 Ethernet #4 (rev. 0xa2)
 :
rlphy0 at nfe0 phy 1: RTL8201L 10/100 media interface, rev. 1
rlphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
2011-01-23 03:15:06 +00:00
jakllsch 689f59981c Make nfe(4) detachable. 2010-11-03 14:03:40 +00:00
jakllsch c319f56c83 Explicitly set PCI_COMMAND_MASTER_ENABLE. 2010-11-02 16:56:47 +00:00
joerg 58e867556f Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
2010-04-05 07:19:28 +00:00
dyoung c1b390d493 A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
2010-02-24 22:37:54 +00:00
pooka 10fe49d72c Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client.  This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached.  However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff.  ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
2010-01-19 22:06:18 +00:00
dyoung cd6e1fbf91 Expand PMF_FN_* macros. 2010-01-08 19:53:10 +00:00
njoly 85cadc2388 Cleanup interrupt establish error messages. Do not mix
aprint_error/aprint_normal/printf calls for a single line.
2009-11-26 15:17:08 +00:00
tsutsui 64cbab9fdb Invert logic around nested pmf(9) registrations for readability. 2009-09-05 14:09:55 +00:00
cegger 051c4248a9 use __arraycount 2009-06-14 06:24:14 +00:00
cegger 35fb64746b bcmp -> memcmp 2009-03-18 15:14:29 +00:00
cegger 2352b93556 bzero -> memset per request from martin@
bcopy -> memcpy

XXX Would changing bcmp to memcpy be a functional change regarding its return value?
2009-03-01 13:44:54 +00:00
cegger 945fa6c58f when nfe_attach() fails, free all resources including
interrupt map, interrupt handler and dma maps.
Also prevent call to bus_dmamap_destroy() when bus_dmamap_create() failed.
The nfe_free_* routines assume, the map pointers are NULL but they
are actually undefined. Make the assumption true by making them NULL
in the error path of bus_dmamap_create().

All together, this fixes crashes when nfe_attach() fails.
ok martin@
2009-03-01 13:34:10 +00:00
cegger 927cfb73c8 MCP79 supports JUMBO frames.
Information from Linux driver.
Patch presented on current-users@ http://mail-index.netbsd.org/current-users/2009/02/11/msg008037.html
2009-03-01 08:29:25 +00:00
cegger 92e9ddc630 flow-control support for MCP65 chip.
XXX other chips may also have flow-control, but only on MCP65 tested.
ok cube@
2009-02-12 10:33:23 +00:00
cegger d5fc4888bc Bracket IRQ masking around nfe_intr() in nfe_init() rather inside nfe_intr().
Proposed by dyoung@ in PR 40345. Should fix PR 40345.
2009-01-18 11:21:06 +00:00
christos 9a5d3f2817 replace bitmask_snprintf(9) with snprintb(3) 2008-12-16 22:35:21 +00:00
dyoung de87fe677d *** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02🇩🇪ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address.  (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior.  Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability.  KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR.  In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr.  That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR.  In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR.  For example, pull ..._init() out of any switch
statement that looks like this:

        switch (...->sa_family) {
        case ...:
                ..._init();
                ...
                break;
        ...
        default:
                ..._init();
                ...
                break;
        }

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

        switch (x & (IFF_UP|IFF_RUNNING)) {
        case 0:
                ...
                break;
        case IFF_RUNNING:
                ...
                break;
        case IFF_UP:
                ...
                break;
        case IFF_UP|IFF_RUNNING:
                ...
                break;
        }

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure.  Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls.  In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source.  In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively.  Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset.  Delete unnecessary casts to void *.  Use
sockaddr_in_init() and sockaddr_in6_init().  Compare pointers with
NULL instead of "testing truth".  Replace some instances of (type
*)0 with NULL.  Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 00:20:01 +00:00
cube c0bb1f4b42 Use MUTEX_DEFAULT to initialise the mutex, per martin@'s input. 2008-06-17 12:59:32 +00:00
jmcneill a6e01338bc Based on changes to nfe_attach in r1.27, wake newer chips from powerdown
mode on resume as well as at attach time.
2008-05-25 22:57:35 +00:00
cube 4e49392569 Restore jumbo frame support and protect access to the DMA space for
received frames with a mutex.

Tested by Paul Goyette, Martin Husemann and myself.
2008-04-20 08:57:37 +00:00
christos 07975baeb4 join line for symmetry. 2008-04-17 20:16:46 +00:00
xtraeme 035163789f Make this build again... HI XTOS. 2008-04-17 19:50:38 +00:00
christos f0b645b98a sync with openbsd; fixes observed corruption issues. 2008-04-17 19:12:26 +00:00
cube 6495be5eed Split device_t and softc, and related cosmetic changes. 2008-03-26 14:46:21 +00:00
isaki d540dc1cd1 Minor style fix. 2008-02-24 05:34:01 +00:00
dyoung 2ccede0a9c Start patching up the kernel so that a network driver always has
the opportunity to handle an ioctl before generic ifioctl handling
occurs.  This will ease extending the kernel and sharing of code
between drivers.

First steps:  Make the signature of ifioctl_common() match struct
ifinet->if_ioctl.  Convert SIOCSIFCAP and SIOCSIFMTU to the new
ifioctl() regime, throughout the kernel.
2008-02-07 01:21:52 +00:00
tsutsui 9e319fb40f Wakeup some newer chips from powerdown mode. From FreeBSD/Linux driver
via OpenBSD.

Tested by wiz@ in PR kern/37868.
2008-01-26 14:13:06 +00:00
dyoung b480b62270 Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange().  Check for
a non-ENXIO error return from mii_mediachg().  (ENXIO indicates
that a PHY is suspended.)

This patch shrinks the source code size by 979 lines.  There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.

I have made a few miscellaneous changes, too:

gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
        on a change of media

Except for the change to mtd(4), no functional changes are intended.

XXX This patch affects more architectures than I can feasibly
XXX compile and run.  I have compiled macppc, sparc64, i386.  I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
2008-01-19 22:10:14 +00:00
tsutsui 4e3d8b015c Handle a quirk of newer MCP6x chips on reading MAC address.
Fix from Richy Kim in PR kern/36576.
2007-12-17 12:41:06 +00:00
jmcneill 4c1d81b2b5 Merge jmcneill-pm branch. 2007-12-09 20:27:42 +00:00
xtraeme 7d0d95af5a Add the MCP{67,73} products on nfe_attach(). 2007-11-14 14:59:50 +00:00
xtraeme a7040ff1de Attach to NVIDIA MCP67/73 Ethernet controllers. 2007-11-14 12:40:54 +00:00
ad d18c6ca4de Merge from vmlocking:
- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.
2007-11-07 00:23:13 +00:00
ad a2a3828545 machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h 2007-10-19 11:59:34 +00:00
cube 9d4a2bf213 - If the chip doesn't support jumbo frames, don't use bus_dmamap_load_mbuf
which expects a properly filled mbuf chain, but bus_dmamap_load for the
  mbuf storage space instead.

- If the chip supports jumbo frames
    + keep track of which RX descriptor uses which jumbo mbuf buffer, so
      that we can rewrite the physaddr field of the descriptor later, as it
      might be partially overwritten by the hw
    + when we're out of jumbo mbufs, and if the packet is small enough,
      copy it into a cluster mbuf

Those changes make my nfe(4) stable in both cases (defining NFE_NO_JUMBO
for the first one).
2007-09-24 13:17:53 +00:00
cube 5b396aa2c0 From OpenBSD, rev 1.72:
In nfe_start() do a fast return if IFF_OACTIVE is set, in
this case we need a Tx interrupt to clean up the DMA ring
before if_start can be properly called.
2007-09-24 13:11:08 +00:00
dyoung dcd8923429 Change a bazillion occurrences of code resembling this,
error = (cmd == SIOCADDMULTI) ?
	    ether_addmulti(ifr, &sc->sc_ec) :
	    ether_delmulti(ifr, &sc->sc_ec);

	if (error == ENETRESET) {

to this,

	if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number.  This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
2007-09-01 07:32:22 +00:00
ad 88ab7da936 Merge some of the less invasive changes from the vmlocking branch:
- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
2007-07-09 20:51:58 +00:00
christos 53524e44ef Kill caddr_t; there will be some MI fallout, but it will be fixed shortly. 2007-03-04 05:59:00 +00:00
tsutsui a111aec3cd Apply patches which may fix RX stall problem on nfe(4):
- make DMA descriptors volatile to avoid possible unintended reordering
  which might cause some race conditions
- process interrupts until all NFE_IRQ_WANTED bits are handled

and also put misc fixes:
- return 1 and call nfe_start() in nfe_intr() only if any own interrupts
  are actually handled
- use bus_dmamap_load_mbuf(9) for RX mbufs rather than bus_dmamap_load(9)
  with mtod(9) and MCLBYTES
- check sc->txq.queued to see if TX descriptors are queued or handled
  in nfe_start() and nfe_txeof()
- use proper BUS_DMASYNC_{PRE,POST} ops
- prepare and use NFE_[RT]X_NEXTDESC() macro
- rename NFE_TX_TCP_CSUM to NFE_TX_TCP_UDP_CSUM since it also enables
  hardware udp4csum-tx for UDP4 packets
- some minor optimization
- misc KNF

Tested and confirmed by matthew green by
"to send >25MB/sec to nfe0 for over one hour,"
and also tested by me (with light TRX load on 100baseTX though)
for a month.
2007-02-28 17:40:11 +00:00
tsutsui e699b95246 Enable hardware checksum support by hardware info taken from FreeBSD.
Tested on nForce3 250 and nForce4 by Chuck Silvers, Cesar Catrian Carreno,
and me.
2007-01-09 10:29:27 +00:00
jmcneill d9c4129a70 A few changes to make this work on the Microsoft Xbox. Should also help
with other users who have been experiencing watchdog timeouts:
 * Mask all interrupts while servicing a tx or rx interrupt.
 * On init, clear IRQ status registers (workaround for buggy netbooters).
2007-01-05 01:33:57 +00:00
tsutsui 7c3bb7972d Pull a TX timeout fix from OpenBSD:
> Defer setting of the valid bit in the first TX descriptor after
> all descriptors have been setup.  Otherwise, hardware may start
> processing descriptors faster than us and crap out.
> Fixes "watchdog timeout" errors.
>
> Original idea from Matthew Dillon @DragonFly.
2007-01-01 04:13:25 +00:00
tsutsui 3b8f579381 Minor style fixes in nfe_attach:
- print PCI device name and revision
- print interrupt and Ethernet address like other devices

Before:
---
nfe0 at pci0 dev 5 function 0LKLN: Picked IRQ 20 with weight 1
: ioapic0 pin 20 (irq 9), address xx:xx:xx:xx:xx:xx

After:
---
nfe0 at pci0 dev 5 function 0: NVIDIA nForce3 ethernet #4 (rev. 0xa2)
LKLN: Picked IRQ 20 with weight 1
nfe0: interrupting at ioapic0 pin 20 (irq 9)
nfe0: Ethernet address xx:xx:xx:xx:xx:xx

(note "Picked IRQ" message is logged by aprint_verbose(9) in acpi(4))
2007-01-01 03:43:04 +00:00
alc 24803bd1c4 remove the KASSERT() introduced in last commit and use VLAN_OUTPUT_TAG() macro.
tested by martin@
pointed out and ok by pavel@, also ok from christos@
2006-12-27 18:36:09 +00:00
alc 9254207181 CID-3667: check if 'mtag != NULL' before dereferencing it 2006-12-25 23:58:36 +00:00
christos 168cd830d2 __unused removal on arguments; approved by core. 2006-11-16 01:32:37 +00:00
christos 4d595fd7b1 - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
2006-10-12 01:30:41 +00:00