History log of /openbsd-current/sys/dev/ic/dc.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.157 13-May-2024 jsg

remove prototypes with no matching function
ok mpi@


Revision tags: OPENBSD_7_5_BASE
# 1.156 10-Nov-2023 bluhm

Make ifq and ifiq interface MP safe.

Rename ifq_set_maxlen() to ifq_init_maxlen(). This function neither
uses WRITE_ONCE() nor a mutex and is called before the ifq mutex
is initialized. The new name expresses that it should be used only
during interface attach when there is no concurrency.

Protect ifq_len(), ifq_empty(), ifiq_len(), and ifiq_empty() with
READ_ONCE(). They can be used without lock as they only read a
single integer.

OK dlg@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.155 22-Feb-2022 guenther

Delete unnecessary #includes of <sys/domain.h> and/or <sys/protosw.h>

net/if_pppx.c pointed out by jsg@
ok gnezdo@ deraadt@ jsg@ mpi@ millert@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.154 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.153 10-Jul-2020 patrick

Change users of IFQ_DEQUEUE(), IFQ_ENQUEUE() and IFQ_LEN() to use the
"new" API.

ok dlg@ tobhe@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.152 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.151 04-May-2016 kettenis

Use BUS_DMA_OVERRUN to cope with the broken DMA engine of the Davicom DM9102
found on some Sun sparc64 machines. This fixes the unrecoverable DMA errors
people have been seeing ever since dlg@ made changes to the pool code that
changes the memory layout.


# 1.150 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.149 28-Nov-2015 dlg

rework dc_start and dc_encap to take advantage of m_defrag.

if the chip needs coalesced packages in tx, set the tx dmamaps up
to only use a single dma descriptor. use m_defrag when bus_dmamap_load_mbuf
returns EFBIG rather than copying the packet to a separate mbuf
with hand rolled code in dc_coal. that in turn makes the ifq_deq_begin,
ifq_deq_commit, and ifq_deq_rollback handling more straightforward.

tested by me on a hppa a180c with a "DEC 21142/3", and fred on bugs@
with a sparc64 netra x1 "Davicom DM9102".


# 1.148 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.147 24-Nov-2015 mpi

The only network driver needing <net/if_types.h> is upl(4) for IFT_OTHER.


# 1.146 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.145 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.144 12-Sep-2015 miod

ifmedia64 fixes.


# 1.143 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


# 1.142 30-Aug-2015 deraadt

Track rom size, for free()


Revision tags: OPENBSD_5_8_BASE
# 1.141 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.140 13-Apr-2015 mpi

Now that if_input() set the receiving interface pointer on mbufs for us
there's no need to do it in m_devget(9).

Stop passing an ``ifp'' will help for upcoming interface pointer -> index
conversion.

While here remove unused ``ifp'' argument from m_clget(9) and kill two
birds^W layer violations in one commit.

ok henning@


# 1.139 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


# 1.138 13-Mar-2015 jasper

convert to if_input()

tested by landry@
ok mpi@


Revision tags: OPENBSD_5_7_BASE
# 1.137 23-Jan-2015 dlg

break after return is useless.


# 1.136 22-Dec-2014 tedu

unifdef INET


# 1.135 18-Nov-2014 brad

dc_init() calls dc_stop() and dc_reset() so remove some redundant calls
to those functions before dc_init() within dc_watchdog() and dc_intr().

ok deraadt@


Revision tags: OPENBSD_5_6_BASE
# 1.134 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.133 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.132 18-Apr-2014 henning

reaching into altq unconditionally (and w/o ifdef ALTQ) is bad, mmkay?


Revision tags: OPENBSD_5_5_BASE
# 1.131 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.130 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.129 02-Dec-2013 brad

Rewrite receive filter handling and ioctl bits. Fixes not being able to
bring the interface out of all multicast mode once a range of multicast
addresses has been found and missing multicast range checking for some
of the dc(4) variants.

Tested with 21143 (represents most of the dc(4) variants and boards) and
ADMtek based adapters. Untested with ASIX and Xircom based adapters.
Putting it in to move forward. I don't expect any issues with the
ASIX/Xircom adapters with the changes as is.

ok naddy@


# 1.128 20-Nov-2013 mpi

Instead of comparing the lower and higher addresses of all the multicast
entries to decide if the IFF_ALLMULTI flag should be set, check if there
is at least one real range between them.

Tested by naddy@


# 1.127 21-Aug-2013 dlg

get rid of the copy argument in m_devget that let you provide an
alternative to bcopy since noone uses it.

while there use memcpy instead of bcopy because we know the memory cannot
overlap.

ok henning@ matthew@ mikeb@ deraadt@


# 1.126 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.125 29-Nov-2012 brad

Remove setting an initial assumed baudrate upon driver attach which is not
necessarily correct, there might not even be a link when attaching.

ok mikeb@ reyk@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.124 07-Jul-2011 henning

use IF_LEN/IFQ_LEN to access and ifqueue's length field. ryan ok
with this nothing in the tree fiddles if ifqueue internals any more, of
course except if.c and if.h (and some altq)


# 1.123 21-Jun-2011 tedu

remove some unnecessary casts. ok blambert deraadt kettenis matthew


# 1.122 05-Mar-2011 kettenis

Wait until the DMA engine is stopped before unmapping buffers and descriptors.
Fixes DMA errors seen on sparc64.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.121 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.120 06-Sep-2010 deraadt

initialize rv to 0 in the activate function


# 1.119 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.118 30-Aug-2010 deraadt

activate functions, when they do not add value, should return the result of config_activate_children


# 1.117 27-Aug-2010 deraadt

Move the dc_pci_activate function to dc.c, and mangle it up with some of
the gunk in dc_powerhook. Then make dc_powerhook just call it
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.116 05-Aug-2010 deraadt

ca_activate function for suspend/resume; tested by mlarkin on a
Davicom DM9102. (bit of noise on suspend or resume, but that can be
dealt with later)


# 1.115 02-Jul-2010 blambert

timeout_add -> timeout_add_msec

ok krw@


# 1.114 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.113 15-Oct-2009 deraadt

Add detach support to a few more drivers, and in others do the neccessary
operations in the detach function in the right order. Also ensure that the
interrupt handlers not trust registers that go away.
read over very carefully by dms, tested by me


# 1.112 10-Aug-2009 deraadt

More cases of shutdown hooks not needed after card is already stopped. In
these cases the xxstop function is a bit more complicated and has a flag of
some sort, but the use of that flag does not matter; DMA is already ceased
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.111 26-Jun-2009 deraadt

If we are going to move to the eeprom-based MAC address finding instead of
CIS-based... some newer devices have the MAC address at offset 8 instead of
offset 3. But we can tell by the first three octets, Intel says.


# 1.110 26-Jun-2009 deraadt

Using information gleamed from the FreeBSD driver, change the MAC address
reading to use the eeprom instead of CIS, and then the Xircom Cardbus cards
can work in the expresscard adaptor, as pci devices.
ok jsg


# 1.109 02-Jun-2009 jsg

make dc at pci detachable; untested.


Revision tags: OPENBSD_4_5_BASE
# 1.108 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.107 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.106 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


# 1.105 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.104 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.103 12-Sep-2008 brad

Some fixes for dc_txeof()..
- Don't reload the watchdog timer in case there are still unhandled
descriptors.
- Don't clear IFF_OACTIVE unless there are at least 6 free TX
descriptors. The function dc_encap() will bail if there are
only 5 or fewer free TX descriptors, causing dc_start() to
abort so it makes no sense to pretend we could process mbufs
again when in fact we can't.
- Always assign idx to sc->dc_cdata.dc_tx_cons; it doesn't make
much sense to exclude the idx == sc->dc_cdata.dc_tx_cons case.

From FreeBSD


# 1.102 11-Sep-2008 brad

ANSI function declarations.


# 1.101 11-Sep-2008 brad

For chips with a broken DC_ISR_RX_STATE which never signals
stopped nor the waiting state and also no other means to check
whether the receiver is idle, we have no choice but to call
mii_tick unconditionally even in the case of the DC_REDUCED_MII_POLL
handling as far as the RX side is concerned. This isn't necessarily
worse than checking whether RX is idle though because unlike as
with TX we're racing with the hardware, which might receive packets
any time while we poll the MII, anyway. Fixes the use of trunk(4)
with the affected interfaces.

From FreeBSD


# 1.100 03-Sep-2008 brad

In dc_setcfg() suppress printing a warning when forcing the receiver
and transmitter to idle state times out for chips where the status
bits in question never change (observed in detail with DM9102A) and
therefore the warning would highly likely be a false positive.

From FreeBSD


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.99 26-Nov-2007 brad

print the comma before the MAC address string in dc_attach() instead of the
PCI front end attach function. This corrects the dmesg output for CardBus
adapters and ensures proper dmesg output if an error occurs in dc_attach().

ok dlg@


# 1.98 01-Oct-2007 krw

More easy bzero() -> M_ZERO. Use 'p = malloc(sizeof(*p) ...'.


Revision tags: OPENBSD_4_2_BASE
# 1.97 08-May-2007 deraadt

dc_detach() is only used by cardbus code, so move it there; ok jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.96 10-Aug-2006 brad

- eliminate re-initialization's when adding IP addresses.
- simplify ioctl handler.


# 1.95 22-May-2006 krw

Attach routines can fail before calling *hook_establish(), and they
often rely on the detach routine for cleanup. So be consistant and
careful by checking for a NULL hook before calling *hook_disestablish
in detach routines.

ok mickey@ brad@ dlg@


# 1.94 07-May-2006 brad

- Return if there is nothing to do in the interrupt handler.
- Check for IFF_RUNNING in the interrupt loop.


# 1.93 23-Apr-2006 kettenis

Make code path for ADMTek variant endian-safe; fixes dc(4) on macppc.
ok brad@


# 1.92 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


Revision tags: OPENBSD_3_9_BASE
# 1.91 28-Jan-2006 brad

remove 2 printf's from dc_coal() too.


# 1.90 28-Jan-2006 brad

remove printf's from dc_newbuf().


# 1.89 07-Nov-2005 brad

splimp -> splnet


Revision tags: OPENBSD_3_8_BASE
# 1.88 25-Jun-2005 brad

re-add ASIX check lost in rev 1.77


# 1.87 23-Jun-2005 brad

clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.


# 1.86 22-May-2005 martin

ALTQ cleanout

ok brad@


# 1.85 22-May-2005 brad

add power hook


# 1.84 30-Apr-2005 brad

try to drain send queue if we lose link during heavy transmit
activity instead of letting it sit and return 'no buffer available'
errors.


# 1.83 23-Apr-2005 brad

- always accept VLAN-sized frames
- support setting the MTU


# 1.82 23-Apr-2005 brad

Fix newer Xircom CBE2-100 cards.

We have to enable the connection to the MII first. Doing so fixes the
problem cards without breaking the older, working cards.

From FreeBSD


# 1.81 31-Mar-2005 brad

- add support for reading Xircom's EEPROM
- sync dc_mii_readreg()

From FreeBSD


Revision tags: OPENBSD_3_7_BASE
# 1.80 15-Jan-2005 brad

make sure interface is in RUNNING state before touching the multicast filters

From NetBSD

NetBSD PR 27678 for details

ok mcbride@


# 1.79 14-Jan-2005 brad

rev 1.63

Avoid an unnecessary copy of a packet if it is already in a single mbuf.
Introduce an additional device flag for those NICs which require the
transmit buffers to be aligned to 32-bit boundaries.

From FreeBSD


# 1.78 08-Jan-2005 brad

rev 1.125

Don't read the MAC address from a copy of the EEPROM in the softc
that has been recorded earlier and overwrite it again later by
reading it directly from the EEPROM again.

Read the MAC address from the PAR0/PAR1 registers instead, which
are autoloaded on reboot.

From FreeBSD

Thanks to David Snyder <dasnyderx at yahoo dot com> for testing on
a AN983 based card which used to come up with a MAC address of
ff:ff:ff:ff:ff:ff.


# 1.77 17-Dec-2004 brad

add missing braces.

From FreeBSD


# 1.76 02-Dec-2004 brad

rev 1.126

Ignore CSR13, CSR14, CSR15 'Media Specific Data' registers
for 21143 based cards which use SIA mode.

This fixes 10mbit mode for ZNYX ZX346Q cards and other
21143 based cards.

rev 1.108

Only use a SIA/SYM media info block if no MII block is detected.
The submitter of PR 32118 told me that this patch also fixes autoselecting
for znyx 4 port cards (10baseT, 100baseTX did work already).

From FreeBSD

ok deraadt@


# 1.75 28-Nov-2004 brad

rev 1.74

Fix if_timer logic to make sure that there is always a timeout
pending if there are packets queued for transmission.

From FreeBSD

ok deraadt@


# 1.74 16-Nov-2004 brad

if_dc.c rev 1.56

Do not call mii_pollstat() from within device tick routines; the status
information is updated by mii_tick().

dcphy.c rev 1.13

Work around an Intel 21143 chip bug.

Rev 1.56 of if_dc.c removed calls to mii_pollstat() from the dc_tick()
routine. dc_tick() is called regularly to detect link up and link down
status, especially when autonegotiating.

The expectation was that mii_tick() (which is still called from dc_tick())
would update status information automatically in all cases where it would
be sensible to do so.

Unfortunately, with authentic 21143 chips this is not the case, and
the driver never successfully autonegotiates. This is because (despite
what it says in the 21143 manual) the chip always claims that link is not
present while the autonegotiation enable bit is set. Autonegotation takes
place and succeeds, but the driver tests the link bits before it switches
off the autonegotiation enable bit, and success is not recognised.

The simplest solution is to call dcphy_status() more often for MII_TICK
calls by dropping out of the switch statement instead of exiting when
we are autonegotiating and link appears to not be present. When
autonegotiation succeeds, dcphy_status() will note the speed and fdx/hdx
state and turn off the autonegotiation enable bit. The next call to
dcphy_status() will notice that link is present, and the dc driver code
will be notified.

Macronix chips also use this code, but implement link detection as
described in the manual, and hence don't need this patch. However, tests
on a Macronix 98715AEC-C show that it does not adversely affect them.

From FreeBSD

ok deraadt@


# 1.73 29-Oct-2004 brad

rev 1.78

Enable the automatic TX underrun recovery for the ADMtek chips.
This solves cvsup update on my laptop which aborts after a while
without this patch.

rev 1.79

Fix the support for the AN985/983 chips, which do not set the
RXSTATE to STOPPED, but to WAIT. This should fix hangs which
could only be solved by replugging the cable.

From FreeBSD

Thanks to C. Bensend <benny at bennyvision dot com> for testing.


# 1.72 14-Oct-2004 brad

rev 1.47

Add a check in the interrupt service routine to return quickly in
case there is nothing to do. This happens normally when the card shares
the interrupt line with other devices.

This code saves a couple of microseconds per interrupt even on a
fast CPU. You normally would not care, except under heavy tinygram
traffic where you can have some 50-100.000 interrupts per second...

rev 1.51

Patch to allow TX underrun handling without issuing a complete
chip reset. Just temporarily turn off the transmitter instead.

From FreeBSD

ok mcbride@
tested by mcbride@, jaredy@, marco@, grange@, <harding at motd dot ca>


# 1.71 06-Oct-2004 brad

typo


# 1.70 06-Oct-2004 brad

Enable round-robin arbitration between transmit and receive unit
in the 21143, instead of giving priority to the receive unit.
This gives a 10-15% performance improvement in the forwarding rate
under heavy load.

From FreeBSD

ok mcbride@ nick@ deraadt@


# 1.69 28-Sep-2004 brad

Use ETHER_MIN_LEN/ETHER_MAX_DIX_LEN


# 1.68 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


Revision tags: OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B
# 1.67 31-May-2004 mcbride

multicast cleanups:
- get rid of hand rolled crc32 logic, use ether_crc32_{le,be}
- accept all multicast if a range is encountered


# 1.66 15-Apr-2004 mickey

user bus_dmamap_load_mbuf and set rcvif on receive


Revision tags: OPENBSD_3_5_BASE
# 1.65 21-Oct-2003 jmc

typos from Tom Cosgrove;

Tom: I did not commit a couple of your changes.

i did not include some punctuation fixes (full stops, etc.)
mnemorable -> mnemonic: i decided memorable was probably better
instrunctions -> instruction: i kept the plural


# 1.64 29-Sep-2003 mickey

add more dmamap_sync()s where appropriate modify loops to insure proper syncing; jason@ testing


# 1.63 25-Sep-2003 mickey

no need for a redundant check; from form@ and jason ok


Revision tags: OPENBSD_3_4_BASE
# 1.62 28-Aug-2003 mickey

fix bzero size; from pechkin


# 1.61 16-Jun-2003 mickey

be more sane w/ byte swapping and leave the le archs at the same behaviour and give be archs a better chance at getting the correct mac address as tested on the mac and hppa where mac has an additional bug w/ the phy bit still remaining and hppa seems fine; jason@ ok


# 1.60 20-May-2003 henning

AN983 endian issue; from FreeBSD via PR 3263 with minor style fixes by me

ok jason@


Revision tags: UBC_SYNC_A
# 1.59 17-May-2003 jason

fix up the media handling for the intel based MACs. Also hack around a
bug in the Momenco firmware on the Leopard-V, which now has one port
working.


# 1.58 29-Apr-2003 jason

grr... %s, not dc%s


# 1.57 29-Apr-2003 jason

- remove last vestige of "old autoconf": dc_unit is dead, long live dv_xname
- remove a bunch of #if 0 stuff (most of which referred to dc_unit, grr)
- delay a bzero until necessary


# 1.56 29-Apr-2003 jason

KNF


Revision tags: OPENBSD_3_3_BASE
# 1.55 25-Feb-2003 tedu

remove redundant check.

ok henning@


# 1.54 31-Jan-2003 deraadt

more quiet


Revision tags: UBC_SYNC_B
# 1.53 21-Oct-2002 henning

ugly hack to make the 21145 work without manual media setting.

many many many thanks to nick@, who booted no less then 8 kernels for me today
while hacking on that (and this includes going downstairs to the basement
and up again 8 times...)

ok jason@


# 1.52 20-Oct-2002 henning

add support for intel 21145
This chip is some strange abnormal 21143 variant. It really only works with
10 MBit/s halfduplex only and autonegotiation is totally broken in hardware.
Should also have a HomePNA phy, but we don't support that.
for now requires and explicit "media 10BaseT".
if anybody has such a chip please mail me.

nick@ is the only one who has the hardware and did an incredible amount of
testing. Thanks for all the help, Nick!

some hints and ok jason@


Revision tags: OPENBSD_3_2_BASE
# 1.51 05-Jul-2002 aaron

Remove an unused #define (belongs only in the PCI attachment source file).


# 1.50 09-Jun-2002 todd

a step towards consistancy; in general:
'struct arpcom foo' -> 'struct arpcom sc_arpcom'
ok itojun@


# 1.49 09-Jun-2002 nordin

Handle out of memory gracefully. ok jason@


# 1.48 18-Apr-2002 jason

add support for Conexant LANfinity RS7112; based on patch from Maurice Nonnekes <maurice@amaze.nl> based on FreeBSD (only minor surgery necessary)


Revision tags: OPENBSD_3_1_BASE
# 1.47 14-Mar-2002 millert

First round of __P removal in sys


# 1.46 17-Feb-2002 deraadt

drivers may not be noisy


# 1.45 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


Revision tags: UBC_BASE
# 1.44 13-Dec-2001 nate

branches: 1.44.2;
Fix old alpha bug recently triggered by conversion to busdma.


# 1.43 08-Dec-2001 jason

Go ahead and fix the xircom filter setup to work on big endian too (untested, but it's pretty similiar to the tested 21143 case).


# 1.42 08-Dec-2001 jason

use htole32() on the data going into the setup frame for the dc_setfilt_21143() case at least.
XXX I'm looking at the other filter setups and they appear to need work for BE too.


# 1.41 06-Dec-2001 jason

add bus_dmamap_sync()'s on the descriptors too
(with all this, my Netra X1 is up and running with an NFS root)


# 1.40 06-Dec-2001 jason

a few more bus_dmamap_sync()'s and some borrowed setup frame macros from NetBSD, and RX works on sparc64.


# 1.39 06-Dec-2001 jason

enough bus_dmamap_sync() and htole()/letoh() to get TX working on sparc64.
ALso, get the MAC address from myetheraddr() instead of trying to use the eeprom on sparc64.


# 1.38 06-Dec-2001 jason

vtophys, R.I.P. (tx now uses bus_dma)


# 1.37 06-Dec-2001 jason

move rx handling over to bus_dma... that just leaves one vtophys() in tx.


# 1.36 06-Dec-2001 jason

move the setup buffer and pad into a bus_dma alloced area
(current score: 2 vtophys calls to go...)


# 1.35 06-Dec-2001 jason

Checkpoint bus_dma work in progress:
- descriptor lists are now bus_dma allocated and manipulated
(for those keeping score: 6 vtophys dead, 4 to go)


# 1.34 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.33 22-Aug-2001 aaron

Support more dc(4) CardBus devices, including the AN985-based Linksys PCMPC200
10/100 CardBus Ethernet adapter (thanks to beck@ for the donation).


# 1.32 12-Aug-2001 mickey

remove some of the redundant vm includes


# 1.31 03-Aug-2001 chris

Set IFCAP_VLAN_MTU, this driver already allows vlan-size frames


# 1.30 02-Jul-2001 jason

these don't depend on pci register defs


# 1.29 27-Jun-2001 kjc

ALTQ'ify network drivers.
- use the new queue macros.
- use IFQ_POLL() to peek at the next packet.
- use IFQ_IS_EMPTY() for empty check.
- drivers should always check if (m == NULL) after IFQ_DEQUEUE(),
since it could return NULL even when IFQ_IS_EMPTY() is FALSE
under rate-limiting.
- drivers are supposed to call if_start from tx complete interrupts
(in order to trigger the next dequeue under rate-limiting).


# 1.28 23-Jun-2001 fgsch

ether_input_mbuf().


Revision tags: OPENBSD_2_9_BASE
# 1.27 13-Apr-2001 aaron

branches: 1.27.4;
Oops, remove an unrelated debugging #if 0.


# 1.26 13-Apr-2001 aaron

Disestablish the shutdownhook on detach.


# 1.25 06-Apr-2001 aaron

- For CardBus 21143 cards, parse the SROM. Makes my SMC EZ CardBus 10/100 work.
- General cleanup in the dc CardBus attachment.
- Split detach up into bus-dependent and bus-independent parts.
- Some function and variable renaming for consistency.


# 1.24 20-Feb-2001 mickey

for ethernet ifaces attach bpf from ether_ifattach; jason@, aaron@, itojun@ ok


# 1.23 09-Feb-2001 art

Bad aaron. Broke alpha.


# 1.22 09-Feb-2001 aaron

Sync with FreeBSD:
- Bugfix: 'reg' variable in dc_apply_fixup() needs to be u_int32_t.
- Bugfix: bzero() mediainfo structures after allocation.
- Call dc_apply_fixup() in dc_setcfg() for the MII case.
- Conditionalize some code in miibus_{read,write}reg to make non-mx98713
cards happy.


# 1.21 09-Feb-2001 aaron

Add support for parsing the media blocks from the SROM on the 21143 adapters.
These changes should make the driver work with the built-in Ethernet on the
Alpha Miata machines. From FreeBSD.

To make sure I didn't break anything (and as a general test), I tested the
modified driver with the following dc(4) variants: Macronix PMAC 98715,
Lite-On PNIC, Lite-On PNIC-II, ADMtek AL981, and ADMtek AN983.


# 1.20 16-Nov-2000 aaron

Note support for Accton EN1217 and EN2242 Ethernet adapters.


Revision tags: OPENBSD_2_8_BASE
# 1.19 30-Oct-2000 aaron

Match the Macronix 98727/98732 chips.


# 1.18 26-Oct-2000 aaron

Add support for Xircom X3201-based CardBus Ethernet cards. Tested successfully
on four different models, including the CBEM56G-100, RBE-100 RealPort, and the
RBEM56G-100 RealPort. This commit adds support only for the LAN components; the
modem is not configured yet. Detach support to come. Based on work from
FreeBSD, mickey@, nate@, and myself.


# 1.17 18-Oct-2000 aaron

Sigh. According to the ASIX data sheets, these boards don't even have RX
or TX state registers (these bits are reserved). So instead, don't do
mii_tick() at all for ASIX boards, since we can't seem to figure out how
to call it at just the right time. Hopefully this will be a temporary hack
until a better solution is found.


# 1.16 17-Oct-2000 aaron

Undo the incorrect fix for my ASIX 88141. Instead of just relying on tx_cnt,
now we check the TX state in the ISR to make sure we are not transmitting
when we run mii_tick(). Based on a suggestion by Bill Paul. The dc driver
should now be ready for some heavy pre-2.8 testing.


# 1.15 16-Oct-2000 aaron

Use mii_attach() directly instead of mii_phy_probe().


# 1.14 11-Oct-2000 aaron

For some reason, with the eeprom width detection code mickey added awhile ago,
special care for the ADMtek AN983 (Centaur-P) chip is no longer needed. This
fixes Ethernet address reading for these cards. Thanks to todd@ for testing.


# 1.13 28-Sep-2000 aaron

If this is a Davicom DM9102A and we're enabling the homePNA link, force
dc_link to 1 and don't activate the tick routine. Without this, dc_start()
always thinks the link is down and never transmits in homePNA mode; from
FreeBSD.


# 1.12 13-Sep-2000 aaron

Sync with FreeBSD. Finally make the OpenBSD-specific changes necessary to make
non-MII 21143-based cards work. The sync just fixes the LED handling on these
kinds of adapters.


# 1.11 07-Sep-2000 aaron

Indentation fix.


# 1.10 26-Aug-2000 aaron

Revert a minor FreeBSD tweak that tends to freeze my machine solid after
large amounts of data transfer (ASIX 88141 card).


# 1.9 08-Aug-2000 aaron

Make fix for preserving LED settings conditional on presence of an Intel
21143 chip; from FreeBSD.


# 1.8 02-Aug-2000 aaron

Sync with FreeBSD. Summary of changes:

- Add support for Accton EN1217 Ethernet adapters.
- Fix problems with LEDs on some cards when clearing the jabber disable bit.
- Handle new Macronix chips whose multicast hash tables are only 128 bits.
- Fix timing issues during autonegotiation with Macronix and PNIC II.


# 1.7 02-Aug-2000 aaron

Don't print out the eeprom width.


# 1.6 02-Aug-2000 peter

Add support for accepting packets up to 4 octets larger than the
interface MTU IFF vlans are enabled.

Additional logic should be added by someone who understand 802.1q to
test if this oversize packet is actually a 802.1q encapsulated, and
reject others.

Fix as per kernel/1328.


# 1.5 21-Jul-2000 mickey

convert to new timeouts; art@ ok


# 1.4 12-Jun-2000 mickey

remove debugging prom dump, sorry


# 1.3 12-Jun-2000 mickey

eeprom width detection code.
idea from netbsd tulip driver.
there is problem w/ an983 card, but aaron@ said he'll work it out.
aaron@ & jason@ ok.


# 1.2 12-Jun-2000 aaron

Fix ADMtek identity crisis.


Revision tags: OPENBSD_2_7_BASE
# 1.1 18-Apr-2000 jason

branches: 1.1.2;
split dc driver into bus dependent and bus independent (pci) parts
(cardbus to come later).


# 1.156 10-Nov-2023 bluhm

Make ifq and ifiq interface MP safe.

Rename ifq_set_maxlen() to ifq_init_maxlen(). This function neither
uses WRITE_ONCE() nor a mutex and is called before the ifq mutex
is initialized. The new name expresses that it should be used only
during interface attach when there is no concurrency.

Protect ifq_len(), ifq_empty(), ifiq_len(), and ifiq_empty() with
READ_ONCE(). They can be used without lock as they only read a
single integer.

OK dlg@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.155 22-Feb-2022 guenther

Delete unnecessary #includes of <sys/domain.h> and/or <sys/protosw.h>

net/if_pppx.c pointed out by jsg@
ok gnezdo@ deraadt@ jsg@ mpi@ millert@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.154 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.153 10-Jul-2020 patrick

Change users of IFQ_DEQUEUE(), IFQ_ENQUEUE() and IFQ_LEN() to use the
"new" API.

ok dlg@ tobhe@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.152 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.151 04-May-2016 kettenis

Use BUS_DMA_OVERRUN to cope with the broken DMA engine of the Davicom DM9102
found on some Sun sparc64 machines. This fixes the unrecoverable DMA errors
people have been seeing ever since dlg@ made changes to the pool code that
changes the memory layout.


# 1.150 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.149 28-Nov-2015 dlg

rework dc_start and dc_encap to take advantage of m_defrag.

if the chip needs coalesced packages in tx, set the tx dmamaps up
to only use a single dma descriptor. use m_defrag when bus_dmamap_load_mbuf
returns EFBIG rather than copying the packet to a separate mbuf
with hand rolled code in dc_coal. that in turn makes the ifq_deq_begin,
ifq_deq_commit, and ifq_deq_rollback handling more straightforward.

tested by me on a hppa a180c with a "DEC 21142/3", and fred on bugs@
with a sparc64 netra x1 "Davicom DM9102".


# 1.148 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.147 24-Nov-2015 mpi

The only network driver needing <net/if_types.h> is upl(4) for IFT_OTHER.


# 1.146 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.145 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.144 12-Sep-2015 miod

ifmedia64 fixes.


# 1.143 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


# 1.142 30-Aug-2015 deraadt

Track rom size, for free()


Revision tags: OPENBSD_5_8_BASE
# 1.141 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.140 13-Apr-2015 mpi

Now that if_input() set the receiving interface pointer on mbufs for us
there's no need to do it in m_devget(9).

Stop passing an ``ifp'' will help for upcoming interface pointer -> index
conversion.

While here remove unused ``ifp'' argument from m_clget(9) and kill two
birds^W layer violations in one commit.

ok henning@


# 1.139 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


# 1.138 13-Mar-2015 jasper

convert to if_input()

tested by landry@
ok mpi@


Revision tags: OPENBSD_5_7_BASE
# 1.137 23-Jan-2015 dlg

break after return is useless.


# 1.136 22-Dec-2014 tedu

unifdef INET


# 1.135 18-Nov-2014 brad

dc_init() calls dc_stop() and dc_reset() so remove some redundant calls
to those functions before dc_init() within dc_watchdog() and dc_intr().

ok deraadt@


Revision tags: OPENBSD_5_6_BASE
# 1.134 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.133 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.132 18-Apr-2014 henning

reaching into altq unconditionally (and w/o ifdef ALTQ) is bad, mmkay?


Revision tags: OPENBSD_5_5_BASE
# 1.131 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.130 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.129 02-Dec-2013 brad

Rewrite receive filter handling and ioctl bits. Fixes not being able to
bring the interface out of all multicast mode once a range of multicast
addresses has been found and missing multicast range checking for some
of the dc(4) variants.

Tested with 21143 (represents most of the dc(4) variants and boards) and
ADMtek based adapters. Untested with ASIX and Xircom based adapters.
Putting it in to move forward. I don't expect any issues with the
ASIX/Xircom adapters with the changes as is.

ok naddy@


# 1.128 20-Nov-2013 mpi

Instead of comparing the lower and higher addresses of all the multicast
entries to decide if the IFF_ALLMULTI flag should be set, check if there
is at least one real range between them.

Tested by naddy@


# 1.127 21-Aug-2013 dlg

get rid of the copy argument in m_devget that let you provide an
alternative to bcopy since noone uses it.

while there use memcpy instead of bcopy because we know the memory cannot
overlap.

ok henning@ matthew@ mikeb@ deraadt@


# 1.126 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.125 29-Nov-2012 brad

Remove setting an initial assumed baudrate upon driver attach which is not
necessarily correct, there might not even be a link when attaching.

ok mikeb@ reyk@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.124 07-Jul-2011 henning

use IF_LEN/IFQ_LEN to access and ifqueue's length field. ryan ok
with this nothing in the tree fiddles if ifqueue internals any more, of
course except if.c and if.h (and some altq)


# 1.123 21-Jun-2011 tedu

remove some unnecessary casts. ok blambert deraadt kettenis matthew


# 1.122 05-Mar-2011 kettenis

Wait until the DMA engine is stopped before unmapping buffers and descriptors.
Fixes DMA errors seen on sparc64.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.121 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.120 06-Sep-2010 deraadt

initialize rv to 0 in the activate function


# 1.119 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.118 30-Aug-2010 deraadt

activate functions, when they do not add value, should return the result of config_activate_children


# 1.117 27-Aug-2010 deraadt

Move the dc_pci_activate function to dc.c, and mangle it up with some of
the gunk in dc_powerhook. Then make dc_powerhook just call it
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.116 05-Aug-2010 deraadt

ca_activate function for suspend/resume; tested by mlarkin on a
Davicom DM9102. (bit of noise on suspend or resume, but that can be
dealt with later)


# 1.115 02-Jul-2010 blambert

timeout_add -> timeout_add_msec

ok krw@


# 1.114 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.113 15-Oct-2009 deraadt

Add detach support to a few more drivers, and in others do the neccessary
operations in the detach function in the right order. Also ensure that the
interrupt handlers not trust registers that go away.
read over very carefully by dms, tested by me


# 1.112 10-Aug-2009 deraadt

More cases of shutdown hooks not needed after card is already stopped. In
these cases the xxstop function is a bit more complicated and has a flag of
some sort, but the use of that flag does not matter; DMA is already ceased
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.111 26-Jun-2009 deraadt

If we are going to move to the eeprom-based MAC address finding instead of
CIS-based... some newer devices have the MAC address at offset 8 instead of
offset 3. But we can tell by the first three octets, Intel says.


# 1.110 26-Jun-2009 deraadt

Using information gleamed from the FreeBSD driver, change the MAC address
reading to use the eeprom instead of CIS, and then the Xircom Cardbus cards
can work in the expresscard adaptor, as pci devices.
ok jsg


# 1.109 02-Jun-2009 jsg

make dc at pci detachable; untested.


Revision tags: OPENBSD_4_5_BASE
# 1.108 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.107 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.106 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


# 1.105 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.104 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.103 12-Sep-2008 brad

Some fixes for dc_txeof()..
- Don't reload the watchdog timer in case there are still unhandled
descriptors.
- Don't clear IFF_OACTIVE unless there are at least 6 free TX
descriptors. The function dc_encap() will bail if there are
only 5 or fewer free TX descriptors, causing dc_start() to
abort so it makes no sense to pretend we could process mbufs
again when in fact we can't.
- Always assign idx to sc->dc_cdata.dc_tx_cons; it doesn't make
much sense to exclude the idx == sc->dc_cdata.dc_tx_cons case.

From FreeBSD


# 1.102 11-Sep-2008 brad

ANSI function declarations.


# 1.101 11-Sep-2008 brad

For chips with a broken DC_ISR_RX_STATE which never signals
stopped nor the waiting state and also no other means to check
whether the receiver is idle, we have no choice but to call
mii_tick unconditionally even in the case of the DC_REDUCED_MII_POLL
handling as far as the RX side is concerned. This isn't necessarily
worse than checking whether RX is idle though because unlike as
with TX we're racing with the hardware, which might receive packets
any time while we poll the MII, anyway. Fixes the use of trunk(4)
with the affected interfaces.

From FreeBSD


# 1.100 03-Sep-2008 brad

In dc_setcfg() suppress printing a warning when forcing the receiver
and transmitter to idle state times out for chips where the status
bits in question never change (observed in detail with DM9102A) and
therefore the warning would highly likely be a false positive.

From FreeBSD


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.99 26-Nov-2007 brad

print the comma before the MAC address string in dc_attach() instead of the
PCI front end attach function. This corrects the dmesg output for CardBus
adapters and ensures proper dmesg output if an error occurs in dc_attach().

ok dlg@


# 1.98 01-Oct-2007 krw

More easy bzero() -> M_ZERO. Use 'p = malloc(sizeof(*p) ...'.


Revision tags: OPENBSD_4_2_BASE
# 1.97 08-May-2007 deraadt

dc_detach() is only used by cardbus code, so move it there; ok jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.96 10-Aug-2006 brad

- eliminate re-initialization's when adding IP addresses.
- simplify ioctl handler.


# 1.95 22-May-2006 krw

Attach routines can fail before calling *hook_establish(), and they
often rely on the detach routine for cleanup. So be consistant and
careful by checking for a NULL hook before calling *hook_disestablish
in detach routines.

ok mickey@ brad@ dlg@


# 1.94 07-May-2006 brad

- Return if there is nothing to do in the interrupt handler.
- Check for IFF_RUNNING in the interrupt loop.


# 1.93 23-Apr-2006 kettenis

Make code path for ADMTek variant endian-safe; fixes dc(4) on macppc.
ok brad@


# 1.92 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


Revision tags: OPENBSD_3_9_BASE
# 1.91 28-Jan-2006 brad

remove 2 printf's from dc_coal() too.


# 1.90 28-Jan-2006 brad

remove printf's from dc_newbuf().


# 1.89 07-Nov-2005 brad

splimp -> splnet


Revision tags: OPENBSD_3_8_BASE
# 1.88 25-Jun-2005 brad

re-add ASIX check lost in rev 1.77


# 1.87 23-Jun-2005 brad

clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.


# 1.86 22-May-2005 martin

ALTQ cleanout

ok brad@


# 1.85 22-May-2005 brad

add power hook


# 1.84 30-Apr-2005 brad

try to drain send queue if we lose link during heavy transmit
activity instead of letting it sit and return 'no buffer available'
errors.


# 1.83 23-Apr-2005 brad

- always accept VLAN-sized frames
- support setting the MTU


# 1.82 23-Apr-2005 brad

Fix newer Xircom CBE2-100 cards.

We have to enable the connection to the MII first. Doing so fixes the
problem cards without breaking the older, working cards.

From FreeBSD


# 1.81 31-Mar-2005 brad

- add support for reading Xircom's EEPROM
- sync dc_mii_readreg()

From FreeBSD


Revision tags: OPENBSD_3_7_BASE
# 1.80 15-Jan-2005 brad

make sure interface is in RUNNING state before touching the multicast filters

From NetBSD

NetBSD PR 27678 for details

ok mcbride@


# 1.79 14-Jan-2005 brad

rev 1.63

Avoid an unnecessary copy of a packet if it is already in a single mbuf.
Introduce an additional device flag for those NICs which require the
transmit buffers to be aligned to 32-bit boundaries.

From FreeBSD


# 1.78 08-Jan-2005 brad

rev 1.125

Don't read the MAC address from a copy of the EEPROM in the softc
that has been recorded earlier and overwrite it again later by
reading it directly from the EEPROM again.

Read the MAC address from the PAR0/PAR1 registers instead, which
are autoloaded on reboot.

From FreeBSD

Thanks to David Snyder <dasnyderx at yahoo dot com> for testing on
a AN983 based card which used to come up with a MAC address of
ff:ff:ff:ff:ff:ff.


# 1.77 17-Dec-2004 brad

add missing braces.

From FreeBSD


# 1.76 02-Dec-2004 brad

rev 1.126

Ignore CSR13, CSR14, CSR15 'Media Specific Data' registers
for 21143 based cards which use SIA mode.

This fixes 10mbit mode for ZNYX ZX346Q cards and other
21143 based cards.

rev 1.108

Only use a SIA/SYM media info block if no MII block is detected.
The submitter of PR 32118 told me that this patch also fixes autoselecting
for znyx 4 port cards (10baseT, 100baseTX did work already).

From FreeBSD

ok deraadt@


# 1.75 28-Nov-2004 brad

rev 1.74

Fix if_timer logic to make sure that there is always a timeout
pending if there are packets queued for transmission.

From FreeBSD

ok deraadt@


# 1.74 16-Nov-2004 brad

if_dc.c rev 1.56

Do not call mii_pollstat() from within device tick routines; the status
information is updated by mii_tick().

dcphy.c rev 1.13

Work around an Intel 21143 chip bug.

Rev 1.56 of if_dc.c removed calls to mii_pollstat() from the dc_tick()
routine. dc_tick() is called regularly to detect link up and link down
status, especially when autonegotiating.

The expectation was that mii_tick() (which is still called from dc_tick())
would update status information automatically in all cases where it would
be sensible to do so.

Unfortunately, with authentic 21143 chips this is not the case, and
the driver never successfully autonegotiates. This is because (despite
what it says in the 21143 manual) the chip always claims that link is not
present while the autonegotiation enable bit is set. Autonegotation takes
place and succeeds, but the driver tests the link bits before it switches
off the autonegotiation enable bit, and success is not recognised.

The simplest solution is to call dcphy_status() more often for MII_TICK
calls by dropping out of the switch statement instead of exiting when
we are autonegotiating and link appears to not be present. When
autonegotiation succeeds, dcphy_status() will note the speed and fdx/hdx
state and turn off the autonegotiation enable bit. The next call to
dcphy_status() will notice that link is present, and the dc driver code
will be notified.

Macronix chips also use this code, but implement link detection as
described in the manual, and hence don't need this patch. However, tests
on a Macronix 98715AEC-C show that it does not adversely affect them.

From FreeBSD

ok deraadt@


# 1.73 29-Oct-2004 brad

rev 1.78

Enable the automatic TX underrun recovery for the ADMtek chips.
This solves cvsup update on my laptop which aborts after a while
without this patch.

rev 1.79

Fix the support for the AN985/983 chips, which do not set the
RXSTATE to STOPPED, but to WAIT. This should fix hangs which
could only be solved by replugging the cable.

From FreeBSD

Thanks to C. Bensend <benny at bennyvision dot com> for testing.


# 1.72 14-Oct-2004 brad

rev 1.47

Add a check in the interrupt service routine to return quickly in
case there is nothing to do. This happens normally when the card shares
the interrupt line with other devices.

This code saves a couple of microseconds per interrupt even on a
fast CPU. You normally would not care, except under heavy tinygram
traffic where you can have some 50-100.000 interrupts per second...

rev 1.51

Patch to allow TX underrun handling without issuing a complete
chip reset. Just temporarily turn off the transmitter instead.

From FreeBSD

ok mcbride@
tested by mcbride@, jaredy@, marco@, grange@, <harding at motd dot ca>


# 1.71 06-Oct-2004 brad

typo


# 1.70 06-Oct-2004 brad

Enable round-robin arbitration between transmit and receive unit
in the 21143, instead of giving priority to the receive unit.
This gives a 10-15% performance improvement in the forwarding rate
under heavy load.

From FreeBSD

ok mcbride@ nick@ deraadt@


# 1.69 28-Sep-2004 brad

Use ETHER_MIN_LEN/ETHER_MAX_DIX_LEN


# 1.68 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


Revision tags: OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B
# 1.67 31-May-2004 mcbride

multicast cleanups:
- get rid of hand rolled crc32 logic, use ether_crc32_{le,be}
- accept all multicast if a range is encountered


# 1.66 15-Apr-2004 mickey

user bus_dmamap_load_mbuf and set rcvif on receive


Revision tags: OPENBSD_3_5_BASE
# 1.65 21-Oct-2003 jmc

typos from Tom Cosgrove;

Tom: I did not commit a couple of your changes.

i did not include some punctuation fixes (full stops, etc.)
mnemorable -> mnemonic: i decided memorable was probably better
instrunctions -> instruction: i kept the plural


# 1.64 29-Sep-2003 mickey

add more dmamap_sync()s where appropriate modify loops to insure proper syncing; jason@ testing


# 1.63 25-Sep-2003 mickey

no need for a redundant check; from form@ and jason ok


Revision tags: OPENBSD_3_4_BASE
# 1.62 28-Aug-2003 mickey

fix bzero size; from pechkin


# 1.61 16-Jun-2003 mickey

be more sane w/ byte swapping and leave the le archs at the same behaviour and give be archs a better chance at getting the correct mac address as tested on the mac and hppa where mac has an additional bug w/ the phy bit still remaining and hppa seems fine; jason@ ok


# 1.60 20-May-2003 henning

AN983 endian issue; from FreeBSD via PR 3263 with minor style fixes by me

ok jason@


Revision tags: UBC_SYNC_A
# 1.59 17-May-2003 jason

fix up the media handling for the intel based MACs. Also hack around a
bug in the Momenco firmware on the Leopard-V, which now has one port
working.


# 1.58 29-Apr-2003 jason

grr... %s, not dc%s


# 1.57 29-Apr-2003 jason

- remove last vestige of "old autoconf": dc_unit is dead, long live dv_xname
- remove a bunch of #if 0 stuff (most of which referred to dc_unit, grr)
- delay a bzero until necessary


# 1.56 29-Apr-2003 jason

KNF


Revision tags: OPENBSD_3_3_BASE
# 1.55 25-Feb-2003 tedu

remove redundant check.

ok henning@


# 1.54 31-Jan-2003 deraadt

more quiet


Revision tags: UBC_SYNC_B
# 1.53 21-Oct-2002 henning

ugly hack to make the 21145 work without manual media setting.

many many many thanks to nick@, who booted no less then 8 kernels for me today
while hacking on that (and this includes going downstairs to the basement
and up again 8 times...)

ok jason@


# 1.52 20-Oct-2002 henning

add support for intel 21145
This chip is some strange abnormal 21143 variant. It really only works with
10 MBit/s halfduplex only and autonegotiation is totally broken in hardware.
Should also have a HomePNA phy, but we don't support that.
for now requires and explicit "media 10BaseT".
if anybody has such a chip please mail me.

nick@ is the only one who has the hardware and did an incredible amount of
testing. Thanks for all the help, Nick!

some hints and ok jason@


Revision tags: OPENBSD_3_2_BASE
# 1.51 05-Jul-2002 aaron

Remove an unused #define (belongs only in the PCI attachment source file).


# 1.50 09-Jun-2002 todd

a step towards consistancy; in general:
'struct arpcom foo' -> 'struct arpcom sc_arpcom'
ok itojun@


# 1.49 09-Jun-2002 nordin

Handle out of memory gracefully. ok jason@


# 1.48 18-Apr-2002 jason

add support for Conexant LANfinity RS7112; based on patch from Maurice Nonnekes <maurice@amaze.nl> based on FreeBSD (only minor surgery necessary)


Revision tags: OPENBSD_3_1_BASE
# 1.47 14-Mar-2002 millert

First round of __P removal in sys


# 1.46 17-Feb-2002 deraadt

drivers may not be noisy


# 1.45 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


Revision tags: UBC_BASE
# 1.44 13-Dec-2001 nate

branches: 1.44.2;
Fix old alpha bug recently triggered by conversion to busdma.


# 1.43 08-Dec-2001 jason

Go ahead and fix the xircom filter setup to work on big endian too (untested, but it's pretty similiar to the tested 21143 case).


# 1.42 08-Dec-2001 jason

use htole32() on the data going into the setup frame for the dc_setfilt_21143() case at least.
XXX I'm looking at the other filter setups and they appear to need work for BE too.


# 1.41 06-Dec-2001 jason

add bus_dmamap_sync()'s on the descriptors too
(with all this, my Netra X1 is up and running with an NFS root)


# 1.40 06-Dec-2001 jason

a few more bus_dmamap_sync()'s and some borrowed setup frame macros from NetBSD, and RX works on sparc64.


# 1.39 06-Dec-2001 jason

enough bus_dmamap_sync() and htole()/letoh() to get TX working on sparc64.
ALso, get the MAC address from myetheraddr() instead of trying to use the eeprom on sparc64.


# 1.38 06-Dec-2001 jason

vtophys, R.I.P. (tx now uses bus_dma)


# 1.37 06-Dec-2001 jason

move rx handling over to bus_dma... that just leaves one vtophys() in tx.


# 1.36 06-Dec-2001 jason

move the setup buffer and pad into a bus_dma alloced area
(current score: 2 vtophys calls to go...)


# 1.35 06-Dec-2001 jason

Checkpoint bus_dma work in progress:
- descriptor lists are now bus_dma allocated and manipulated
(for those keeping score: 6 vtophys dead, 4 to go)


# 1.34 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.33 22-Aug-2001 aaron

Support more dc(4) CardBus devices, including the AN985-based Linksys PCMPC200
10/100 CardBus Ethernet adapter (thanks to beck@ for the donation).


# 1.32 12-Aug-2001 mickey

remove some of the redundant vm includes


# 1.31 03-Aug-2001 chris

Set IFCAP_VLAN_MTU, this driver already allows vlan-size frames


# 1.30 02-Jul-2001 jason

these don't depend on pci register defs


# 1.29 27-Jun-2001 kjc

ALTQ'ify network drivers.
- use the new queue macros.
- use IFQ_POLL() to peek at the next packet.
- use IFQ_IS_EMPTY() for empty check.
- drivers should always check if (m == NULL) after IFQ_DEQUEUE(),
since it could return NULL even when IFQ_IS_EMPTY() is FALSE
under rate-limiting.
- drivers are supposed to call if_start from tx complete interrupts
(in order to trigger the next dequeue under rate-limiting).


# 1.28 23-Jun-2001 fgsch

ether_input_mbuf().


Revision tags: OPENBSD_2_9_BASE
# 1.27 13-Apr-2001 aaron

branches: 1.27.4;
Oops, remove an unrelated debugging #if 0.


# 1.26 13-Apr-2001 aaron

Disestablish the shutdownhook on detach.


# 1.25 06-Apr-2001 aaron

- For CardBus 21143 cards, parse the SROM. Makes my SMC EZ CardBus 10/100 work.
- General cleanup in the dc CardBus attachment.
- Split detach up into bus-dependent and bus-independent parts.
- Some function and variable renaming for consistency.


# 1.24 20-Feb-2001 mickey

for ethernet ifaces attach bpf from ether_ifattach; jason@, aaron@, itojun@ ok


# 1.23 09-Feb-2001 art

Bad aaron. Broke alpha.


# 1.22 09-Feb-2001 aaron

Sync with FreeBSD:
- Bugfix: 'reg' variable in dc_apply_fixup() needs to be u_int32_t.
- Bugfix: bzero() mediainfo structures after allocation.
- Call dc_apply_fixup() in dc_setcfg() for the MII case.
- Conditionalize some code in miibus_{read,write}reg to make non-mx98713
cards happy.


# 1.21 09-Feb-2001 aaron

Add support for parsing the media blocks from the SROM on the 21143 adapters.
These changes should make the driver work with the built-in Ethernet on the
Alpha Miata machines. From FreeBSD.

To make sure I didn't break anything (and as a general test), I tested the
modified driver with the following dc(4) variants: Macronix PMAC 98715,
Lite-On PNIC, Lite-On PNIC-II, ADMtek AL981, and ADMtek AN983.


# 1.20 16-Nov-2000 aaron

Note support for Accton EN1217 and EN2242 Ethernet adapters.


Revision tags: OPENBSD_2_8_BASE
# 1.19 30-Oct-2000 aaron

Match the Macronix 98727/98732 chips.


# 1.18 26-Oct-2000 aaron

Add support for Xircom X3201-based CardBus Ethernet cards. Tested successfully
on four different models, including the CBEM56G-100, RBE-100 RealPort, and the
RBEM56G-100 RealPort. This commit adds support only for the LAN components; the
modem is not configured yet. Detach support to come. Based on work from
FreeBSD, mickey@, nate@, and myself.


# 1.17 18-Oct-2000 aaron

Sigh. According to the ASIX data sheets, these boards don't even have RX
or TX state registers (these bits are reserved). So instead, don't do
mii_tick() at all for ASIX boards, since we can't seem to figure out how
to call it at just the right time. Hopefully this will be a temporary hack
until a better solution is found.


# 1.16 17-Oct-2000 aaron

Undo the incorrect fix for my ASIX 88141. Instead of just relying on tx_cnt,
now we check the TX state in the ISR to make sure we are not transmitting
when we run mii_tick(). Based on a suggestion by Bill Paul. The dc driver
should now be ready for some heavy pre-2.8 testing.


# 1.15 16-Oct-2000 aaron

Use mii_attach() directly instead of mii_phy_probe().


# 1.14 11-Oct-2000 aaron

For some reason, with the eeprom width detection code mickey added awhile ago,
special care for the ADMtek AN983 (Centaur-P) chip is no longer needed. This
fixes Ethernet address reading for these cards. Thanks to todd@ for testing.


# 1.13 28-Sep-2000 aaron

If this is a Davicom DM9102A and we're enabling the homePNA link, force
dc_link to 1 and don't activate the tick routine. Without this, dc_start()
always thinks the link is down and never transmits in homePNA mode; from
FreeBSD.


# 1.12 13-Sep-2000 aaron

Sync with FreeBSD. Finally make the OpenBSD-specific changes necessary to make
non-MII 21143-based cards work. The sync just fixes the LED handling on these
kinds of adapters.


# 1.11 07-Sep-2000 aaron

Indentation fix.


# 1.10 26-Aug-2000 aaron

Revert a minor FreeBSD tweak that tends to freeze my machine solid after
large amounts of data transfer (ASIX 88141 card).


# 1.9 08-Aug-2000 aaron

Make fix for preserving LED settings conditional on presence of an Intel
21143 chip; from FreeBSD.


# 1.8 02-Aug-2000 aaron

Sync with FreeBSD. Summary of changes:

- Add support for Accton EN1217 Ethernet adapters.
- Fix problems with LEDs on some cards when clearing the jabber disable bit.
- Handle new Macronix chips whose multicast hash tables are only 128 bits.
- Fix timing issues during autonegotiation with Macronix and PNIC II.


# 1.7 02-Aug-2000 aaron

Don't print out the eeprom width.


# 1.6 02-Aug-2000 peter

Add support for accepting packets up to 4 octets larger than the
interface MTU IFF vlans are enabled.

Additional logic should be added by someone who understand 802.1q to
test if this oversize packet is actually a 802.1q encapsulated, and
reject others.

Fix as per kernel/1328.


# 1.5 21-Jul-2000 mickey

convert to new timeouts; art@ ok


# 1.4 12-Jun-2000 mickey

remove debugging prom dump, sorry


# 1.3 12-Jun-2000 mickey

eeprom width detection code.
idea from netbsd tulip driver.
there is problem w/ an983 card, but aaron@ said he'll work it out.
aaron@ & jason@ ok.


# 1.2 12-Jun-2000 aaron

Fix ADMtek identity crisis.


Revision tags: OPENBSD_2_7_BASE
# 1.1 18-Apr-2000 jason

branches: 1.1.2;
split dc driver into bus dependent and bus independent (pci) parts
(cardbus to come later).


# 1.155 22-Feb-2022 guenther

Delete unnecessary #includes of <sys/domain.h> and/or <sys/protosw.h>

net/if_pppx.c pointed out by jsg@
ok gnezdo@ deraadt@ jsg@ mpi@ millert@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.154 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.153 10-Jul-2020 patrick

Change users of IFQ_DEQUEUE(), IFQ_ENQUEUE() and IFQ_LEN() to use the
"new" API.

ok dlg@ tobhe@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.152 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.151 04-May-2016 kettenis

Use BUS_DMA_OVERRUN to cope with the broken DMA engine of the Davicom DM9102
found on some Sun sparc64 machines. This fixes the unrecoverable DMA errors
people have been seeing ever since dlg@ made changes to the pool code that
changes the memory layout.


# 1.150 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.149 28-Nov-2015 dlg

rework dc_start and dc_encap to take advantage of m_defrag.

if the chip needs coalesced packages in tx, set the tx dmamaps up
to only use a single dma descriptor. use m_defrag when bus_dmamap_load_mbuf
returns EFBIG rather than copying the packet to a separate mbuf
with hand rolled code in dc_coal. that in turn makes the ifq_deq_begin,
ifq_deq_commit, and ifq_deq_rollback handling more straightforward.

tested by me on a hppa a180c with a "DEC 21142/3", and fred on bugs@
with a sparc64 netra x1 "Davicom DM9102".


# 1.148 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.147 24-Nov-2015 mpi

The only network driver needing <net/if_types.h> is upl(4) for IFT_OTHER.


# 1.146 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.145 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.144 12-Sep-2015 miod

ifmedia64 fixes.


# 1.143 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


# 1.142 30-Aug-2015 deraadt

Track rom size, for free()


Revision tags: OPENBSD_5_8_BASE
# 1.141 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.140 13-Apr-2015 mpi

Now that if_input() set the receiving interface pointer on mbufs for us
there's no need to do it in m_devget(9).

Stop passing an ``ifp'' will help for upcoming interface pointer -> index
conversion.

While here remove unused ``ifp'' argument from m_clget(9) and kill two
birds^W layer violations in one commit.

ok henning@


# 1.139 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


# 1.138 13-Mar-2015 jasper

convert to if_input()

tested by landry@
ok mpi@


Revision tags: OPENBSD_5_7_BASE
# 1.137 23-Jan-2015 dlg

break after return is useless.


# 1.136 22-Dec-2014 tedu

unifdef INET


# 1.135 18-Nov-2014 brad

dc_init() calls dc_stop() and dc_reset() so remove some redundant calls
to those functions before dc_init() within dc_watchdog() and dc_intr().

ok deraadt@


Revision tags: OPENBSD_5_6_BASE
# 1.134 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.133 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.132 18-Apr-2014 henning

reaching into altq unconditionally (and w/o ifdef ALTQ) is bad, mmkay?


Revision tags: OPENBSD_5_5_BASE
# 1.131 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.130 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.129 02-Dec-2013 brad

Rewrite receive filter handling and ioctl bits. Fixes not being able to
bring the interface out of all multicast mode once a range of multicast
addresses has been found and missing multicast range checking for some
of the dc(4) variants.

Tested with 21143 (represents most of the dc(4) variants and boards) and
ADMtek based adapters. Untested with ASIX and Xircom based adapters.
Putting it in to move forward. I don't expect any issues with the
ASIX/Xircom adapters with the changes as is.

ok naddy@


# 1.128 20-Nov-2013 mpi

Instead of comparing the lower and higher addresses of all the multicast
entries to decide if the IFF_ALLMULTI flag should be set, check if there
is at least one real range between them.

Tested by naddy@


# 1.127 21-Aug-2013 dlg

get rid of the copy argument in m_devget that let you provide an
alternative to bcopy since noone uses it.

while there use memcpy instead of bcopy because we know the memory cannot
overlap.

ok henning@ matthew@ mikeb@ deraadt@


# 1.126 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.125 29-Nov-2012 brad

Remove setting an initial assumed baudrate upon driver attach which is not
necessarily correct, there might not even be a link when attaching.

ok mikeb@ reyk@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.124 07-Jul-2011 henning

use IF_LEN/IFQ_LEN to access and ifqueue's length field. ryan ok
with this nothing in the tree fiddles if ifqueue internals any more, of
course except if.c and if.h (and some altq)


# 1.123 21-Jun-2011 tedu

remove some unnecessary casts. ok blambert deraadt kettenis matthew


# 1.122 05-Mar-2011 kettenis

Wait until the DMA engine is stopped before unmapping buffers and descriptors.
Fixes DMA errors seen on sparc64.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.121 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.120 06-Sep-2010 deraadt

initialize rv to 0 in the activate function


# 1.119 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.118 30-Aug-2010 deraadt

activate functions, when they do not add value, should return the result of config_activate_children


# 1.117 27-Aug-2010 deraadt

Move the dc_pci_activate function to dc.c, and mangle it up with some of
the gunk in dc_powerhook. Then make dc_powerhook just call it
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.116 05-Aug-2010 deraadt

ca_activate function for suspend/resume; tested by mlarkin on a
Davicom DM9102. (bit of noise on suspend or resume, but that can be
dealt with later)


# 1.115 02-Jul-2010 blambert

timeout_add -> timeout_add_msec

ok krw@


# 1.114 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.113 15-Oct-2009 deraadt

Add detach support to a few more drivers, and in others do the neccessary
operations in the detach function in the right order. Also ensure that the
interrupt handlers not trust registers that go away.
read over very carefully by dms, tested by me


# 1.112 10-Aug-2009 deraadt

More cases of shutdown hooks not needed after card is already stopped. In
these cases the xxstop function is a bit more complicated and has a flag of
some sort, but the use of that flag does not matter; DMA is already ceased
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.111 26-Jun-2009 deraadt

If we are going to move to the eeprom-based MAC address finding instead of
CIS-based... some newer devices have the MAC address at offset 8 instead of
offset 3. But we can tell by the first three octets, Intel says.


# 1.110 26-Jun-2009 deraadt

Using information gleamed from the FreeBSD driver, change the MAC address
reading to use the eeprom instead of CIS, and then the Xircom Cardbus cards
can work in the expresscard adaptor, as pci devices.
ok jsg


# 1.109 02-Jun-2009 jsg

make dc at pci detachable; untested.


Revision tags: OPENBSD_4_5_BASE
# 1.108 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.107 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.106 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


# 1.105 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.104 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.103 12-Sep-2008 brad

Some fixes for dc_txeof()..
- Don't reload the watchdog timer in case there are still unhandled
descriptors.
- Don't clear IFF_OACTIVE unless there are at least 6 free TX
descriptors. The function dc_encap() will bail if there are
only 5 or fewer free TX descriptors, causing dc_start() to
abort so it makes no sense to pretend we could process mbufs
again when in fact we can't.
- Always assign idx to sc->dc_cdata.dc_tx_cons; it doesn't make
much sense to exclude the idx == sc->dc_cdata.dc_tx_cons case.

From FreeBSD


# 1.102 11-Sep-2008 brad

ANSI function declarations.


# 1.101 11-Sep-2008 brad

For chips with a broken DC_ISR_RX_STATE which never signals
stopped nor the waiting state and also no other means to check
whether the receiver is idle, we have no choice but to call
mii_tick unconditionally even in the case of the DC_REDUCED_MII_POLL
handling as far as the RX side is concerned. This isn't necessarily
worse than checking whether RX is idle though because unlike as
with TX we're racing with the hardware, which might receive packets
any time while we poll the MII, anyway. Fixes the use of trunk(4)
with the affected interfaces.

From FreeBSD


# 1.100 03-Sep-2008 brad

In dc_setcfg() suppress printing a warning when forcing the receiver
and transmitter to idle state times out for chips where the status
bits in question never change (observed in detail with DM9102A) and
therefore the warning would highly likely be a false positive.

From FreeBSD


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.99 26-Nov-2007 brad

print the comma before the MAC address string in dc_attach() instead of the
PCI front end attach function. This corrects the dmesg output for CardBus
adapters and ensures proper dmesg output if an error occurs in dc_attach().

ok dlg@


# 1.98 01-Oct-2007 krw

More easy bzero() -> M_ZERO. Use 'p = malloc(sizeof(*p) ...'.


Revision tags: OPENBSD_4_2_BASE
# 1.97 08-May-2007 deraadt

dc_detach() is only used by cardbus code, so move it there; ok jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.96 10-Aug-2006 brad

- eliminate re-initialization's when adding IP addresses.
- simplify ioctl handler.


# 1.95 22-May-2006 krw

Attach routines can fail before calling *hook_establish(), and they
often rely on the detach routine for cleanup. So be consistant and
careful by checking for a NULL hook before calling *hook_disestablish
in detach routines.

ok mickey@ brad@ dlg@


# 1.94 07-May-2006 brad

- Return if there is nothing to do in the interrupt handler.
- Check for IFF_RUNNING in the interrupt loop.


# 1.93 23-Apr-2006 kettenis

Make code path for ADMTek variant endian-safe; fixes dc(4) on macppc.
ok brad@


# 1.92 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


Revision tags: OPENBSD_3_9_BASE
# 1.91 28-Jan-2006 brad

remove 2 printf's from dc_coal() too.


# 1.90 28-Jan-2006 brad

remove printf's from dc_newbuf().


# 1.89 07-Nov-2005 brad

splimp -> splnet


Revision tags: OPENBSD_3_8_BASE
# 1.88 25-Jun-2005 brad

re-add ASIX check lost in rev 1.77


# 1.87 23-Jun-2005 brad

clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.


# 1.86 22-May-2005 martin

ALTQ cleanout

ok brad@


# 1.85 22-May-2005 brad

add power hook


# 1.84 30-Apr-2005 brad

try to drain send queue if we lose link during heavy transmit
activity instead of letting it sit and return 'no buffer available'
errors.


# 1.83 23-Apr-2005 brad

- always accept VLAN-sized frames
- support setting the MTU


# 1.82 23-Apr-2005 brad

Fix newer Xircom CBE2-100 cards.

We have to enable the connection to the MII first. Doing so fixes the
problem cards without breaking the older, working cards.

From FreeBSD


# 1.81 31-Mar-2005 brad

- add support for reading Xircom's EEPROM
- sync dc_mii_readreg()

From FreeBSD


Revision tags: OPENBSD_3_7_BASE
# 1.80 15-Jan-2005 brad

make sure interface is in RUNNING state before touching the multicast filters

From NetBSD

NetBSD PR 27678 for details

ok mcbride@


# 1.79 14-Jan-2005 brad

rev 1.63

Avoid an unnecessary copy of a packet if it is already in a single mbuf.
Introduce an additional device flag for those NICs which require the
transmit buffers to be aligned to 32-bit boundaries.

From FreeBSD


# 1.78 08-Jan-2005 brad

rev 1.125

Don't read the MAC address from a copy of the EEPROM in the softc
that has been recorded earlier and overwrite it again later by
reading it directly from the EEPROM again.

Read the MAC address from the PAR0/PAR1 registers instead, which
are autoloaded on reboot.

From FreeBSD

Thanks to David Snyder <dasnyderx at yahoo dot com> for testing on
a AN983 based card which used to come up with a MAC address of
ff:ff:ff:ff:ff:ff.


# 1.77 17-Dec-2004 brad

add missing braces.

From FreeBSD


# 1.76 02-Dec-2004 brad

rev 1.126

Ignore CSR13, CSR14, CSR15 'Media Specific Data' registers
for 21143 based cards which use SIA mode.

This fixes 10mbit mode for ZNYX ZX346Q cards and other
21143 based cards.

rev 1.108

Only use a SIA/SYM media info block if no MII block is detected.
The submitter of PR 32118 told me that this patch also fixes autoselecting
for znyx 4 port cards (10baseT, 100baseTX did work already).

From FreeBSD

ok deraadt@


# 1.75 28-Nov-2004 brad

rev 1.74

Fix if_timer logic to make sure that there is always a timeout
pending if there are packets queued for transmission.

From FreeBSD

ok deraadt@


# 1.74 16-Nov-2004 brad

if_dc.c rev 1.56

Do not call mii_pollstat() from within device tick routines; the status
information is updated by mii_tick().

dcphy.c rev 1.13

Work around an Intel 21143 chip bug.

Rev 1.56 of if_dc.c removed calls to mii_pollstat() from the dc_tick()
routine. dc_tick() is called regularly to detect link up and link down
status, especially when autonegotiating.

The expectation was that mii_tick() (which is still called from dc_tick())
would update status information automatically in all cases where it would
be sensible to do so.

Unfortunately, with authentic 21143 chips this is not the case, and
the driver never successfully autonegotiates. This is because (despite
what it says in the 21143 manual) the chip always claims that link is not
present while the autonegotiation enable bit is set. Autonegotation takes
place and succeeds, but the driver tests the link bits before it switches
off the autonegotiation enable bit, and success is not recognised.

The simplest solution is to call dcphy_status() more often for MII_TICK
calls by dropping out of the switch statement instead of exiting when
we are autonegotiating and link appears to not be present. When
autonegotiation succeeds, dcphy_status() will note the speed and fdx/hdx
state and turn off the autonegotiation enable bit. The next call to
dcphy_status() will notice that link is present, and the dc driver code
will be notified.

Macronix chips also use this code, but implement link detection as
described in the manual, and hence don't need this patch. However, tests
on a Macronix 98715AEC-C show that it does not adversely affect them.

From FreeBSD

ok deraadt@


# 1.73 29-Oct-2004 brad

rev 1.78

Enable the automatic TX underrun recovery for the ADMtek chips.
This solves cvsup update on my laptop which aborts after a while
without this patch.

rev 1.79

Fix the support for the AN985/983 chips, which do not set the
RXSTATE to STOPPED, but to WAIT. This should fix hangs which
could only be solved by replugging the cable.

From FreeBSD

Thanks to C. Bensend <benny at bennyvision dot com> for testing.


# 1.72 14-Oct-2004 brad

rev 1.47

Add a check in the interrupt service routine to return quickly in
case there is nothing to do. This happens normally when the card shares
the interrupt line with other devices.

This code saves a couple of microseconds per interrupt even on a
fast CPU. You normally would not care, except under heavy tinygram
traffic where you can have some 50-100.000 interrupts per second...

rev 1.51

Patch to allow TX underrun handling without issuing a complete
chip reset. Just temporarily turn off the transmitter instead.

From FreeBSD

ok mcbride@
tested by mcbride@, jaredy@, marco@, grange@, <harding at motd dot ca>


# 1.71 06-Oct-2004 brad

typo


# 1.70 06-Oct-2004 brad

Enable round-robin arbitration between transmit and receive unit
in the 21143, instead of giving priority to the receive unit.
This gives a 10-15% performance improvement in the forwarding rate
under heavy load.

From FreeBSD

ok mcbride@ nick@ deraadt@


# 1.69 28-Sep-2004 brad

Use ETHER_MIN_LEN/ETHER_MAX_DIX_LEN


# 1.68 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


Revision tags: OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B
# 1.67 31-May-2004 mcbride

multicast cleanups:
- get rid of hand rolled crc32 logic, use ether_crc32_{le,be}
- accept all multicast if a range is encountered


# 1.66 15-Apr-2004 mickey

user bus_dmamap_load_mbuf and set rcvif on receive


Revision tags: OPENBSD_3_5_BASE
# 1.65 21-Oct-2003 jmc

typos from Tom Cosgrove;

Tom: I did not commit a couple of your changes.

i did not include some punctuation fixes (full stops, etc.)
mnemorable -> mnemonic: i decided memorable was probably better
instrunctions -> instruction: i kept the plural


# 1.64 29-Sep-2003 mickey

add more dmamap_sync()s where appropriate modify loops to insure proper syncing; jason@ testing


# 1.63 25-Sep-2003 mickey

no need for a redundant check; from form@ and jason ok


Revision tags: OPENBSD_3_4_BASE
# 1.62 28-Aug-2003 mickey

fix bzero size; from pechkin


# 1.61 16-Jun-2003 mickey

be more sane w/ byte swapping and leave the le archs at the same behaviour and give be archs a better chance at getting the correct mac address as tested on the mac and hppa where mac has an additional bug w/ the phy bit still remaining and hppa seems fine; jason@ ok


# 1.60 20-May-2003 henning

AN983 endian issue; from FreeBSD via PR 3263 with minor style fixes by me

ok jason@


Revision tags: UBC_SYNC_A
# 1.59 17-May-2003 jason

fix up the media handling for the intel based MACs. Also hack around a
bug in the Momenco firmware on the Leopard-V, which now has one port
working.


# 1.58 29-Apr-2003 jason

grr... %s, not dc%s


# 1.57 29-Apr-2003 jason

- remove last vestige of "old autoconf": dc_unit is dead, long live dv_xname
- remove a bunch of #if 0 stuff (most of which referred to dc_unit, grr)
- delay a bzero until necessary


# 1.56 29-Apr-2003 jason

KNF


Revision tags: OPENBSD_3_3_BASE
# 1.55 25-Feb-2003 tedu

remove redundant check.

ok henning@


# 1.54 31-Jan-2003 deraadt

more quiet


Revision tags: UBC_SYNC_B
# 1.53 21-Oct-2002 henning

ugly hack to make the 21145 work without manual media setting.

many many many thanks to nick@, who booted no less then 8 kernels for me today
while hacking on that (and this includes going downstairs to the basement
and up again 8 times...)

ok jason@


# 1.52 20-Oct-2002 henning

add support for intel 21145
This chip is some strange abnormal 21143 variant. It really only works with
10 MBit/s halfduplex only and autonegotiation is totally broken in hardware.
Should also have a HomePNA phy, but we don't support that.
for now requires and explicit "media 10BaseT".
if anybody has such a chip please mail me.

nick@ is the only one who has the hardware and did an incredible amount of
testing. Thanks for all the help, Nick!

some hints and ok jason@


Revision tags: OPENBSD_3_2_BASE
# 1.51 05-Jul-2002 aaron

Remove an unused #define (belongs only in the PCI attachment source file).


# 1.50 09-Jun-2002 todd

a step towards consistancy; in general:
'struct arpcom foo' -> 'struct arpcom sc_arpcom'
ok itojun@


# 1.49 09-Jun-2002 nordin

Handle out of memory gracefully. ok jason@


# 1.48 18-Apr-2002 jason

add support for Conexant LANfinity RS7112; based on patch from Maurice Nonnekes <maurice@amaze.nl> based on FreeBSD (only minor surgery necessary)


Revision tags: OPENBSD_3_1_BASE
# 1.47 14-Mar-2002 millert

First round of __P removal in sys


# 1.46 17-Feb-2002 deraadt

drivers may not be noisy


# 1.45 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


Revision tags: UBC_BASE
# 1.44 13-Dec-2001 nate

branches: 1.44.2;
Fix old alpha bug recently triggered by conversion to busdma.


# 1.43 08-Dec-2001 jason

Go ahead and fix the xircom filter setup to work on big endian too (untested, but it's pretty similiar to the tested 21143 case).


# 1.42 08-Dec-2001 jason

use htole32() on the data going into the setup frame for the dc_setfilt_21143() case at least.
XXX I'm looking at the other filter setups and they appear to need work for BE too.


# 1.41 06-Dec-2001 jason

add bus_dmamap_sync()'s on the descriptors too
(with all this, my Netra X1 is up and running with an NFS root)


# 1.40 06-Dec-2001 jason

a few more bus_dmamap_sync()'s and some borrowed setup frame macros from NetBSD, and RX works on sparc64.


# 1.39 06-Dec-2001 jason

enough bus_dmamap_sync() and htole()/letoh() to get TX working on sparc64.
ALso, get the MAC address from myetheraddr() instead of trying to use the eeprom on sparc64.


# 1.38 06-Dec-2001 jason

vtophys, R.I.P. (tx now uses bus_dma)


# 1.37 06-Dec-2001 jason

move rx handling over to bus_dma... that just leaves one vtophys() in tx.


# 1.36 06-Dec-2001 jason

move the setup buffer and pad into a bus_dma alloced area
(current score: 2 vtophys calls to go...)


# 1.35 06-Dec-2001 jason

Checkpoint bus_dma work in progress:
- descriptor lists are now bus_dma allocated and manipulated
(for those keeping score: 6 vtophys dead, 4 to go)


# 1.34 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.33 22-Aug-2001 aaron

Support more dc(4) CardBus devices, including the AN985-based Linksys PCMPC200
10/100 CardBus Ethernet adapter (thanks to beck@ for the donation).


# 1.32 12-Aug-2001 mickey

remove some of the redundant vm includes


# 1.31 03-Aug-2001 chris

Set IFCAP_VLAN_MTU, this driver already allows vlan-size frames


# 1.30 02-Jul-2001 jason

these don't depend on pci register defs


# 1.29 27-Jun-2001 kjc

ALTQ'ify network drivers.
- use the new queue macros.
- use IFQ_POLL() to peek at the next packet.
- use IFQ_IS_EMPTY() for empty check.
- drivers should always check if (m == NULL) after IFQ_DEQUEUE(),
since it could return NULL even when IFQ_IS_EMPTY() is FALSE
under rate-limiting.
- drivers are supposed to call if_start from tx complete interrupts
(in order to trigger the next dequeue under rate-limiting).


# 1.28 23-Jun-2001 fgsch

ether_input_mbuf().


Revision tags: OPENBSD_2_9_BASE
# 1.27 13-Apr-2001 aaron

branches: 1.27.4;
Oops, remove an unrelated debugging #if 0.


# 1.26 13-Apr-2001 aaron

Disestablish the shutdownhook on detach.


# 1.25 06-Apr-2001 aaron

- For CardBus 21143 cards, parse the SROM. Makes my SMC EZ CardBus 10/100 work.
- General cleanup in the dc CardBus attachment.
- Split detach up into bus-dependent and bus-independent parts.
- Some function and variable renaming for consistency.


# 1.24 20-Feb-2001 mickey

for ethernet ifaces attach bpf from ether_ifattach; jason@, aaron@, itojun@ ok


# 1.23 09-Feb-2001 art

Bad aaron. Broke alpha.


# 1.22 09-Feb-2001 aaron

Sync with FreeBSD:
- Bugfix: 'reg' variable in dc_apply_fixup() needs to be u_int32_t.
- Bugfix: bzero() mediainfo structures after allocation.
- Call dc_apply_fixup() in dc_setcfg() for the MII case.
- Conditionalize some code in miibus_{read,write}reg to make non-mx98713
cards happy.


# 1.21 09-Feb-2001 aaron

Add support for parsing the media blocks from the SROM on the 21143 adapters.
These changes should make the driver work with the built-in Ethernet on the
Alpha Miata machines. From FreeBSD.

To make sure I didn't break anything (and as a general test), I tested the
modified driver with the following dc(4) variants: Macronix PMAC 98715,
Lite-On PNIC, Lite-On PNIC-II, ADMtek AL981, and ADMtek AN983.


# 1.20 16-Nov-2000 aaron

Note support for Accton EN1217 and EN2242 Ethernet adapters.


Revision tags: OPENBSD_2_8_BASE
# 1.19 30-Oct-2000 aaron

Match the Macronix 98727/98732 chips.


# 1.18 26-Oct-2000 aaron

Add support for Xircom X3201-based CardBus Ethernet cards. Tested successfully
on four different models, including the CBEM56G-100, RBE-100 RealPort, and the
RBEM56G-100 RealPort. This commit adds support only for the LAN components; the
modem is not configured yet. Detach support to come. Based on work from
FreeBSD, mickey@, nate@, and myself.


# 1.17 18-Oct-2000 aaron

Sigh. According to the ASIX data sheets, these boards don't even have RX
or TX state registers (these bits are reserved). So instead, don't do
mii_tick() at all for ASIX boards, since we can't seem to figure out how
to call it at just the right time. Hopefully this will be a temporary hack
until a better solution is found.


# 1.16 17-Oct-2000 aaron

Undo the incorrect fix for my ASIX 88141. Instead of just relying on tx_cnt,
now we check the TX state in the ISR to make sure we are not transmitting
when we run mii_tick(). Based on a suggestion by Bill Paul. The dc driver
should now be ready for some heavy pre-2.8 testing.


# 1.15 16-Oct-2000 aaron

Use mii_attach() directly instead of mii_phy_probe().


# 1.14 11-Oct-2000 aaron

For some reason, with the eeprom width detection code mickey added awhile ago,
special care for the ADMtek AN983 (Centaur-P) chip is no longer needed. This
fixes Ethernet address reading for these cards. Thanks to todd@ for testing.


# 1.13 28-Sep-2000 aaron

If this is a Davicom DM9102A and we're enabling the homePNA link, force
dc_link to 1 and don't activate the tick routine. Without this, dc_start()
always thinks the link is down and never transmits in homePNA mode; from
FreeBSD.


# 1.12 13-Sep-2000 aaron

Sync with FreeBSD. Finally make the OpenBSD-specific changes necessary to make
non-MII 21143-based cards work. The sync just fixes the LED handling on these
kinds of adapters.


# 1.11 07-Sep-2000 aaron

Indentation fix.


# 1.10 26-Aug-2000 aaron

Revert a minor FreeBSD tweak that tends to freeze my machine solid after
large amounts of data transfer (ASIX 88141 card).


# 1.9 08-Aug-2000 aaron

Make fix for preserving LED settings conditional on presence of an Intel
21143 chip; from FreeBSD.


# 1.8 02-Aug-2000 aaron

Sync with FreeBSD. Summary of changes:

- Add support for Accton EN1217 Ethernet adapters.
- Fix problems with LEDs on some cards when clearing the jabber disable bit.
- Handle new Macronix chips whose multicast hash tables are only 128 bits.
- Fix timing issues during autonegotiation with Macronix and PNIC II.


# 1.7 02-Aug-2000 aaron

Don't print out the eeprom width.


# 1.6 02-Aug-2000 peter

Add support for accepting packets up to 4 octets larger than the
interface MTU IFF vlans are enabled.

Additional logic should be added by someone who understand 802.1q to
test if this oversize packet is actually a 802.1q encapsulated, and
reject others.

Fix as per kernel/1328.


# 1.5 21-Jul-2000 mickey

convert to new timeouts; art@ ok


# 1.4 12-Jun-2000 mickey

remove debugging prom dump, sorry


# 1.3 12-Jun-2000 mickey

eeprom width detection code.
idea from netbsd tulip driver.
there is problem w/ an983 card, but aaron@ said he'll work it out.
aaron@ & jason@ ok.


# 1.2 12-Jun-2000 aaron

Fix ADMtek identity crisis.


Revision tags: OPENBSD_2_7_BASE
# 1.1 18-Apr-2000 jason

branches: 1.1.2;
split dc driver into bus dependent and bus independent (pci) parts
(cardbus to come later).


# 1.154 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.153 10-Jul-2020 patrick

Change users of IFQ_DEQUEUE(), IFQ_ENQUEUE() and IFQ_LEN() to use the
"new" API.

ok dlg@ tobhe@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.152 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.151 04-May-2016 kettenis

Use BUS_DMA_OVERRUN to cope with the broken DMA engine of the Davicom DM9102
found on some Sun sparc64 machines. This fixes the unrecoverable DMA errors
people have been seeing ever since dlg@ made changes to the pool code that
changes the memory layout.


# 1.150 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.149 28-Nov-2015 dlg

rework dc_start and dc_encap to take advantage of m_defrag.

if the chip needs coalesced packages in tx, set the tx dmamaps up
to only use a single dma descriptor. use m_defrag when bus_dmamap_load_mbuf
returns EFBIG rather than copying the packet to a separate mbuf
with hand rolled code in dc_coal. that in turn makes the ifq_deq_begin,
ifq_deq_commit, and ifq_deq_rollback handling more straightforward.

tested by me on a hppa a180c with a "DEC 21142/3", and fred on bugs@
with a sparc64 netra x1 "Davicom DM9102".


# 1.148 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.147 24-Nov-2015 mpi

The only network driver needing <net/if_types.h> is upl(4) for IFT_OTHER.


# 1.146 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.145 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.144 12-Sep-2015 miod

ifmedia64 fixes.


# 1.143 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


# 1.142 30-Aug-2015 deraadt

Track rom size, for free()


Revision tags: OPENBSD_5_8_BASE
# 1.141 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.140 13-Apr-2015 mpi

Now that if_input() set the receiving interface pointer on mbufs for us
there's no need to do it in m_devget(9).

Stop passing an ``ifp'' will help for upcoming interface pointer -> index
conversion.

While here remove unused ``ifp'' argument from m_clget(9) and kill two
birds^W layer violations in one commit.

ok henning@


# 1.139 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


# 1.138 13-Mar-2015 jasper

convert to if_input()

tested by landry@
ok mpi@


Revision tags: OPENBSD_5_7_BASE
# 1.137 23-Jan-2015 dlg

break after return is useless.


# 1.136 22-Dec-2014 tedu

unifdef INET


# 1.135 18-Nov-2014 brad

dc_init() calls dc_stop() and dc_reset() so remove some redundant calls
to those functions before dc_init() within dc_watchdog() and dc_intr().

ok deraadt@


Revision tags: OPENBSD_5_6_BASE
# 1.134 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.133 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.132 18-Apr-2014 henning

reaching into altq unconditionally (and w/o ifdef ALTQ) is bad, mmkay?


Revision tags: OPENBSD_5_5_BASE
# 1.131 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.130 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.129 02-Dec-2013 brad

Rewrite receive filter handling and ioctl bits. Fixes not being able to
bring the interface out of all multicast mode once a range of multicast
addresses has been found and missing multicast range checking for some
of the dc(4) variants.

Tested with 21143 (represents most of the dc(4) variants and boards) and
ADMtek based adapters. Untested with ASIX and Xircom based adapters.
Putting it in to move forward. I don't expect any issues with the
ASIX/Xircom adapters with the changes as is.

ok naddy@


# 1.128 20-Nov-2013 mpi

Instead of comparing the lower and higher addresses of all the multicast
entries to decide if the IFF_ALLMULTI flag should be set, check if there
is at least one real range between them.

Tested by naddy@


# 1.127 21-Aug-2013 dlg

get rid of the copy argument in m_devget that let you provide an
alternative to bcopy since noone uses it.

while there use memcpy instead of bcopy because we know the memory cannot
overlap.

ok henning@ matthew@ mikeb@ deraadt@


# 1.126 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.125 29-Nov-2012 brad

Remove setting an initial assumed baudrate upon driver attach which is not
necessarily correct, there might not even be a link when attaching.

ok mikeb@ reyk@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.124 07-Jul-2011 henning

use IF_LEN/IFQ_LEN to access and ifqueue's length field. ryan ok
with this nothing in the tree fiddles if ifqueue internals any more, of
course except if.c and if.h (and some altq)


# 1.123 21-Jun-2011 tedu

remove some unnecessary casts. ok blambert deraadt kettenis matthew


# 1.122 05-Mar-2011 kettenis

Wait until the DMA engine is stopped before unmapping buffers and descriptors.
Fixes DMA errors seen on sparc64.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.121 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.120 06-Sep-2010 deraadt

initialize rv to 0 in the activate function


# 1.119 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.118 30-Aug-2010 deraadt

activate functions, when they do not add value, should return the result of config_activate_children


# 1.117 27-Aug-2010 deraadt

Move the dc_pci_activate function to dc.c, and mangle it up with some of
the gunk in dc_powerhook. Then make dc_powerhook just call it
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.116 05-Aug-2010 deraadt

ca_activate function for suspend/resume; tested by mlarkin on a
Davicom DM9102. (bit of noise on suspend or resume, but that can be
dealt with later)


# 1.115 02-Jul-2010 blambert

timeout_add -> timeout_add_msec

ok krw@


# 1.114 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.113 15-Oct-2009 deraadt

Add detach support to a few more drivers, and in others do the neccessary
operations in the detach function in the right order. Also ensure that the
interrupt handlers not trust registers that go away.
read over very carefully by dms, tested by me


# 1.112 10-Aug-2009 deraadt

More cases of shutdown hooks not needed after card is already stopped. In
these cases the xxstop function is a bit more complicated and has a flag of
some sort, but the use of that flag does not matter; DMA is already ceased
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.111 26-Jun-2009 deraadt

If we are going to move to the eeprom-based MAC address finding instead of
CIS-based... some newer devices have the MAC address at offset 8 instead of
offset 3. But we can tell by the first three octets, Intel says.


# 1.110 26-Jun-2009 deraadt

Using information gleamed from the FreeBSD driver, change the MAC address
reading to use the eeprom instead of CIS, and then the Xircom Cardbus cards
can work in the expresscard adaptor, as pci devices.
ok jsg


# 1.109 02-Jun-2009 jsg

make dc at pci detachable; untested.


Revision tags: OPENBSD_4_5_BASE
# 1.108 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.107 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.106 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


# 1.105 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.104 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.103 12-Sep-2008 brad

Some fixes for dc_txeof()..
- Don't reload the watchdog timer in case there are still unhandled
descriptors.
- Don't clear IFF_OACTIVE unless there are at least 6 free TX
descriptors. The function dc_encap() will bail if there are
only 5 or fewer free TX descriptors, causing dc_start() to
abort so it makes no sense to pretend we could process mbufs
again when in fact we can't.
- Always assign idx to sc->dc_cdata.dc_tx_cons; it doesn't make
much sense to exclude the idx == sc->dc_cdata.dc_tx_cons case.

From FreeBSD


# 1.102 11-Sep-2008 brad

ANSI function declarations.


# 1.101 11-Sep-2008 brad

For chips with a broken DC_ISR_RX_STATE which never signals
stopped nor the waiting state and also no other means to check
whether the receiver is idle, we have no choice but to call
mii_tick unconditionally even in the case of the DC_REDUCED_MII_POLL
handling as far as the RX side is concerned. This isn't necessarily
worse than checking whether RX is idle though because unlike as
with TX we're racing with the hardware, which might receive packets
any time while we poll the MII, anyway. Fixes the use of trunk(4)
with the affected interfaces.

From FreeBSD


# 1.100 03-Sep-2008 brad

In dc_setcfg() suppress printing a warning when forcing the receiver
and transmitter to idle state times out for chips where the status
bits in question never change (observed in detail with DM9102A) and
therefore the warning would highly likely be a false positive.

From FreeBSD


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.99 26-Nov-2007 brad

print the comma before the MAC address string in dc_attach() instead of the
PCI front end attach function. This corrects the dmesg output for CardBus
adapters and ensures proper dmesg output if an error occurs in dc_attach().

ok dlg@


# 1.98 01-Oct-2007 krw

More easy bzero() -> M_ZERO. Use 'p = malloc(sizeof(*p) ...'.


Revision tags: OPENBSD_4_2_BASE
# 1.97 08-May-2007 deraadt

dc_detach() is only used by cardbus code, so move it there; ok jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.96 10-Aug-2006 brad

- eliminate re-initialization's when adding IP addresses.
- simplify ioctl handler.


# 1.95 22-May-2006 krw

Attach routines can fail before calling *hook_establish(), and they
often rely on the detach routine for cleanup. So be consistant and
careful by checking for a NULL hook before calling *hook_disestablish
in detach routines.

ok mickey@ brad@ dlg@


# 1.94 07-May-2006 brad

- Return if there is nothing to do in the interrupt handler.
- Check for IFF_RUNNING in the interrupt loop.


# 1.93 23-Apr-2006 kettenis

Make code path for ADMTek variant endian-safe; fixes dc(4) on macppc.
ok brad@


# 1.92 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


Revision tags: OPENBSD_3_9_BASE
# 1.91 28-Jan-2006 brad

remove 2 printf's from dc_coal() too.


# 1.90 28-Jan-2006 brad

remove printf's from dc_newbuf().


# 1.89 07-Nov-2005 brad

splimp -> splnet


Revision tags: OPENBSD_3_8_BASE
# 1.88 25-Jun-2005 brad

re-add ASIX check lost in rev 1.77


# 1.87 23-Jun-2005 brad

clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.


# 1.86 22-May-2005 martin

ALTQ cleanout

ok brad@


# 1.85 22-May-2005 brad

add power hook


# 1.84 30-Apr-2005 brad

try to drain send queue if we lose link during heavy transmit
activity instead of letting it sit and return 'no buffer available'
errors.


# 1.83 23-Apr-2005 brad

- always accept VLAN-sized frames
- support setting the MTU


# 1.82 23-Apr-2005 brad

Fix newer Xircom CBE2-100 cards.

We have to enable the connection to the MII first. Doing so fixes the
problem cards without breaking the older, working cards.

From FreeBSD


# 1.81 31-Mar-2005 brad

- add support for reading Xircom's EEPROM
- sync dc_mii_readreg()

From FreeBSD


Revision tags: OPENBSD_3_7_BASE
# 1.80 15-Jan-2005 brad

make sure interface is in RUNNING state before touching the multicast filters

From NetBSD

NetBSD PR 27678 for details

ok mcbride@


# 1.79 14-Jan-2005 brad

rev 1.63

Avoid an unnecessary copy of a packet if it is already in a single mbuf.
Introduce an additional device flag for those NICs which require the
transmit buffers to be aligned to 32-bit boundaries.

From FreeBSD


# 1.78 08-Jan-2005 brad

rev 1.125

Don't read the MAC address from a copy of the EEPROM in the softc
that has been recorded earlier and overwrite it again later by
reading it directly from the EEPROM again.

Read the MAC address from the PAR0/PAR1 registers instead, which
are autoloaded on reboot.

From FreeBSD

Thanks to David Snyder <dasnyderx at yahoo dot com> for testing on
a AN983 based card which used to come up with a MAC address of
ff:ff:ff:ff:ff:ff.


# 1.77 17-Dec-2004 brad

add missing braces.

From FreeBSD


# 1.76 02-Dec-2004 brad

rev 1.126

Ignore CSR13, CSR14, CSR15 'Media Specific Data' registers
for 21143 based cards which use SIA mode.

This fixes 10mbit mode for ZNYX ZX346Q cards and other
21143 based cards.

rev 1.108

Only use a SIA/SYM media info block if no MII block is detected.
The submitter of PR 32118 told me that this patch also fixes autoselecting
for znyx 4 port cards (10baseT, 100baseTX did work already).

From FreeBSD

ok deraadt@


# 1.75 28-Nov-2004 brad

rev 1.74

Fix if_timer logic to make sure that there is always a timeout
pending if there are packets queued for transmission.

From FreeBSD

ok deraadt@


# 1.74 16-Nov-2004 brad

if_dc.c rev 1.56

Do not call mii_pollstat() from within device tick routines; the status
information is updated by mii_tick().

dcphy.c rev 1.13

Work around an Intel 21143 chip bug.

Rev 1.56 of if_dc.c removed calls to mii_pollstat() from the dc_tick()
routine. dc_tick() is called regularly to detect link up and link down
status, especially when autonegotiating.

The expectation was that mii_tick() (which is still called from dc_tick())
would update status information automatically in all cases where it would
be sensible to do so.

Unfortunately, with authentic 21143 chips this is not the case, and
the driver never successfully autonegotiates. This is because (despite
what it says in the 21143 manual) the chip always claims that link is not
present while the autonegotiation enable bit is set. Autonegotation takes
place and succeeds, but the driver tests the link bits before it switches
off the autonegotiation enable bit, and success is not recognised.

The simplest solution is to call dcphy_status() more often for MII_TICK
calls by dropping out of the switch statement instead of exiting when
we are autonegotiating and link appears to not be present. When
autonegotiation succeeds, dcphy_status() will note the speed and fdx/hdx
state and turn off the autonegotiation enable bit. The next call to
dcphy_status() will notice that link is present, and the dc driver code
will be notified.

Macronix chips also use this code, but implement link detection as
described in the manual, and hence don't need this patch. However, tests
on a Macronix 98715AEC-C show that it does not adversely affect them.

From FreeBSD

ok deraadt@


# 1.73 29-Oct-2004 brad

rev 1.78

Enable the automatic TX underrun recovery for the ADMtek chips.
This solves cvsup update on my laptop which aborts after a while
without this patch.

rev 1.79

Fix the support for the AN985/983 chips, which do not set the
RXSTATE to STOPPED, but to WAIT. This should fix hangs which
could only be solved by replugging the cable.

From FreeBSD

Thanks to C. Bensend <benny at bennyvision dot com> for testing.


# 1.72 14-Oct-2004 brad

rev 1.47

Add a check in the interrupt service routine to return quickly in
case there is nothing to do. This happens normally when the card shares
the interrupt line with other devices.

This code saves a couple of microseconds per interrupt even on a
fast CPU. You normally would not care, except under heavy tinygram
traffic where you can have some 50-100.000 interrupts per second...

rev 1.51

Patch to allow TX underrun handling without issuing a complete
chip reset. Just temporarily turn off the transmitter instead.

From FreeBSD

ok mcbride@
tested by mcbride@, jaredy@, marco@, grange@, <harding at motd dot ca>


# 1.71 06-Oct-2004 brad

typo


# 1.70 06-Oct-2004 brad

Enable round-robin arbitration between transmit and receive unit
in the 21143, instead of giving priority to the receive unit.
This gives a 10-15% performance improvement in the forwarding rate
under heavy load.

From FreeBSD

ok mcbride@ nick@ deraadt@


# 1.69 28-Sep-2004 brad

Use ETHER_MIN_LEN/ETHER_MAX_DIX_LEN


# 1.68 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


Revision tags: OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B
# 1.67 31-May-2004 mcbride

multicast cleanups:
- get rid of hand rolled crc32 logic, use ether_crc32_{le,be}
- accept all multicast if a range is encountered


# 1.66 15-Apr-2004 mickey

user bus_dmamap_load_mbuf and set rcvif on receive


Revision tags: OPENBSD_3_5_BASE
# 1.65 21-Oct-2003 jmc

typos from Tom Cosgrove;

Tom: I did not commit a couple of your changes.

i did not include some punctuation fixes (full stops, etc.)
mnemorable -> mnemonic: i decided memorable was probably better
instrunctions -> instruction: i kept the plural


# 1.64 29-Sep-2003 mickey

add more dmamap_sync()s where appropriate modify loops to insure proper syncing; jason@ testing


# 1.63 25-Sep-2003 mickey

no need for a redundant check; from form@ and jason ok


Revision tags: OPENBSD_3_4_BASE
# 1.62 28-Aug-2003 mickey

fix bzero size; from pechkin


# 1.61 16-Jun-2003 mickey

be more sane w/ byte swapping and leave the le archs at the same behaviour and give be archs a better chance at getting the correct mac address as tested on the mac and hppa where mac has an additional bug w/ the phy bit still remaining and hppa seems fine; jason@ ok


# 1.60 20-May-2003 henning

AN983 endian issue; from FreeBSD via PR 3263 with minor style fixes by me

ok jason@


Revision tags: UBC_SYNC_A
# 1.59 17-May-2003 jason

fix up the media handling for the intel based MACs. Also hack around a
bug in the Momenco firmware on the Leopard-V, which now has one port
working.


# 1.58 29-Apr-2003 jason

grr... %s, not dc%s


# 1.57 29-Apr-2003 jason

- remove last vestige of "old autoconf": dc_unit is dead, long live dv_xname
- remove a bunch of #if 0 stuff (most of which referred to dc_unit, grr)
- delay a bzero until necessary


# 1.56 29-Apr-2003 jason

KNF


Revision tags: OPENBSD_3_3_BASE
# 1.55 25-Feb-2003 tedu

remove redundant check.

ok henning@


# 1.54 31-Jan-2003 deraadt

more quiet


Revision tags: UBC_SYNC_B
# 1.53 21-Oct-2002 henning

ugly hack to make the 21145 work without manual media setting.

many many many thanks to nick@, who booted no less then 8 kernels for me today
while hacking on that (and this includes going downstairs to the basement
and up again 8 times...)

ok jason@


# 1.52 20-Oct-2002 henning

add support for intel 21145
This chip is some strange abnormal 21143 variant. It really only works with
10 MBit/s halfduplex only and autonegotiation is totally broken in hardware.
Should also have a HomePNA phy, but we don't support that.
for now requires and explicit "media 10BaseT".
if anybody has such a chip please mail me.

nick@ is the only one who has the hardware and did an incredible amount of
testing. Thanks for all the help, Nick!

some hints and ok jason@


Revision tags: OPENBSD_3_2_BASE
# 1.51 05-Jul-2002 aaron

Remove an unused #define (belongs only in the PCI attachment source file).


# 1.50 09-Jun-2002 todd

a step towards consistancy; in general:
'struct arpcom foo' -> 'struct arpcom sc_arpcom'
ok itojun@


# 1.49 09-Jun-2002 nordin

Handle out of memory gracefully. ok jason@


# 1.48 18-Apr-2002 jason

add support for Conexant LANfinity RS7112; based on patch from Maurice Nonnekes <maurice@amaze.nl> based on FreeBSD (only minor surgery necessary)


Revision tags: OPENBSD_3_1_BASE
# 1.47 14-Mar-2002 millert

First round of __P removal in sys


# 1.46 17-Feb-2002 deraadt

drivers may not be noisy


# 1.45 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


Revision tags: UBC_BASE
# 1.44 13-Dec-2001 nate

branches: 1.44.2;
Fix old alpha bug recently triggered by conversion to busdma.


# 1.43 08-Dec-2001 jason

Go ahead and fix the xircom filter setup to work on big endian too (untested, but it's pretty similiar to the tested 21143 case).


# 1.42 08-Dec-2001 jason

use htole32() on the data going into the setup frame for the dc_setfilt_21143() case at least.
XXX I'm looking at the other filter setups and they appear to need work for BE too.


# 1.41 06-Dec-2001 jason

add bus_dmamap_sync()'s on the descriptors too
(with all this, my Netra X1 is up and running with an NFS root)


# 1.40 06-Dec-2001 jason

a few more bus_dmamap_sync()'s and some borrowed setup frame macros from NetBSD, and RX works on sparc64.


# 1.39 06-Dec-2001 jason

enough bus_dmamap_sync() and htole()/letoh() to get TX working on sparc64.
ALso, get the MAC address from myetheraddr() instead of trying to use the eeprom on sparc64.


# 1.38 06-Dec-2001 jason

vtophys, R.I.P. (tx now uses bus_dma)


# 1.37 06-Dec-2001 jason

move rx handling over to bus_dma... that just leaves one vtophys() in tx.


# 1.36 06-Dec-2001 jason

move the setup buffer and pad into a bus_dma alloced area
(current score: 2 vtophys calls to go...)


# 1.35 06-Dec-2001 jason

Checkpoint bus_dma work in progress:
- descriptor lists are now bus_dma allocated and manipulated
(for those keeping score: 6 vtophys dead, 4 to go)


# 1.34 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.33 22-Aug-2001 aaron

Support more dc(4) CardBus devices, including the AN985-based Linksys PCMPC200
10/100 CardBus Ethernet adapter (thanks to beck@ for the donation).


# 1.32 12-Aug-2001 mickey

remove some of the redundant vm includes


# 1.31 03-Aug-2001 chris

Set IFCAP_VLAN_MTU, this driver already allows vlan-size frames


# 1.30 02-Jul-2001 jason

these don't depend on pci register defs


# 1.29 27-Jun-2001 kjc

ALTQ'ify network drivers.
- use the new queue macros.
- use IFQ_POLL() to peek at the next packet.
- use IFQ_IS_EMPTY() for empty check.
- drivers should always check if (m == NULL) after IFQ_DEQUEUE(),
since it could return NULL even when IFQ_IS_EMPTY() is FALSE
under rate-limiting.
- drivers are supposed to call if_start from tx complete interrupts
(in order to trigger the next dequeue under rate-limiting).


# 1.28 23-Jun-2001 fgsch

ether_input_mbuf().


Revision tags: OPENBSD_2_9_BASE
# 1.27 13-Apr-2001 aaron

branches: 1.27.4;
Oops, remove an unrelated debugging #if 0.


# 1.26 13-Apr-2001 aaron

Disestablish the shutdownhook on detach.


# 1.25 06-Apr-2001 aaron

- For CardBus 21143 cards, parse the SROM. Makes my SMC EZ CardBus 10/100 work.
- General cleanup in the dc CardBus attachment.
- Split detach up into bus-dependent and bus-independent parts.
- Some function and variable renaming for consistency.


# 1.24 20-Feb-2001 mickey

for ethernet ifaces attach bpf from ether_ifattach; jason@, aaron@, itojun@ ok


# 1.23 09-Feb-2001 art

Bad aaron. Broke alpha.


# 1.22 09-Feb-2001 aaron

Sync with FreeBSD:
- Bugfix: 'reg' variable in dc_apply_fixup() needs to be u_int32_t.
- Bugfix: bzero() mediainfo structures after allocation.
- Call dc_apply_fixup() in dc_setcfg() for the MII case.
- Conditionalize some code in miibus_{read,write}reg to make non-mx98713
cards happy.


# 1.21 09-Feb-2001 aaron

Add support for parsing the media blocks from the SROM on the 21143 adapters.
These changes should make the driver work with the built-in Ethernet on the
Alpha Miata machines. From FreeBSD.

To make sure I didn't break anything (and as a general test), I tested the
modified driver with the following dc(4) variants: Macronix PMAC 98715,
Lite-On PNIC, Lite-On PNIC-II, ADMtek AL981, and ADMtek AN983.


# 1.20 16-Nov-2000 aaron

Note support for Accton EN1217 and EN2242 Ethernet adapters.


Revision tags: OPENBSD_2_8_BASE
# 1.19 30-Oct-2000 aaron

Match the Macronix 98727/98732 chips.


# 1.18 26-Oct-2000 aaron

Add support for Xircom X3201-based CardBus Ethernet cards. Tested successfully
on four different models, including the CBEM56G-100, RBE-100 RealPort, and the
RBEM56G-100 RealPort. This commit adds support only for the LAN components; the
modem is not configured yet. Detach support to come. Based on work from
FreeBSD, mickey@, nate@, and myself.


# 1.17 18-Oct-2000 aaron

Sigh. According to the ASIX data sheets, these boards don't even have RX
or TX state registers (these bits are reserved). So instead, don't do
mii_tick() at all for ASIX boards, since we can't seem to figure out how
to call it at just the right time. Hopefully this will be a temporary hack
until a better solution is found.


# 1.16 17-Oct-2000 aaron

Undo the incorrect fix for my ASIX 88141. Instead of just relying on tx_cnt,
now we check the TX state in the ISR to make sure we are not transmitting
when we run mii_tick(). Based on a suggestion by Bill Paul. The dc driver
should now be ready for some heavy pre-2.8 testing.


# 1.15 16-Oct-2000 aaron

Use mii_attach() directly instead of mii_phy_probe().


# 1.14 11-Oct-2000 aaron

For some reason, with the eeprom width detection code mickey added awhile ago,
special care for the ADMtek AN983 (Centaur-P) chip is no longer needed. This
fixes Ethernet address reading for these cards. Thanks to todd@ for testing.


# 1.13 28-Sep-2000 aaron

If this is a Davicom DM9102A and we're enabling the homePNA link, force
dc_link to 1 and don't activate the tick routine. Without this, dc_start()
always thinks the link is down and never transmits in homePNA mode; from
FreeBSD.


# 1.12 13-Sep-2000 aaron

Sync with FreeBSD. Finally make the OpenBSD-specific changes necessary to make
non-MII 21143-based cards work. The sync just fixes the LED handling on these
kinds of adapters.


# 1.11 07-Sep-2000 aaron

Indentation fix.


# 1.10 26-Aug-2000 aaron

Revert a minor FreeBSD tweak that tends to freeze my machine solid after
large amounts of data transfer (ASIX 88141 card).


# 1.9 08-Aug-2000 aaron

Make fix for preserving LED settings conditional on presence of an Intel
21143 chip; from FreeBSD.


# 1.8 02-Aug-2000 aaron

Sync with FreeBSD. Summary of changes:

- Add support for Accton EN1217 Ethernet adapters.
- Fix problems with LEDs on some cards when clearing the jabber disable bit.
- Handle new Macronix chips whose multicast hash tables are only 128 bits.
- Fix timing issues during autonegotiation with Macronix and PNIC II.


# 1.7 02-Aug-2000 aaron

Don't print out the eeprom width.


# 1.6 02-Aug-2000 peter

Add support for accepting packets up to 4 octets larger than the
interface MTU IFF vlans are enabled.

Additional logic should be added by someone who understand 802.1q to
test if this oversize packet is actually a 802.1q encapsulated, and
reject others.

Fix as per kernel/1328.


# 1.5 21-Jul-2000 mickey

convert to new timeouts; art@ ok


# 1.4 12-Jun-2000 mickey

remove debugging prom dump, sorry


# 1.3 12-Jun-2000 mickey

eeprom width detection code.
idea from netbsd tulip driver.
there is problem w/ an983 card, but aaron@ said he'll work it out.
aaron@ & jason@ ok.


# 1.2 12-Jun-2000 aaron

Fix ADMtek identity crisis.


Revision tags: OPENBSD_2_7_BASE
# 1.1 18-Apr-2000 jason

branches: 1.1.2;
split dc driver into bus dependent and bus independent (pci) parts
(cardbus to come later).


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.152 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.151 04-May-2016 kettenis

Use BUS_DMA_OVERRUN to cope with the broken DMA engine of the Davicom DM9102
found on some Sun sparc64 machines. This fixes the unrecoverable DMA errors
people have been seeing ever since dlg@ made changes to the pool code that
changes the memory layout.


# 1.150 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.149 28-Nov-2015 dlg

rework dc_start and dc_encap to take advantage of m_defrag.

if the chip needs coalesced packages in tx, set the tx dmamaps up
to only use a single dma descriptor. use m_defrag when bus_dmamap_load_mbuf
returns EFBIG rather than copying the packet to a separate mbuf
with hand rolled code in dc_coal. that in turn makes the ifq_deq_begin,
ifq_deq_commit, and ifq_deq_rollback handling more straightforward.

tested by me on a hppa a180c with a "DEC 21142/3", and fred on bugs@
with a sparc64 netra x1 "Davicom DM9102".


# 1.148 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.147 24-Nov-2015 mpi

The only network driver needing <net/if_types.h> is upl(4) for IFT_OTHER.


# 1.146 20-Nov-2015 dlg

shuffle struct ifqueue so in flight mbufs are protected by a mutex.

the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.

the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.

the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.

to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.

the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.

ok mpi@ jmatthew@


# 1.145 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.144 12-Sep-2015 miod

ifmedia64 fixes.


# 1.143 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


# 1.142 30-Aug-2015 deraadt

Track rom size, for free()


Revision tags: OPENBSD_5_8_BASE
# 1.141 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.140 13-Apr-2015 mpi

Now that if_input() set the receiving interface pointer on mbufs for us
there's no need to do it in m_devget(9).

Stop passing an ``ifp'' will help for upcoming interface pointer -> index
conversion.

While here remove unused ``ifp'' argument from m_clget(9) and kill two
birds^W layer violations in one commit.

ok henning@


# 1.139 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


# 1.138 13-Mar-2015 jasper

convert to if_input()

tested by landry@
ok mpi@


Revision tags: OPENBSD_5_7_BASE
# 1.137 23-Jan-2015 dlg

break after return is useless.


# 1.136 22-Dec-2014 tedu

unifdef INET


# 1.135 18-Nov-2014 brad

dc_init() calls dc_stop() and dc_reset() so remove some redundant calls
to those functions before dc_init() within dc_watchdog() and dc_intr().

ok deraadt@


Revision tags: OPENBSD_5_6_BASE
# 1.134 22-Jul-2014 mpi

Fewer <netinet/in_systm.h>


# 1.133 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.132 18-Apr-2014 henning

reaching into altq unconditionally (and w/o ifdef ALTQ) is bad, mmkay?


Revision tags: OPENBSD_5_5_BASE
# 1.131 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.130 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.129 02-Dec-2013 brad

Rewrite receive filter handling and ioctl bits. Fixes not being able to
bring the interface out of all multicast mode once a range of multicast
addresses has been found and missing multicast range checking for some
of the dc(4) variants.

Tested with 21143 (represents most of the dc(4) variants and boards) and
ADMtek based adapters. Untested with ASIX and Xircom based adapters.
Putting it in to move forward. I don't expect any issues with the
ASIX/Xircom adapters with the changes as is.

ok naddy@


# 1.128 20-Nov-2013 mpi

Instead of comparing the lower and higher addresses of all the multicast
entries to decide if the IFF_ALLMULTI flag should be set, check if there
is at least one real range between them.

Tested by naddy@


# 1.127 21-Aug-2013 dlg

get rid of the copy argument in m_devget that let you provide an
alternative to bcopy since noone uses it.

while there use memcpy instead of bcopy because we know the memory cannot
overlap.

ok henning@ matthew@ mikeb@ deraadt@


# 1.126 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.125 29-Nov-2012 brad

Remove setting an initial assumed baudrate upon driver attach which is not
necessarily correct, there might not even be a link when attaching.

ok mikeb@ reyk@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.124 07-Jul-2011 henning

use IF_LEN/IFQ_LEN to access and ifqueue's length field. ryan ok
with this nothing in the tree fiddles if ifqueue internals any more, of
course except if.c and if.h (and some altq)


# 1.123 21-Jun-2011 tedu

remove some unnecessary casts. ok blambert deraadt kettenis matthew


# 1.122 05-Mar-2011 kettenis

Wait until the DMA engine is stopped before unmapping buffers and descriptors.
Fixes DMA errors seen on sparc64.

ok miod@


Revision tags: OPENBSD_4_9_BASE
# 1.121 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.120 06-Sep-2010 deraadt

initialize rv to 0 in the activate function


# 1.119 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.118 30-Aug-2010 deraadt

activate functions, when they do not add value, should return the result of config_activate_children


# 1.117 27-Aug-2010 deraadt

Move the dc_pci_activate function to dc.c, and mangle it up with some of
the gunk in dc_powerhook. Then make dc_powerhook just call it
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.116 05-Aug-2010 deraadt

ca_activate function for suspend/resume; tested by mlarkin on a
Davicom DM9102. (bit of noise on suspend or resume, but that can be
dealt with later)


# 1.115 02-Jul-2010 blambert

timeout_add -> timeout_add_msec

ok krw@


# 1.114 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.113 15-Oct-2009 deraadt

Add detach support to a few more drivers, and in others do the neccessary
operations in the detach function in the right order. Also ensure that the
interrupt handlers not trust registers that go away.
read over very carefully by dms, tested by me


# 1.112 10-Aug-2009 deraadt

More cases of shutdown hooks not needed after card is already stopped. In
these cases the xxstop function is a bit more complicated and has a flag of
some sort, but the use of that flag does not matter; DMA is already ceased
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.111 26-Jun-2009 deraadt

If we are going to move to the eeprom-based MAC address finding instead of
CIS-based... some newer devices have the MAC address at offset 8 instead of
offset 3. But we can tell by the first three octets, Intel says.


# 1.110 26-Jun-2009 deraadt

Using information gleamed from the FreeBSD driver, change the MAC address
reading to use the eeprom instead of CIS, and then the Xircom Cardbus cards
can work in the expresscard adaptor, as pci devices.
ok jsg


# 1.109 02-Jun-2009 jsg

make dc at pci detachable; untested.


Revision tags: OPENBSD_4_5_BASE
# 1.108 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.107 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.106 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


# 1.105 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.104 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.103 12-Sep-2008 brad

Some fixes for dc_txeof()..
- Don't reload the watchdog timer in case there are still unhandled
descriptors.
- Don't clear IFF_OACTIVE unless there are at least 6 free TX
descriptors. The function dc_encap() will bail if there are
only 5 or fewer free TX descriptors, causing dc_start() to
abort so it makes no sense to pretend we could process mbufs
again when in fact we can't.
- Always assign idx to sc->dc_cdata.dc_tx_cons; it doesn't make
much sense to exclude the idx == sc->dc_cdata.dc_tx_cons case.

From FreeBSD


# 1.102 11-Sep-2008 brad

ANSI function declarations.


# 1.101 11-Sep-2008 brad

For chips with a broken DC_ISR_RX_STATE which never signals
stopped nor the waiting state and also no other means to check
whether the receiver is idle, we have no choice but to call
mii_tick unconditionally even in the case of the DC_REDUCED_MII_POLL
handling as far as the RX side is concerned. This isn't necessarily
worse than checking whether RX is idle though because unlike as
with TX we're racing with the hardware, which might receive packets
any time while we poll the MII, anyway. Fixes the use of trunk(4)
with the affected interfaces.

From FreeBSD


# 1.100 03-Sep-2008 brad

In dc_setcfg() suppress printing a warning when forcing the receiver
and transmitter to idle state times out for chips where the status
bits in question never change (observed in detail with DM9102A) and
therefore the warning would highly likely be a false positive.

From FreeBSD


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.99 26-Nov-2007 brad

print the comma before the MAC address string in dc_attach() instead of the
PCI front end attach function. This corrects the dmesg output for CardBus
adapters and ensures proper dmesg output if an error occurs in dc_attach().

ok dlg@


# 1.98 01-Oct-2007 krw

More easy bzero() -> M_ZERO. Use 'p = malloc(sizeof(*p) ...'.


Revision tags: OPENBSD_4_2_BASE
# 1.97 08-May-2007 deraadt

dc_detach() is only used by cardbus code, so move it there; ok jsg


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.96 10-Aug-2006 brad

- eliminate re-initialization's when adding IP addresses.
- simplify ioctl handler.


# 1.95 22-May-2006 krw

Attach routines can fail before calling *hook_establish(), and they
often rely on the detach routine for cleanup. So be consistant and
careful by checking for a NULL hook before calling *hook_disestablish
in detach routines.

ok mickey@ brad@ dlg@


# 1.94 07-May-2006 brad

- Return if there is nothing to do in the interrupt handler.
- Check for IFF_RUNNING in the interrupt loop.


# 1.93 23-Apr-2006 kettenis

Make code path for ADMTek variant endian-safe; fixes dc(4) on macppc.
ok brad@


# 1.92 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


Revision tags: OPENBSD_3_9_BASE
# 1.91 28-Jan-2006 brad

remove 2 printf's from dc_coal() too.


# 1.90 28-Jan-2006 brad

remove printf's from dc_newbuf().


# 1.89 07-Nov-2005 brad

splimp -> splnet


Revision tags: OPENBSD_3_8_BASE
# 1.88 25-Jun-2005 brad

re-add ASIX check lost in rev 1.77


# 1.87 23-Jun-2005 brad

clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.


# 1.86 22-May-2005 martin

ALTQ cleanout

ok brad@


# 1.85 22-May-2005 brad

add power hook


# 1.84 30-Apr-2005 brad

try to drain send queue if we lose link during heavy transmit
activity instead of letting it sit and return 'no buffer available'
errors.


# 1.83 23-Apr-2005 brad

- always accept VLAN-sized frames
- support setting the MTU


# 1.82 23-Apr-2005 brad

Fix newer Xircom CBE2-100 cards.

We have to enable the connection to the MII first. Doing so fixes the
problem cards without breaking the older, working cards.

From FreeBSD


# 1.81 31-Mar-2005 brad

- add support for reading Xircom's EEPROM
- sync dc_mii_readreg()

From FreeBSD


Revision tags: OPENBSD_3_7_BASE
# 1.80 15-Jan-2005 brad

make sure interface is in RUNNING state before touching the multicast filters

From NetBSD

NetBSD PR 27678 for details

ok mcbride@


# 1.79 14-Jan-2005 brad

rev 1.63

Avoid an unnecessary copy of a packet if it is already in a single mbuf.
Introduce an additional device flag for those NICs which require the
transmit buffers to be aligned to 32-bit boundaries.

From FreeBSD


# 1.78 08-Jan-2005 brad

rev 1.125

Don't read the MAC address from a copy of the EEPROM in the softc
that has been recorded earlier and overwrite it again later by
reading it directly from the EEPROM again.

Read the MAC address from the PAR0/PAR1 registers instead, which
are autoloaded on reboot.

From FreeBSD

Thanks to David Snyder <dasnyderx at yahoo dot com> for testing on
a AN983 based card which used to come up with a MAC address of
ff:ff:ff:ff:ff:ff.


# 1.77 17-Dec-2004 brad

add missing braces.

From FreeBSD


# 1.76 02-Dec-2004 brad

rev 1.126

Ignore CSR13, CSR14, CSR15 'Media Specific Data' registers
for 21143 based cards which use SIA mode.

This fixes 10mbit mode for ZNYX ZX346Q cards and other
21143 based cards.

rev 1.108

Only use a SIA/SYM media info block if no MII block is detected.
The submitter of PR 32118 told me that this patch also fixes autoselecting
for znyx 4 port cards (10baseT, 100baseTX did work already).

From FreeBSD

ok deraadt@


# 1.75 28-Nov-2004 brad

rev 1.74

Fix if_timer logic to make sure that there is always a timeout
pending if there are packets queued for transmission.

From FreeBSD

ok deraadt@


# 1.74 16-Nov-2004 brad

if_dc.c rev 1.56

Do not call mii_pollstat() from within device tick routines; the status
information is updated by mii_tick().

dcphy.c rev 1.13

Work around an Intel 21143 chip bug.

Rev 1.56 of if_dc.c removed calls to mii_pollstat() from the dc_tick()
routine. dc_tick() is called regularly to detect link up and link down
status, especially when autonegotiating.

The expectation was that mii_tick() (which is still called from dc_tick())
would update status information automatically in all cases where it would
be sensible to do so.

Unfortunately, with authentic 21143 chips this is not the case, and
the driver never successfully autonegotiates. This is because (despite
what it says in the 21143 manual) the chip always claims that link is not
present while the autonegotiation enable bit is set. Autonegotation takes
place and succeeds, but the driver tests the link bits before it switches
off the autonegotiation enable bit, and success is not recognised.

The simplest solution is to call dcphy_status() more often for MII_TICK
calls by dropping out of the switch statement instead of exiting when
we are autonegotiating and link appears to not be present. When
autonegotiation succeeds, dcphy_status() will note the speed and fdx/hdx
state and turn off the autonegotiation enable bit. The next call to
dcphy_status() will notice that link is present, and the dc driver code
will be notified.

Macronix chips also use this code, but implement link detection as
described in the manual, and hence don't need this patch. However, tests
on a Macronix 98715AEC-C show that it does not adversely affect them.

From FreeBSD

ok deraadt@


# 1.73 29-Oct-2004 brad

rev 1.78

Enable the automatic TX underrun recovery for the ADMtek chips.
This solves cvsup update on my laptop which aborts after a while
without this patch.

rev 1.79

Fix the support for the AN985/983 chips, which do not set the
RXSTATE to STOPPED, but to WAIT. This should fix hangs which
could only be solved by replugging the cable.

From FreeBSD

Thanks to C. Bensend <benny at bennyvision dot com> for testing.


# 1.72 14-Oct-2004 brad

rev 1.47

Add a check in the interrupt service routine to return quickly in
case there is nothing to do. This happens normally when the card shares
the interrupt line with other devices.

This code saves a couple of microseconds per interrupt even on a
fast CPU. You normally would not care, except under heavy tinygram
traffic where you can have some 50-100.000 interrupts per second...

rev 1.51

Patch to allow TX underrun handling without issuing a complete
chip reset. Just temporarily turn off the transmitter instead.

From FreeBSD

ok mcbride@
tested by mcbride@, jaredy@, marco@, grange@, <harding at motd dot ca>


# 1.71 06-Oct-2004 brad

typo


# 1.70 06-Oct-2004 brad

Enable round-robin arbitration between transmit and receive unit
in the 21143, instead of giving priority to the receive unit.
This gives a 10-15% performance improvement in the forwarding rate
under heavy load.

From FreeBSD

ok mcbride@ nick@ deraadt@


# 1.69 28-Sep-2004 brad

Use ETHER_MIN_LEN/ETHER_MAX_DIX_LEN


# 1.68 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


Revision tags: OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B
# 1.67 31-May-2004 mcbride

multicast cleanups:
- get rid of hand rolled crc32 logic, use ether_crc32_{le,be}
- accept all multicast if a range is encountered


# 1.66 15-Apr-2004 mickey

user bus_dmamap_load_mbuf and set rcvif on receive


Revision tags: OPENBSD_3_5_BASE
# 1.65 21-Oct-2003 jmc

typos from Tom Cosgrove;

Tom: I did not commit a couple of your changes.

i did not include some punctuation fixes (full stops, etc.)
mnemorable -> mnemonic: i decided memorable was probably better
instrunctions -> instruction: i kept the plural


# 1.64 29-Sep-2003 mickey

add more dmamap_sync()s where appropriate modify loops to insure proper syncing; jason@ testing


# 1.63 25-Sep-2003 mickey

no need for a redundant check; from form@ and jason ok


Revision tags: OPENBSD_3_4_BASE
# 1.62 28-Aug-2003 mickey

fix bzero size; from pechkin


# 1.61 16-Jun-2003 mickey

be more sane w/ byte swapping and leave the le archs at the same behaviour and give be archs a better chance at getting the correct mac address as tested on the mac and hppa where mac has an additional bug w/ the phy bit still remaining and hppa seems fine; jason@ ok


# 1.60 20-May-2003 henning

AN983 endian issue; from FreeBSD via PR 3263 with minor style fixes by me

ok jason@


Revision tags: UBC_SYNC_A
# 1.59 17-May-2003 jason

fix up the media handling for the intel based MACs. Also hack around a
bug in the Momenco firmware on the Leopard-V, which now has one port
working.


# 1.58 29-Apr-2003 jason

grr... %s, not dc%s


# 1.57 29-Apr-2003 jason

- remove last vestige of "old autoconf": dc_unit is dead, long live dv_xname
- remove a bunch of #if 0 stuff (most of which referred to dc_unit, grr)
- delay a bzero until necessary


# 1.56 29-Apr-2003 jason

KNF


Revision tags: OPENBSD_3_3_BASE
# 1.55 25-Feb-2003 tedu

remove redundant check.

ok henning@


# 1.54 31-Jan-2003 deraadt

more quiet


Revision tags: UBC_SYNC_B
# 1.53 21-Oct-2002 henning

ugly hack to make the 21145 work without manual media setting.

many many many thanks to nick@, who booted no less then 8 kernels for me today
while hacking on that (and this includes going downstairs to the basement
and up again 8 times...)

ok jason@


# 1.52 20-Oct-2002 henning

add support for intel 21145
This chip is some strange abnormal 21143 variant. It really only works with
10 MBit/s halfduplex only and autonegotiation is totally broken in hardware.
Should also have a HomePNA phy, but we don't support that.
for now requires and explicit "media 10BaseT".
if anybody has such a chip please mail me.

nick@ is the only one who has the hardware and did an incredible amount of
testing. Thanks for all the help, Nick!

some hints and ok jason@


Revision tags: OPENBSD_3_2_BASE
# 1.51 05-Jul-2002 aaron

Remove an unused #define (belongs only in the PCI attachment source file).


# 1.50 09-Jun-2002 todd

a step towards consistancy; in general:
'struct arpcom foo' -> 'struct arpcom sc_arpcom'
ok itojun@


# 1.49 09-Jun-2002 nordin

Handle out of memory gracefully. ok jason@


# 1.48 18-Apr-2002 jason

add support for Conexant LANfinity RS7112; based on patch from Maurice Nonnekes <maurice@amaze.nl> based on FreeBSD (only minor surgery necessary)


Revision tags: OPENBSD_3_1_BASE
# 1.47 14-Mar-2002 millert

First round of __P removal in sys


# 1.46 17-Feb-2002 deraadt

drivers may not be noisy


# 1.45 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


Revision tags: UBC_BASE
# 1.44 13-Dec-2001 nate

branches: 1.44.2;
Fix old alpha bug recently triggered by conversion to busdma.


# 1.43 08-Dec-2001 jason

Go ahead and fix the xircom filter setup to work on big endian too (untested, but it's pretty similiar to the tested 21143 case).


# 1.42 08-Dec-2001 jason

use htole32() on the data going into the setup frame for the dc_setfilt_21143() case at least.
XXX I'm looking at the other filter setups and they appear to need work for BE too.


# 1.41 06-Dec-2001 jason

add bus_dmamap_sync()'s on the descriptors too
(with all this, my Netra X1 is up and running with an NFS root)


# 1.40 06-Dec-2001 jason

a few more bus_dmamap_sync()'s and some borrowed setup frame macros from NetBSD, and RX works on sparc64.


# 1.39 06-Dec-2001 jason

enough bus_dmamap_sync() and htole()/letoh() to get TX working on sparc64.
ALso, get the MAC address from myetheraddr() instead of trying to use the eeprom on sparc64.


# 1.38 06-Dec-2001 jason

vtophys, R.I.P. (tx now uses bus_dma)


# 1.37 06-Dec-2001 jason

move rx handling over to bus_dma... that just leaves one vtophys() in tx.


# 1.36 06-Dec-2001 jason

move the setup buffer and pad into a bus_dma alloced area
(current score: 2 vtophys calls to go...)


# 1.35 06-Dec-2001 jason

Checkpoint bus_dma work in progress:
- descriptor lists are now bus_dma allocated and manipulated
(for those keeping score: 6 vtophys dead, 4 to go)


# 1.34 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.33 22-Aug-2001 aaron

Support more dc(4) CardBus devices, including the AN985-based Linksys PCMPC200
10/100 CardBus Ethernet adapter (thanks to beck@ for the donation).


# 1.32 12-Aug-2001 mickey

remove some of the redundant vm includes


# 1.31 03-Aug-2001 chris

Set IFCAP_VLAN_MTU, this driver already allows vlan-size frames


# 1.30 02-Jul-2001 jason

these don't depend on pci register defs


# 1.29 27-Jun-2001 kjc

ALTQ'ify network drivers.
- use the new queue macros.
- use IFQ_POLL() to peek at the next packet.
- use IFQ_IS_EMPTY() for empty check.
- drivers should always check if (m == NULL) after IFQ_DEQUEUE(),
since it could return NULL even when IFQ_IS_EMPTY() is FALSE
under rate-limiting.
- drivers are supposed to call if_start from tx complete interrupts
(in order to trigger the next dequeue under rate-limiting).


# 1.28 23-Jun-2001 fgsch

ether_input_mbuf().


Revision tags: OPENBSD_2_9_BASE
# 1.27 13-Apr-2001 aaron

branches: 1.27.4;
Oops, remove an unrelated debugging #if 0.


# 1.26 13-Apr-2001 aaron

Disestablish the shutdownhook on detach.


# 1.25 06-Apr-2001 aaron

- For CardBus 21143 cards, parse the SROM. Makes my SMC EZ CardBus 10/100 work.
- General cleanup in the dc CardBus attachment.
- Split detach up into bus-dependent and bus-independent parts.
- Some function and variable renaming for consistency.


# 1.24 20-Feb-2001 mickey

for ethernet ifaces attach bpf from ether_ifattach; jason@, aaron@, itojun@ ok


# 1.23 09-Feb-2001 art

Bad aaron. Broke alpha.


# 1.22 09-Feb-2001 aaron

Sync with FreeBSD:
- Bugfix: 'reg' variable in dc_apply_fixup() needs to be u_int32_t.
- Bugfix: bzero() mediainfo structures after allocation.
- Call dc_apply_fixup() in dc_setcfg() for the MII case.
- Conditionalize some code in miibus_{read,write}reg to make non-mx98713
cards happy.


# 1.21 09-Feb-2001 aaron

Add support for parsing the media blocks from the SROM on the 21143 adapters.
These changes should make the driver work with the built-in Ethernet on the
Alpha Miata machines. From FreeBSD.

To make sure I didn't break anything (and as a general test), I tested the
modified driver with the following dc(4) variants: Macronix PMAC 98715,
Lite-On PNIC, Lite-On PNIC-II, ADMtek AL981, and ADMtek AN983.


# 1.20 16-Nov-2000 aaron

Note support for Accton EN1217 and EN2242 Ethernet adapters.


Revision tags: OPENBSD_2_8_BASE
# 1.19 30-Oct-2000 aaron

Match the Macronix 98727/98732 chips.


# 1.18 26-Oct-2000 aaron

Add support for Xircom X3201-based CardBus Ethernet cards. Tested successfully
on four different models, including the CBEM56G-100, RBE-100 RealPort, and the
RBEM56G-100 RealPort. This commit adds support only for the LAN components; the
modem is not configured yet. Detach support to come. Based on work from
FreeBSD, mickey@, nate@, and myself.


# 1.17 18-Oct-2000 aaron

Sigh. According to the ASIX data sheets, these boards don't even have RX
or TX state registers (these bits are reserved). So instead, don't do
mii_tick() at all for ASIX boards, since we can't seem to figure out how
to call it at just the right time. Hopefully this will be a temporary hack
until a better solution is found.


# 1.16 17-Oct-2000 aaron

Undo the incorrect fix for my ASIX 88141. Instead of just relying on tx_cnt,
now we check the TX state in the ISR to make sure we are not transmitting
when we run mii_tick(). Based on a suggestion by Bill Paul. The dc driver
should now be ready for some heavy pre-2.8 testing.


# 1.15 16-Oct-2000 aaron

Use mii_attach() directly instead of mii_phy_probe().


# 1.14 11-Oct-2000 aaron

For some reason, with the eeprom width detection code mickey added awhile ago,
special care for the ADMtek AN983 (Centaur-P) chip is no longer needed. This
fixes Ethernet address reading for these cards. Thanks to todd@ for testing.


# 1.13 28-Sep-2000 aaron

If this is a Davicom DM9102A and we're enabling the homePNA link, force
dc_link to 1 and don't activate the tick routine. Without this, dc_start()
always thinks the link is down and never transmits in homePNA mode; from
FreeBSD.


# 1.12 13-Sep-2000 aaron

Sync with FreeBSD. Finally make the OpenBSD-specific changes necessary to make
non-MII 21143-based cards work. The sync just fixes the LED handling on these
kinds of adapters.


# 1.11 07-Sep-2000 aaron

Indentation fix.


# 1.10 26-Aug-2000 aaron

Revert a minor FreeBSD tweak that tends to freeze my machine solid after
large amounts of data transfer (ASIX 88141 card).


# 1.9 08-Aug-2000 aaron

Make fix for preserving LED settings conditional on presence of an Intel
21143 chip; from FreeBSD.


# 1.8 02-Aug-2000 aaron

Sync with FreeBSD. Summary of changes:

- Add support for Accton EN1217 Ethernet adapters.
- Fix problems with LEDs on some cards when clearing the jabber disable bit.
- Handle new Macronix chips whose multicast hash tables are only 128 bits.
- Fix timing issues during autonegotiation with Macronix and PNIC II.


# 1.7 02-Aug-2000 aaron

Don't print out the eeprom width.


# 1.6 02-Aug-2000 peter

Add support for accepting packets up to 4 octets larger than the
interface MTU IFF vlans are enabled.

Additional logic should be added by someone who understand 802.1q to
test if this oversize packet is actually a 802.1q encapsulated, and
reject others.

Fix as per kernel/1328.


# 1.5 21-Jul-2000 mickey

convert to new timeouts; art@ ok


# 1.4 12-Jun-2000 mickey

remove debugging prom dump, sorry


# 1.3 12-Jun-2000 mickey

eeprom width detection code.
idea from netbsd tulip driver.
there is problem w/ an983 card, but aaron@ said he'll work it out.
aaron@ & jason@ ok.


# 1.2 12-Jun-2000 aaron

Fix ADMtek identity crisis.


Revision tags: OPENBSD_2_7_BASE
# 1.1 18-Apr-2000 jason

branches: 1.1.2;
split dc driver into bus dependent and bus independent (pci) parts
(cardbus to come later).